Skip to content
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
merged 167 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
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 Jan 24, 2020
d61f256
updated to ninja-next, added some small fixes, and added simple test
dmoody256 May 6, 2020
d6ea93a
added some more test and update ninja tool to handle commands
dmoody256 May 6, 2020
7643726
update to pass import.py test and support multiple environments
dmoody256 May 6, 2020
d7626f2
added more test, including ninja speed test
dmoody256 May 7, 2020
ec8c313
fixed sider issues
dmoody256 May 7, 2020
6eb1818
update tests to work on windows, added some environment support for w…
dmoody256 May 8, 2020
234143d
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 May 14, 2020
c111cef
is link should use the base nodes lstat instead of local fs stat
dmoody256 May 14, 2020
82395cb
removed NINJA_SYNTAX completely
dmoody256 May 21, 2020
e50f080
removed old sconscript changes
dmoody256 May 22, 2020
5d4b169
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 Jun 3, 2020
2cd3d8f
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 Jun 3, 2020
71a64aa
update to build godot
dmoody256 Jun 9, 2020
017d73a
revert ninja install requirement
dmoody256 Jun 22, 2020
6dae389
handle files which are not file or alias by reinvoking scons
dmoody256 Jun 26, 2020
5eb70dd
updated with some changes from latest mongodb version:
dmoody256 Jul 20, 2020
d2ddf4a
fixed sider issues
dmoody256 Jul 20, 2020
142adbe
updated warning to the latest API
dmoody256 Jul 20, 2020
3471412
Sync with mongo ninja file
dmoody256 Dec 31, 2020
4b8406b
Update ninja to new scons layout
dmoody256 Dec 31, 2020
3f66125
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic Jan 24, 2020
b5e71b1
updated to ninja-next, added some small fixes, and added simple test
dmoody256 May 6, 2020
237a2e6
added some more test and update ninja tool to handle commands
dmoody256 May 6, 2020
9a8adf1
update to pass import.py test and support multiple environments
dmoody256 May 6, 2020
b9a2711
update CI to install ninja pypi package
dmoody256 May 6, 2020
30f7c82
added more test, including ninja speed test
dmoody256 May 7, 2020
4f37786
fixed sider issues
dmoody256 May 7, 2020
ae9161b
update tests to work on windows, added some environment support for w…
dmoody256 May 8, 2020
d8a4fed
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 May 14, 2020
80d6c25
is link should use the base nodes lstat instead of local fs stat
dmoody256 May 14, 2020
3fa4902
removed NINJA_SYNTAX completely
dmoody256 May 21, 2020
ac7b133
removed old sconscript changes
dmoody256 May 22, 2020
57a67bb
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 Jun 3, 2020
97cb0e6
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 Jun 3, 2020
4fc4d2e
update to build godot
dmoody256 Jun 9, 2020
03e57a5
revert ninja install requirement
dmoody256 Jun 22, 2020
4b95861
handle files which are not file or alias by reinvoking scons
dmoody256 Jun 26, 2020
51c10b6
updated with some changes from latest mongodb version:
dmoody256 Jul 20, 2020
b683911
fixed sider issues
dmoody256 Jul 20, 2020
cc1ce35
updated warning to the latest API
dmoody256 Jul 20, 2020
7f72e3a
Sync with mongo ninja file
dmoody256 Dec 31, 2020
b6bd880
Update ninja to new scons layout
dmoody256 Dec 31, 2020
c887599
Fix int function not returning int value
bdbaddog Jan 27, 2021
3fc1e82
Refactor ninja -> module, change NINJA_BIN -> NINJA
bdbaddog Jan 27, 2021
9edbe3b
refactor test a bit, explicitly use ninja found by test framework
bdbaddog Jan 27, 2021
8ca8f71
remove f-string to retain py3.5 compatibility
bdbaddog Feb 12, 2021
785438e
can't name module ninja as it will conflict with the non-SCons ninja …
bdbaddog Jan 28, 2021
cd738f8
refactor initiazation state variable to be more module specific
bdbaddog Feb 12, 2021
046e37f
Fix ninja tool rules for macos/ar for static libs to skip response f…
bdbaddog Feb 12, 2021
b805e2d
[ci skip] Initial doc structure added
bdbaddog Feb 16, 2021
8cefb50
Incremental checkin. Fleshing out the various env vars used by ninja …
bdbaddog Feb 16, 2021
49590e2
Fix path to SCons/Docbooks style files. Add some content. Still a WIP
bdbaddog Feb 18, 2021
b6fc959
[ci skip] fix copyright header
bdbaddog Mar 15, 2021
5092eef
Add API to see if a node has a given attribute stored in node.attributes
bdbaddog Mar 15, 2021
fb554f6
Incremental update with code reorganization. Currently broken. Some d…
bdbaddog Mar 15, 2021
f5315e8
add sconstest.skip to file fixture dir for ninja system tests
bdbaddog Mar 25, 2021
5972f95
fix broken target check in ninja_execute. It was improperly adding al…
bdbaddog Mar 28, 2021
0d77bc2
address sider issues. Also update copyright text to current version
bdbaddog Mar 28, 2021
edf9643
Continue fixing sider complaints.
bdbaddog Mar 28, 2021
93ad3b1
more sider fixes
bdbaddog Mar 28, 2021
6cf598e
fix sider issue
bdbaddog Mar 28, 2021
adb3cb2
Incremental checkin. Functionality restored after refactor broke it.
bdbaddog Apr 10, 2021
70b783c
Address sider issues
bdbaddog Apr 10, 2021
791e793
Fix ninja.xml syntax error
bdbaddog Apr 11, 2021
1cb4dc8
No need to have ninja.py which just references ninjaCommon, rename pa…
bdbaddog Apr 13, 2021
8fa2fe1
Updated from MongoDB commit: https://github.com/mongodb/mongo/commit/…
bdbaddog Apr 13, 2021
d9a3a47
Add --experimental=ninja
bdbaddog Apr 13, 2021
0bc7e21
Gate ninja tool being initialized by --experimental=ninja
bdbaddog Apr 13, 2021
6437d84
update tests to use SetOption('experimental','ninja')
bdbaddog Apr 13, 2021
908f5eb
fix sider complaint
bdbaddog Apr 13, 2021
3df3a4f
switch to using SCons.Node.SConscriptNodes to get list of sconscripts…
bdbaddog Apr 13, 2021
9e5a766
Quiet sider complaint
bdbaddog May 18, 2021
08ea935
Continue refactor. Simplify __init__, and move logic to reasonably na…
bdbaddog May 24, 2021
548d1ff
Merge branch 'master' into ninja-generation
bdbaddog May 24, 2021
bd30cb0
Fix sider complaints
bdbaddog May 24, 2021
b4c7a09
Merge branch 'ninja-generation' of github.com:dmoody256/scons into ni…
bdbaddog May 24, 2021
ceba1ff
Address mwichmann's comments on PR. Mostly doc and a few import relat…
bdbaddog May 30, 2021
0a80633
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic Jan 24, 2020
4b1efb9
updated to ninja-next, added some small fixes, and added simple test
dmoody256 May 6, 2020
a242c6c
added some more test and update ninja tool to handle commands
dmoody256 May 6, 2020
ef73084
update to pass import.py test and support multiple environments
dmoody256 May 6, 2020
bdf6f50
added more test, including ninja speed test
dmoody256 May 7, 2020
dd17dd4
fixed sider issues
dmoody256 May 7, 2020
d2a46f8
update tests to work on windows, added some environment support for w…
dmoody256 May 8, 2020
8450dc1
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 May 14, 2020
c342e53
is link should use the base nodes lstat instead of local fs stat
dmoody256 May 14, 2020
ed07dc9
removed NINJA_SYNTAX completely
dmoody256 May 21, 2020
ef4413d
removed old sconscript changes
dmoody256 May 22, 2020
e6c20b3
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 Jun 3, 2020
05e9acc
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 Jun 3, 2020
4b7ddc9
update to build godot
dmoody256 Jun 9, 2020
c6764c5
revert ninja install requirement
dmoody256 Jun 22, 2020
df31cad
handle files which are not file or alias by reinvoking scons
dmoody256 Jun 26, 2020
5eb4b76
updated with some changes from latest mongodb version:
dmoody256 Jul 20, 2020
53758dc
fixed sider issues
dmoody256 Jul 20, 2020
492b34c
updated warning to the latest API
dmoody256 Jul 20, 2020
5f75843
Sync with mongo ninja file
dmoody256 Dec 31, 2020
b9d9518
Update ninja to new scons layout
dmoody256 Dec 31, 2020
366e83d
[WIP] write a tool to generate build.ninja files from SCons
chasinglogic Jan 24, 2020
d9c27b8
updated to ninja-next, added some small fixes, and added simple test
dmoody256 May 6, 2020
c715e94
added some more test and update ninja tool to handle commands
dmoody256 May 6, 2020
b7bf996
update to pass import.py test and support multiple environments
dmoody256 May 6, 2020
13aafe5
update CI to install ninja pypi package
dmoody256 May 6, 2020
aa38ad5
added more test, including ninja speed test
dmoody256 May 7, 2020
f901137
fixed sider issues
dmoody256 May 7, 2020
1c77822
update tests to work on windows, added some environment support for w…
dmoody256 May 8, 2020
c2fda14
used different method for pushing ninja file to bottom of DAG, use im…
dmoody256 May 14, 2020
cb94dc1
is link should use the base nodes lstat instead of local fs stat
dmoody256 May 14, 2020
ac0bc43
removed NINJA_SYNTAX completely
dmoody256 May 21, 2020
53fdf4f
removed old sconscript changes
dmoody256 May 22, 2020
60c6d88
merge commit a7541c60e5904e7deafdedf5bb040cc8924ac7d3 from https://gi…
dmoody256 Jun 3, 2020
d1092d6
merge commit 18cbf0d581162b2d15d66577b1fe08fe22006699 from https://gi…
dmoody256 Jun 3, 2020
d63a2d6
update to build godot
dmoody256 Jun 9, 2020
e7fc941
revert ninja install requirement
dmoody256 Jun 22, 2020
ea80011
handle files which are not file or alias by reinvoking scons
dmoody256 Jun 26, 2020
e9d0fd6
updated with some changes from latest mongodb version:
dmoody256 Jul 20, 2020
830641d
fixed sider issues
dmoody256 Jul 20, 2020
9414687
updated warning to the latest API
dmoody256 Jul 20, 2020
00c20a8
Sync with mongo ninja file
dmoody256 Dec 31, 2020
5206ffc
Update ninja to new scons layout
dmoody256 Dec 31, 2020
987c7a3
Fix int function not returning int value
bdbaddog Jan 27, 2021
0f49632
Refactor ninja -> module, change NINJA_BIN -> NINJA
bdbaddog Jan 27, 2021
400b3a3
refactor test a bit, explicitly use ninja found by test framework
bdbaddog Jan 27, 2021
f3b33c8
remove f-string to retain py3.5 compatibility
bdbaddog Feb 12, 2021
ef2cdf1
can't name module ninja as it will conflict with the non-SCons ninja …
bdbaddog Jan 28, 2021
e7f455f
refactor initiazation state variable to be more module specific
bdbaddog Feb 12, 2021
37ae2b8
Fix ninja tool rules for macos/ar for static libs to skip response f…
bdbaddog Feb 12, 2021
a7f25ea
[ci skip] Initial doc structure added
bdbaddog Feb 16, 2021
1af172f
Incremental checkin. Fleshing out the various env vars used by ninja …
bdbaddog Feb 16, 2021
1c56150
Fix path to SCons/Docbooks style files. Add some content. Still a WIP
bdbaddog Feb 18, 2021
8756657
[ci skip] fix copyright header
bdbaddog Mar 15, 2021
b4786e1
Add API to see if a node has a given attribute stored in node.attributes
bdbaddog Mar 15, 2021
1ddb0bd
Incremental update with code reorganization. Currently broken. Some d…
bdbaddog Mar 15, 2021
ccc5e26
add sconstest.skip to file fixture dir for ninja system tests
bdbaddog Mar 25, 2021
41e4859
fix broken target check in ninja_execute. It was improperly adding al…
bdbaddog Mar 28, 2021
554a02f
address sider issues. Also update copyright text to current version
bdbaddog Mar 28, 2021
6da2859
Continue fixing sider complaints.
bdbaddog Mar 28, 2021
a368c73
more sider fixes
bdbaddog Mar 28, 2021
a40215b
fix sider issue
bdbaddog Mar 28, 2021
5c871e3
Incremental checkin. Functionality restored after refactor broke it.
bdbaddog Apr 10, 2021
07119cd
Address sider issues
bdbaddog Apr 10, 2021
1d456a8
Fix ninja.xml syntax error
bdbaddog Apr 11, 2021
9651189
No need to have ninja.py which just references ninjaCommon, rename pa…
bdbaddog Apr 13, 2021
a9783b0
Updated from MongoDB commit: https://github.com/mongodb/mongo/commit/…
bdbaddog Apr 13, 2021
f0035f7
Add --experimental=ninja
bdbaddog Apr 13, 2021
1810449
Gate ninja tool being initialized by --experimental=ninja
bdbaddog Apr 13, 2021
b20646d
update tests to use SetOption('experimental','ninja')
bdbaddog Apr 13, 2021
f8415ba
fix sider complaint
bdbaddog Apr 13, 2021
3ed0272
switch to using SCons.Node.SConscriptNodes to get list of sconscripts…
bdbaddog Apr 13, 2021
0a430bb
Quiet sider complaint
bdbaddog May 18, 2021
31e1abf
Continue refactor. Simplify __init__, and move logic to reasonably na…
bdbaddog May 24, 2021
764ddca
Fix sider complaints
bdbaddog May 24, 2021
208eb11
Address mwichmann's comments on PR. Mostly doc and a few import relat…
bdbaddog May 30, 2021
a20a886
updates to get working with mongodb build
dmoody256 Jun 2, 2021
a9bf0d4
update from mongodb for limiting ninja max jobs from commit: 0b620c24…
dmoody256 Jun 2, 2021
2a78d0b
Merge remote-tracking branch 'dmoody/ninja-generation' into ninja-gen…
bdbaddog Jun 7, 2021
76aa3ea
resolve sider complaint
bdbaddog Jun 7, 2021
c80bd2f
rename NINJA_BUILDDIR -> NINJA_DIR
bdbaddog Jun 24, 2021
a262a13
Rename DISABLE_AUTO_NINJA -> NINJA_DISABLE_AUTO_RUN
bdbaddog Jun 24, 2021
2889a57
incremental doc updates to indicate experimental state of ninja builder
bdbaddog Jul 7, 2021
f359308
Updates to docs to indicate experimental status
bdbaddog Jul 8, 2021
24ec1b3
Resolve sider issue
bdbaddog Jul 9, 2021
91364b3
add ninja entity and wrap all ninja.build with <filename> tags
bdbaddog Jul 9, 2021
20b5f24
Fix broken markup, regenerate files
bdbaddog Jul 9, 2021
6c08f31
Add info to CHANGES.txt on ninja
bdbaddog Jul 9, 2021
0b866fc
Merge branch 'master' into ninja-generation
bdbaddog Jul 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SCons/Node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,11 @@ def is_conftest(self):
return False
return True

def check_attributes(self, name):
""" Simple API to check if the node.attributes for name has been set"""
return getattr(getattr(self, "attributes", None), name, None)


def alter_targets(self):
"""Return a list of alternate targets for this Node.
"""
Expand Down
3 changes: 2 additions & 1 deletion SCons/SConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def TryBuild(self, builder, text=None, extension=""):

f = "_".join([f, textSig, textSigCounter])
textFile = self.confdir.File(f + extension)
self._set_conftest_node(sourcetext)
self._set_conftest_node(textFile)
textFileNode = self.env.SConfSourceBuilder(target=textFile,
source=sourcetext)
nodesToBeBuilt.extend(textFileNode)
Expand All @@ -625,6 +625,7 @@ def TryBuild(self, builder, text=None, extension=""):
pref = self.env.subst( builder.builder.prefix )
suff = self.env.subst( builder.builder.suffix )
target = self.confdir.File(pref + f + suff)
self._set_conftest_node(target)

try:
# Slide our wrapper into the construction environment as
Expand Down
4 changes: 2 additions & 2 deletions SCons/Script/SConsOptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

diskcheck_all = SCons.Node.FS.diskcheck_types()

experimental_features = {'warp_speed', 'transporter'}
experimental_features = {'warp_speed', 'transporter', 'ninja'}
Copy link
Collaborator

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?

Copy link
Contributor

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?



def diskcheck_convert(value):
Expand Down Expand Up @@ -749,7 +749,7 @@ def experimental_callback(option, opt, value, parser):
op.add_option('--experimental',
dest='experimental',
action='callback',
default={}, # empty set
default=set(), # empty set
type='str',
# choices=experimental_options+experimental_features,
callback =experimental_callback,
Expand Down
40 changes: 40 additions & 0 deletions SCons/Tool/ninja/Globals.py
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
268 changes: 268 additions & 0 deletions SCons/Tool/ninja/Methods.py
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
Loading