-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ninja generation tool - experimental version #3642
Merged
+4,453
−639
Merged
Changes from 162 commits
Commits
Show all changes
167 commits
Select commit
Hold shift + click to select a range
cc6a52f
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic d61f256
updated to ninja-next, added some small fixes, and added simple test
dmoody256 d6ea93a
added some more test and update ninja tool to handle commands
dmoody256 7643726
update to pass import.py test and support multiple environments
dmoody256 d7626f2
added more test, including ninja speed test
dmoody256 ec8c313
fixed sider issues
dmoody256 6eb1818
update tests to work on windows, added some environment support for w…
dmoody256 234143d
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 c111cef
is link should use the base nodes lstat instead of local fs stat
dmoody256 82395cb
removed NINJA_SYNTAX completely
dmoody256 e50f080
removed old sconscript changes
dmoody256 5d4b169
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 2cd3d8f
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 71a64aa
update to build godot
dmoody256 017d73a
revert ninja install requirement
dmoody256 6dae389
handle files which are not file or alias by reinvoking scons
dmoody256 5eb70dd
updated with some changes from latest mongodb version:
dmoody256 d2ddf4a
fixed sider issues
dmoody256 142adbe
updated warning to the latest API
dmoody256 3471412
Sync with mongo ninja file
dmoody256 4b8406b
Update ninja to new scons layout
dmoody256 3f66125
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic b5e71b1
updated to ninja-next, added some small fixes, and added simple test
dmoody256 237a2e6
added some more test and update ninja tool to handle commands
dmoody256 9a8adf1
update to pass import.py test and support multiple environments
dmoody256 b9a2711
update CI to install ninja pypi package
dmoody256 30f7c82
added more test, including ninja speed test
dmoody256 4f37786
fixed sider issues
dmoody256 ae9161b
update tests to work on windows, added some environment support for w…
dmoody256 d8a4fed
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 80d6c25
is link should use the base nodes lstat instead of local fs stat
dmoody256 3fa4902
removed NINJA_SYNTAX completely
dmoody256 ac7b133
removed old sconscript changes
dmoody256 57a67bb
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 97cb0e6
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 4fc4d2e
update to build godot
dmoody256 03e57a5
revert ninja install requirement
dmoody256 4b95861
handle files which are not file or alias by reinvoking scons
dmoody256 51c10b6
updated with some changes from latest mongodb version:
dmoody256 b683911
fixed sider issues
dmoody256 cc1ce35
updated warning to the latest API
dmoody256 7f72e3a
Sync with mongo ninja file
dmoody256 b6bd880
Update ninja to new scons layout
dmoody256 c887599
Fix int function not returning int value
bdbaddog 3fc1e82
Refactor ninja -> module, change NINJA_BIN -> NINJA
bdbaddog 9edbe3b
refactor test a bit, explicitly use ninja found by test framework
bdbaddog 8ca8f71
remove f-string to retain py3.5 compatibility
bdbaddog 785438e
can't name module ninja as it will conflict with the non-SCons ninja …
bdbaddog cd738f8
refactor initiazation state variable to be more module specific
bdbaddog 046e37f
Fix ninja tool rules for macos/ar for static libs to skip response f…
bdbaddog b805e2d
[ci skip] Initial doc structure added
bdbaddog 8cefb50
Incremental checkin. Fleshing out the various env vars used by ninja …
bdbaddog 49590e2
Fix path to SCons/Docbooks style files. Add some content. Still a WIP
bdbaddog b6fc959
[ci skip] fix copyright header
bdbaddog 5092eef
Add API to see if a node has a given attribute stored in node.attributes
bdbaddog fb554f6
Incremental update with code reorganization. Currently broken. Some d…
bdbaddog f5315e8
add sconstest.skip to file fixture dir for ninja system tests
bdbaddog 5972f95
fix broken target check in ninja_execute. It was improperly adding al…
bdbaddog 0d77bc2
address sider issues. Also update copyright text to current version
bdbaddog edf9643
Continue fixing sider complaints.
bdbaddog 93ad3b1
more sider fixes
bdbaddog 6cf598e
fix sider issue
bdbaddog adb3cb2
Incremental checkin. Functionality restored after refactor broke it.
bdbaddog 70b783c
Address sider issues
bdbaddog 791e793
Fix ninja.xml syntax error
bdbaddog 1cb4dc8
No need to have ninja.py which just references ninjaCommon, rename pa…
bdbaddog 8fa2fe1
Updated from MongoDB commit: https://github.com/mongodb/mongo/commit/…
bdbaddog d9a3a47
Add --experimental=ninja
bdbaddog 0bc7e21
Gate ninja tool being initialized by --experimental=ninja
bdbaddog 6437d84
update tests to use SetOption('experimental','ninja')
bdbaddog 908f5eb
fix sider complaint
bdbaddog 3df3a4f
switch to using SCons.Node.SConscriptNodes to get list of sconscripts…
bdbaddog 9e5a766
Quiet sider complaint
bdbaddog 08ea935
Continue refactor. Simplify __init__, and move logic to reasonably na…
bdbaddog 548d1ff
Merge branch 'master' into ninja-generation
bdbaddog bd30cb0
Fix sider complaints
bdbaddog b4c7a09
Merge branch 'ninja-generation' of github.com:dmoody256/scons into ni…
bdbaddog ceba1ff
Address mwichmann's comments on PR. Mostly doc and a few import relat…
bdbaddog 0a80633
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic 4b1efb9
updated to ninja-next, added some small fixes, and added simple test
dmoody256 a242c6c
added some more test and update ninja tool to handle commands
dmoody256 ef73084
update to pass import.py test and support multiple environments
dmoody256 bdf6f50
added more test, including ninja speed test
dmoody256 dd17dd4
fixed sider issues
dmoody256 d2a46f8
update tests to work on windows, added some environment support for w…
dmoody256 8450dc1
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 c342e53
is link should use the base nodes lstat instead of local fs stat
dmoody256 ed07dc9
removed NINJA_SYNTAX completely
dmoody256 ef4413d
removed old sconscript changes
dmoody256 e6c20b3
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 05e9acc
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 4b7ddc9
update to build godot
dmoody256 c6764c5
revert ninja install requirement
dmoody256 df31cad
handle files which are not file or alias by reinvoking scons
dmoody256 5eb4b76
updated with some changes from latest mongodb version:
dmoody256 53758dc
fixed sider issues
dmoody256 492b34c
updated warning to the latest API
dmoody256 5f75843
Sync with mongo ninja file
dmoody256 b9d9518
Update ninja to new scons layout
dmoody256 366e83d
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic d9c27b8
updated to ninja-next, added some small fixes, and added simple test
dmoody256 c715e94
added some more test and update ninja tool to handle commands
dmoody256 b7bf996
update to pass import.py test and support multiple environments
dmoody256 13aafe5
update CI to install ninja pypi package
dmoody256 aa38ad5
added more test, including ninja speed test
dmoody256 f901137
fixed sider issues
dmoody256 1c77822
update tests to work on windows, added some environment support for w…
dmoody256 c2fda14
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 cb94dc1
is link should use the base nodes lstat instead of local fs stat
dmoody256 ac0bc43
removed NINJA_SYNTAX completely
dmoody256 53fdf4f
removed old sconscript changes
dmoody256 60c6d88
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 d1092d6
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 d63a2d6
update to build godot
dmoody256 e7fc941
revert ninja install requirement
dmoody256 ea80011
handle files which are not file or alias by reinvoking scons
dmoody256 e9d0fd6
updated with some changes from latest mongodb version:
dmoody256 830641d
fixed sider issues
dmoody256 9414687
updated warning to the latest API
dmoody256 00c20a8
Sync with mongo ninja file
dmoody256 5206ffc
Update ninja to new scons layout
dmoody256 987c7a3
Fix int function not returning int value
bdbaddog 0f49632
Refactor ninja -> module, change NINJA_BIN -> NINJA
bdbaddog 400b3a3
refactor test a bit, explicitly use ninja found by test framework
bdbaddog f3b33c8
remove f-string to retain py3.5 compatibility
bdbaddog ef2cdf1
can't name module ninja as it will conflict with the non-SCons ninja …
bdbaddog e7f455f
refactor initiazation state variable to be more module specific
bdbaddog 37ae2b8
Fix ninja tool rules for macos/ar for static libs to skip response f…
bdbaddog a7f25ea
[ci skip] Initial doc structure added
bdbaddog 1af172f
Incremental checkin. Fleshing out the various env vars used by ninja …
bdbaddog 1c56150
Fix path to SCons/Docbooks style files. Add some content. Still a WIP
bdbaddog 8756657
[ci skip] fix copyright header
bdbaddog b4786e1
Add API to see if a node has a given attribute stored in node.attributes
bdbaddog 1ddb0bd
Incremental update with code reorganization. Currently broken. Some d…
bdbaddog ccc5e26
add sconstest.skip to file fixture dir for ninja system tests
bdbaddog 41e4859
fix broken target check in ninja_execute. It was improperly adding al…
bdbaddog 554a02f
address sider issues. Also update copyright text to current version
bdbaddog 6da2859
Continue fixing sider complaints.
bdbaddog a368c73
more sider fixes
bdbaddog a40215b
fix sider issue
bdbaddog 5c871e3
Incremental checkin. Functionality restored after refactor broke it.
bdbaddog 07119cd
Address sider issues
bdbaddog 1d456a8
Fix ninja.xml syntax error
bdbaddog 9651189
No need to have ninja.py which just references ninjaCommon, rename pa…
bdbaddog a9783b0
Updated from MongoDB commit: https://github.com/mongodb/mongo/commit/…
bdbaddog f0035f7
Add --experimental=ninja
bdbaddog 1810449
Gate ninja tool being initialized by --experimental=ninja
bdbaddog b20646d
update tests to use SetOption('experimental','ninja')
bdbaddog f8415ba
fix sider complaint
bdbaddog 3ed0272
switch to using SCons.Node.SConscriptNodes to get list of sconscripts…
bdbaddog 0a430bb
Quiet sider complaint
bdbaddog 31e1abf
Continue refactor. Simplify __init__, and move logic to reasonably na…
bdbaddog 764ddca
Fix sider complaints
bdbaddog 208eb11
Address mwichmann's comments on PR. Mostly doc and a few import relat…
bdbaddog a20a886
updates to get working with mongodb build
dmoody256 a9bf0d4
update from mongodb for limiting ninja max jobs from commit: 0b620c24…
dmoody256 2a78d0b
Merge remote-tracking branch 'dmoody/ninja-generation' into ninja-gen…
bdbaddog 76aa3ea
resolve sider complaint
bdbaddog c80bd2f
rename NINJA_BUILDDIR -> NINJA_DIR
bdbaddog a262a13
Rename DISABLE_AUTO_NINJA -> NINJA_DISABLE_AUTO_RUN
bdbaddog 2889a57
incremental doc updates to indicate experimental state of ninja builder
bdbaddog f359308
Updates to docs to indicate experimental status
bdbaddog 24ec1b3
Resolve sider issue
bdbaddog 91364b3
add ninja entity and wrap all ninja.build with <filename> tags
bdbaddog 20b5f24
Fix broken markup, regenerate files
bdbaddog 6c08f31
Add info to CHANGES.txt on ninja
bdbaddog 0b866fc
Merge branch 'master' into ninja-generation
bdbaddog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# MIT License | ||
# | ||
# Copyright The SCons Foundation | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining | ||
# a copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and to | ||
# permit persons to whom the Software is furnished to do so, subject to | ||
# the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import SCons.Action | ||
|
||
NINJA_RULES = "__NINJA_CUSTOM_RULES" | ||
NINJA_POOLS = "__NINJA_CUSTOM_POOLS" | ||
NINJA_CUSTOM_HANDLERS = "__NINJA_CUSTOM_HANDLERS" | ||
NINJA_BUILD = "NINJA_BUILD" | ||
NINJA_WHEREIS_MEMO = {} | ||
NINJA_STAT_MEMO = {} | ||
__NINJA_RULE_MAPPING = {} | ||
|
||
|
||
# These are the types that get_command can do something with | ||
COMMAND_TYPES = ( | ||
SCons.Action.CommandAction, | ||
SCons.Action.CommandGeneratorAction, | ||
) | ||
ninja_builder_initialized = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
# MIT License | ||
# | ||
# Copyright The SCons Foundation | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining | ||
# a copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and to | ||
# permit persons to whom the Software is furnished to do so, subject to | ||
# the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | ||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
import shlex | ||
import textwrap | ||
|
||
import SCons | ||
from SCons.Tool.ninja import NINJA_CUSTOM_HANDLERS, NINJA_RULES, NINJA_POOLS | ||
from SCons.Tool.ninja.Globals import __NINJA_RULE_MAPPING | ||
from SCons.Tool.ninja.Utils import get_targets_sources, get_dependencies, get_order_only, get_outputs, get_inputs, \ | ||
get_rule, get_path, generate_command, get_command_env, get_comstr | ||
|
||
|
||
def register_custom_handler(env, name, handler): | ||
"""Register a custom handler for SCons function actions.""" | ||
env[NINJA_CUSTOM_HANDLERS][name] = handler | ||
|
||
|
||
def register_custom_rule_mapping(env, pre_subst_string, rule): | ||
"""Register a function to call for a given rule.""" | ||
SCons.Tool.ninja.Globals.__NINJA_RULE_MAPPING[pre_subst_string] = rule | ||
|
||
|
||
def register_custom_rule(env, rule, command, description="", deps=None, pool=None, use_depfile=False, use_response_file=False, response_file_content="$rspc"): | ||
"""Allows specification of Ninja rules from inside SCons files.""" | ||
rule_obj = { | ||
"command": command, | ||
"description": description if description else "{} $out".format(rule), | ||
} | ||
|
||
if use_depfile: | ||
rule_obj["depfile"] = os.path.join(get_path(env['NINJA_DIR']), '$out.depfile') | ||
|
||
if deps is not None: | ||
rule_obj["deps"] = deps | ||
|
||
if pool is not None: | ||
rule_obj["pool"] = pool | ||
|
||
if use_response_file: | ||
rule_obj["rspfile"] = "$out.rsp" | ||
rule_obj["rspfile_content"] = response_file_content | ||
|
||
env[NINJA_RULES][rule] = rule_obj | ||
|
||
|
||
def register_custom_pool(env, pool, size): | ||
"""Allows the creation of custom Ninja pools""" | ||
env[NINJA_POOLS][pool] = size | ||
|
||
|
||
def set_build_node_callback(env, node, callback): | ||
if not node.is_conftest(): | ||
node.attributes.ninja_build_callback = callback | ||
|
||
|
||
def get_generic_shell_command(env, node, action, targets, sources, executor=None): | ||
return ( | ||
"GENERATED_CMD", | ||
{ | ||
"cmd": generate_command(env, node, action, targets, sources, executor=executor), | ||
"env": get_command_env(env), | ||
}, | ||
# Since this function is a rule mapping provider, it must return a list of dependencies, | ||
# and usually this would be the path to a tool, such as a compiler, used for this rule. | ||
# However this function is to generic to be able to reliably extract such deps | ||
# from the command, so we return a placeholder empty list. It should be noted that | ||
# generally this function will not be used solely and is more like a template to generate | ||
# the basics for a custom provider which may have more specific options for a provider | ||
# function for a custom NinjaRuleMapping. | ||
[] | ||
) | ||
|
||
|
||
def CheckNinjaCompdbExpand(env, context): | ||
""" Configure check testing if ninja's compdb can expand response files""" | ||
|
||
# TODO: When would this be false? | ||
context.Message('Checking if ninja compdb can expand response files... ') | ||
ret, output = context.TryAction( | ||
action='ninja -f $SOURCE -t compdb -x CMD_RSP > $TARGET', | ||
extension='.ninja', | ||
text=textwrap.dedent(""" | ||
rule CMD_RSP | ||
command = $cmd @$out.rsp > fake_output.txt | ||
description = Building $out | ||
rspfile = $out.rsp | ||
rspfile_content = $rspc | ||
build fake_output.txt: CMD_RSP fake_input.txt | ||
cmd = echo | ||
pool = console | ||
rspc = "test" | ||
""")) | ||
result = '@fake_output.txt.rsp' not in output | ||
context.Result(result) | ||
return result | ||
|
||
|
||
def get_command(env, node, action): # pylint: disable=too-many-branches | ||
"""Get the command to execute for node.""" | ||
if node.env: | ||
sub_env = node.env | ||
else: | ||
sub_env = env | ||
executor = node.get_executor() | ||
tlist, slist = get_targets_sources(node) | ||
|
||
# Generate a real CommandAction | ||
if isinstance(action, SCons.Action.CommandGeneratorAction): | ||
# pylint: disable=protected-access | ||
action = action._generate(tlist, slist, sub_env, 1, executor=executor) | ||
|
||
variables = {} | ||
|
||
comstr = get_comstr(sub_env, action, tlist, slist) | ||
if not comstr: | ||
return None | ||
|
||
provider = __NINJA_RULE_MAPPING.get(comstr, get_generic_shell_command) | ||
rule, variables, provider_deps = provider(sub_env, node, action, tlist, slist, executor=executor) | ||
|
||
# Get the dependencies for all targets | ||
implicit = list({dep for tgt in tlist for dep in get_dependencies(tgt)}) | ||
|
||
# Now add in the other dependencies related to the command, | ||
# e.g. the compiler binary. The ninja rule can be user provided so | ||
# we must do some validation to resolve the dependency path for ninja. | ||
for provider_dep in provider_deps: | ||
|
||
provider_dep = sub_env.subst(provider_dep) | ||
if not provider_dep: | ||
continue | ||
|
||
# If the tool is a node, then SCons will resolve the path later, if its not | ||
# a node then we assume it generated from build and make sure it is existing. | ||
if isinstance(provider_dep, SCons.Node.Node) or os.path.exists(provider_dep): | ||
implicit.append(provider_dep) | ||
continue | ||
|
||
# in some case the tool could be in the local directory and be supplied without the ext | ||
# such as in windows, so append the executable suffix and check. | ||
prog_suffix = sub_env.get('PROGSUFFIX', '') | ||
provider_dep_ext = provider_dep if provider_dep.endswith(prog_suffix) else provider_dep + prog_suffix | ||
if os.path.exists(provider_dep_ext): | ||
implicit.append(provider_dep_ext) | ||
continue | ||
|
||
# Many commands will assume the binary is in the path, so | ||
# we accept this as a possible input from a given command. | ||
|
||
provider_dep_abspath = sub_env.WhereIs(provider_dep) or sub_env.WhereIs(provider_dep, path=os.environ["PATH"]) | ||
if provider_dep_abspath: | ||
implicit.append(provider_dep_abspath) | ||
continue | ||
|
||
# Possibly these could be ignore and the build would still work, however it may not always | ||
# rebuild correctly, so we hard stop, and force the user to fix the issue with the provided | ||
# ninja rule. | ||
raise Exception("Could not resolve path for %s dependency on node '%s'" % (provider_dep, node)) | ||
|
||
ninja_build = { | ||
"order_only": get_order_only(node), | ||
"outputs": get_outputs(node), | ||
"inputs": get_inputs(node), | ||
"implicit": implicit, | ||
"rule": get_rule(node, rule), | ||
"variables": variables, | ||
} | ||
|
||
# Don't use sub_env here because we require that NINJA_POOL be set | ||
# on a per-builder call basis to prevent accidental strange | ||
# behavior like env['NINJA_POOL'] = 'console' and sub_env can be | ||
# the global Environment object if node.env is None. | ||
# Example: | ||
# | ||
# Allowed: | ||
# | ||
# env.Command("ls", NINJA_POOL="ls_pool") | ||
# | ||
# Not allowed and ignored: | ||
# | ||
# env["NINJA_POOL"] = "ls_pool" | ||
# env.Command("ls") | ||
# | ||
# TODO: Why not alloe env['NINJA_POOL'] ? (bdbaddog) | ||
if node.env and node.env.get("NINJA_POOL", None) is not None: | ||
ninja_build["pool"] = node.env["NINJA_POOL"] | ||
|
||
return ninja_build | ||
|
||
|
||
def gen_get_response_file_command(env, rule, tool, tool_is_dynamic=False, custom_env={}): | ||
"""Generate a response file command provider for rule name.""" | ||
|
||
# If win32 using the environment with a response file command will cause | ||
# ninja to fail to create the response file. Additionally since these rules | ||
# generally are not piping through cmd.exe /c any environment variables will | ||
# make CreateProcess fail to start. | ||
# | ||
# On POSIX we can still set environment variables even for compile | ||
# commands so we do so. | ||
use_command_env = not env["PLATFORM"] == "win32" | ||
if "$" in tool: | ||
tool_is_dynamic = True | ||
|
||
def get_response_file_command(env, node, action, targets, sources, executor=None): | ||
if hasattr(action, "process"): | ||
cmd_list, _, _ = action.process(targets, sources, env, executor=executor) | ||
cmd_list = [str(c).replace("$", "$$") for c in cmd_list[0]] | ||
else: | ||
command = generate_command( | ||
env, node, action, targets, sources, executor=executor | ||
) | ||
cmd_list = shlex.split(command) | ||
|
||
if tool_is_dynamic: | ||
tool_command = env.subst( | ||
tool, target=targets, source=sources, executor=executor | ||
) | ||
else: | ||
tool_command = tool | ||
|
||
try: | ||
# Add 1 so we always keep the actual tool inside of cmd | ||
tool_idx = cmd_list.index(tool_command) + 1 | ||
except ValueError: | ||
raise Exception( | ||
"Could not find tool {} in {} generated from {}".format( | ||
tool, cmd_list, get_comstr(env, action, targets, sources) | ||
) | ||
) | ||
|
||
cmd, rsp_content = cmd_list[:tool_idx], cmd_list[tool_idx:] | ||
rsp_content = ['"' + rsp_content_item + '"' for rsp_content_item in rsp_content] | ||
rsp_content = " ".join(rsp_content) | ||
|
||
variables = {"rspc": rsp_content, rule: cmd} | ||
if use_command_env: | ||
variables["env"] = get_command_env(env) | ||
|
||
for key, value in custom_env.items(): | ||
variables["env"] += env.subst( | ||
"export %s=%s;" % (key, value), target=targets, source=sources, executor=executor | ||
) + " " | ||
return rule, variables, [tool_command] | ||
|
||
return get_response_file_command |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you intending to leave the two "dummy" names in now there's a real one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Easter eggs are fun?