From 719ad105165e942ee39f42749ee48d06e7567c90 Mon Sep 17 00:00:00 2001 From: Daniel Moody Date: Tue, 7 Jun 2022 15:05:42 -0500 Subject: Added command line variable to pass ninja args through scons. --- CHANGES.txt | 2 ++ RELEASE.txt | 1 + SCons/Tool/ninja/__init__.py | 12 +++++++++++- SCons/Tool/ninja/ninja.xml | 11 ++++++++++- test/ninja/generate_and_build.py | 3 ++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 03692d6..90e2d4e 100755 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -116,6 +116,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER Note that these are called for every build command run by SCons. It could have considerable performance impact if not used carefully. to connect to the server during start up. + - Ninja: Added command line variable NINJA_CMD_ARGS that allows to pass through ninja command line args. + From Mats Wichmann: - Tweak the way default site_scons paths on Windows are expressed to diff --git a/RELEASE.txt b/RELEASE.txt index cfa8afc..699e51e 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -24,6 +24,7 @@ NEW FUNCTIONALITY performance impact if not used carefully. - Added MSVC_USE_SETTINGS variable to pass a dictionary to configure the msvc compiler system environment as an alternative to bypassing Visual Studio autodetection entirely. +- Ninja: Added command line variable NINJA_CMD_ARGS that allows to pass through ninja command line args. DEPRECATED FUNCTIONALITY diff --git a/SCons/Tool/ninja/__init__.py b/SCons/Tool/ninja/__init__.py index 04a7abb..27a2957 100644 --- a/SCons/Tool/ninja/__init__.py +++ b/SCons/Tool/ninja/__init__.py @@ -33,6 +33,7 @@ import sys import SCons import SCons.Script import SCons.Tool.ninja.Globals +from SCons.Script import Variables from SCons.Script import GetOption from .Globals import NINJA_RULES, NINJA_POOLS, NINJA_CUSTOM_HANDLERS, NINJA_DEFAULT_TARGETS, NINJA_CMDLINE_TARGETS @@ -87,7 +88,7 @@ def ninja_builder(env, target, source): if str(env.get("NINJA_DISABLE_AUTO_RUN")).lower() not in ['1', 'true']: num_jobs = env.get('NINJA_MAX_JOBS', env.GetOption("num_jobs")) - cmd += ['-j' + str(num_jobs)] + NINJA_CMDLINE_TARGETS + cmd += ['-j' + str(num_jobs)] + env.get('NINJA_CMD_ARGS', '').split() + NINJA_CMDLINE_TARGETS print(f"ninja will be run with command line targets: {' '.join(NINJA_CMDLINE_TARGETS)}") print("Executing:", str(' '.join(cmd))) @@ -185,6 +186,15 @@ def generate(env): env["NINJA_DISABLE_AUTO_RUN"] = env.get("NINJA_DISABLE_AUTO_RUN", GetOption('disable_execute_ninja')) env["NINJA_FILE_NAME"] = env.get("NINJA_FILE_NAME", "build.ninja") + if env.get("NINJA_CMD_ARGS") is not None: + env["NINJA_CMD_ARGS"] = env.get("NINJA_CMD_ARGS") + else: + vars = Variables() + vars.Add("NINJA_CMD_ARGS") + var_env = env.Clone() + vars.Update(var_env) + env["NINJA_CMD_ARGS"] = var_env.get("NINJA_CMD_ARGS", '') + # Add the Ninja builder. always_exec_ninja_action = AlwaysExecAction(ninja_builder, {}) ninja_builder_obj = SCons.Builder.Builder(action=always_exec_ninja_action, diff --git a/SCons/Tool/ninja/ninja.xml b/SCons/Tool/ninja/ninja.xml index 6b247d0..0929684 100644 --- a/SCons/Tool/ninja/ninja.xml +++ b/SCons/Tool/ninja/ninja.xml @@ -77,7 +77,7 @@ See its __doc__ string for a discussion of the format. IMPLICIT_COMMAND_DEPENDENCIES NINJA_SCONS_DAEMON_KEEP_ALIVE NINJA_SCONS_DAEMON_PORT - + NINJA_CMD_ARGS @@ -395,5 +395,14 @@ python -m pip install ninja + + + + A string which will pass arguments through SCons to the ninja command when scons executes ninja. + Has no effect if &cv-NINJA_DISABLE_AUTO_RUN; is set. + + + + diff --git a/test/ninja/generate_and_build.py b/test/ninja/generate_and_build.py index 91be108..83b7387 100644 --- a/test/ninja/generate_and_build.py +++ b/test/ninja/generate_and_build.py @@ -49,10 +49,11 @@ test.dir_fixture('ninja-fixture') test.file_fixture('ninja_test_sconscripts/sconstruct_generate_and_build', 'SConstruct') # generate simple build -test.run(stdout=None) +test.run(stdout=None, arguments='NINJA_CMD_ARGS=-v') test.must_contain_all_lines(test.stdout(), ['Generating: build.ninja']) test.must_contain_all(test.stdout(), 'Executing:') test.must_contain_all(test.stdout(), 'ninja%(_exe)s -f' % locals()) +test.must_contain_all(test.stdout(), ' -j1 -v') test.run(program=test.workpath('foo' + _exe), stdout="foo.c") # clean build and ninja files -- cgit v0.12