diff options
author | Daniel Moody <daniel.moody@mongodb.com> | 2022-04-07 12:50:12 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-26 04:10:29 +0000 |
commit | 8467a3225b586a6c35391e169ee5fc4c5c552600 (patch) | |
tree | 7444be6e47cfcc11da83f36b73efda5730c16333 | |
parent | 225adcd8145472f1733c293c2bf8e6cb95c00e63 (diff) | |
download | mongo-8467a3225b586a6c35391e169ee5fc4c5c552600.tar.gz |
SERVER-64664 add alias tagging for ninja to determine generated sources.
(cherry picked from commit 2fef432fa6e7cf3fd4f22ba3b193222c2887f14f)
-rw-r--r-- | SConstruct | 2 | ||||
-rw-r--r-- | site_scons/site_tools/ninja.py | 74 |
2 files changed, 53 insertions, 23 deletions
diff --git a/SConstruct b/SConstruct index 70923c5bdcc..06037bd1791 100644 --- a/SConstruct +++ b/SConstruct @@ -4790,6 +4790,8 @@ if get_option('ninja') != 'disabled': ) env.NinjaRegisterFunctionHandler("test_list_builder_action", ninja_test_list_builder) + env['NINJA_GENERATED_SOURCE_ALIAS_NAME'] = 'generated-sources' + if get_option('separate-debug') == "on" or env.TargetOSIs("windows"): diff --git a/site_scons/site_tools/ninja.py b/site_scons/site_tools/ninja.py index 671526d7b4e..8505ce8e7ba 100644 --- a/site_scons/site_tools/ninja.py +++ b/site_scons/site_tools/ninja.py @@ -660,26 +660,56 @@ class NinjaState: kwargs['pool'] = 'local_pool' ninja.rule(rule, **kwargs) - generated_source_files = sorted({ - output - # First find builds which have header files in their outputs. - for build in self.builds.values() - if self.has_generated_sources(build["outputs"]) - for output in build["outputs"] - # Collect only the header files from the builds with them - # in their output. We do this because is_generated_source - # returns True if it finds a header in any of the outputs, - # here we need to filter so we only have the headers and - # not the other outputs. - if self.is_generated_source(output) - }) - - if generated_source_files: - ninja.build( - outputs="_generated_sources", - rule="phony", - implicit=generated_source_files + # If the user supplied an alias to determine generated sources, use that, otherwise + # determine what the generated sources are dynamically. + generated_sources_alias = self.env.get('NINJA_GENERATED_SOURCE_ALIAS_NAME') + generated_sources_build = None + + if generated_sources_alias: + generated_sources_build = self.builds.get(generated_sources_alias) + if generated_sources_build is None or generated_sources_build["rule"] != 'phony': + raise Exception( + "ERROR: 'NINJA_GENERATED_SOURCE_ALIAS_NAME' set, but no matching Alias object found." + ) + + if generated_sources_alias and generated_sources_build: + 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 + and set(build["outputs"]).isdisjoint(generated_source_files) + ) + else: + generated_sources_build = None + generated_source_files = sorted({ + output + # First find builds which have header files in their outputs. + for build in self.builds.values() + if self.has_generated_sources(build["outputs"]) + for output in build["outputs"] + # Collect only the header files from the builds with them + # in their output. We do this because is_generated_source + # returns True if it finds a header in any of the outputs, + # here we need to filter so we only have the headers and + # not the other outputs. + if self.is_generated_source(output) + }) + + if generated_source_files: + generated_sources_alias = "_ninja_generated_sources" + ninja.build( + outputs=generated_sources_alias, + rule="phony", + implicit=generated_source_files + ) + def check_generated_source_deps(build): + return ( + not build["rule"] == "INSTALL" + and set(build["outputs"]).isdisjoint(generated_source_files) + and set(build.get("implicit", [])).isdisjoint(generated_source_files) + ) template_builders = [] @@ -698,9 +728,7 @@ class NinjaState: # cycle. if ( generated_source_files - and not build["rule"] == "INSTALL" - and set(build["outputs"]).isdisjoint(generated_source_files) - and set(build.get("implicit", [])).isdisjoint(generated_source_files) + and check_generated_source_deps(build) ): # Make all non-generated source targets depend on @@ -710,7 +738,7 @@ class NinjaState: # sure that all of these sources are generated before # other builds. order_only = build.get("order_only", []) - order_only.append("_generated_sources") + order_only.append(generated_sources_alias) build["order_only"] = order_only if "order_only" in build: build["order_only"].sort() |