From e79b602298ca3810c4ee0c99a23ae3ae50c879b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Aradi?= Date: Fri, 19 May 2017 17:22:42 +0200 Subject: [PATCH 1/3] Enable variables for output in configure_file --- mesonbuild/interpreter.py | 4 ++++ test cases/common/16 configure file/config4a.h.in | 2 ++ test cases/common/16 configure file/config4b.h.in | 2 ++ test cases/common/16 configure file/meson.build | 12 ++++++++++++ test cases/common/16 configure file/prog4.c | 6 ++++++ 5 files changed, 26 insertions(+) create mode 100644 test cases/common/16 configure file/config4a.h.in create mode 100644 test cases/common/16 configure file/config4b.h.in create mode 100644 test cases/common/16 configure file/prog4.c diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 454ee66cb..39d596ff3 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -2344,6 +2344,10 @@ class Interpreter(InterpreterBase): output = kwargs['output'] if not isinstance(output, str): raise InterpreterException('Output file name must be a string') + if ifile_abs: + values = mesonlib.get_filenames_templates_dict([ifile_abs], None) + outputs = mesonlib.substitute_values([output], values) + output = outputs[0] if os.path.split(output)[0] != '': raise InterpreterException('Output file name must not contain a subdirectory.') (ofile_path, ofile_fname) = os.path.split(os.path.join(self.subdir, output)) diff --git a/test cases/common/16 configure file/config4a.h.in b/test cases/common/16 configure file/config4a.h.in new file mode 100644 index 000000000..aafd195c2 --- /dev/null +++ b/test cases/common/16 configure file/config4a.h.in @@ -0,0 +1,2 @@ +/* Dummy file */ +#define RESULTA @ZERO@ diff --git a/test cases/common/16 configure file/config4b.h.in b/test cases/common/16 configure file/config4b.h.in new file mode 100644 index 000000000..3408bab6f --- /dev/null +++ b/test cases/common/16 configure file/config4b.h.in @@ -0,0 +1,2 @@ +/* Dummy file */ +#define RESULTB @ZERO@ diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build index 8ffc28cc3..0d0e46107 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -74,3 +74,15 @@ configure_file(output : 'config3.h', configuration : dump) test('Configless.', executable('dumpprog', 'dumpprog.c')) + + +# Config file generation in a loop with @BASENAME@ substitution +dump = configuration_data() +dump.set('ZERO', 0) +config_templates = files(['config4a.h.in', 'config4b.h.in']) +foreach config_template : config_templates + configure_file(input : config_template, output : '@BASENAME@', + configuration : dump) +endforeach + +test('Substituted', executable('prog4', 'prog4.c')) diff --git a/test cases/common/16 configure file/prog4.c b/test cases/common/16 configure file/prog4.c new file mode 100644 index 000000000..92dc7cbb6 --- /dev/null +++ b/test cases/common/16 configure file/prog4.c @@ -0,0 +1,6 @@ +#include +#include + +int main(int argc, char **argv) { + return RESULTA + RESULTB; +} From 28dededf083b6cae170a175309d064502fcc9eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Aradi?= Date: Fri, 2 Jun 2017 21:09:11 +0200 Subject: [PATCH 2/3] Update reference manual and release notes --- docs/markdown/Reference-manual.md | 2 +- docs/markdown/Release-notes-for-0.41.0.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index fab317d76..4c2f8efc9 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -124,7 +124,7 @@ When a list of strings is passed to the `command:` keyword argument, it takes an These are all the supported keyword arguments: - `input` the input file name. If it's not specified in configuration mode, all the variables in the `configuration:` object (see above) are written to the `output:` file. -- `output` the output file name. In configuration mode, the permissions of the input file (if it is specified) are copied to the output file. +- `output` the output file name (may contain `@PLAINNAME@` or `@BASENAME@` substitutions). In configuration mode, the permissions of the input file (if it is specified) are copied to the output file. - `configuration` as explained above, this is where you pass the configuration data object as returned by `configuration_data()` - `command` as explained above, if specified, Meson does not create the file itself but rather runs the specified command, which allows you to do fully custom file generation - `install_dir` the subdirectory to install the generated file to (e.g. `share/myproject`), if omitted the file is not installed. diff --git a/docs/markdown/Release-notes-for-0.41.0.md b/docs/markdown/Release-notes-for-0.41.0.md index 80bf0b303..f995cc54b 100644 --- a/docs/markdown/Release-notes-for-0.41.0.md +++ b/docs/markdown/Release-notes-for-0.41.0.md @@ -67,3 +67,7 @@ coverage must be combined before producing a report (`coverage3 combine`.) All known issues have been fixed and Meson can now build reproducible Debian packages out of the box. +## Extended template substitution in configure_file + +The output argument of `configure_file()` is parsed for @BASENAME@ and +@PLAINNAME@ substitutions. From 706b3cafab114e8d7ff7306cb471259ae1597e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Aradi?= Date: Sat, 3 Jun 2017 11:37:56 +0200 Subject: [PATCH 3/3] Add version for configure_file extension in reference manual --- docs/markdown/Reference-manual.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 4c2f8efc9..29c073cd5 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -124,7 +124,7 @@ When a list of strings is passed to the `command:` keyword argument, it takes an These are all the supported keyword arguments: - `input` the input file name. If it's not specified in configuration mode, all the variables in the `configuration:` object (see above) are written to the `output:` file. -- `output` the output file name (may contain `@PLAINNAME@` or `@BASENAME@` substitutions). In configuration mode, the permissions of the input file (if it is specified) are copied to the output file. +- `output` the output file name (since v0.41.0, may contain `@PLAINNAME@` or `@BASENAME@` substitutions). In configuration mode, the permissions of the input file (if it is specified) are copied to the output file. - `configuration` as explained above, this is where you pass the configuration data object as returned by `configuration_data()` - `command` as explained above, if specified, Meson does not create the file itself but rather runs the specified command, which allows you to do fully custom file generation - `install_dir` the subdirectory to install the generated file to (e.g. `share/myproject`), if omitted the file is not installed.