|
19 | 19 |
|
20 | 20 | import std; |
21 | 21 | import mcpp.build.plan; |
| 22 | +import mcpp.build.ninja; |
22 | 23 | import mcpp.manifest; |
23 | 24 | import mcpp.modgraph.graph; |
24 | 25 | import mcpp.modgraph.scanner; |
@@ -310,3 +311,47 @@ TEST(ModuleAddress, EveryNamedArgumentFileIsOneThePlanStates) { |
310 | 311 | // another package or of a member. |
311 | 312 | EXPECT_EQ(named, 3u); |
312 | 313 | } |
| 314 | + |
| 315 | +// The argument file of a module map, as each compiler reads it. MSVC takes an |
| 316 | +// option's value only from the same line of a command file (`D8004: '/reference' |
| 317 | +// requires an argument` on windows-2025 when they were on two lines), and reads |
| 318 | +// a non-ASCII path only with a byte order mark; clang reads GNU rules, where a |
| 319 | +// word with a space is quoted. |
| 320 | +TEST(ModuleAddress, ArgumentFilesAreWrittenAsEachCompilerReadsThem) { |
| 321 | + Tmp t; |
| 322 | + auto read = [](const std::filesystem::path& p) { |
| 323 | + std::ifstream in(p, std::ios::binary); |
| 324 | + return std::string(std::istreambuf_iterator<char>(in), {}); |
| 325 | + }; |
| 326 | + |
| 327 | + BuildPlan msvc; |
| 328 | + msvc.outputDir = t.path / "msvc"; |
| 329 | + msvc.toolchain.compiler = mcpp::toolchain::CompilerId::MSVC; |
| 330 | + ModuleScope ms; |
| 331 | + ms.mapFile = "modmap/core-1.map"; |
| 332 | + ms.content = "m ifc.cache/core/m.ifc\n"; |
| 333 | + ms.argsFile = "modmap/core-1.modmap"; |
| 334 | + ms.arguments = {"/reference", "m=C:/build/ifc.cache/core/m.ifc", |
| 335 | + "/reference", "n=C:/build/ifc.cache/core/n.ifc"}; |
| 336 | + msvc.moduleScopes.emplace("core-1", ms); |
| 337 | + write_module_maps(msvc); |
| 338 | + EXPECT_EQ(read(msvc.outputDir / "modmap/core-1.modmap"), |
| 339 | + "\xEF\xBB\xBF/reference m=C:/build/ifc.cache/core/m.ifc\n" |
| 340 | + "/reference n=C:/build/ifc.cache/core/n.ifc\n"); |
| 341 | + EXPECT_EQ(read(msvc.outputDir / "modmap/core-1.map"), ms.content); |
| 342 | + |
| 343 | + BuildPlan clang; |
| 344 | + clang.outputDir = t.path / "clang"; |
| 345 | + clang.toolchain.compiler = mcpp::toolchain::CompilerId::Clang; |
| 346 | + ModuleScope cs; |
| 347 | + cs.mapFile = "modmap/core-2.map"; |
| 348 | + cs.content = "m pcm.cache/core/m.pcm\n"; |
| 349 | + cs.argsFile = "modmap/core-2.modmap"; |
| 350 | + cs.arguments = {"-fmodule-file=m=/build dir/pcm.cache/core/m.pcm", |
| 351 | + "-fmodule-file=n=/build/pcm.cache/core/n.pcm"}; |
| 352 | + clang.moduleScopes.emplace("core-2", cs); |
| 353 | + write_module_maps(clang); |
| 354 | + EXPECT_EQ(read(clang.outputDir / "modmap/core-2.modmap"), |
| 355 | + "\"-fmodule-file=m=/build dir/pcm.cache/core/m.pcm\"\n" |
| 356 | + "-fmodule-file=n=/build/pcm.cache/core/n.pcm\n"); |
| 357 | +} |
0 commit comments