aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2018-10-02 06:13:44 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2018-10-04 21:20:57 +0300
commitc0c075c1298ad9018a62d75a632af1c0d0d7d0f8 (patch)
treecadf15c9de967df71bf047233790d722faf46ff1
parent577d6bfdb483452b2a9434ba3a1d7031094b0cbd (diff)
downloadmeson-c0c075c1298ad9018a62d75a632af1c0d0d7d0f8.zip
meson-c0c075c1298ad9018a62d75a632af1c0d0d7d0f8.tar.gz
meson-c0c075c1298ad9018a62d75a632af1c0d0d7d0f8.tar.bz2
Make custom dist scripts accept arguments.
meson.add_dist_script, introduced in #3906, did not accept any arguments other than script name. Since all other meson.add_*_script methods do accept args, this makes the dist script accept them as well.
-rw-r--r--docs/markdown/Reference-manual.md4
-rw-r--r--mesonbuild/interpreter.py9
-rw-r--r--mesonbuild/scripts/dist.py21
-rw-r--r--test cases/unit/35 dist script/meson.build2
-rwxr-xr-xtest cases/unit/35 dist script/replacer.py6
5 files changed, 25 insertions, 17 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index a098b7b..0fb9f17 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -1433,14 +1433,14 @@ The `meson` object allows you to introspect various properties of the
system. This object is always mapped in the `meson` variable. It has
the following methods.
-- `add_dist_script` causes the script given as argument to run during
+- `add_dist_script(script_name, arg1, arg, ...)` causes the script given as argument to run during
`dist` operation after the distribution source has been generated
but before it is archived. Note that this runs the script file that
is in the _staging_ directory, not the one in the source
directory. If the script file can not be found in the staging
directory, it is a hard error. This command can only invoked from
the main project, calling it from a subproject is a hard
- error. Available since 0.48.0.
+ error. Available since 0.48.0. Before 0.49.0, the function only accepted a single argument.
- `add_install_script(script_name, arg1, arg2, ...)` causes the script
given as an argument to be run during the install step, this script
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 131c24e..a4d9472 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1686,12 +1686,15 @@ class MesonMain(InterpreterObject):
@permittedKwargs({})
def add_dist_script_method(self, args, kwargs):
- if len(args) != 1:
- raise InterpreterException('add_dist_script takes exactly one argument')
+ if len(args) < 1:
+ raise InterpreterException('add_dist_script takes one or more arguments')
+ if len(args) > 1:
+ FeatureNew('Calling "add_dist_script" with multiple arguments', '0.49.0').use(self.interpreter.subproject)
check_stringlist(args, 'add_dist_script argument must be a string')
if self.interpreter.subproject != '':
raise InterpreterException('add_dist_script may not be used in a subproject.')
- self.build.dist_scripts.append(os.path.join(self.interpreter.subdir, args[0]))
+ script = self._find_source_script(args[0], args[1:])
+ self.build.dist_scripts.append(script)
@noPosargs
@permittedKwargs({})
diff --git a/mesonbuild/scripts/dist.py b/mesonbuild/scripts/dist.py
index 68cfcd0..56ac585 100644
--- a/mesonbuild/scripts/dist.py
+++ b/mesonbuild/scripts/dist.py
@@ -81,16 +81,17 @@ def run_dist_scripts(dist_root, dist_scripts):
env = os.environ.copy()
env['MESON_DIST_ROOT'] = dist_root
for d in dist_scripts:
- print('Processing dist script %s' % d)
- ddir, dname = os.path.split(d)
- ep = ExternalProgram(dname,
- search_dir=os.path.join(dist_root, ddir),
- silent=True)
- if not ep.found():
- sys.exit('Script %s could not be found in dist directory' % d)
- pc = subprocess.run(ep.command, env=env)
- if pc.returncode != 0:
- sys.exit('Dist script errored out')
+ script = d['exe']
+ args = d['args']
+ name = ' '.join(script + args)
+ print('Running custom dist script {!r}'.format(name))
+ try:
+ rc = subprocess.call(script + args, env=env)
+ if rc != 0:
+ sys.exit('Dist script errored out')
+ except OSError:
+ print('Failed to run dist script {!r}'.format(name))
+ sys.exit(1)
def git_have_dirty_index(src_root):
diff --git a/test cases/unit/35 dist script/meson.build b/test cases/unit/35 dist script/meson.build
index 3415ec4..fd672a9 100644
--- a/test cases/unit/35 dist script/meson.build
+++ b/test cases/unit/35 dist script/meson.build
@@ -4,4 +4,4 @@ project('dist script', 'c',
exe = executable('comparer', 'prog.c')
test('compare', exe)
-meson.add_dist_script('replacer.py')
+meson.add_dist_script('replacer.py', '"incorrect"', '"correct"')
diff --git a/test cases/unit/35 dist script/replacer.py b/test cases/unit/35 dist script/replacer.py
index adda365..96ccdcc 100755
--- a/test cases/unit/35 dist script/replacer.py
+++ b/test cases/unit/35 dist script/replacer.py
@@ -2,11 +2,15 @@
import os
import pathlib
+import sys
+
+if len(sys.argv) < 3:
+ sys.exit('usage: replacer.py <pattern> <replacement>')
source_root = pathlib.Path(os.environ['MESON_DIST_ROOT'])
modfile = source_root / 'prog.c'
contents = modfile.read_text()
-contents = contents.replace('"incorrect"', '"correct"')
+contents = contents.replace(sys.argv[1], sys.argv[2])
modfile.write_text(contents)