diff options
| -rw-r--r-- | etc/evergreen.yml | 6 | ||||
| -rw-r--r-- | etc/evergreen_yml_components/definitions.yml | 50 | ||||
| -rw-r--r-- | evergreen/ninja_determinism_status.sh | 1 | ||||
| -rw-r--r-- | evergreen/ninja_determinism_test.sh | 22 | ||||
| -rw-r--r-- | site_scons/site_tools/auto_install_binaries.py | 21 | ||||
| -rw-r--r-- | site_scons/site_tools/ninja.py | 55 | ||||
| -rw-r--r-- | src/mongo/db/SConscript | 1 | ||||
| -rw-r--r-- | src/mongo/unittest/SConscript | 25 |
8 files changed, 144 insertions, 37 deletions
diff --git a/etc/evergreen.yml b/etc/evergreen.yml index 770496c05c1..7a28152bfeb 100644 --- a/etc/evergreen.yml +++ b/etc/evergreen.yml @@ -358,6 +358,7 @@ buildvariants: - name: compile_ninja_TG distros: - rhel80-build + - name: ninja_determinism_TG - &enterprise-rhel80-dynamic-v4gcc-debug-experimental-template name: enterprise-rhel80-dynamic-v4gcc-debug-experimental @@ -1045,6 +1046,9 @@ buildvariants: - name: compile_ninja_TG distros: - windows-vsCurrent-large + - name: ninja_determinism_TG + distros: + - windows-vsCurrent-large - name: enterprise-windows-cxx20-debug-experimental display_name: "~ Enterprise Windows C++20 DEBUG" @@ -1176,6 +1180,7 @@ buildvariants: tasks: - name: compile_ninja_next_TG - name: compile_ninja_TG + - name: ninja_determinism_TG - name: enterprise-macos-rosetta-2 display_name: "Enterprise macOS Via Rosetta 2" @@ -1482,6 +1487,7 @@ buildvariants: - name: compile_ninja_TG distros: - rhel80-xlarge + - name: ninja_determinism_TG - &enterprise-rhel-80-64-bit-dynamic-all-feature-flags-required-template name: enterprise-rhel-80-64-bit-dynamic-all-feature-flags-required diff --git a/etc/evergreen_yml_components/definitions.yml b/etc/evergreen_yml_components/definitions.yml index 09c41440ed0..aec70a19154 100644 --- a/etc/evergreen_yml_components/definitions.yml +++ b/etc/evergreen_yml_components/definitions.yml @@ -2275,7 +2275,7 @@ tasks: tags: [] commands: - func: "scons compile" - vars: + vars: &compile-ninja-vars generating_for_ninja: true separate_debug: off task_install_action: @@ -2322,6 +2322,49 @@ tasks: targets: install-core +- name: ninja_determinism + tags: [] + commands: + - command: expansions.update + params: + updates: + - key: generating_for_ninja + value: "true" + - key: separate_debug + value: off + - key: task_install_action + value: default + - key: task_compile_flags + value: --ninja + - key: targets + value: generate-ninja + - *f_expansions_write + - command: subprocess.exec + params: + binary: bash + args: + - "src/evergreen/ninja_determinism_test.sh" + env: + repeat: "5" + - command: s3.put + params: + aws_key: ${aws_key} + aws_secret: ${aws_secret} + local_file: src/ninja.tgz + remote_file: ${project}/${build_variant}/${revision}/artifacts/ninja-determinism-${build_id}-${task_name}-${execution}.tgz + bucket: mciuploads + permissions: private + content_type: application/gzip + display_name: Ninja Determinism Test Artifacts + visibility: signed + optional: true + - command: subprocess.exec + type: test + params: + binary: bash + args: + - "src/evergreen/ninja_determinism_status.sh" + - name: libdeps_graph_linting tags: [] commands: @@ -7391,6 +7434,11 @@ task_groups: display_name: build.ninja - <<: *compile_task_group_template + name: ninja_determinism_TG + tasks: + - ninja_determinism + +- <<: *compile_task_group_template name: server_discovery_and_monitoring_json_test_TG tasks: - server_discovery_and_monitoring_json_test diff --git a/evergreen/ninja_determinism_status.sh b/evergreen/ninja_determinism_status.sh new file mode 100644 index 00000000000..1972cd178e2 --- /dev/null +++ b/evergreen/ninja_determinism_status.sh @@ -0,0 +1 @@ +exit < src/ninja_determinism.txt diff --git a/evergreen/ninja_determinism_test.sh b/evergreen/ninja_determinism_test.sh new file mode 100644 index 00000000000..6d351846b74 --- /dev/null +++ b/evergreen/ninja_determinism_test.sh @@ -0,0 +1,22 @@ +set -o errexit +set -o verbose + +for i in $(seq 1 $repeat); do + bash ./src/evergreen/scons_compile.sh + cd src + if [ $i == 1 ]; then + mv build.ninja build.ninja.a + mv build build.a + mv scons_stdout.log scons_stdout.log.a + else + if ! diff build.ninja build.ninja.a > build.ninja.diff; then + tar -cvf ninja.tgz build.ninja{,.a} build{,.a} build.ninja.diff scons_stdout.log{,.a} + echo "1" > ninja_determinism.txt + exit 0 + fi + rm -rf build.ninja build build.ninja.diff scons_stdout.log + fi + cd .. +done + +echo "0" > src/ninja_determinism.txt diff --git a/site_scons/site_tools/auto_install_binaries.py b/site_scons/site_tools/auto_install_binaries.py index acc248c5229..fc34fddd8ae 100644 --- a/site_scons/site_tools/auto_install_binaries.py +++ b/site_scons/site_tools/auto_install_binaries.py @@ -270,8 +270,8 @@ def scan_for_transitive_install(node, env, _path): installed_children = set( grandchild - for child in node.children() - for direct_children in child.children() + for source in node.sources + for direct_children in source.children() for grandchild in direct_children.get_executor().get_all_targets() if direct_children.get_executor() and grandchild.has_builder() ) @@ -286,20 +286,9 @@ def scan_for_transitive_install(node, env, _path): child_component = get_component(child) child_entry = get_alias_map_entry(env, child_component, child_role) - # This is where component inheritance happens. We need a default - # component for everything so we can store it but if during - # transitive scanning we see a child with the default component here - # we will move that file to our component. This prevents - # over-stepping the DAG bounds since the default component is likely - # to be large and an explicitly tagged file is unlikely to depend on - # everything in it. - if child_component == env.get(DEFAULT_COMPONENT): - setattr(node.attributes, COMPONENT, component) - for f in auto_installed_files: - child_entry.files.discard(f) - entry.files.update(auto_installed_files) - elif component != child_component: - entry.dependencies.add(child_entry) + if component != child_component: + if child_component != env.get(DEFAULT_COMPONENT): + entry.dependencies.add(child_entry) results.update(auto_installed_files) diff --git a/site_scons/site_tools/ninja.py b/site_scons/site_tools/ninja.py index d069e16382b..2fb4b84a107 100644 --- a/site_scons/site_tools/ninja.py +++ b/site_scons/site_tools/ninja.py @@ -31,6 +31,7 @@ import shlex import tempfile import textwrap +from collections import OrderedDict from glob import glob from os.path import join as joinpath from os.path import splitext @@ -699,7 +700,8 @@ class NinjaState: if generated_source_files: generated_sources_alias = "_ninja_generated_sources" - ninja.build( + ninja_sorted_build( + ninja, outputs=generated_sources_alias, rule="phony", implicit=generated_source_files @@ -782,8 +784,9 @@ class NinjaState: ) if remaining_outputs: - ninja.build( - outputs=sorted(remaining_outputs), rule="phony", implicit=first_output, + ninja_sorted_build( + ninja, outputs=sorted(remaining_outputs), rule="phony", + implicit=first_output, ) build["outputs"] = first_output @@ -801,7 +804,7 @@ class NinjaState: if "inputs" in build: build["inputs"].sort() - ninja.build(**build) + ninja_sorted_build(ninja, **build) template_builds = {'rule': "TEMPLATE"} for template_builder in template_builders: @@ -821,7 +824,7 @@ class NinjaState: template_builds[agg_key] = new_val if template_builds.get("outputs", []): - ninja.build(**template_builds) + ninja_sorted_build(ninja, **template_builds) # We have to glob the SCons files here to teach the ninja file # how to regenerate itself. We'll never see ourselves in the @@ -845,8 +848,9 @@ class NinjaState: self.env['NINJA_REGENERATE_DEPS'], ) - ninja.build( - ninja_in_file_path, + ninja_sorted_build( + ninja, + outputs=ninja_in_file_path, rule="REGENERATE", variables={ "self": ninja_file_path, @@ -856,8 +860,9 @@ class NinjaState: # This sets up a dependency edge between build.ninja.in and build.ninja # without actually taking any action to transform one into the other # because we write both files ourselves later. - ninja.build( - ninja_file_path, + ninja_sorted_build( + ninja, + outputs=ninja_file_path, rule="NOOP", inputs=[ninja_in_file_path], implicit=[__file__], @@ -866,8 +871,9 @@ class NinjaState: # If we ever change the name/s of the rules that include # compile commands (i.e. something like CC) we will need to # update this build to reflect that complete list. - ninja.build( - "compile_commands.json", + ninja_sorted_build( + ninja, + outputs="compile_commands.json", rule="CMD", pool="console", implicit=[ninja_file], @@ -878,8 +884,10 @@ class NinjaState: }, ) - ninja.build( - "compiledb", rule="phony", implicit=["compile_commands.json"], order_only=[generated_sources_alias], + ninja_sorted_build( + ninja, outputs="compiledb", rule="phony", + implicit=["compile_commands.json"], + order_only=[generated_sources_alias], ) # Look in SCons's list of DEFAULT_TARGETS, find the ones that @@ -948,9 +956,26 @@ def get_comstr(env, action, targets, sources): return action.genstring(targets, sources, env) +def ninja_recursive_sorted_dict(build): + sorted_dict = OrderedDict() + for key, val in sorted(build.items()): + if isinstance(val, dict): + sorted_dict[key] = ninja_recursive_sorted_dict(val) + elif isinstance(val, list) and key in ('inputs', 'outputs', 'implicit', 'order_only', 'implicit_outputs'): + sorted_dict[key] = sorted(val) + else: + sorted_dict[key] = val + return sorted_dict + + +def ninja_sorted_build(ninja, **build): + sorted_dict = ninja_recursive_sorted_dict(build) + ninja.build(**sorted_dict) + + def get_command_env(env): """ - Return a string that sets the enrivonment for any environment variables that + Return a string that sets the environment for any environment variables that differ between the OS environment and the SCons command ENV. It will be compatible with the default shell of the operating system. @@ -973,7 +998,7 @@ def get_command_env(env): windows = env["PLATFORM"] == "win32" command_env = "" - for key, value in scons_specified_env.items(): + for key, value in sorted(scons_specified_env.items()): # Ensure that the ENV values are all strings: if is_List(value): # If the value is a list, then we assume it is a diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index e7ed7cb15e1..8b635d03e47 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -2330,6 +2330,7 @@ env.Program( '$BUILD_DIR/mongo/util/signal_handlers', 'traffic_reader', ], + AIB_COMPONENT="mongotrafficreader" ) env.Library( diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript index b045b3f7429..f4d3cf21b7b 100644 --- a/src/mongo/unittest/SConscript +++ b/src/mongo/unittest/SConscript @@ -28,7 +28,10 @@ utEnv.Library( '$BUILD_DIR/third_party/shim_pcrecpp', '$BUILD_DIR/third_party/shim_yaml' ], - AIB_COMPONENT='unittests' + AIB_COMPONENT='unittest', + AIB_COMPONENTS_EXTRA=[ + 'test', + ] ) env.Library( @@ -45,7 +48,10 @@ env.Library( '$BUILD_DIR/mongo/db/wire_version', '$BUILD_DIR/mongo/util/options_parser/options_parser', ], - AIB_COMPONENT='unittests' + AIB_COMPONENT='unittest', + AIB_COMPONENTS_EXTRA=[ + 'test', + ] ) env.Library( @@ -70,7 +76,10 @@ env.Library( '$BUILD_DIR/mongo/util/options_parser/options_parser_init', '$BUILD_DIR/mongo/util/testing_options', ], - AIB_COMPONENT='integration-tests' + AIB_COMPONENT='integration-test', + AIB_COMPONENTS_EXTRA=[ + 'test', + ] ) bmEnv = env.Clone() @@ -87,7 +96,10 @@ bmEnv.Library( '$BUILD_DIR/mongo/base', '$BUILD_DIR/third_party/shim_benchmark', ], - AIB_COMPONENT='benchmarks' + AIB_COMPONENT='benchmark', + AIB_COMPONENTS_EXTRA=[ + 'test', + ] ) env.Library( @@ -98,7 +110,10 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/executor/task_executor_interface', ], - AIB_COMPONENT='benchmarks' + AIB_COMPONENT='benchmark', + AIB_COMPONENTS_EXTRA=[ + 'test', + ] ) env.CppUnitTest( |
