@@ -1378,6 +1378,32 @@ std::optional<Refusal> stage_member(PackRun& run, GroupJob& g, MemberJob& m) {
13781378// One pass serves every member of the group: each member has its own stage,
13791379// the programs act for the member they belong to (`BuildOverrides::
13801380// pack_stages`), and one ninja drive builds every member's edges.
1381+
1382+ // Copy a provider's distributable `product` into `dir` under its own name, with
1383+ // those of `beside` (outputs the product consumed) below the product's own
1384+ // directory, at their places relative to it. Each destination is replaced, and
1385+ // nothing else in `dir` is touched. Returns why it failed, or nothing.
1386+ std::string copy_distributable (const std::filesystem::path& product,
1387+ const std::vector<std::filesystem::path>& beside,
1388+ const std::filesystem::path& dir) {
1389+ namespace fs = std::filesystem;
1390+ const auto base = product.parent_path ().lexically_normal ();
1391+ std::vector<std::pair<fs::path, fs::path>> copies{{product, dir / product.filename ()}};
1392+ for (auto const & b : beside) {
1393+ const auto rel = b.lexically_normal ().lexically_relative (base);
1394+ if (rel.empty () || *rel.begin () == " .." ) continue ;
1395+ copies.emplace_back (b, dir / rel);
1396+ }
1397+ std::error_code ec;
1398+ for (auto const & [from, to] : copies) {
1399+ fs::remove_all (to, ec);
1400+ if (to.has_parent_path ()) fs::create_directories (to.parent_path (), ec);
1401+ fs::copy (from, to, fs::copy_options::recursive, ec);
1402+ if (ec) return std::format (" cannot write {}: {}" , to.string (), ec.message ());
1403+ }
1404+ return {};
1405+ }
1406+
13811407std::optional<Refusal> dispatch_group (PackRun& run, GroupJob& g, mcpp::build::Backend& be) {
13821408 // WHICH ARTIFACT ACTIONS THIS BUILD ALREADY HAD, before a format was
13831409 // requested. The dispatch below reports what the REQUEST introduced,
@@ -1637,18 +1663,20 @@ std::optional<Refusal> dispatch_group(PackRun& run, GroupJob& g, mcpp::build::Ba
16371663 reported.push_back (std::move (abs));
16381664 }
16391665 if (!produced) continue ;
1640- // `-o <directory>/`: the distributable below it, under its own name.
1666+ // `-o <directory>/`: the distributable below it, under its own name,
1667+ // with the outputs it consumed that lie in its own directory, at their
1668+ // places relative to it. A page reads its script and module from beside
1669+ // it (dist-web's index.html, web-consumer.js, web-consumer.wasm); copied
1670+ // alone it loads nothing (2026.11.23.1 wrote dist/pack/index.html only).
16411671 if (!run.opts .outputDir .empty ())
16421672 for (auto & r : reported) {
16431673 const auto into = std::filesystem::absolute (run.opts .outputDir / r.filename (), ec).lexically_normal ();
16441674 // A provider may have written it there already (the okb is
16451675 // written beside the staged tree, in target/dist/): removing
16461676 // the destination would remove the product.
16471677 if (into == r.lexically_normal ()) continue ;
1648- std::filesystem::remove_all (into, ec);
1649- std::filesystem::copy (r, into, std::filesystem::copy_options::recursive, ec);
1650- if (ec) {
1651- mcpp::ui::error (about (run, m, std::format (" cannot write {}: {}" , into.string (), ec.message ())));
1678+ if (auto why = copy_distributable (r, intermediate, into.parent_path ()); !why.empty ()) {
1679+ mcpp::ui::error (about (run, m, why));
16521680 m.result .rc = 1 ;
16531681 break ;
16541682 }
0 commit comments