From feba925e50e5e37634ff8ba363dbc28ff12f4e7b Mon Sep 17 00:00:00 2001 From: Mathew Robinson Date: Tue, 6 Aug 2019 18:42:44 -0400 Subject: [PATCH] SERVER-42656 Add scons targets for building and executing unittests --- site_scons/site_tools/mongo_benchmark.py | 16 +++++++++++++++- site_scons/site_tools/mongo_unittest.py | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/site_scons/site_tools/mongo_benchmark.py b/site_scons/site_tools/mongo_benchmark.py index d9c6a02f91e..3877aa0aa00 100644 --- a/site_scons/site_tools/mongo_benchmark.py +++ b/site_scons/site_tools/mongo_benchmark.py @@ -1,5 +1,6 @@ """Pseudo-builders for building and registering benchmarks. """ +import os from SCons.Script import Action def exists(env): @@ -37,7 +38,20 @@ def build_benchmark(env, target, source, **kwargs): bmEnv.RegisterBenchmark(result[0]) hygienic = bmEnv.GetOption('install-mode') == 'hygienic' if not hygienic: - bmEnv.Install("#/build/benchmark/", result[0]) + installed_test = bmEnv.Install("#/build/benchmark/", result[0]) + env.Command( + target="#+{}".format(os.path.basename(installed_test[0].path)), + source=installed_test, + action="${SOURCES[0]}" + ) + else: + test_bin_name = os.path.basename(result[0].path) + env.Command( + target="#+{}".format(test_bin_name), + source=["$PREFIX_BINDIR/{}".format(test_bin_name)], + action="${SOURCES[0]}" + ) + return result diff --git a/site_scons/site_tools/mongo_unittest.py b/site_scons/site_tools/mongo_unittest.py index d666ad9f833..924313fe311 100644 --- a/site_scons/site_tools/mongo_unittest.py +++ b/site_scons/site_tools/mongo_unittest.py @@ -1,4 +1,6 @@ '''Pseudo-builders for building and registering unit tests.''' +import os + from SCons.Script import Action @@ -39,9 +41,23 @@ def build_cpp_unit_test(env, target, source, **kwargs): result = env.Program(target, source, **kwargs) env.RegisterUnitTest(result[0]) + hygienic = env.GetOption('install-mode') == 'hygienic' if not hygienic: - env.Install('#/build/unittests/', result[0]) + installed_test = env.Install('#/build/unittests/', result[0]) + env.Command( + target="#+{}".format(os.path.basename(installed_test[0].path)), + source=installed_test, + action="${SOURCES[0]}" + ) + else: + test_bin_name = os.path.basename(result[0].path) + env.Command( + target="#+{}".format(test_bin_name), + source=["$PREFIX_BINDIR/{}".format(test_bin_name)], + action="${SOURCES[0]}" + ) + return result