@@ -94,15 +94,20 @@ namespace libc = mcpplibs::mwrap::libc::macros;
9494// legs/<triple>/programs/<program> the package's own programs, which a
9595// test finds as MCPP_BIN_<NAME> (L5)
9696//
97- // `mcpp-tests.json` (schema 1): `package`, `cwd` (the directory the tests run
97+ // `mcpp-tests.json` (schema 1, or 2 with `named_programs` ): `package`, `cwd` (the directory the tests run
9898// in, relative to the project root: the package's own), and `legs`, each with
9999// its `triple`, `programs` (environment name to path) and `tests` (`name`,
100100// `program`, the `files` beside it, the test `protocol` it implements, 0 for
101101// none, as the build decided it, and `own_files`, the files that are its own:
102102// an archive is run by the same runner as a build's tests). Paths are relative to the archive's directory and use `/`.
103103export namespace mcpp ::build::test_archive {
104104
105+ // Schema 2 is an archive whose legs name programs it does not carry
106+ // (`named_programs`, `--no-programs`): an mcpp that reads only schema 1 refuses
107+ // it, rather than running its tests without the programs they test. Every
108+ // other archive is written as schema 1, and both are read.
105109inline constexpr int kSchema = 1 ;
110+ inline constexpr int kSchemaNamed = 2 ;
106111inline constexpr std::string_view kManifestName = " mcpp-tests.json" ;
107112
108113struct Test {
@@ -188,14 +193,16 @@ nlohmann::json to_json(const Manifest& m) {
188193 if (!l.named .empty ()) leg[" named_programs" ] = l.named ;
189194 legs.push_back (std::move (leg));
190195 }
191- return {{" schema" , kSchema }, {" mcpp" , std::string (mcpp::MCPP_VERSION )},
196+ const bool named = std::ranges::any_of (m.legs , [](auto const & l) { return !l.named .empty (); });
197+ return {{" schema" , named ? kSchemaNamed : kSchema }, {" mcpp" , std::string (mcpp::MCPP_VERSION )},
192198 {" package" , m.package }, {" cwd" , m.cwd }, {" legs" , std::move (legs)}};
193199}
194200
195201std::expected<Manifest, std::string> from_json (const nlohmann::json& d) {
196- if (!d.is_object () || d.value (" schema" , 0 ) != kSchema )
197- return std::unexpected (std::format (" {} is not a schema-{} test archive manifest" ,
198- kManifestName , kSchema ));
202+ const int schema = d.is_object () ? d.value (" schema" , 0 ) : 0 ;
203+ if (schema != kSchema && schema != kSchemaNamed )
204+ return std::unexpected (std::format (" {} is not a schema-{} or schema-{} test archive manifest" ,
205+ kManifestName , kSchema , kSchemaNamed ));
199206 Manifest m;
200207 m.package = d.value (" package" , " " );
201208 m.cwd = d.value (" cwd" , " " );
@@ -1350,7 +1357,9 @@ std::optional<std::filesystem::path> platform_tool(const mcpp::build::BuildConte
13501357// A preparation that provisions no tool -- the run of an archive
13511358// (PrepareIntent::RunBuilt) -- has not located the platform's tool for this
13521359// machine either. Its runner is then the platform's runner for this machine's
1353- // architecture, the same program, made the way another architecture's is.
1360+ // architecture, the same program, made the way another architecture's is
1361+ // (under the checkout's target/carrier-pack/). Any other preparation that did
1362+ // not locate the tool reports the runner not found, as before.
13541363struct RunnerTool {
13551364 std::filesystem::path program;
13561365 std::string arch; // the architecture it is built for
@@ -1359,7 +1368,9 @@ std::expected<std::optional<RunnerTool>, std::string>
13591368runner_tool (const mcpp::build::BuildContext& ctx, std::string_view word, std::string_view tripleKey,
13601369 bool noRunner, bool build = true ) {
13611370 auto tool = platform_tool (ctx, word);
1362- if (!tool && !ctx.plan .platform .fields .tools .contains (std::string (word))) return std::nullopt ;
1371+ const bool provisionedNone = ctx.intent == mcpp::build::PrepareIntent::RunBuilt;
1372+ if (!tool && !(provisionedNone && ctx.plan .platform .fields .tools .contains (std::string (word))))
1373+ return std::nullopt ;
13631374 auto t = mcpp::toolchain::triple::parse (tripleKey);
13641375 std::string arch = t ? std::string (t->arch ) : std::string{};
13651376 if (!t || mcpp::platform::runner_reach (ctx.plan .platform .fields .runner , t->arch ,
@@ -6282,17 +6293,6 @@ export int run_test_archive(std::span<const std::string> passthrough, BuildOverr
62826293 const auto cwd = opened->manifest .cwd .empty () ? *root : *root / opened->manifest .cwd ;
62836294 // THE PROGRAMS THE RUN NAMES: an archive written with `--no-programs`
62846295 // carries none of the package's programs.
6285- std::map<std::string, std::string> namedPrograms;
6286- {
6287- std::vector<std::pair<std::string, std::string>> named;
6288- for (auto const & leg : opened->manifest .legs )
6289- for (auto const & env : leg.named ) named.emplace_back (env, " " );
6290- if (auto why = programs_from_environment (named)) {
6291- mcpp::ui::error (std::format (" --archive {}: {}" , testOpts.archive .string (), *why));
6292- return 2 ;
6293- }
6294- namedPrograms.insert (named.begin (), named.end ());
6295- }
62966296 int passed = 0 , failed = 0 , notRun = 0 , notReached = 0 ;
62976297 std::vector<std::string> reasons;
62986298 for (auto const & leg : opened->manifest .legs ) {
@@ -6325,7 +6325,20 @@ export int run_test_archive(std::span<const std::string> passthrough, BuildOverr
63256325 std::vector<std::pair<std::string, std::string>> legEnv;
63266326 for (auto const & [env, path] : leg.programs )
63276327 legEnv.emplace_back (env, (opened->root / path).lexically_normal ().string ());
6328- for (auto const & env : leg.named ) legEnv.emplace_back (env, namedPrograms[env]);
6328+ // THE PROGRAMS THE LEG NAMES, from this run's environment, asked for
6329+ // once the leg is known to run here: a leg another machine runs needs
6330+ // none of them. One the environment does not name is refused before
6331+ // any of the leg's tests run.
6332+ if (!leg.named .empty ()) {
6333+ std::vector<std::pair<std::string, std::string>> named;
6334+ for (auto const & env : leg.named ) named.emplace_back (env, " " );
6335+ if (auto why = programs_from_environment (named)) {
6336+ mcpp::ui::error (std::format (" --archive {}: the {} leg: {}" , testOpts.archive .string (),
6337+ leg.triple , *why));
6338+ return 2 ;
6339+ }
6340+ legEnv.insert (legEnv.end (), named.begin (), named.end ());
6341+ }
63296342 // THE LEG'S TESTS, RUN AS A BUILD'S ARE: through the runner, the
63306343 // protocol each implements, a process per file of its cases, the
63316344 // workers, the store (SPEC-015 §4; docs/08).
@@ -6352,8 +6365,7 @@ export int run_test_archive(std::span<const std::string> passthrough, BuildOverr
63526365 // (runner_handoff_env): the files the program carries, each named
63536366 // by its place beside the program, as the archive keeps it. The
63546367 // records are written in the archive's run directory, beside the
6355- // programs they describe: the checkout's output tree is not
6356- // touched by a run that builds nothing.
6368+ // programs they describe, not among the checkout's build outputs.
63576369 if (!tb.runnerTmpl .empty () || !tb.runUnderPrefix .empty ()) {
63586370 std::vector<std::pair<std::string, fs::path>> carried;
63596371 for (auto const & f : t.files ) {
0 commit comments