-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add full_path() method to files objects #8487
Conversation
Besides failing tests, known missing parts of PR:
|
d46ce66
to
8e9bdae
Compare
8e9bdae
to
7ea4636
Compare
This should probably be But more importantly the documentation should be upfront and explicit about the fact that this is a very dangerous thing to do. Strings do not carry dependency information so if you, for example, pass the result to some target, Meson will not know of the dependency between the two and neither will Ninja. This can easily lead to broken builds. The right thing to do in almost all cases is to put the file object directly in the command argument array and Meson will do the right thing. Unfortunately based on experience people will not do that as they assume it "would not work". |
@jpakkane thanks for your input. I think you are definitely correct about the documentation being super explicit about this method having very specific use-cases. |
I understand your concern but unfortunately all other meson objects already have |
@tristan957 I think this is the wrong approach, why not add support for File object in |
If that is the only thing this would be used for, then definitely. |
I was thinking that it could make sense to model files as FileHolders from an interpreter perspective, and this could be a good PR to possibly match how other interpreter object are also modeled as Holders. I am honestly struggling to come up with use cases for this method, and people who care about this should propose their use cases. I thought I had one while redoing the build system on my project, but I seem to have gotten away without needing it. Re full_path() vs absolute_path(): I think coming up with internal consistency should be prio #1. Once that is done, if absolute_path() is the way to go, then I don't think the churn is that big a deal because Meson is extremely consistent in its usage of full_path(), so people could just s/full_path/absolute_path/ in a single commit. |
FileHolder makes a lot of sense, yes. But the question is whether it's worth the pain. The only use case I see so far can trivially be done without it. |
I am just going to put the PR on hold until people come up with good use cases. |
If this is something you need, then it should be added regardless of what happens to this PR. I |
That is not something that I need currently. If other people do, then I can add it. |
What did you need this for, then? In Meson we purposefully avoid adding features just because they seem useful. Every feature must have an actual use case or requirement behind it. |
There was an issue for it and I wanted to fix it for other people. |
I have a project where files can be reloaded at runtime when debugging, the files are also part of the build so it just makes sense to generate the asset/source<->fullpath associations from meson for change monitoring and reloading. |
That seems like a reasonable request pending maintainer approval. |
@@ -2645,7 +2662,7 @@ def func_import(self, node, args, kwargs): | |||
@stringArgs | |||
@noKwargs | |||
def func_files(self, node, args, kwargs): | |||
return [mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args] | |||
return [FileHolder(mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname), self.environment.source_dir, self.environment.build_dir) for fname in args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it is not that easy, there are many places where we do isinstance(f, mesonlib.File)
, and they won't work any more because the type is now FileHolder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically, in every API that takes file objects you now have to unholder() them first in interpreter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xclaesse I am willing to put in the work to create FileHolder
if people think it is an improvement in the interpreter code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interpreterbase.py
has a method_call
method that deals with method calls to non-interpreterobjects.
This object is an entry in the file array returned by [`files()`](#files). This | ||
object contains the following methods: | ||
|
||
- `full_path()`: returns a string of the full path to the file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a warning of something like: "Use this method with caution. The return value is a string and carries no dependency information. Thus if you use it as an argument to a command, Meson does not know that it refers to an actual file and can not set up dependencies properly. Whenever possible you should use the file object directly in the command line. It will be autoexpanded to point to the file and all necessary dependencies are set up automatically."
Thank you for the effort! A small example that I need that function for currently: This results in these meson files:
elsewhere/meson.build:
Note, that I was not fully able to find a workaround. This here is probably the best:
Putting a file into the format function seems to result in the path relative to the source_root but I'm not sure at all about this. How it is in subprojects? |
You can set the workdir for the test. Does that help you? |
Hmm, nothing other in the script depends on the working directory so it would be a possible workaround, yes. |
BTW, in the above code the dependency to the resource file is gone for the test target (like @jpakkane already mentioned). It does not seem simple, though, to add it back. At least, the |
@jpakkane wrote:
@tristan957 wrote:
FWIW, I've needed this in postgres' meson conversion, for an error check during configure. We need to make sure that there are no in-tree files left over from configure, as they'll sometimes get "preferred" (due to |
I am happy to work on this again if it would be accepted by @jpakkane. Don't want to put in effort for it to languish again. |
Fixed by #12408. |
I am missing some places where mesonlib.File is probably assumed. This is a work in progress, but it worked in my very minimal test case.
The holder pattern is quite nice. Wasn't super hard to contribute this at all.
Fixes #8433