Skip to content

Commit f1723d8

Browse files
authored
Merge pull request #4655 from bdbaddog/fix_new_ninja_package
Fixed ninja binary location logic to use ninja.BIN_DIR.
2 parents c580a72 + eeb5dfd commit f1723d8

38 files changed

+154
-196
lines changed

CHANGES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
8585
via top-level `from __future__ import annotations`.
8686
- Implemented type hints for Nodes.
8787

88+
From William Deegan:
89+
- Update ninja tool to use ninja.BIN_DIR to find pypi packaged ninja binary.
90+
python ninja package version 1.11.1.2 changed the location and previous
91+
logic no longer worked.
92+
- Added TestSCons.NINJA_BINARY to TestSCons to centralize logic to find ninja binary
93+
- Refactored SCons.Tool.ninja -> SCons.Tool.ninja_tool, and added alias so
94+
env.Tool('ninja') will still work. This avoids conflicting with the pypi module ninja.
95+
8896
From Alex James:
8997
- On Darwin, PermissionErrors are now handled while trying to access
9098
/etc/paths.d. This may occur if SCons is invoked in a sandboxed

RELEASE.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ FIXES
140140
- Make sure unknown variables from a Variables file are recognized
141141
as such (issue #4645)
142142

143+
- Update ninja tool to use ninja.BIN_DIR to find pypi packaged ninja binary.
144+
python ninja package version 1.11.1.2 changed the location and previous
145+
logic no longer worked.
146+
147+
143148
IMPROVEMENTS
144149
------------
145150

@@ -196,6 +201,11 @@ DEVELOPMENT
196201

197202
- Implemented type hints for Nodes.
198203

204+
- Added TestSCons.NINJA_BINARY to TestSCons to centralize logic to find ninja binary
205+
206+
- Refactored SCons.Tool.ninja -> SCons.Tool.ninja_tool, and added alias so env.Tool('ninja')
207+
will still work. This avoids conflicting with the pypi module ninja.
208+
199209
Thanks to the following contributors listed below for their contributions to this release.
200210
==========================================================================================
201211
.. code-block:: text

SCons/Tool/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
'gettext': 'gettext_tool',
103103
'clang++': 'clangxx',
104104
'as': 'asm',
105+
'ninja' : 'ninja_tool'
105106
}
106107

107108

File renamed without changes.

SCons/Tool/ninja/Methods.py renamed to SCons/Tool/ninja_tool/Methods.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
import SCons
3232
from SCons.Subst import SUBST_CMD
33-
from SCons.Tool.ninja import NINJA_CUSTOM_HANDLERS, NINJA_RULES, NINJA_POOLS
34-
from SCons.Tool.ninja.Globals import __NINJA_RULE_MAPPING
35-
from SCons.Tool.ninja.Utils import get_targets_sources, get_dependencies, get_order_only, get_outputs, get_inputs, \
33+
from SCons.Tool.ninja_tool import NINJA_CUSTOM_HANDLERS, NINJA_RULES, NINJA_POOLS
34+
from SCons.Tool.ninja_tool.Globals import __NINJA_RULE_MAPPING
35+
from SCons.Tool.ninja_tool.Utils import get_targets_sources, get_dependencies, get_order_only, get_outputs, get_inputs, \
3636
get_rule, get_path, generate_command, get_command_env, get_comstr
3737

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

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

5151

5252
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:

SCons/Tool/ninja/NinjaState.py renamed to SCons/Tool/ninja_tool/NinjaState.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ def __init__(self, env, ninja_file, ninja_syntax) -> None:
6060
if not self.ninja_bin_path:
6161
# default to using ninja installed with python module
6262
ninja_bin = 'ninja.exe' if env["PLATFORM"] == "win32" else 'ninja'
63+
6364
self.ninja_bin_path = os.path.abspath(os.path.join(
64-
ninja.__file__,
65-
os.pardir,
66-
'data',
67-
'bin',
68-
ninja_bin))
65+
ninja.BIN_DIR, ninja_bin
66+
))
67+
6968
if not os.path.exists(self.ninja_bin_path):
7069
# couldn't find it, just give the bin name and hope
7170
# its in the path later
@@ -398,7 +397,7 @@ def generate(self):
398397
self.rules.update({key: non_rsp_rule})
399398
else:
400399
self.rules.update({key: rule})
401-
400+
402401
self.pools.update(self.env.get(NINJA_POOLS, {}))
403402

404403
content = io.StringIO()
@@ -435,7 +434,7 @@ def generate(self):
435434
generated_source_files = sorted(
436435
[] if not generated_sources_build else generated_sources_build['implicit']
437436
)
438-
437+
439438
def check_generated_source_deps(build):
440439
return (
441440
build != generated_sources_build
@@ -464,7 +463,7 @@ def check_generated_source_deps(build):
464463
rule="phony",
465464
implicit=generated_source_files
466465
)
467-
466+
468467
def check_generated_source_deps(build):
469468
return (
470469
not build["rule"] == "INSTALL"
@@ -661,15 +660,15 @@ def check_generated_source_deps(build):
661660
all_targets = [str(node) for node in NINJA_DEFAULT_TARGETS]
662661
else:
663662
all_targets = list(all_targets)
664-
663+
665664
if len(all_targets) == 0:
666665
all_targets = ["phony_default"]
667666
ninja_sorted_build(
668667
ninja,
669668
outputs=all_targets,
670669
rule="phony",
671670
)
672-
671+
673672
ninja.default([self.ninja_syntax.escape_path(path) for path in sorted(all_targets)])
674673

675674
with NamedTemporaryFile(delete=False, mode='w') as temp_ninja_file:
@@ -754,7 +753,7 @@ def action_to_ninja_build(self, node, action=None):
754753
# Ninja builders out of being sources of ninja builders but I
755754
# can't fix every DAG problem so we just skip ninja_builders
756755
# if we find one
757-
if SCons.Tool.ninja.NINJA_STATE.ninja_file == str(node):
756+
if SCons.Tool.ninja_tool.NINJA_STATE.ninja_file == str(node):
758757
build = None
759758
elif isinstance(action, SCons.Action.FunctionAction):
760759
build = self.handle_func_action(node, action)
File renamed without changes.
File renamed without changes.

SCons/Tool/ninja/Utils.py renamed to SCons/Tool/ninja_tool/Utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,14 @@ def ninja_stat(_self, path):
413413
"""
414414

415415
try:
416-
return SCons.Tool.ninja.Globals.NINJA_STAT_MEMO[path]
416+
return SCons.Tool.ninja_tool.Globals.NINJA_STAT_MEMO[path]
417417
except KeyError:
418418
try:
419419
result = os.stat(path)
420420
except os.error:
421421
result = None
422422

423-
SCons.Tool.ninja.Globals.NINJA_STAT_MEMO[path] = result
423+
SCons.Tool.ninja_tool.Globals.NINJA_STAT_MEMO[path] = result
424424
return result
425425

426426

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

449449

SCons/Tool/ninja/__init__.py renamed to SCons/Tool/ninja_tool/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import SCons
3434
import SCons.Script
35-
import SCons.Tool.ninja.Globals
35+
from SCons.Tool.ninja_tool.Globals import ninja_builder_initialized
3636
from SCons.Script import GetOption
3737
from SCons.Util import sanitize_shell_env
3838

@@ -187,13 +187,13 @@ def ninja_emitter(target, source, env):
187187

188188
def generate(env):
189189
"""Generate the NINJA builders."""
190-
global NINJA_STATE, NINJA_CMDLINE_TARGETS
190+
global NINJA_STATE, NINJA_CMDLINE_TARGETS, ninja_builder_initialized
191191

192192
if 'ninja' not in GetOption('experimental'):
193193
return
194194

195-
if not SCons.Tool.ninja.Globals.ninja_builder_initialized:
196-
SCons.Tool.ninja.Globals.ninja_builder_initialized = True
195+
if not ninja_builder_initialized:
196+
ninja_builder_initialized = True
197197

198198
ninja_add_command_line_options()
199199

@@ -255,7 +255,7 @@ def ninja_generate_deps(env):
255255
pass
256256
else:
257257
env.Append(CCFLAGS='$CCDEPFLAGS')
258-
258+
259259
env.AddMethod(CheckNinjaCompdbExpand, "CheckNinjaCompdbExpand")
260260

261261
# Provide a way for custom rule authors to easily access command

0 commit comments

Comments
 (0)