meson icon indicating copy to clipboard operation
meson copied to clipboard

object returned by configure_file() cannot be passed to join_paths()

Open whot opened this issue 7 years ago • 7 comments

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

whot avatar May 18 '17 00:05 whot

configure_file() returns FileHolder. It's not Strings nor File. The documentation says it return a File. Isn't it a bug?

yashi avatar Oct 07 '21 19:10 yashi

No, FileHolder is a representation of a File object in the interpreter, File is the object that the middel and backend interact with.

dcbaker avatar Oct 07 '21 19:10 dcbaker

OK. So, the internal representation is just leaking. Thanks.

yashi avatar Oct 07 '21 20:10 yashi

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.

dcbaker avatar Oct 07 '21 20:10 dcbaker

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?

eli-schwartz avatar Oct 20 '22 04:10 eli-schwartz

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.

whot avatar Nov 16 '22 10:11 whot

just:

dog = run_command('cat', f)

should work, and if that doesn't work, that's a bug

dcbaker avatar Nov 17 '22 18:11 dcbaker