Skip to content

Commit

Permalink
renamed SCons.Tool.ninja -> SCons.Tool.ninja_tool and added alias in …
Browse files Browse the repository at this point in the history
…tool loading logic. This fixes changes in this PR breaking JavaCommonTests because pypi's ninja module and SCons.Tool.ninja had the same name which python couldn't differentiate
  • Loading branch information
bdbaddog committed Nov 25, 2024
1 parent 0b5ab8b commit 6d70e82
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions SCons/Tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'gettext': 'gettext_tool',
'clang++': 'clangxx',
'as': 'asm',
'ninja' : 'ninja_tool'
}


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

import SCons
from SCons.Subst import SUBST_CMD
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, \
from SCons.Tool.ninja_tool import NINJA_CUSTOM_HANDLERS, NINJA_RULES, NINJA_POOLS
from SCons.Tool.ninja_tool.Globals import __NINJA_RULE_MAPPING
from SCons.Tool.ninja_tool.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

if TYPE_CHECKING:
Expand All @@ -46,7 +46,7 @@ def register_custom_handler(env, name, handler) -> None:

def register_custom_rule_mapping(env, pre_subst_string, rule) -> None:
"""Register a function to call for a given rule."""
SCons.Tool.ninja.Globals.__NINJA_RULE_MAPPING[pre_subst_string] = rule
__NINJA_RULE_MAPPING[pre_subst_string] = rule


def register_custom_rule(env, rule, command, description: str="", deps=None, pool=None, use_depfile: bool=False, use_response_file: bool=False, response_file_content: str="$rspc") -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def action_to_ninja_build(self, node, action=None):
# Ninja builders out of being sources of ninja builders but I
# can't fix every DAG problem so we just skip ninja_builders
# if we find one
if SCons.Tool.ninja.NINJA_STATE.ninja_file == str(node):
if SCons.Tool.ninja_tool.NINJA_STATE.ninja_file == str(node):
build = None
elif isinstance(action, SCons.Action.FunctionAction):
build = self.handle_func_action(node, action)
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions SCons/Tool/ninja/Utils.py → SCons/Tool/ninja_tool/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,14 @@ def ninja_stat(_self, path):
"""

try:
return SCons.Tool.ninja.Globals.NINJA_STAT_MEMO[path]
return SCons.Tool.ninja_tool.Globals.NINJA_STAT_MEMO[path]
except KeyError:
try:
result = os.stat(path)
except os.error:
result = None

SCons.Tool.ninja.Globals.NINJA_STAT_MEMO[path] = result
SCons.Tool.ninja_tool.Globals.NINJA_STAT_MEMO[path] = result
return result


Expand All @@ -430,7 +430,7 @@ def ninja_whereis(thing, *_args, **_kwargs):
# Optimize for success, this gets called significantly more often
# when the value is already memoized than when it's not.
try:
return SCons.Tool.ninja.Globals.NINJA_WHEREIS_MEMO[thing]
return SCons.Tool.ninja_tool.Globals.NINJA_WHEREIS_MEMO[thing]
except KeyError:
# TODO: Fix this to respect env['ENV']['PATH']... WPD
# We do not honor any env['ENV'] or env[*] variables in the
Expand All @@ -443,7 +443,7 @@ def ninja_whereis(thing, *_args, **_kwargs):
# with shell quoting is nigh impossible. So I've decided to
# cross that bridge when it's absolutely required.
path = shutil.which(thing)
SCons.Tool.ninja.Globals.NINJA_WHEREIS_MEMO[thing] = path
SCons.Tool.ninja_tool.Globals.NINJA_WHEREIS_MEMO[thing] = path
return path


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import SCons
import SCons.Script
import SCons.Tool.ninja.Globals
from SCons.Tool.ninja_tool.Globals import ninja_builder_initialized
from SCons.Script import GetOption
from SCons.Util import sanitize_shell_env

Expand Down Expand Up @@ -187,13 +187,13 @@ def ninja_emitter(target, source, env):

def generate(env):
"""Generate the NINJA builders."""
global NINJA_STATE, NINJA_CMDLINE_TARGETS
global NINJA_STATE, NINJA_CMDLINE_TARGETS, ninja_builder_initialized

if 'ninja' not in GetOption('experimental'):
return

if not SCons.Tool.ninja.Globals.ninja_builder_initialized:
SCons.Tool.ninja.Globals.ninja_builder_initialized = True
if not ninja_builder_initialized:
ninja_builder_initialized = True

ninja_add_command_line_options()

Expand Down Expand Up @@ -255,7 +255,7 @@ def ninja_generate_deps(env):
pass
else:
env.Append(CCFLAGS='$CCDEPFLAGS')

env.AddMethod(CheckNinjaCompdbExpand, "CheckNinjaCompdbExpand")

# Provide a way for custom rule authors to easily access command
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 6d70e82

Please sign in to comment.