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

WIP: Fix ninja warnings/exceptions #4427

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 10 additions & 4 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ NOTE: The 4.0.0 Release of SCons dropped Python 2.7 Support
NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer supported

RELEASE VERSION/DATE TO BE FILLED IN LATER


From Ataf Fazledin Ahamed:
- Use of NotImplemented instead of NotImplementedError for special methods
of _ListVariable class

From Michał Górny:
- Remove unecessary dependencies on pypi packages from setup.cfg

From Sten Grüner:
- Fix of the --debug=sconscript option to return exist statements when using return
statement with stop flag enabled

From Ataf Fazledin Ahamed:
- Use of NotImplemented instead of NotImplementedError for special methods
of _ListVariable class
From Mats Wichmann
- Complete one warning from ninja tool (it did not actually issue the
warning) and change three exceptions to different types. Fixes #4036.

RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700

Expand Down
25 changes: 13 additions & 12 deletions SCons/Tool/ninja/NinjaState.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from .Globals import COMMAND_TYPES, NINJA_RULES, NINJA_POOLS, \
NINJA_CUSTOM_HANDLERS, NINJA_DEFAULT_TARGETS
from .Rules import _install_action_function, _mkdir_action_function, _lib_symlink_action_function, _copy_action_function
from .Utils import get_path, alias_to_ninja_build, generate_depfile, ninja_noop, get_order_only, \
from .Utils import NinjaExperimentalWarning, get_path, alias_to_ninja_build, generate_depfile, ninja_noop, get_order_only, \
get_outputs, get_inputs, get_dependencies, get_rule, get_command_env, to_escaped_list, ninja_sorted_build
from .Methods import get_command

Expand Down Expand Up @@ -398,7 +398,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 +435,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 +464,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 +661,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 @@ -807,12 +807,13 @@ def handle_func_action(self, node, action):
if handler is not None:
return handler(node.env if node.env else self.env, node)

SCons.Warnings.SConsWarning(
"Found unhandled function action {}, "
" generating scons command to build\n"
"Note: this is less efficient than Ninja,"
" you can write your own ninja build generator for"
" this function using NinjaRegisterFunctionHandler".format(name)
SCons.Warnings.warn(
NinjaExperimentalWarning,
f"Found unhandled function action {name!r}, "
" generating SCons command to build.\n"
"Note: this is less efficient than using ninja to build. "
"You can add a ninja build generator for this function "
"using NinjaRegisterFunctionHandler."
)

return {
Expand Down
19 changes: 11 additions & 8 deletions SCons/Tool/ninja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
gen_get_response_file_command
from .Overrides import ninja_hack_linkcom, ninja_hack_arcom, NinjaNoResponseFiles, ninja_always_serial, AlwaysExecAction
from .Utils import ninja_add_command_line_options, \
ninja_noop, ninja_print_conf_log, ninja_csig, ninja_contents, ninja_stat, ninja_whereis, NinjaExperimentalWarning
ninja_noop, ninja_print_conf_log, ninja_csig, ninja_contents, ninja_stat, ninja_whereis

try:
import ninja
Expand Down Expand Up @@ -161,7 +161,7 @@ def exists(env):
if NINJA_BINARY:
return NINJA_BINARY
else:
raise SCons.Warnings.SConsWarning("Failed to import ninja, attempt normal SCons build.")
raise ImportError("Failed to import ninja, attempt normal SCons build.")


def ninja_emitter(target, source, env):
Expand All @@ -185,7 +185,7 @@ def ninja_emitter(target, source, env):
return target, source


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

Expand All @@ -198,7 +198,7 @@ def generate(env):
ninja_add_command_line_options()

if not NINJA_BINARY:
raise SCons.Warnings.SConsWarning("Failed to import ninja, attempt normal SCons build.")
raise ImportError("Failed to import ninja, attempt normal SCons build.")

env["NINJA_DISABLE_AUTO_RUN"] = env.get("NINJA_DISABLE_AUTO_RUN", GetOption('disable_execute_ninja'))
env["NINJA_FILE_NAME"] = env.get("NINJA_FILE_NAME", "build.ninja")
Expand Down Expand Up @@ -232,20 +232,23 @@ def generate(env):
SCons.Script.BUILD_TARGETS = SCons.Script.TargetList(env.Alias("$NINJA_ALIAS_NAME", ninja_file))
else:
if str(NINJA_STATE.ninja_file) != env["NINJA_FILE_NAME"]:
SCons.Warnings.SConsWarning("Generating multiple ninja files not supported, set ninja file name before tool initialization.")
raise SCons.Errors.UserError(
"Generating multiple ninja files not supported, "
"set ninja file name before tool initialization."
)
ninja_file = [NINJA_STATE.ninja_file]


def ninja_generate_deps(env):
"""Return a list of SConscripts

TODO: Should we also include files loaded from site_scons/***
or even all loaded modules? https://stackoverflow.com/questions/4858100/how-to-list-imported-modules
TODO: Do we want this to be Nodes?
"""
return sorted([str(s) for s in SCons.Node.SConscriptNodes])

env['_NINJA_REGENERATE_DEPS_FUNC'] = ninja_generate_deps

env['NINJA_REGENERATE_DEPS'] = env.get('NINJA_REGENERATE_DEPS', '${_NINJA_REGENERATE_DEPS_FUNC(__env__)}')

# This adds the required flags such that the generated compile
Expand All @@ -255,7 +258,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 Expand Up @@ -332,7 +335,7 @@ def robust_rule_mapping(var, rule, tool) -> None:
ninja_hack_arcom(env)

if GetOption('disable_ninja'):
return env
return

print("Initializing ninja tool... this feature is experimental. SCons internals and all environments will be affected.")
print(f"SCons running in ninja mode. {env['NINJA_FILE']} will be generated.")
Expand Down
Loading