diff options
-rw-r--r-- | SConstruct | 48 | ||||
-rw-r--r-- | site_scons/site_tools/mongo_benchmark.py | 2 | ||||
-rw-r--r-- | site_scons/site_tools/mongo_integrationtest.py | 2 | ||||
-rw-r--r-- | site_scons/site_tools/mongo_libfuzzer.py | 2 | ||||
-rw-r--r-- | site_scons/site_tools/mongo_unittest.py | 2 | ||||
-rw-r--r-- | src/mongo/unittest/SConscript | 5 |
6 files changed, 57 insertions, 4 deletions
diff --git a/SConstruct b/SConstruct index 14cc7e23f0b..d5c3eeb4246 100644 --- a/SConstruct +++ b/SConstruct @@ -1843,6 +1843,54 @@ def init_no_global_libdeps_tag_expand(source, target, env, for_signature): env['LIBDEPS_TAG_EXPANSIONS'].append(init_no_global_libdeps_tag_expand) +link_guard_rules = { + "test" : ["dist"] +} + +class LibdepsLinkGuard(SCons.Errors.UserError): + pass + +def checkComponentType(target_comps, comp, target, lib): + """ + For a libdep and each AIB_COMPONENT its labeled as, check if its violates + any of the link gaurd rules. + """ + for target_comp in target_comps: + for link_guard_rule in link_guard_rules: + if (target_comp in link_guard_rules[link_guard_rule] + and link_guard_rule in comp): + raise LibdepsLinkGuard(textwrap.dedent(f"""\n + LibdepsLinkGuard: + \tTarget '{target[0]}' links LIBDEP '{lib}' + \tbut is listed as AIB_COMPONENT '{target_comp}' which is not allowed link libraries + \twith AIB_COMPONENTS that include the word '{link_guard_rule}'\n""")) + +def get_comps(env): + """util function for extracting all AIB_COMPONENTS as a list""" + comps = env.get("AIB_COMPONENTS_EXTRA", []) + comp = env.get("AIB_COMPONENT", None) + if comp: + comps += [comp] + return comps + +def link_guard_libdeps_tag_expand(source, target, env, for_signature): + """ + Callback function called on all binaries to check if a certain binary + from a given component is linked to another binary of a given component, + the goal being to define rules that prevents test components from being + linked into production or releaseable components. + """ + for lib in libdeps.get_libdeps(source, target, env, for_signature): + if not lib.env: + continue + + for comp in get_comps(lib.env): + checkComponentType(get_comps(env), comp, target, lib) + + return [] + +env['LIBDEPS_TAG_EXPANSIONS'].append(link_guard_libdeps_tag_expand) + # ---- other build setup ----- if debugBuild: env.SetConfigHeaderDefine("MONGO_CONFIG_DEBUG_BUILD") diff --git a/site_scons/site_tools/mongo_benchmark.py b/site_scons/site_tools/mongo_benchmark.py index 1f862c16465..5fe35b038d3 100644 --- a/site_scons/site_tools/mongo_benchmark.py +++ b/site_scons/site_tools/mongo_benchmark.py @@ -58,7 +58,7 @@ def build_benchmark(env, target, source, **kwargs): benchmark_test_components ) - kwargs["AIB_COMPONENTS_EXTRA"] = benchmark_test_components + kwargs["AIB_COMPONENTS_EXTRA"] = list(benchmark_test_components) result = bmEnv.Program(target, source, **kwargs) bmEnv.RegisterTest("$BENCHMARK_LIST", result[0]) diff --git a/site_scons/site_tools/mongo_integrationtest.py b/site_scons/site_tools/mongo_integrationtest.py index 5e74a077c61..9bd5146ac50 100644 --- a/site_scons/site_tools/mongo_integrationtest.py +++ b/site_scons/site_tools/mongo_integrationtest.py @@ -52,7 +52,7 @@ def build_cpp_integration_test(env, target, source, **kwargs): integration_test_components ) else: - kwargs["AIB_COMPONENTS_EXTRA"] = integration_test_components + kwargs["AIB_COMPONENTS_EXTRA"] = list(integration_test_components) result = env.Program(target, source, **kwargs) env.RegisterTest("$INTEGRATION_TEST_LIST", result[0]) diff --git a/site_scons/site_tools/mongo_libfuzzer.py b/site_scons/site_tools/mongo_libfuzzer.py index 8b4a176ff5d..3f15032ca56 100644 --- a/site_scons/site_tools/mongo_libfuzzer.py +++ b/site_scons/site_tools/mongo_libfuzzer.py @@ -58,7 +58,7 @@ def build_cpp_libfuzzer_test(env, target, source, **kwargs): libfuzzer_test_components ) - kwargs["AIB_COMPONENTS_EXTRA"] = libfuzzer_test_components + kwargs["AIB_COMPONENTS_EXTRA"] = list(libfuzzer_test_components) result = myenv.Program(target, source, **kwargs) myenv.RegisterTest("$LIBFUZZER_TEST_LIST", result[0]) diff --git a/site_scons/site_tools/mongo_unittest.py b/site_scons/site_tools/mongo_unittest.py index 5a165926bb7..33373282606 100644 --- a/site_scons/site_tools/mongo_unittest.py +++ b/site_scons/site_tools/mongo_unittest.py @@ -57,7 +57,7 @@ def build_cpp_unit_test(env, target, source, **kwargs): unit_test_components ) else: - kwargs["AIB_COMPONENTS_EXTRA"] = unit_test_components + kwargs["AIB_COMPONENTS_EXTRA"] = list(unit_test_components) result = env.Program(target, source, **kwargs) env.RegisterTest("$UNITTEST_LIST", result[0]) diff --git a/src/mongo/unittest/SConscript b/src/mongo/unittest/SConscript index 54d2ee54c52..7b7e09341dd 100644 --- a/src/mongo/unittest/SConscript +++ b/src/mongo/unittest/SConscript @@ -23,6 +23,7 @@ env.Library( '$BUILD_DIR/mongo/util/options_parser/options_parser', '$BUILD_DIR/third_party/shim_pcrecpp', ], + AIB_COMPONENT='unittests' ) env.Library( @@ -39,6 +40,7 @@ env.Library( '$BUILD_DIR/mongo/db/wire_version', '$BUILD_DIR/mongo/util/options_parser/options_parser', ], + AIB_COMPONENT='unittests' ) env.Library( @@ -62,6 +64,7 @@ env.Library( '$BUILD_DIR/mongo/util/options_parser/options_parser', '$BUILD_DIR/mongo/util/options_parser/options_parser_init', ], + AIB_COMPONENT='integration-tests' ) bmEnv = env.Clone() @@ -76,6 +79,7 @@ bmEnv.Library( '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/third_party/shim_benchmark', ], + AIB_COMPONENT='benchmarks' ) env.Library( @@ -86,6 +90,7 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/executor/task_executor_interface', ], + AIB_COMPONENT='benchmarks' ) env.CppUnitTest( |