summaryrefslogtreecommitdiff
path: root/mesonbuild/msubprojects.py
diff options
context:
space:
mode:
authorAntonio Ospite <antonio.ospite@collabora.com>2019-03-29 18:23:13 +0100
committerAntonio Ospite <antonio.ospite@collabora.com>2019-04-01 11:51:02 +0200
commite680dbe0658851bc73d8e664909df9619365e714 (patch)
tree2418b3cf85e6c040a2516732b7f5bdd90b8ed4a9 /mesonbuild/msubprojects.py
parent5905533fcd7fb9663023e6cf98d95667620d2f12 (diff)
downloadmeson-e680dbe0658851bc73d8e664909df9619365e714.tar.gz
Add 'meson subprojects foreach' command
Sometimes it is convenient to run an arbitrary command (e.g. 'git diff') on all subprojects. Add a 'meson subprojects foreach' command to take care of that. For this command the common argument 'subprojects' does not make sense, so only add '--sourcedir' and cover the case of a missing options.subprojects in run().
Diffstat (limited to 'mesonbuild/msubprojects.py')
-rwxr-xr-x[-rw-r--r--]mesonbuild/msubprojects.py37
1 files changed, 30 insertions, 7 deletions
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index 2c1bf8b6c..c31b07d37 100644..100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -1,4 +1,5 @@
import os, subprocess
+import argparse
from . import mlog
from .mesonlib import Popen_safe
@@ -167,6 +168,18 @@ def download(wrap, repo_dir, options):
except WrapException as e:
mlog.log(' ->', mlog.red(str(e)))
+def foreach(wrap, repo_dir, options):
+ mlog.log('Executing command in %s' % repo_dir)
+ if not os.path.isdir(repo_dir):
+ mlog.log(' -> Not downloaded yet')
+ return
+ try:
+ subprocess.check_call([options.command] + options.args, cwd=repo_dir)
+ mlog.log('')
+ except subprocess.CalledProcessError as e:
+ out = e.output.decode().strip()
+ mlog.log(' -> ', mlog.red(out))
+
def add_common_arguments(p):
p.add_argument('--sourcedir', default='.',
help='Path to source directory')
@@ -197,6 +210,15 @@ def add_arguments(parser):
add_common_arguments(p)
p.set_defaults(subprojects_func=download)
+ p = subparsers.add_parser('foreach', help='Execute a command in each subproject directory.')
+ p.add_argument('command', metavar='command ...',
+ help='Command to execute in each subproject directory')
+ p.add_argument('args', nargs=argparse.REMAINDER,
+ help=argparse.SUPPRESS)
+ p.add_argument('--sourcedir', default='.',
+ help='Path to source directory')
+ p.set_defaults(subprojects_func=foreach)
+
def run(options):
src_dir = os.path.relpath(os.path.realpath(options.sourcedir))
if not os.path.isfile(os.path.join(src_dir, 'meson.build')):
@@ -207,13 +229,14 @@ def run(options):
mlog.log('Directory', mlog.bold(src_dir), 'does not seem to have subprojects.')
return 0
files = []
- for name in options.subprojects:
- f = os.path.join(subprojects_dir, name + '.wrap')
- if not os.path.isfile(f):
- mlog.error('Subproject', mlog.bold(name), 'not found.')
- return 1
- else:
- files.append(f)
+ if hasattr(options, 'subprojects'):
+ for name in options.subprojects:
+ f = os.path.join(subprojects_dir, name + '.wrap')
+ if not os.path.isfile(f):
+ mlog.error('Subproject', mlog.bold(name), 'not found.')
+ return 1
+ else:
+ files.append(f)
if not files:
for f in os.listdir(subprojects_dir):
if f.endswith('.wrap'):