@ -21,8 +21,12 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
help = ' Path to build directory ' )
parser . add_argument ( ' --workdir ' , ' -w ' , type = Path , default = None ,
help = ' Directory to cd into before running (default: builddir, Since 1.0.0) ' )
parser . add_argument ( ' --dump ' , action = ' store_true ' ,
help = ' Only print required environment (Since 0.62.0) ' )
parser . add_argument ( ' --dump ' , nargs = ' ? ' , const = True ,
help = ' Only print required environment (Since 0.62.0) ' +
' Takes an optional file path (Since 1.1.0) ' )
parser . add_argument ( ' --dump-format ' , default = ' export ' ,
choices = [ ' sh ' , ' export ' , ' vscode ' ] ,
help = ' Format used with --dump (Since 1.1.0) ' )
parser . add_argument ( ' devcmd ' , nargs = argparse . REMAINDER , metavar = ' command ' ,
help = ' Command to run in developer environment (default: interactive shell) ' )
@ -48,7 +52,7 @@ def reduce_winepath(env: T.Dict[str, str]) -> None:
env [ ' WINEPATH ' ] = get_wine_shortpath ( [ winecmd ] , winepath . split ( ' ; ' ) )
mlog . log ( ' Meson detected wine and has set WINEPATH accordingly ' )
def get_env ( b : build . Build , dump : bool ) - > T . Tuple [ T . Dict [ str , str ] , T . Set [ str ] ] :
def get_env ( b : build . Build , dump_fmt : T . Optional [ str ] ) - > T . Tuple [ T . Dict [ str , str ] , T . Set [ str ] ] :
extra_env = build . EnvironmentVariables ( )
extra_env . set ( ' MESON_DEVENV ' , [ ' 1 ' ] )
extra_env . set ( ' MESON_PROJECT_NAME ' , [ b . project_name ] )
@ -57,10 +61,11 @@ def get_env(b: build.Build, dump: bool) -> T.Tuple[T.Dict[str, str], T.Set[str]]
if sysroot :
extra_env . set ( ' QEMU_LD_PREFIX ' , [ sysroot ] )
env = { } if dump else os . environ . copy ( )
env = { } if dump_fmt else os . environ . copy ( )
default_fmt = ' $ {0} ' if dump_fmt in { ' sh ' , ' export ' } else None
varnames = set ( )
for i in itertools . chain ( b . devenv , { extra_env } ) :
env = i . get_env ( env , dump )
env = i . get_env ( env , default_fmt )
varnames | = i . get_names ( )
reduce_winepath ( env )
@ -138,6 +143,12 @@ def write_gdb_script(privatedir: Path, install_data: 'InstallData', workdir: Pat
mlog . log ( ' - Change current workdir to ' , mlog . bold ( str ( rel_path . parent ) ) ,
' or use ' , mlog . bold ( f ' --init-command { rel_path } ' ) )
def dump ( devenv : T . Dict [ str , str ] , varnames : T . Set [ str ] , dump_format : T . Optional [ str ] , output : T . Optional [ T . TextIO ] = None ) - > None :
for name in varnames :
print ( f ' { name } = " { devenv [ name ] } " ' , file = output )
if dump_format == ' export ' :
print ( f ' export { name } ' , file = output )
def run ( options : argparse . Namespace ) - > int :
privatedir = Path ( options . builddir ) / ' meson-private '
buildfile = privatedir / ' build.dat '
@ -146,13 +157,16 @@ def run(options: argparse.Namespace) -> int:
b = build . load ( options . builddir )
workdir = options . workdir or options . builddir
devenv , varnames = get_env ( b , options . dump )
dump_fmt = options . dump_format if options . dump else None
devenv , varnames = get_env ( b , dump_fmt )
if options . dump :
if options . devcmd :
raise MesonException ( ' --dump option does not allow running other command. ' )
for name in varnames :
print ( f ' { name } = " { devenv [ name ] } " ' )
print ( f ' export { name } ' )
if options . dump is True :
dump ( devenv , varnames , dump_fmt )
else :
with open ( options . dump , " w " , encoding = ' utf-8 ' ) as output :
dump ( devenv , varnames , dump_fmt , output )
return 0
if b . environment . need_exe_wrapper ( ) :