Skip to content

Commit

Permalink
forall: add --group argument
Browse files Browse the repository at this point in the history
This was requested by a user in a comment in issue zephyrproject-rtos#144.
The purpose is to make it easy to run commands on interesting subsets
of projects in a convenient way.

See help text for details.

Signed-off-by: Martí Bolívar <[email protected]>
  • Loading branch information
mbolivar-nordic committed Mar 27, 2023
1 parent b78c8c1 commit efb84a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,12 @@ def do_add_parser(self, parser_adder):
required=True)
parser.add_argument('-a', '--all', action='store_true',
help='include inactive projects'),
parser.add_argument('-g', '--group', dest='groups',
default=[], action='append',
help='''only run COMMAND if a project is
in this group; if given more than once,
the command will be run if the project is
in any of the groups''')
parser.add_argument('projects', metavar='PROJECT', nargs='*',
help='''projects (by name or path) to operate on;
defaults to active cloned projects''')
Expand All @@ -1465,7 +1471,10 @@ def do_run(self, args, user_args):
self._setup_logging(args)

failed = []
group_set = set(args.groups)
for project in self._cloned_projects(args, only_active=not args.all):
if group_set and not group_set.intersection(set(project.groups)):
continue
self.banner(
f'running "{args.subcommand}" in {project.name_and_path}:')
rc = subprocess.Popen(args.subcommand, shell=True,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ def test_forall(west_init_tmpdir):
'=== running "echo foo" in net-tools (net-tools):',
'foo']

assert cmd('forall --group Kconfiglib-group -c "echo foo"'
).splitlines() == [
'=== running "echo foo" in Kconfiglib (subdir/Kconfiglib):',
'foo',
]

def test_update_projects(west_init_tmpdir):
# Test the 'west update' command. It calls through to the same backend
Expand Down

0 comments on commit efb84a6

Please sign in to comment.