Utils.py (SCons-4.3.0) | : | Utils.py (SCons-4.4.0) | ||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | |||
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | |||
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
import os | import os | |||
import shutil | import shutil | |||
from os.path import join as joinpath | from os.path import join as joinpath | |||
from collections import OrderedDict | ||||
import SCons | import SCons | |||
from SCons.Action import get_default_ENV, _string_from_cmd_list | from SCons.Action import get_default_ENV, _string_from_cmd_list | |||
from SCons.Script import AddOption | from SCons.Script import AddOption | |||
from SCons.Util import is_List, flatten_sequence | from SCons.Util import is_List, flatten_sequence | |||
class NinjaExperimentalWarning(SCons.Warnings.WarningOnByDefault): | ||||
pass | ||||
def ninja_add_command_line_options(): | def ninja_add_command_line_options(): | |||
""" | """ | |||
Add additional command line arguments to SCons specific to the ninja tool | Add additional command line arguments to SCons specific to the ninja tool | |||
""" | """ | |||
AddOption('--disable-execute-ninja', | AddOption('--disable-execute-ninja', | |||
dest='disable_execute_ninja', | dest='disable_execute_ninja', | |||
metavar='BOOL', | metavar='BOOL', | |||
action="store_true", | action="store_true", | |||
default=False, | default=False, | |||
help='Disable automatically running ninja after scons') | help='Disable automatically running ninja after scons') | |||
AddOption('--disable-ninja', | AddOption('--disable-ninja', | |||
dest='disable_ninja', | dest='disable_ninja', | |||
metavar='BOOL', | metavar='BOOL', | |||
action="store_true", | action="store_true", | |||
default=False, | default=False, | |||
help='Disable ninja generation and build with scons even if tool i s loaded. '+ | help='Disable ninja generation and build with scons even if tool i s loaded. '+ | |||
'Also used by ninja to build targets which only scons can bui ld.') | 'Also used by ninja to build targets which only scons can bui ld.') | |||
AddOption('--skip-ninja-regen', | ||||
dest='skip_ninja_regen', | ||||
metavar='BOOL', | ||||
action="store_true", | ||||
default=False, | ||||
help='Allow scons to skip regeneration of the ninja file and resta | ||||
rting of the daemon. ' + | ||||
'Care should be taken in cases where Glob is in use or SCons | ||||
generated files are used in ' + | ||||
'command lines.') | ||||
def is_valid_dependent_node(node): | def is_valid_dependent_node(node): | |||
""" | """ | |||
Return True if node is not an alias or is an alias that has children | Return True if node is not an alias or is an alias that has children | |||
This prevents us from making phony targets that depend on other | This prevents us from making phony targets that depend on other | |||
phony targets that will never have an associated ninja build | phony targets that will never have an associated ninja build | |||
target. | target. | |||
We also have to specify that it's an alias when doing the builder | We also have to specify that it's an alias when doing the builder | |||
check because some nodes (like src files) won't have builders but | check because some nodes (like src files) won't have builders but | |||
skipping to change at line 242 | skipping to change at line 255 | |||
def ninja_noop(*_args, **_kwargs): | def ninja_noop(*_args, **_kwargs): | |||
""" | """ | |||
A general purpose no-op function. | A general purpose no-op function. | |||
There are many things that happen in SCons that we don't need and | There are many things that happen in SCons that we don't need and | |||
also don't return anything. We use this to disable those functions | also don't return anything. We use this to disable those functions | |||
instead of creating multiple definitions of the same thing. | instead of creating multiple definitions of the same thing. | |||
""" | """ | |||
return None | return None | |||
def get_command_env(env): | def ninja_recursive_sorted_dict(build): | |||
sorted_dict = OrderedDict() | ||||
for key, val in sorted(build.items()): | ||||
if isinstance(val, dict): | ||||
sorted_dict[key] = ninja_recursive_sorted_dict(val) | ||||
else: | ||||
sorted_dict[key] = val | ||||
return sorted_dict | ||||
def ninja_sorted_build(ninja, **build): | ||||
sorted_dict = ninja_recursive_sorted_dict(build) | ||||
ninja.build(**sorted_dict) | ||||
def get_command_env(env, target, source): | ||||
""" | """ | |||
Return a string that sets the environment for any environment variables that | Return a string that sets the environment for any environment variables that | |||
differ between the OS environment and the SCons command ENV. | differ between the OS environment and the SCons command ENV. | |||
It will be compatible with the default shell of the operating system. | It will be compatible with the default shell of the operating system. | |||
""" | """ | |||
try: | try: | |||
return env["NINJA_ENV_VAR_CACHE"] | return env["NINJA_ENV_VAR_CACHE"] | |||
except KeyError: | except KeyError: | |||
pass | pass | |||
# Scan the ENV looking for any keys which do not exist in | # Scan the ENV looking for any keys which do not exist in | |||
# os.environ or differ from it. We assume if it's a new or | # os.environ or differ from it. We assume if it's a new or | |||
# differing key from the process environment then it's | # differing key from the process environment then it's | |||
# important to pass down to commands in the Ninja file. | # important to pass down to commands in the Ninja file. | |||
ENV = get_default_ENV(env) | ENV = SCons.Action._resolve_shell_env(env, target, source) | |||
scons_specified_env = { | scons_specified_env = { | |||
key: value | key: value | |||
for key, value in ENV.items() | for key, value in ENV.items() | |||
# TODO: Remove this filter, unless there's a good reason to keep. SCons' s behavior shouldn't depend on shell's. | # TODO: Remove this filter, unless there's a good reason to keep. SCons' s behavior shouldn't depend on shell's. | |||
if key not in os.environ or os.environ.get(key, None) != value | if key not in os.environ or os.environ.get(key, None) != value | |||
} | } | |||
windows = env["PLATFORM"] == "win32" | windows = env["PLATFORM"] == "win32" | |||
command_env = "" | command_env = "" | |||
for key, value in scons_specified_env.items(): | for key, value in scons_specified_env.items(): | |||
skipping to change at line 349 | skipping to change at line 375 | |||
if isinstance(self, SCons.Node.Node) and self.is_sconscript(): | if isinstance(self, SCons.Node.Node) and self.is_sconscript(): | |||
return original(self) | return original(self) | |||
return "dummy_ninja_csig" | return "dummy_ninja_csig" | |||
return wrapper | return wrapper | |||
def ninja_contents(original): | def ninja_contents(original): | |||
"""Return a dummy content without doing IO""" | """Return a dummy content without doing IO""" | |||
def wrapper(self): | def wrapper(self): | |||
if isinstance(self, SCons.Node.Node) and self.is_sconscript(): | if isinstance(self, SCons.Node.Node) and (self.is_sconscript() or self.i s_conftest()): | |||
return original(self) | return original(self) | |||
return bytes("dummy_ninja_contents", encoding="utf-8") | return bytes("dummy_ninja_contents", encoding="utf-8") | |||
return wrapper | return wrapper | |||
def ninja_stat(_self, path): | def ninja_stat(_self, path): | |||
""" | """ | |||
Eternally memoized stat call. | Eternally memoized stat call. | |||
SCons is very aggressive about clearing out cached values. For our | SCons is very aggressive about clearing out cached values. For our | |||
End of changes. 6 change blocks. | ||||
3 lines changed or deleted | 31 lines changed or added |