From 486629381013201dff81141570b3b6d5ab5b266f Mon Sep 17 00:00:00 2001 From: Justin Nolan Date: Wed, 13 May 2026 14:00:41 +0200 Subject: [PATCH] Prevents VariantDir from duplicating source files --- SConstruct | 25 +++++++++++++++---------- deps/lexy-vdf | 2 +- deps/openvic-dataloader | 2 +- scripts | 2 +- tests/SCsub | 8 ++++---- tests/benchmarks/SCsub | 8 ++++---- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/SConstruct b/SConstruct index 7efb885dc..3c156c1e2 100644 --- a/SConstruct +++ b/SConstruct @@ -54,12 +54,14 @@ env.openvic_simulation = {} # Tweak this if you want to use different folders, or more folders, to store your source code in. source_path = "src/openvic-simulation" include_path = "src" -# Mirror the simulation source tree into the per-config build dir +# Out-of-source build: variant tree holds object files and generated headers, +# not copies of the source. Compile diagnostics therefore reference original +# source paths. sim_variant = build_dir + "/" + source_path # forward slashes so VariantDir matches sim_variant_parent = build_dir + "/" + include_path # variant of "src/" -env.VariantDir(sim_variant, source_path, duplicate=True) +env.VariantDir(sim_variant, source_path, duplicate=False) -env.Append(CPPPATH=[[env.Dir(p) for p in [sim_variant, sim_variant_parent]]]) +env.Append(CPPPATH=[[env.Dir(p) for p in [sim_variant, sim_variant_parent, source_path, include_path]]]) gen_commit_info = env.CommandNoCache( sim_variant + "/gen/commit_info.gen.hpp", @@ -98,8 +100,9 @@ Default(gen_commit_info, gen_license_info, gen_author_info) # Exclude pch.cpp from the regular source list so it isn't compiled twice # (env.PCH below builds it once with /Yc). +pch_cpp_source = source_path + "/pch.cpp" pch_cpp_variant = sim_variant + "/pch.cpp" -sources = env.GlobRecursive("*.cpp", [sim_variant], pch_cpp_variant) +sources = env.GlobRecursiveVariant("*.cpp", source_path, sim_variant, pch_cpp_source) env.simulation_sources = sources library = None @@ -130,8 +133,8 @@ if env["build_ovsim_library"]: library = env.StaticLibrary(target=env.File(os.path.join(BINDIR, library_name)), source=sources) default_args += [library] - # VariantDir(..., duplicate=True) copies sources into build_dir but does - # not register the copies as targets, so `scons -c` leaves them behind. + # Ensure `scons -c` wipes the per-config build dir, including any stragglers + # (gen headers, .pch caches) not directly attached to the library target. env.Clean(library, env.Dir(build_dir)) env.Append(LIBPATH=[env.Dir(BINDIR)]) @@ -139,7 +142,9 @@ if env["build_ovsim_library"]: env.openvic_simulation["LIBPATH"] = env["LIBPATH"] env.openvic_simulation["LIBS"] = env["LIBS"] - env.openvic_simulation["INCPATH"] = [env.Dir(sim_variant_parent)] + env.exposed_includes + # Variant parent for generated headers (gen/*.gen.hpp); source parent for + # authored headers (MSVC's preprocessor needs both physically in -I). + env.openvic_simulation["INCPATH"] = [env.Dir(sim_variant_parent), env.Dir(include_path)] + env.exposed_includes env.openvic_simulation["GEN_FILES"] = gen_files headless_program = None @@ -150,10 +155,10 @@ if env["build_ovsim_headless"]: headless_env = env.Clone() headless_src = "src/headless" headless_variant = build_dir + "/" + headless_src - headless_env.VariantDir(headless_variant, headless_src, duplicate=True) + headless_env.VariantDir(headless_variant, headless_src, duplicate=False) headless_env.Append(CPPDEFINES=["OPENVIC_SIM_HEADLESS"]) - headless_env.Append(CPPPATH=[headless_env.Dir(headless_variant)]) - headless_env.headless_sources = env.GlobRecursive("*.cpp", [headless_variant]) + headless_env.Append(CPPPATH=[headless_env.Dir(headless_variant), headless_env.Dir(headless_src)]) + headless_env.headless_sources = env.GlobRecursiveVariant("*.cpp", headless_src, headless_variant) if not env["build_ovsim_library"]: headless_env.headless_sources += sources headless_program = headless_env.Program( diff --git a/deps/lexy-vdf b/deps/lexy-vdf index b241a1708..f0b942600 160000 --- a/deps/lexy-vdf +++ b/deps/lexy-vdf @@ -1 +1 @@ -Subproject commit b241a1708be097b0f511021f3b6f5d8ea382250a +Subproject commit f0b9426009752479b71911f55ddc836282d55ec3 diff --git a/deps/openvic-dataloader b/deps/openvic-dataloader index 9b37b6acd..f98c87ada 160000 --- a/deps/openvic-dataloader +++ b/deps/openvic-dataloader @@ -1 +1 @@ -Subproject commit 9b37b6acdd0686cc58c269ef3b087c50cf6b635d +Subproject commit f98c87ada832e95b720f15b49a13f95457710a67 diff --git a/scripts b/scripts index d8f908cb2..76abb7ead 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit d8f908cb2d7b4a4564d12f71cbfe97bed241195f +Subproject commit 76abb7eadb24eb8bdb696fd5928ba41d68a36298 diff --git a/tests/SCsub b/tests/SCsub index c885eae89..0a1159212 100644 --- a/tests/SCsub +++ b/tests/SCsub @@ -44,12 +44,12 @@ source_path = "src" # relative to this SCsub (i.e. tests/src under the sim root tests_name = "openvic-simulation" tests_env = env.Clone() -# Mirror tests/src into the per-config build dir +# Out-of-source build: variant tree holds object files only. tests_variant = env["build_dir"] + "/tests/" + source_path -tests_env.VariantDir(tests_variant, source_path, duplicate=True) +tests_env.VariantDir(tests_variant, source_path, duplicate=False) tests_env.Append(CPPDEFINES=["OPENVIC_SIMULATION_TESTS"]) -tests_env.Append(CPPPATH=[tests_env.Dir(tests_variant)]) -tests_env.tests_sources = env.GlobRecursive("*.cpp", [tests_variant]) +tests_env.Append(CPPPATH=[tests_env.Dir(tests_variant), tests_env.Dir(source_path)]) +tests_env.tests_sources = env.GlobRecursiveVariant("*.cpp", source_path, tests_variant) SConscript("deps/SCsub", {"env": tests_env}) diff --git a/tests/benchmarks/SCsub b/tests/benchmarks/SCsub index 4ccb97985..055a5a5fa 100644 --- a/tests/benchmarks/SCsub +++ b/tests/benchmarks/SCsub @@ -44,13 +44,13 @@ source_path = "src" # relative to this SCsub (i.e. tests/benchmarks/src under t benchmarks_name = "openvic-simulation" benchmarks_env = env.Clone() -# Mirror benchmarks/src into the per-config build dir +# Out-of-source build: variant tree holds object files only. benchmarks_variant = env["build_dir"] + "/tests/benchmarks/" + source_path -benchmarks_env.VariantDir(benchmarks_variant, source_path, duplicate=True) +benchmarks_env.VariantDir(benchmarks_variant, source_path, duplicate=False) benchmarks_env.Append(CPPDEFINES=["OPENVIC_SIMULATION_BENCHMARKS"]) -benchmarks_env.Append(CPPPATH=[benchmarks_env.Dir(benchmarks_variant)]) -benchmarks_env.benchmarks_sources = env.GlobRecursive("*.cpp", [benchmarks_variant]) +benchmarks_env.Append(CPPPATH=[benchmarks_env.Dir(benchmarks_variant), benchmarks_env.Dir(source_path)]) +benchmarks_env.benchmarks_sources = env.GlobRecursiveVariant("*.cpp", source_path, benchmarks_variant) SConscript("deps/SCsub", {"env": benchmarks_env, "parent_env": env})