jw.pkg.cmds.projects.CmdBuild: --source-profile -> --env-reinit

Replace --source-profile by --env-reinit and --env-keep to allow more
fine-grained control over environment manipulation.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-19 08:14:34 +01:00
commit d814052aac

View file

@ -24,8 +24,10 @@ class CmdBuild(Cmd): # export
default=False, help='Don\'t build anything, just print the build order.')
parser.add_argument('-I', '--ignore-deps', action='store_true',
default=False, help='Don\'t build dependencies, i.e. build only modules specified on the command line')
parser.add_argument('--source-profile', choices=['no', 'add', 'replace'],
default='no', help='Source /etc/profile before each build step')
parser.add_argument('--env-reinit', action='store_true',
default=False, help='Source /etc/profile before each build step. Discard environment unless --env-keep is specified')
parser.add_argument('--env-keep', default='none', help='Comma seperated list of environment variables to keep, '
+ '"all" or "none", only meaningful if --env-reinit is specified')
parser.add_argument('target', default='all', help='Build target')
parser.add_argument('modules', nargs='+', default='', help='Modules to be built')
@ -100,8 +102,17 @@ class CmdBuild(Cmd): # export
title = '---- [%d/%d]: Running "%s" in %s -' % (cur_project, num_projects, ' '.join(make_cmd), wd)
env = None
if args.source_profile != 'no':
env = await get_profile_env(add=True if args.source_profile == 'add' else False)
if args.env_reinit:
keep: bool|list[str] = False
if args.env_keep is not None:
match args.env_keep:
case 'all':
keep=True
case 'none':
keep=False
case _:
keep = args.env_keep.split(',')
env = await get_profile_env(keep=keep)
try:
stdout, stderr = await run_cmd(