aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Reference-manual.md16
-rw-r--r--docs/markdown/snippets/pass_file_to_add_script.md15
-rw-r--r--mesonbuild/interpreter.py28
-rw-r--r--test cases/common/54 install script/meson.build8
-rwxr-xr-x[-rw-r--r--]test cases/common/54 install script/myinstall.py0
-rw-r--r--test cases/common/54 install script/test.json1
6 files changed, 58 insertions, 10 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index f758e71..3970d6d 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -1824,21 +1824,29 @@ the following methods.
it from a subproject is a hard error. *(since 0.49.0)* Accepts multiple arguments
for the fscript. *(since 0.54.0)* The `MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT`
environment variables are set when dist scripts are run.
+
*(since 0.55.0)* The output of `configure_file`, `files`, and `find_program`
as well as strings.
+ *(since 0.57.0)* `file` objects and the output of `configure_file` may be
+ *used as the `script_name` parameter.
+
- `add_install_script(script_name, arg1, arg2, ...)`: causes the script
given as an argument to be run during the install step, this script
will have the environment variables `MESON_SOURCE_ROOT`,
`MESON_BUILD_ROOT`, `MESON_INSTALL_PREFIX`,
`MESON_INSTALL_DESTDIR_PREFIX`, and `MESONINTROSPECT` set.
All positional arguments are passed as parameters.
+
+ *(since 0.54.0)* If `meson install` is called with the `--quiet` option, the
+ environment variable `MESON_INSTALL_QUIET` will be set.
+
*(since 0.55.0)* The output of `configure_file`, `files`, `find_program`,
`custom_target`, indexes of `custom_target`, `executable`, `library`, and
other built targets as well as strings.
- *(since 0.54.0)* If `meson install` is called with the `--quiet` option, the
- environment variable `MESON_INSTALL_QUIET` will be set.
+ *(since 0.57.0)* `file` objects and the output of `configure_file` may be
+ *used as the `script_name` parameter.
Meson uses the `DESTDIR` environment variable as set by the
inherited environment to determine the (temporary) installation
@@ -1866,9 +1874,13 @@ the following methods.
executable given as an argument after all project files have been
generated. This script will have the environment variables
`MESON_SOURCE_ROOT` and `MESON_BUILD_ROOT` set.
+
*(since 0.55.0)* The output of `configure_file`, `files`, and `find_program`
as well as strings.
+ *(since 0.57.0)* `file` objects and the output of `configure_file` may be
+ *used as the `script_name` parameter.
+
- `backend()` *(since 0.37.0)*: returns a string representing the
current backend: `ninja`, `vs2010`, `vs2015`, `vs2017`, `vs2019`,
or `xcode`.
diff --git a/docs/markdown/snippets/pass_file_to_add_script.md b/docs/markdown/snippets/pass_file_to_add_script.md
new file mode 100644
index 0000000..10d08e0
--- /dev/null
+++ b/docs/markdown/snippets/pass_file_to_add_script.md
@@ -0,0 +1,15 @@
+## The `add_*_script` methods now accept a File as the first argument
+
+Meson now accepts `file` objects, including those produced by
+`configure_file` as the `prog` (first) parameter of the various
+`add_*_script` methods
+
+```meson
+install_script = configure_file(
+ configuration : conf,
+ input : 'myscript.py.in',
+ output : 'myscript.py',
+)
+
+meson.add_install_script(install_script, other, params)
+```
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index be0309e..a92ce7b 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1947,26 +1947,29 @@ class MesonMain(InterpreterObject):
'backend': self.backend_method,
})
- def _find_source_script(self, prog: T.Union[str, ExecutableHolder], args):
+ def _find_source_script(self, prog: T.Union[str, mesonlib.File, ExecutableHolder], args):
if isinstance(prog, ExecutableHolder):
prog_path = self.interpreter.backend.get_target_filename(prog.held_object)
return build.RunScript([prog_path], args)
elif isinstance(prog, ExternalProgramHolder):
return build.RunScript(prog.get_command(), args)
-
# Prefer scripts in the current source directory
search_dir = os.path.join(self.interpreter.environment.source_dir,
self.interpreter.subdir)
key = (prog, search_dir)
if key in self._found_source_scripts:
found = self._found_source_scripts[key]
+ elif isinstance(prog, mesonlib.File):
+ prog = prog.rel_to_builddir(self.interpreter.environment.source_dir)
+ found = dependencies.ExternalProgram(prog, search_dir=self.interpreter.environment.build_dir)
else:
found = dependencies.ExternalProgram(prog, search_dir=search_dir)
- if found.found():
- self._found_source_scripts[key] = found
- else:
- m = 'Script or command {!r} not found or not executable'
- raise InterpreterException(m.format(prog))
+
+ if found.found():
+ self._found_source_scripts[key] = found
+ else:
+ m = 'Script or command {!r} not found or not executable'
+ raise InterpreterException(m.format(prog))
return build.RunScript(found.get_command(), args)
def _process_script_args(
@@ -2016,9 +2019,12 @@ class MesonMain(InterpreterObject):
return script_args
@permittedKwargs(set())
- def add_install_script_method(self, args: 'T.Tuple[T.Union[str, ExecutableHolder], T.Union[str, mesonlib.File, CustomTargetHolder, CustomTargetIndexHolder, ConfigureFileHolder], ...]', kwargs):
+ def add_install_script_method(self, args: 'T.Tuple[T.Union[str, mesonlib.File, ExecutableHolder], T.Union[str, mesonlib.File, CustomTargetHolder, CustomTargetIndexHolder, ConfigureFileHolder], ...]', kwargs):
if len(args) < 1:
raise InterpreterException('add_install_script takes one or more arguments')
+ if isinstance(args[0], mesonlib.File):
+ FeatureNew.single_use('Passing file object to script parameter of add_install_script',
+ '0.57.0', self.interpreter.subproject)
script_args = self._process_script_args('add_install_script', args[1:], allow_built=True)
script = self._find_source_script(args[0], script_args)
self.build.install_scripts.append(script)
@@ -2027,6 +2033,9 @@ class MesonMain(InterpreterObject):
def add_postconf_script_method(self, args, kwargs):
if len(args) < 1:
raise InterpreterException('add_postconf_script takes one or more arguments')
+ if isinstance(args[0], mesonlib.File):
+ FeatureNew.single_use('Passing file object to script parameter of add_postconf_script',
+ '0.57.0', self.interpreter.subproject)
script_args = self._process_script_args('add_postconf_script', args[1:], allow_built=True)
script = self._find_source_script(args[0], script_args)
self.build.postconf_scripts.append(script)
@@ -2038,6 +2047,9 @@ class MesonMain(InterpreterObject):
if len(args) > 1:
FeatureNew.single_use('Calling "add_dist_script" with multiple arguments',
'0.49.0', self.interpreter.subproject)
+ if isinstance(args[0], mesonlib.File):
+ FeatureNew.single_use('Passing file object to script parameter of add_dist_script',
+ '0.57.0', self.interpreter.subproject)
if self.interpreter.subproject != '':
raise InterpreterException('add_dist_script may not be used in a subproject.')
script_args = self._process_script_args('add_dist_script', args[1:], allow_built=True)
diff --git a/test cases/common/54 install script/meson.build b/test cases/common/54 install script/meson.build
index 696e3f6..eab95ab 100644
--- a/test cases/common/54 install script/meson.build
+++ b/test cases/common/54 install script/meson.build
@@ -25,3 +25,11 @@ t = custom_target(
meson.add_install_script('myinstall.py', 'customtarget', t, '--mode=copy')
meson.add_install_script('myinstall.py', 'customtargetindex', t[0], '--mode=copy')
+
+installer = configure_file(
+ input : 'myinstall.py',
+ output : 'myinstall_copy.py',
+ copy : true,
+)
+
+meson.add_install_script(installer, 'otherdir', afile, '--mode=copy')
diff --git a/test cases/common/54 install script/myinstall.py b/test cases/common/54 install script/myinstall.py
index a573342..a573342 100644..100755
--- a/test cases/common/54 install script/myinstall.py
+++ b/test cases/common/54 install script/myinstall.py
diff --git a/test cases/common/54 install script/test.json b/test cases/common/54 install script/test.json
index 3804fe1..7ac2607 100644
--- a/test cases/common/54 install script/test.json
+++ b/test cases/common/54 install script/test.json
@@ -7,6 +7,7 @@
{"type": "file", "file": "usr/this/does/something-different.dat.in"},
{"type": "file", "file": "usr/dir/a file.txt"},
{"type": "file", "file": "usr/dir/conf.txt"},
+ {"type": "file", "file": "usr/otherdir/a file.txt"},
{"type": "file", "file": "usr/customtarget/1.txt"},
{"type": "file", "file": "usr/customtarget/2.txt"},
{"type": "file", "file": "usr/customtargetindex/1.txt"}