diff --git a/src/west/app/project.py b/src/west/app/project.py index 53814acb..bb19d7e8 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -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''') @@ -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, diff --git a/tests/test_project.py b/tests/test_project.py index b6fd29b7..1bc29843 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -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