diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2022-11-03 09:59:27 -0400 |
---|---|---|
committer | Xavier Claessens <xavier.claessens@collabora.com> | 2022-12-06 07:59:48 -0500 |
commit | 3e7433086c19fbaa5029f2926515f3ca5087299c (patch) | |
tree | ac38644507b3229dee4350e39a6289a152709c67 /mesonbuild/mdevenv.py | |
parent | d0054f2c3c3497e22069d1efb5b1d985d75fe5ca (diff) | |
download | meson-3e7433086c19fbaa5029f2926515f3ca5087299c.zip meson-3e7433086c19fbaa5029f2926515f3ca5087299c.tar.gz meson-3e7433086c19fbaa5029f2926515f3ca5087299c.tar.bz2 |
devenv: Add --workdir option
Most of the time it is preferable to remain the the top source dir
instead of going into the builddir. Add --workdir argument to be able to
have a different workdir than builddir, but keep it default to builddir
for backward compatibility, and also because it makes gdb integration
better.
Diffstat (limited to 'mesonbuild/mdevenv.py')
-rw-r--r-- | mesonbuild/mdevenv.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py index b75d18b..6223b14 100644 --- a/mesonbuild/mdevenv.py +++ b/mesonbuild/mdevenv.py @@ -6,7 +6,7 @@ import itertools from pathlib import Path from . import build, minstall, dependencies -from .mesonlib import MesonException, RealPathAction, is_windows, setup_vsenv, OptionKey, quote_arg, get_wine_shortpath +from .mesonlib import MesonException, is_windows, setup_vsenv, OptionKey, quote_arg, get_wine_shortpath from . import mlog import typing as T @@ -16,8 +16,10 @@ if T.TYPE_CHECKING: POWERSHELL_EXES = {'pwsh.exe', 'powershell.exe'} def add_arguments(parser: argparse.ArgumentParser) -> None: - parser.add_argument('-C', dest='wd', action=RealPathAction, - help='Directory to cd into before running') + parser.add_argument('-C', dest='builddir', type=Path, default='.', + 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('devcmd', nargs=argparse.REMAINDER, metavar='command', @@ -123,11 +125,12 @@ def write_gdb_script(privatedir: Path, install_data: 'InstallData') -> None: mlog.log('Meson detected GDB helpers and added config in', mlog.bold(str(gdbinit_path))) def run(options: argparse.Namespace) -> int: - privatedir = Path(options.wd) / 'meson-private' + privatedir = Path(options.builddir) / 'meson-private' buildfile = privatedir / 'build.dat' if not buildfile.is_file(): - raise MesonException(f'Directory {options.wd!r} does not seem to be a Meson build directory.') - b = build.load(options.wd) + raise MesonException(f'Directory {options.builddir!r} does not seem to be a Meson build directory.') + b = build.load(options.builddir) + workdir = options.workdir or options.builddir devenv, varnames = get_env(b) if options.dump: @@ -182,7 +185,7 @@ def run(options: argparse.Namespace) -> int: try: return subprocess.call(args, close_fds=False, env=devenv, - cwd=options.wd) + cwd=workdir) except subprocess.CalledProcessError as e: return e.returncode except FileNotFoundError: |