Skip to content

Commit

Permalink
app: project: Improve forall
Browse files Browse the repository at this point in the history
* Add environment variables when running forall for each project.
* Add a "quiet" argument to prevent printing the banner

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
  • Loading branch information
pdgendt committed Jul 19, 2024
1 parent 155b242 commit c918f7c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,17 @@ def __init__(self):
Runs a shell (on a Unix OS) or batch (on Windows) command
within the repository of each of the specified PROJECTs.
The following variables are set when running your command:
WEST_PROJECT_NAME
WEST_PROJECT_PATH
WEST_PROJECT_REVISION
WEST_PROJECT_URL
WEST_PROJECT_REMOTE
Use proper escaping, for example:
west forall -q -c "echo \\$WEST_PROJECT_NAME"
If the command has multiple words, you must quote the -c
option to prevent the shell from splitting it up. Since
the command is run through the shell, you can use
Expand All @@ -1617,6 +1628,8 @@ def do_add_parser(self, parser_adder):
required=True)
parser.add_argument('-a', '--all', action='store_true',
help='include inactive projects'),
parser.add_argument('-q', '--quiet', action='store_true',
help='do not print banner'),
parser.add_argument('-g', '--group', dest='groups',
default=[], action='append',
help='''only run COMMAND if a project is
Expand All @@ -1631,12 +1644,21 @@ def do_add_parser(self, parser_adder):
def do_run(self, args, user_args):
failed = []
group_set = set(args.groups)
env = os.environ.copy()
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,

env["WEST_PROJECT_NAME"] = project.name
env["WEST_PROJECT_PATH"] = project.path
env["WEST_PROJECT_REVISION"] = project.revision
env["WEST_PROJECT_URL"] = project.url
env["WEST_PROJECT_REMOTE"] = project.remote_name

if not args.quiet:
self.banner(
f'running "{args.subcommand}" in {project.name_and_path}:')
rc = subprocess.Popen(args.subcommand, shell=True, env=env,
cwd=project.abspath).wait()
if rc:
failed.append(project)
Expand Down
1 change: 1 addition & 0 deletions src/west/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ def __init__(self, path: Optional[PathType] = None,
self.url: str = ''
self.submodules = False
self.revision: str = 'HEAD'
self.remote_name: str = ''
self.clone_depth: Optional[int] = None
self.groups = []
self.userdata: Optional[Any] = userdata
Expand Down

0 comments on commit c918f7c

Please sign in to comment.