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.
24 This module is to hold logic which overrides default SCons behaviors to enable
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
:
39 ] = '${TEMPFILE("$LINK $LINKFLAGS /OUT:$TARGET.windows $_LIBDIRFLAGS $_LIBFLAGS $_PDB $SOURCES.windows", "$LINKCOMSTR")}'
42 ] = '${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}'
45 def ninja_hack_arcom(env
) -> None:
47 Force ARCOM so use 's' flag on ar instead of separately running ranlib
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
:
59 env
["ARFLAGS"] = SCons
.Util
.CLVar([old_arflags
])
61 # Disable running ranlib, since we added 's' above
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
):
71 def _print_cmd_str(*_args
, **_kwargs
) -> None:
72 """Disable this method"""
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
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
):
96 return super().__call
__(*args
, **kwargs
)