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

Fixed ninja binary location logic to use ninja.BIN_DIR. #4655

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
via top-level `from __future__ import annotations`.
- Implemented type hints for Nodes.

From William Deegan:
- Update ninja tool to use ninja.BIN_DIR to find pypi packaged ninja binary.
python ninja package version 1.11.1.2 changed the location and previous
logic no longer worked.
- Added TestSCons.NINJA_BINARY to TestSCons to centralize logic to find ninja binary
- Refactored SCons.Tool.ninja -> SCons.Tool.ninja_tool, and added alias so
env.Tool('ninja') will still work. This avoids conflicting with the pypi module ninja.

From Alex James:
- On Darwin, PermissionErrors are now handled while trying to access
/etc/paths.d. This may occur if SCons is invoked in a sandboxed
Expand Down
10 changes: 10 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ FIXES
- Make sure unknown variables from a Variables file are recognized
as such (issue #4645)

- Update ninja tool to use ninja.BIN_DIR to find pypi packaged ninja binary.
python ninja package version 1.11.1.2 changed the location and previous
logic no longer worked.


IMPROVEMENTS
------------

Expand Down Expand Up @@ -196,6 +201,11 @@ DEVELOPMENT

- Implemented type hints for Nodes.

- Added TestSCons.NINJA_BINARY to TestSCons to centralize logic to find ninja binary

- Refactored SCons.Tool.ninja -> SCons.Tool.ninja_tool, and added alias so env.Tool('ninja')
will still work. This avoids conflicting with the pypi module ninja.

Thanks to the following contributors listed below for their contributions to this release.
==========================================================================================
.. code-block:: text
Expand Down
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 @@ -60,12 +60,11 @@ def __init__(self, env, ninja_file, ninja_syntax) -> None:
if not self.ninja_bin_path:
# default to using ninja installed with python module
ninja_bin = 'ninja.exe' if env["PLATFORM"] == "win32" else 'ninja'

self.ninja_bin_path = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
ninja_bin))
ninja.BIN_DIR, ninja_bin
))

if not os.path.exists(self.ninja_bin_path):
# couldn't find it, just give the bin name and hope
# its in the path later
Expand Down Expand Up @@ -398,7 +397,7 @@ def generate(self):
self.rules.update({key: non_rsp_rule})
else:
self.rules.update({key: rule})

self.pools.update(self.env.get(NINJA_POOLS, {}))

content = io.StringIO()
Expand Down Expand Up @@ -435,7 +434,7 @@ def generate(self):
generated_source_files = sorted(
[] if not generated_sources_build else generated_sources_build['implicit']
)

def check_generated_source_deps(build):
return (
build != generated_sources_build
Expand Down Expand Up @@ -464,7 +463,7 @@ def check_generated_source_deps(build):
rule="phony",
implicit=generated_source_files
)

def check_generated_source_deps(build):
return (
not build["rule"] == "INSTALL"
Expand Down Expand Up @@ -661,15 +660,15 @@ def check_generated_source_deps(build):
all_targets = [str(node) for node in NINJA_DEFAULT_TARGETS]
else:
all_targets = list(all_targets)

if len(all_targets) == 0:
all_targets = ["phony_default"]
ninja_sorted_build(
ninja,
outputs=all_targets,
rule="phony",
)

ninja.default([self.ninja_syntax.escape_path(path) for path in sorted(all_targets)])

with NamedTemporaryFile(delete=False, mode='w') as temp_ninja_file:
Expand Down Expand Up @@ -754,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.
9 changes: 1 addition & 8 deletions test/ninja/build_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# 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 TestSCons
from TestCmd import IS_WINDOWS, IS_MACOS
from TestSCons import _exe, _lib, lib_, _dll, dll_
Expand All @@ -36,12 +34,7 @@
except ImportError:
test.skip_test("Could not find ninja module. Skipping test.\n")

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/command_line_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/copy_function_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
4 changes: 1 addition & 3 deletions test/ninja/default_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(
os.path.join(ninja.__file__, os.pardir, 'data', 'bin', 'ninja' + _exe)
)
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
4 changes: 1 addition & 3 deletions test/ninja/force_scons_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(
os.path.join(ninja.__file__, os.pardir, "data", "bin", "ninja" + _exe)
)
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture("ninja-fixture")

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/generate_and_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/generate_and_build_cxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/generate_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
4 changes: 1 addition & 3 deletions test/ninja/generated_sources_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.BIN_DIR,
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/iterative_speedup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
4 changes: 1 addition & 3 deletions test/ninja/mingw_command_generator_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.BIN_DIR,
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
4 changes: 1 addition & 3 deletions test/ninja/mingw_depfile_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.BIN_DIR,
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.dir_fixture('ninja-fixture')

Expand Down
7 changes: 1 addition & 6 deletions test/ninja/mkdir_function_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test.write('SConstruct', """
SetOption('experimental','ninja')
Expand Down
7 changes: 1 addition & 6 deletions test/ninja/multi_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
_python_ = TestSCons._python_
_exe = TestSCons._exe

ninja_bin = os.path.abspath(os.path.join(
ninja.__file__,
os.pardir,
'data',
'bin',
'ninja' + _exe))
ninja_bin = TestSCons.NINJA_BINARY

test = TestSCons.TestSCons()

Expand Down
Loading