Followon to PR #4348: more bool fixes
[scons.git] / SCons / Tool / ninja / Overrides.py
blob83d2efb11e9deebbcaf5d06e105dffb2a77d31b8
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 """
24 This module is to hold logic which overrides default SCons behaviors to enable
25 ninja file generation
26 """
27 import SCons
30 def ninja_hack_linkcom(env) -> None:
31 # TODO: change LINKCOM and SHLINKCOM to handle embedding manifest exe checks
32 # without relying on the SCons hacks that SCons uses by default.
33 if env["PLATFORM"] == "win32":
34 from SCons.Tool.mslink import compositeLinkAction
36 if env.get("LINKCOM", None) == compositeLinkAction:
37 env[
38 "LINKCOM"
39 ] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $_LIBDIRFLAGS $_LIBFLAGS $_PDB $SOURCES.windows", "$LINKCOMSTR")}'
40 env[
41 "SHLINKCOM"
42 ] = '${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}'
45 def ninja_hack_arcom(env) -> None:
46 """
47 Force ARCOM so use 's' flag on ar instead of separately running ranlib
48 """
49 if env["PLATFORM"] != "win32" and env.get("RANLIBCOM"):
50 # There is no way to translate the ranlib list action into
51 # Ninja so add the s flag and disable ranlib.
53 # This is equivalent to Meson.
54 # https://github.com/mesonbuild/meson/blob/master/mesonbuild/linkers.py#L143
55 old_arflags = str(env["ARFLAGS"])
56 if "s" not in old_arflags:
57 old_arflags += "s"
59 env["ARFLAGS"] = SCons.Util.CLVar([old_arflags])
61 # Disable running ranlib, since we added 's' above
62 env["RANLIBCOM"] = ""
65 class NinjaNoResponseFiles(SCons.Platform.TempFileMunge):
66 """Overwrite the __call__ method of SCons' TempFileMunge to not delete."""
68 def __call__(self, target, source, env, for_signature):
69 return self.cmd
71 def _print_cmd_str(*_args, **_kwargs) -> None:
72 """Disable this method"""
73 pass
76 def ninja_always_serial(self, num, taskmaster) -> None:
77 """Replacement for SCons.Job.Jobs constructor which always uses the Serial Job class."""
78 # We still set self.num_jobs to num even though it's a lie. The
79 # only consumer of this attribute is the Parallel Job class AND
80 # the Main.py function which instantiates a Jobs class. It checks
81 # if Jobs.num_jobs is equal to options.num_jobs, so if the user
82 # provides -j12 but we set self.num_jobs = 1 they get an incorrect
83 # warning about this version of Python not supporting parallel
84 # builds. So here we lie so the Main.py will not give a false
85 # warning to users.
86 self.num_jobs = num
87 self.job = SCons.Taskmaster.Job.Serial(taskmaster)
90 # pylint: disable=too-few-public-methods
91 class AlwaysExecAction(SCons.Action.FunctionAction):
92 """Override FunctionAction.__call__ to always execute."""
94 def __call__(self, *args, **kwargs):
95 kwargs["execute"] = 1
96 return super().__call__(*args, **kwargs)