Skip to content
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

"always broken" str.format() warning vs getting filenames from 'file' #12406

Closed
anarazel opened this issue Oct 20, 2023 · 4 comments · Fixed by #12408
Closed

"always broken" str.format() warning vs getting filenames from 'file' #12406

anarazel opened this issue Oct 20, 2023 · 4 comments · Fixed by #12408

Comments

@anarazel
Copy link
Contributor

Hi,

Starting in 1.3 meson warns about using '@0@'.format(file). Previously that was, to my knowledge, the only way to get the file path of a file from configure_file() or files(). Now, clearly that wasn't intentionally supported, so I probably don't get to complain too much that that doesn't work anymore. However, there's not really any supported way of getting the filename from 'file', which isn't great.

For postgres I have two uses for wanting the filename for a 'file':

  1. Checking that there no source tree files with the same name as configure_file(). Postgres historically (and for now still) supports building in-tree with autoconf/make and our homegrown msvc buildscripts. When that build is incompletely cleaned up, the old generated configuration files end up in the source tree, and will often get used by the compiler (there's to my knowledge no way to make a compiler to prefer a file in a different directory for #include "filename". This has lead to numerous odd build failures. Sometimes such failures happen way later, when the contents of the generated files have evolved. For that reason postgres meson build checks if there are any generated files with conflicting names in the source tree. There aren't that many configure_file()s, so I guess we can manually maintain the list of conflicting names, instead of getting them from the object returned by configure_file() (although the directory handling would be more complicated that way).

  2. Generating custom_target() output names for source files in a lot of different directories. Unfortunately for the use case (compiling C files a second time, to LLVM IR, for JIT inlining), generators were too restrictive. Because we have source files with the same name in different directories, @BASENAME@ does not suffice to get non-conflicting output names. The current meson code looks like this:

  foreach srcfile : bitcode_module['srcfiles']
    srcfilename = '@0@'.format(srcfile)
    targetname = '@0@_@1@_@2@.bc'.format(
      bitcode_name,
      fs.parent(srcfilename).underscorify(), fs.name(srcfilename))
    bitcode_targets += custom_target(
      targetname,
...

Is there any chance to provide an alternative way to get the filename from a file, or to add 'file' to the list of types that are allowed to be formatted?

I also have repeatedly found it useful to be able to print the filename of a 'file' for error(), warning() etc. Afaict there's no way to do that anymore that doesn't trigger the new deprecation messages.

CC: @eli-schwartz

Regards,

Andres

@eli-schwartz
Copy link
Member

Previously that was, to my knowledge, the only way to get the file path of a file from configure_file() or files(). Now, clearly that wasn't intentionally supported, so I probably don't get to complain too much that that doesn't work anymore. However, there's not really any supported way of getting the filename from 'file', which isn't great.

There's a bigger hole than that. You can't get the file path of that file even with the unsupported, currently-issues-a-warning approach. The best you can do is get the relative filepath "from either the source root or the build root, but you do not know which one".

I'm sure there were people depending on that, as well as people for whom it is a nasty surprise. Changing it seems inadvisable, but keeping it is also inadvisable, hence the deprecation... (this is not the only reason for me, but it is a big one).

@anarazel
Copy link
Contributor Author

Well, deprecating it would make more sense if there were a replacement (like file.path() or such)... What are the chances of getting some replacement for the deprecated functionality into 1.3?

@xclaesse
Copy link
Member

Adding file.full_path() makes sense IMHO.

xclaesse added a commit to xclaesse/meson that referenced this issue Oct 21, 2023
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: mesonbuild#12406
@xclaesse
Copy link
Member

@anarazel #12408

xclaesse added a commit to xclaesse/meson that referenced this issue Oct 21, 2023
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: mesonbuild#12406
xclaesse added a commit to xclaesse/meson that referenced this issue Oct 22, 2023
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: mesonbuild#12406
xclaesse added a commit to xclaesse/meson that referenced this issue Nov 23, 2023
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: mesonbuild#12406
jpakkane pushed a commit that referenced this issue Nov 24, 2023
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: #12406
gerioldman pushed a commit to gerioldman/meson that referenced this issue Jul 2, 2024
This is needed now that str.format() is not allowing it any more. It is
also more consistent with other objects that have that method as well,
such as build targets.

Fixes: mesonbuild#12406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants