diff options
author | TheQwertiest <qwertiest@mail.ru> | 2020-05-21 17:05:04 +0300 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2020-06-28 18:13:49 -0400 |
commit | 4d0233540f15c686c199d8f464fc7499a094645e (patch) | |
tree | 2b9969d0bb330124abad9fcc71842c2760cc1479 | |
parent | b9b15816e85c3bc596a44650837af1c687fd6398 (diff) | |
download | meson-4d0233540f15c686c199d8f464fc7499a094645e.zip meson-4d0233540f15c686c199d8f464fc7499a094645e.tar.gz meson-4d0233540f15c686c199d8f464fc7499a094645e.tar.bz2 |
Added ability to pass arguments to backend in `meson compile`
-rw-r--r-- | docs/markdown/Commands.md | 31 | ||||
-rw-r--r-- | docs/markdown/snippets/add_compile_backend_arg.md | 26 | ||||
-rw-r--r-- | mesonbuild/mcompile.py | 35 | ||||
-rwxr-xr-x | run_unittests.py | 15 |
4 files changed, 96 insertions, 11 deletions
diff --git a/docs/markdown/Commands.md b/docs/markdown/Commands.md index dbcfee4..4d3de55 100644 --- a/docs/markdown/Commands.md +++ b/docs/markdown/Commands.md @@ -137,7 +137,7 @@ meson configure builddir -Doption=new_value ``` $ meson compile [-h] [-j JOBS] [-l LOAD_AVERAGE] [--clean] [-C BUILDDIR] - [--verbose] + [--verbose] [--ninja-args NINJA_ARGS] [--vs-args VS_ARGS] ``` Builds a default or a specified target of a configured meson project. @@ -155,6 +155,30 @@ optional arguments: -C BUILDDIR The directory containing build files to be built. --verbose Show more verbose output. + --ninja-args NINJA_ARGS Arguments to pass to `ninja` (applied + only on `ninja` backend). + --vs-args VS_ARGS Arguments to pass to `msbuild` (applied + only on `vs` backend). +``` + +#### Backend specific arguments + +*(since 0.55.0)* + +`BACKEND-args` use the following syntax: + +If you only pass a single string, then it is considered to have all values separated by commas. Thus invoking the following command: + +``` +$ meson compile --ninja-args=-n,-d,explain +``` + +would add `-n`, `-d` and `explain` arguments to ninja invocation. + +If you need to have commas or spaces in your string values, then you need to pass the value with proper shell quoting like this: + +``` +$ meson compile "--ninja-args=['a,b', 'c d']" ``` #### Examples: @@ -164,6 +188,11 @@ Build the project: meson compile -C builddir ``` +Execute a dry run on ninja backend with additional debug info: +``` +meson compile --ninja-args=-n,-d,explain +``` + ### dist *(since 0.52.0)* diff --git a/docs/markdown/snippets/add_compile_backend_arg.md b/docs/markdown/snippets/add_compile_backend_arg.md new file mode 100644 index 0000000..76e2abb --- /dev/null +++ b/docs/markdown/snippets/add_compile_backend_arg.md @@ -0,0 +1,26 @@ +## Added ability to specify backend arguments in `meson compile` + +It's now possible to specify backend specific arguments in `meson compile`. + +Usage: `meson compile [--vs-args=args] [--ninja-args=args]` + +``` + --ninja-args NINJA_ARGS Arguments to pass to `ninja` (applied only on `ninja` backend). + --vs-args VS_ARGS Arguments to pass to `msbuild` (applied only on `vs` backend). +``` + +These arguments use the following syntax: + +If you only pass a single string, then it is considered to have all values separated by commas. Thus invoking the following command: + +``` +$ meson compile --ninja-args=-n,-d,explain +``` + +would add `-n`, `-d` and `explain` arguments to ninja invocation. + +If you need to have commas or spaces in your string values, then you need to pass the value with proper shell quoting like this: + +``` +$ meson compile "--ninja-args=['a,b', 'c d']" +``` diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py index 0bcb56e..3799ce3 100644 --- a/mesonbuild/mcompile.py +++ b/mesonbuild/mcompile.py @@ -14,6 +14,7 @@ """Entrypoint script for backend agnostic compile.""" +import argparse import sys import typing as T from pathlib import Path @@ -23,10 +24,11 @@ from . import mesonlib from . import coredata from .mesonlib import MesonException from mesonbuild.environment import detect_ninja +from mesonbuild.coredata import UserArrayOption + +def array_arg(value: str) -> T.List[str]: + return UserArrayOption(None, value, allow_dups=True, user_input=True).value -if T.TYPE_CHECKING: - import argparse - def validate_builddir(builddir: Path): if not (builddir / 'meson-private' / 'coredata.dat' ).is_file(): raise MesonException('Current directory is not a meson build directory: `{}`.\n' @@ -58,31 +60,31 @@ def get_parsed_args_ninja(options: 'argparse.Namespace', builddir: Path): cmd.append('-v') if options.clean: cmd.append('clean') - + return cmd def get_parsed_args_vs(options: 'argparse.Namespace', builddir: Path): slns = list(builddir.glob('*.sln')) assert len(slns) == 1, 'More than one solution in a project?' - + sln = slns[0] cmd = ['msbuild', str(sln.resolve())] - + # In msbuild `-m` with no number means "detect cpus", the default is `-m1` if options.jobs > 0: cmd.append('-m{}'.format(options.jobs)) else: cmd.append('-m') - + if options.load_average: mlog.warning('Msbuild does not have a load-average switch, ignoring.') if not options.verbose: cmd.append('/v:minimal') if options.clean: cmd.append('/t:Clean') - + return cmd - + def add_arguments(parser: 'argparse.ArgumentParser') -> None: """Add compile specific arguments.""" parser.add_argument( @@ -117,7 +119,18 @@ def add_arguments(parser: 'argparse.ArgumentParser') -> None: action='store_true', help='Show more verbose output.' ) - + parser.add_argument( + '--ninja-args', + type=array_arg, + default=[], + help='Arguments to pass to `ninja` (applied only on `ninja` backend).' + ) + parser.add_argument( + '--vs-args', + type=array_arg, + default=[], + help='Arguments to pass to `msbuild` (applied only on `vs` backend).' + ) def run(options: 'argparse.Namespace') -> int: bdir = options.builddir # type: Path @@ -128,8 +141,10 @@ def run(options: 'argparse.Namespace') -> int: backend = get_backend_from_coredata(bdir) if backend == 'ninja': cmd = get_parsed_args_ninja(options, bdir) + cmd += options.ninja_args elif backend.startswith('vs'): cmd = get_parsed_args_vs(options, bdir) + cmd += options.vs_args else: # TODO: xcode? raise MesonException( diff --git a/run_unittests.py b/run_unittests.py index 9e8aa50..1af0d8b 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -4636,6 +4636,7 @@ recommended as it is not supported on some platforms''') testdir = os.path.join(self.common_test_dir, '1 trivial') self.init(testdir) + self._run([*self.meson_command, 'compile', '-C', self.builddir]) # If compile worked then we should get a program self.assertPathExists(os.path.join(self.builddir, prog)) @@ -4643,6 +4644,20 @@ recommended as it is not supported on some platforms''') self._run([*self.meson_command, 'compile', '-C', self.builddir, '--clean']) self.assertPathDoesNotExist(os.path.join(self.builddir, prog)) + # `--$BACKEND-args` + + if self.backend is Backend.ninja: + self.init(testdir, extra_args=['--wipe']) + # Dry run - should not create a program + self._run([*self.meson_command, 'compile', '-C', self.builddir, '--ninja-args=-n']) + self.assertPathDoesNotExist(os.path.join(self.builddir, prog)) + elif self.backend is Backend.vs: + self.init(testdir, extra_args=['--wipe']) + self._run([*self.meson_command, 'compile', '-C', self.builddir]) + # Explicitly clean the target through msbuild interface + self._run([*self.meson_command, 'compile', '-C', self.builddir, '--vs-args=-t:{}:Clean'.format(re.sub(r'[\%\$\@\;\.\(\)\']', '_', prog))]) + self.assertPathDoesNotExist(os.path.join(self.builddir, prog)) + def test_spurious_reconfigure_built_dep_file(self): testdir = os.path.join(self.unit_test_dir, '75 dep files') |