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-25 14:41:09 +0000 |
commit | 6c8521729466a841127e62e54bbbaaaebbf35330 (patch) | |
tree | 33241f8684c32067b0e6432c587251297cd9ad9c | |
parent | 2db61e54f7e964e02fab5d3c89e04fa007c782d0 (diff) | |
download | mongo-6c8521729466a841127e62e54bbbaaaebbf35330.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 | 75 |
2 files changed, 53 insertions, 24 deletions
diff --git a/SConstruct b/SConstruct index f283528f25e..1e1b8b0f85c 100644 --- a/SConstruct +++ b/SConstruct @@ -4223,6 +4223,8 @@ if get_option('ninja') != 'disabled': ) env.NinjaRegisterFunctionHandler("test_list_builder_action", ninja_test_list_builder) + env['NINJA_GENERATED_SOURCE_ALIAS_NAME'] = 'generated-sources' + # TODO: Later, this should live somewhere more graceful. if get_option('install-mode') == 'hygienic': diff --git a/site_scons/site_tools/ninja.py b/site_scons/site_tools/ninja.py index 0b915ce136a..aa6aa30be31 100644 --- a/site_scons/site_tools/ninja.py +++ b/site_scons/site_tools/ninja.py @@ -642,27 +642,56 @@ class NinjaState: for rule, kwargs in self.rules.items(): ninja.rule(rule, **kwargs) - # TODO SERVER-64664 - 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 = [] @@ -681,9 +710,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 @@ -693,7 +720,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() |