summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2022-05-19 13:52:58 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-05-19 19:32:09 +0000
commitafeee70cd37b9083f0012bea17444a2840a433d6 (patch)
tree4131ec36e7839696e71d79c678284d3187d9178d /site_scons
parent6d4ad1d61f40dcd6d724464d1875a06e13da6b93 (diff)
downloadmongo-afeee70cd37b9083f0012bea17444a2840a433d6.tar.gz
SERVER-65273 parse denylist files to build icecream locally for some files
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/site_tools/icecream.py92
-rw-r--r--site_scons/site_tools/ninja.py16
2 files changed, 63 insertions, 45 deletions
diff --git a/site_scons/site_tools/icecream.py b/site_scons/site_tools/icecream.py
index f4ffb5fdf3e..c95a542f008 100644
--- a/site_scons/site_tools/icecream.py
+++ b/site_scons/site_tools/icecream.py
@@ -33,22 +33,6 @@ _icecream_version_min = parse_version("1.1rc2")
_icecream_version_gcc_remote_cpp = parse_version("1.2")
-# I'd prefer to use value here, but amazingly, its __str__ returns the
-# *initial* value of the Value and not the built value, if
-# available. That seems like a bug. In the meantime, make our own very
-# sinmple Substition thing.
-class _BoundSubstitution:
- def __init__(self, env, expression):
- self.env = env
- self.expression = expression
- self.result = None
-
- def __str__(self):
- if self.result is None:
- self.result = self.env.subst(self.expression)
- return self.result
-
-
def icecc_create_env(env, target, source, for_signature):
# Safe to assume unix here because icecream only works on Unix
mkdir = "mkdir -p ${TARGET.dir}"
@@ -450,35 +434,65 @@ def generate(env):
if "ICECC_SCHEDULER" in env:
env["ENV"]["USE_SCHEDULER"] = env["ICECC_SCHEDULER"]
- # If ccache is in play we actually want the icecc binary in the
- # CCACHE_PREFIX environment variable, not on the command line, per
- # the ccache documentation on compiler wrappers. Otherwise, just
- # put $ICECC on the command line. We wrap it in the magic "don't
- # consider this part of the build signature" sigils in the hope
- # that enabling and disabling icecream won't cause rebuilds. This
- # is unlikely to really work, since above we have maybe changed
- # compiler flags (things like -fdirectives-only), but we still try
- # to do the right thing.
+ # Make a generator to expand to what icecream binary to use in
+ # the case where we are not a conftest or a deny list source file.
+ def icecc_generator(target, source, env, for_signature):
+ # TODO: SERVER-60915 use new conftest API
+ if "conftest" in str(target[0]):
+ return ''
+
+ if env.subst('$ICECC_LOCAL_COMPILATION_FILTER', target=target, source=source) == 'True':
+ return '$ICERUN'
+
+ return '$ICECREAM_RUN_ICECC'
+
+ env['ICECC_GENERATOR'] = icecc_generator
+
if ccache_enabled:
+
+ # Don't want to overwrite some existing generator
+ # if there is an existing one, we will need to chain them
+ if env.get('SHELL_ENV_GENERATOR') is not None:
+ existing_gen = env.get('SHELL_ENV_GENERATOR')
+ else:
+ existing_gen = None
+
+ # If ccache is in play we actually want the icecc binary in the
+ # CCACHE_PREFIX environment variable, not on the command line, per
+ # the ccache documentation on compiler wrappers. Otherwise, just
+ # put $ICECC on the command line. We wrap it in the magic "don't
+ # consider this part of the build signature" sigils in the hope
+ # that enabling and disabling icecream won't cause rebuilds. This
+ # is unlikely to really work, since above we have maybe changed
+ # compiler flags (things like -fdirectives-only), but we still try
+ # to do the right thing.
+ #
# If the path to CCACHE_PREFIX isn't absolute, then it will
# look it up in PATH. That isn't what we want here, we make
# the path absolute.
- env['ENV']['CCACHE_PREFIX'] = _BoundSubstitution(env, "${ICECREAM_RUN_ICECC.abspath}")
+ def icecc_ccache_prefix_gen(env, target, source):
+ # TODO: SERVER-60915 use new conftest API
+ if "conftest" in str(target[0]):
+ return env['ENV']
+
+ if existing_gen:
+ shell_env = existing_gen(env, target, source)
+ else:
+ shell_env = env['ENV'].copy()
+ shell_env['CCACHE_PREFIX'] = env.File(env.subst("$ICECC_GENERATOR", target=target, source=source)).abspath
+ return shell_env
+
+
+ env['SHELL_ENV_GENERATOR'] = icecc_ccache_prefix_gen
+
else:
- # Make a generator to expand to ICECC in the case where we are
- # not a conftest. We never want to run conftests remotely.
- # Ideally, we would do this for the CCACHE_PREFIX case above,
- # but unfortunately if we did we would never actually see the
- # conftests, because the BoundSubst means that we will never
- # have a meaningful `target` variable when we are in ENV.
- # Instead, rely on the ccache.py tool to do it's own filtering
- # out of conftests.
- def icecc_generator(target, source, env, for_signature):
- if "conftest" not in str(target[0]):
- return '$ICECREAM_RUN_ICECC'
- return ''
- env['ICECC_GENERATOR'] = icecc_generator
+ # We wrap it in the magic "don't
+ # consider this part of the build signature" sigils in the hope
+ # that enabling and disabling icecream won't cause rebuilds. This
+ # is unlikely to really work, since above we have maybe changed
+ # compiler flags (things like -fdirectives-only), but we still try
+ # to do the right thing.
icecc_string = "$( $ICECC_GENERATOR $)"
env["CCCOM"] = " ".join([icecc_string, env["CCCOM"]])
env["CXXCOM"] = " ".join([icecc_string, env["CXXCOM"]])
diff --git a/site_scons/site_tools/ninja.py b/site_scons/site_tools/ninja.py
index ca35d8659b0..1c76bd92478 100644
--- a/site_scons/site_tools/ninja.py
+++ b/site_scons/site_tools/ninja.py
@@ -387,12 +387,16 @@ class SConsToNinjaTranslator:
# Make sure we didn't generate an empty cmdline
if cmdline:
+
+ env = node.env if node.env else self.env
+ sources = [get_path(src_file(s)) for s in node.sources]
+
ninja_build = {
"outputs": all_outputs,
"rule": "CMD",
"variables": {
"cmd": cmdline,
- "env": get_command_env(node.env if node.env else self.env),
+ "env": get_command_env(env, all_outputs, sources),
},
"implicit": dependencies,
}
@@ -949,7 +953,7 @@ def get_comstr(env, action, targets, sources):
return action.genstring(targets, sources, env)
-def get_command_env(env):
+def get_command_env(env, target, source):
"""
Return a string that sets the enrivonment for any environment variables that
differ between the OS environment and the SCons command ENV.
@@ -965,7 +969,7 @@ def get_command_env(env):
# os.environ or differ from it. We assume if it's a new or
# differing key from the process environment then it's
# important to pass down to commands in the Ninja file.
- ENV = get_default_ENV(env)
+ ENV = env.get('SHELL_ENV_GENERATOR', get_default_ENV)(env, target, source)
scons_specified_env = {
key: value
for key, value in ENV.items()
@@ -998,7 +1002,7 @@ def get_command_env(env):
# doesn't make builds on paths with spaces (Ninja and SCons issues)
# nor expanding response file paths with spaces (Ninja issue) work.
value = value.replace(r' ', r'$ ')
- command_env += "export {}='{}';".format(key, value)
+ command_env += "export {}='{}';".format(key, env.subst(value, target=target, source=source))
env["NINJA_ENV_VAR_CACHE"] = command_env
return command_env
@@ -1054,7 +1058,7 @@ def gen_get_response_file_command(env, rule, tool, tool_is_dynamic=False, custom
variables = {"rspc": rsp_content}
variables[rule] = cmd
if use_command_env:
- variables["env"] = get_command_env(env)
+ variables["env"] = get_command_env(env, targets, sources)
for key, value in custom_env.items():
variables["env"] += env.subst(
@@ -1101,7 +1105,7 @@ def get_generic_shell_command(env, node, action, targets, sources, executor=None
rule,
{
"cmd": generate_command(env, node, action, targets, sources, executor=None),
- "env": get_command_env(env),
+ "env": get_command_env(env, targets, sources),
},
# Since this function is a rule mapping provider, it must return a list of dependencies,
# and usually this would be the path to a tool, such as a compiler, used for this rule.