Skip to content

Commit 8ce9c60

Browse files
committed
A polyglot pack of every system leaves out the systems the file is not started on (uefi, dos); one touch helper for the e2e cases, past the present
1 parent f7b9e0d commit 8ce9c60

9 files changed

Lines changed: 45 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@
5050
environment (`subos/default/.xlings.json`) as well as the project's, and with
5151
the turn in the project's directory it collided on Windows with an install of
5252
another project ("Failed to write file"). One turn per home orders both.
53+
- `mcpp pack --pkg-format polyglot --systems all` leaves out the systems a
54+
polyglot file is not started on: openkal-platform 0.28.0 names `uefi-x86_64`
55+
and `dos-i686` among its runner hosts, and the pack refused ("a polyglot file
56+
holds no program of uefi"). They are reported as not covered, with
57+
`--pkg-format single-file` as the way to make them; naming one of them
58+
explicitly is still refused.
5359
- A host tool built by two builds of one home at once is published by both:
5460
each writes through a temporary of its own (`mcpp.build.stage`), and a store
5561
entry already equal to the tool is published. With one temporary name for

‎src/pack/pack.cppm‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,10 @@ std::vector<SingleFileRow> single_file_rows(const Plan& plan) {
35923592
if (all && r.skipped.empty() && plan.platform.active)
35933593
if (auto why = detail::unbuilt_carrier(plan.platform, system, arch, true))
35943594
r.skipped = *why;
3595+
// `all` in one polyglot file: the systems the file is started on.
3596+
if (all && r.skipped.empty() && plan.opts.polyglot && !polyglot::holds(system))
3597+
r.skipped = std::format("a polyglot file is started by a shell or by the Windows loader, "
3598+
"and {} starts a program of its own (--pkg-format single-file)", system);
35953599
rows.push_back(std::move(r));
35963600
}
35973601
return rows;

‎src/pack/polyglot.cppm‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ std::expected<std::string, std::string> assemble(std::string_view name, const st
4848
// Whether `head`, the first bytes of a file, are a file `assemble` wrote.
4949
bool is_polyglot(std::string_view head);
5050

51+
// Whether the file can hold a program of `system`: a system that states its
52+
// `uname` (the script selects by it), or a stated system without one (its
53+
// program is the PE the file leads with). A program a firmware or another
54+
// loader starts by itself (`uefi`, `dos`) is no program of such a file.
55+
bool holds(std::string_view system);
56+
5157
} // namespace mcpp::pack::polyglot
5258

5359
namespace mcpp::pack::polyglot {
@@ -139,6 +145,10 @@ std::string stage_one(std::uint64_t at, std::uint64_t length) {
139145

140146
} // namespace
141147

148+
bool holds(std::string_view system) {
149+
return !uname_of(system).empty() || mcpp::toolchain::target::find_system(system) != nullptr;
150+
}
151+
142152
bool is_polyglot(std::string_view head) {
143153
return head.starts_with("MZqFpD='\n") || head.starts_with("#!/bin/sh\n" "o=$0;");
144154
}

‎tests/e2e/build/basics.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ std::vector<std::string> lines_of(std::string_view text) {
6060
return out;
6161
}
6262

63-
// A file's modification time moved past its present one (`sleep 1; touch file`).
64-
void touch(const fs::path& f) { fs::last_write_time(f, fs::last_write_time(f) + std::chrono::seconds(2)); }
63+
using s::touch;
6564

6665
// The first file under `root` whose path ends with `tail` (`find <root> -path '*<tail>'`).
6766
std::optional<fs::path> path_ending(const fs::path& root, std::string_view tail) {

‎tests/e2e/build/flags.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ std::vector<std::string> lines_of(std::string_view text) {
6060
return out;
6161
}
6262

63-
// A file's modification time moved past its present one (`sleep 1; touch file`).
64-
void touch(const fs::path& f) { fs::last_write_time(f, fs::last_write_time(f) + std::chrono::seconds(2)); }
63+
using s::touch;
6564

6665
// The first file under `root` whose path ends with `tail` (`find <root> -path '*<tail>'`).
6766
std::optional<fs::path> path_ending(const fs::path& root, std::string_view tail) {

‎tests/e2e/build/link.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ std::vector<std::string> lines_of(std::string_view text) {
5959
return out;
6060
}
6161

62-
// A file's modification time moved past its present one (`sleep 1; touch file`).
63-
void touch(const fs::path& f) { fs::last_write_time(f, fs::last_write_time(f) + std::chrono::seconds(2)); }
62+
using s::touch;
6463

6564
// The first file under `root` whose path ends with `tail` (`find <root> -path '*<tail>'`).
6665
std::optional<fs::path> path_ending(const fs::path& root, std::string_view tail) {

‎tests/e2e/build/sources.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ std::vector<std::string> lines_of(std::string_view text) {
5959
return out;
6060
}
6161

62-
// A file's modification time moved past its present one (`sleep 1; touch file`).
63-
void touch(const fs::path& f) { fs::last_write_time(f, fs::last_write_time(f) + std::chrono::seconds(2)); }
62+
using s::touch;
6463

6564
// The first file under `root` whose path ends with `tail` (`find <root> -path '*<tail>'`).
6665
std::optional<fs::path> path_ending(const fs::path& root, std::string_view tail) {

‎tests/support/src/support.cppm‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ fs::file_time_type file_time(std::chrono::sys_time<Duration> t) {
118118
return file_now + std::chrono::duration_cast<fs::file_time_type::duration>(t - sys_now);
119119
}
120120

121+
// A file's modification time moved past the present and its own (`sleep 1; touch file`), so a
122+
// build sees it changed. Its own time alone is not enough: the file was written before a build
123+
// that may take longer than the step, whose outputs are then newer than the file touched
124+
// (`basics/04` on Windows, run 43649417016).
125+
inline void touch(const fs::path& f) {
126+
fs::last_write_time(f, (std::max)(fs::file_time_type::clock::now(), fs::last_write_time(f)) + std::chrono::seconds(2));
127+
}
128+
121129
// ---- mcpp ----------------------------------------------------------------------------------------
122130

123131
// The mcpp under test: MCPP_E2E_MCPP when it is set (a released mcpp, tested by the cases of an

‎tests/unit/test_pack_polyglot.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,16 @@ UTest recognises_its_own_heads_only{"PackPolyglot/RecognisesItsOwnHeadsOnly", []
9292
expect(!pg::is_polyglot("#!/bin/sh\necho hi\n"));
9393
expect(!pg::is_polyglot(""));
9494
}};
95+
96+
// The file is started by a shell, which selects by `uname`, or by the Windows
97+
// loader, whose program leads it. A system a firmware or another loader starts
98+
// (`uefi`, a runner host of openkal-platform 0.28.0) is no system of the file:
99+
// `--systems all` leaves it out rather than refusing the pack.
100+
UTest holds_the_systems_a_shell_or_the_windows_loader_starts{"PackPolyglot/HoldsTheSystemsAShellOrTheWindowsLoaderStarts", [] {
101+
expect(mcpp::pack::polyglot::holds("linux"));
102+
expect(mcpp::pack::polyglot::holds("macos"));
103+
expect(mcpp::pack::polyglot::holds("freebsd"));
104+
expect(mcpp::pack::polyglot::holds("windows"));
105+
expect(!mcpp::pack::polyglot::holds("uefi"));
106+
expect(!mcpp::pack::polyglot::holds("dos"));
107+
}};

0 commit comments

Comments
 (0)