test: two builds of one module are refused before anything compiles
The fixture is P -> M and P -> A -> M, where M's own flag --wide changes a struct it exports. Loaded with --wide --split, P gives M its args without --wide while A passes them on whole: Build(P) has to fail, name the module and both paths, and leave no bin/ anywhere. Loaded with --wide alone, both paths give M the same list, there is one M, and the build has to go through. Before the fix the first case built cleanly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d5b80fcf7e
commit
3d2023cb5c
8 changed files with 188 additions and 0 deletions
6
tests/DuplicateModule/fixture/a/interfaces/A.cppm
Normal file
6
tests/DuplicateModule/fixture/a/interfaces/A.cppm
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
export module A;
|
||||
import std;
|
||||
import M;
|
||||
export std::int32_t ASize() {
|
||||
return Size();
|
||||
}
|
||||
24
tests/DuplicateModule/fixture/a/project.cpp
Normal file
24
tests/DuplicateModule/fixture/a/project.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
// Loads M with the default, so M gets whatever A was given.
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
Configuration* m = LocalProject({ .projectFile = "../m/project.cpp" });
|
||||
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "A";
|
||||
cfg.outputName = "A";
|
||||
cfg.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(cfg, args);
|
||||
cfg.dependencies = { m };
|
||||
std::array<fs::path, 1> ifaces = { "interfaces/A" };
|
||||
std::array<fs::path, 0> impls = {};
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
12
tests/DuplicateModule/fixture/m/interfaces/M.cppm
Normal file
12
tests/DuplicateModule/fixture/m/interfaces/M.cppm
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
export module M;
|
||||
import std;
|
||||
// --wide gives S more members, so the two builds of M the test asks for
|
||||
// differ in what they declare.
|
||||
#ifdef WIDE
|
||||
export struct S { std::int32_t a; std::int32_t b; std::int64_t pad[4]; };
|
||||
#else
|
||||
export struct S { std::int32_t a; std::int32_t b; };
|
||||
#endif
|
||||
export std::int32_t Size() {
|
||||
return static_cast<std::int32_t>(sizeof(S));
|
||||
}
|
||||
22
tests/DuplicateModule/fixture/m/project.cpp
Normal file
22
tests/DuplicateModule/fixture/m/project.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
// --wide is this project's own flag, and it changes what M declares.
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "M";
|
||||
cfg.outputName = "M";
|
||||
cfg.type = ConfigurationType::LibraryStatic;
|
||||
ApplyStandardArgs(cfg, args);
|
||||
if (std::ranges::contains(args, std::string_view("--wide"))) cfg.compileFlags.push_back("-DWIDE");
|
||||
std::array<fs::path, 1> ifaces = { "interfaces/M" };
|
||||
std::array<fs::path, 0> impls = {};
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
6
tests/DuplicateModule/fixture/p/main.cpp
Normal file
6
tests/DuplicateModule/fixture/p/main.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import std;
|
||||
import M;
|
||||
import A;
|
||||
int main() {
|
||||
return Size() == ASize() ? 0 : 1;
|
||||
}
|
||||
32
tests/DuplicateModule/fixture/p/project.cpp
Normal file
32
tests/DuplicateModule/fixture/p/project.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||||
|
||||
import std;
|
||||
import Crafter.Build;
|
||||
namespace fs = std::filesystem;
|
||||
using namespace Crafter;
|
||||
|
||||
// Loads M itself and through A, which passes on all of its args. With
|
||||
// --split, the list P gives M leaves --wide out, as a filter meant for one
|
||||
// sibling would, and the two paths load M with two different lists.
|
||||
extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> args) {
|
||||
const bool split = std::ranges::contains(args, std::string_view("--split"));
|
||||
std::vector<std::string> mArgs;
|
||||
for (std::string_view arg : args) {
|
||||
if (!split || arg != "--wide") mArgs.emplace_back(arg);
|
||||
}
|
||||
Configuration* m = LocalProject({ .projectFile = "../m/project.cpp", .args = mArgs });
|
||||
Configuration* a = LocalProject({ .projectFile = "../a/project.cpp" });
|
||||
|
||||
Configuration cfg;
|
||||
cfg.path = "./";
|
||||
cfg.name = "P";
|
||||
cfg.outputName = "P";
|
||||
cfg.type = ConfigurationType::Executable;
|
||||
ApplyStandardArgs(cfg, args);
|
||||
cfg.dependencies = { m, a };
|
||||
std::array<fs::path, 0> ifaces = {};
|
||||
std::array<fs::path, 1> impls = { "main" };
|
||||
cfg.GetInterfacesAndImplementations(ifaces, impls);
|
||||
return cfg;
|
||||
}
|
||||
Loading…
Reference in a new issue