meson
meson copied to clipboard
object returned by configure_file() cannot be passed to join_paths()
The object returned by configure_file() cannot be used in join_paths(), but it converts nicely to strings during a format() call. That seems inconsistent, and makes constructing paths from those files a bit awkward. Simple test project below:
project('test', 'c')
c = configuration_data()
f = configure_file(input: 'foo', output : 'foo', configuration : c)
# This works
message('@0@/@1@'.format(meson.build_root(), f))
# This fails: Arguments must be strings.
join_paths(meson.build_root(), f)
output is
....
Message: /home/whot/tmp/2017-05-18-Thu/builddir/foo
Meson encountered an error in file meson.build, line 8, column 0:
Arguments must be strings.
FAILED: build.ninja
This seems to be roughly similar to #1633
configure_file()
returns FileHolder
. It's not Strings
nor File
.
The documentation says it return a File
. Isn't it a bug?
No, FileHolder
is a representation of a File
object in the interpreter, File
is the object that the middel and backend interact with.
OK. So, the internal representation is just leaking. Thanks.
There's been a ton of work in that area in 0.60.0, specifically in fixing layering violations between interpreter objects and the middle/backend objects, so some of that may be resolved now.
Current versions of Meson error with:
meson.build:10:0: ERROR: join_paths argument 2 was of type "File" but should have been "str"
Which is consistent with what I think has always been the intention of this function (files are documented to be "Opaque object that stores the path to an existing file"), but the error message is a bit better.
More generally I'm not sure what the goal here is. Because join_paths() is a string building function whose purpose is to give you some sugar in manipulating paths into what you actually want. But files()
objects are actual on-disk files that remember where they are, they have absolute locations (join_paths will always discard the prefix instead of prepending it to an absolute path) and it feels a bit like it would defeat the purpose of a files() object if you could reduce it back down to a string and combine it with other strings.
and makes constructing paths from those files a bit awkward
Can you describe why in practice this would be useful?
More generally I'm not sure what the goal here is.
hmm, me neither. it has been 5 years since, my memory doesn't last that long anymore :smile: I think this may have been something where the resulting file's path had to be used as input to some other call. Like this pseudo code:
f = configure_file(input: 'foo', output : 'foo', configuration : c)
dog = run_command('cat', join_paths(meson.build_root(), f))
Mind you this is really just a guess, and other features to meson have been added since so the original use-case, whatever it was, may be possible through other means now. Feel free to close this one.
just:
dog = run_command('cat', f)
should work, and if that doesn't work, that's a bug