Skip to content

Commit 49e2bb1

Browse files
fix(build): a taken over directory keeps no compiler record of its predecessor
A split compile keeps its slot's records beside each object, and the completion certificate names the object by its absolute path. A new fingerprint of a configuration's lineage takes its predecessor's directory over, so after an mcpp upgrade the certificates named the predecessor's objects and the next build refused them at admission until mcpp clean. The takeover drops them, and a certificate of another directory found at admission (a moved or restored directory) authorizes nothing and is dropped: the object is compiled again. e2e 1022. Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 4cdf099 commit 49e2bb1

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

‎src/build/prepare/build_dir.cpp‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ std::string toolchain_text(const mcpp::toolchain::Fingerprint& fp) {
4040
return std::format("compiler {}\ndriver {}\nstdlib {}\n", fp.parts[1], fp.parts[2], fp.parts[4]);
4141
}
4242

43+
// THE COMPILER RECORDS OF THE PREDECESSOR ARE NOT TAKEN OVER. Beside each object
44+
// a split compile keeps its slot's records (`<object>.sched.*`, compiler
45+
// transactions): the attempt's transaction, its completion certificate, its
46+
// status and the BMI it preserved. They name the predecessor's paths, and a
47+
// certificate that names another directory's object is refused at the next
48+
// build's admission ("cached compiler certificate does not name its own
49+
// object") -- every build of the configuration after an mcpp upgrade failed so.
50+
// They describe attempts made there, and none is running (the predecessor's
51+
// lock is held), so they are removed: an object they would have admitted is
52+
// compiled again.
53+
void drop_compiler_records(const std::filesystem::path& objects) {
54+
namespace fs = std::filesystem;
55+
std::error_code ec;
56+
std::vector<fs::path> records;
57+
for (fs::recursive_directory_iterator it(objects, ec), end; !ec && it != end; it.increment(ec)) {
58+
const auto name = it->path().filename().string();
59+
if (name.ends_with(".sched") || name.find(".sched.") != std::string::npos) records.push_back(it->path());
60+
}
61+
for (const auto& r : records) {
62+
std::error_code rec;
63+
fs::remove_all(r, rec);
64+
}
65+
}
66+
4367
std::string read_small(const std::filesystem::path& file) {
4468
std::ifstream in(file, std::ios::binary);
4569
return {std::istreambuf_iterator<char>(in), {}};
@@ -83,6 +107,7 @@ void adopt_predecessor_dir(const PrepareState& state, const std::filesystem::pat
83107
fs::remove_all(outputDir / name, mec);
84108
fs::rename(e.path(), outputDir / name, mec);
85109
}
110+
drop_compiler_records(outputDir / "obj");
86111
mcpp::log::info("build/dir", std::format("{} continues as {}", shown,
87112
outputDir.lexically_relative(state.workRoot).generic_string()));
88113
}

‎src/build/schedule/compiler_transaction.cpp‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,18 @@ std::expected<void,std::string> admit_completed(const fs::path& certificate,
6060
const auto name=spelling(certificate);
6161
const auto slot=named(std::string_view(name).substr(0,name.size()-std::string_view(".completed").size()));
6262
const auto object=named(std::string_view(name).substr(0,name.size()-std::string_view(".sched.completed").size()));
63-
if(named(v[1])!=object)return std::unexpected("cached compiler certificate does not name its own object");
63+
if(named(v[1])!=object) {
64+
// A certificate of another directory's object: the directory was taken over,
65+
// moved or restored elsewhere. It authorizes nothing here, so the slot's
66+
// records go and the object is compiled again; nothing it names is touched.
67+
std::error_code rec;
68+
const auto prefix=spelling(slot.filename())+".";
69+
std::vector<fs::path> records;
70+
for(const auto& e:fs::directory_iterator(slot.parent_path(),rec))
71+
if(spelling(e.path().filename()).starts_with(prefix))records.push_back(e.path());
72+
for(const auto& r:records){std::error_code one;fs::remove(r,one);}
73+
return {};
74+
}
6475
const auto bmi=named(v[0]);const auto cache=output_directory/"gcm.cache";
6576
const auto relative=bmi.lexically_relative(cache);
6677
if(!bmi.is_absolute()||bmi!=bmi.lexically_normal()||relative.empty()||relative.is_absolute()
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
# requires: gcc
3+
# 1022 -- a build directory taken over keeps no compiler record of another
4+
# directory (2026.11.7.1). A split compile (`bmi_schedule`, GCC's detach-codegen)
5+
# keeps its slot's records beside each object (`<object>.sched.*`), and the
6+
# completion certificate names the object by its absolute path. A new
7+
# fingerprint of a configuration's lineage takes its predecessor's directory
8+
# over (design 2026-10-31 §8), and the certificates there named the
9+
# predecessor's objects: the next build refused them at admission ("cached
10+
# compiler certificate does not name its own object"), and every build of the
11+
# configuration after an mcpp upgrade failed so, until `mcpp clean`.
12+
#
13+
# The predecessor is made with plain files: a dev build's directory, renamed,
14+
# whose `lineage` is the release configuration's, so the release build takes it
15+
# over while its certificates name the dev build's objects.
16+
#
17+
# Criteria:
18+
# A. The release build takes the predecessor over and builds.
19+
# B. No record of the predecessor is left beside the objects.
20+
# C. A certificate of another directory found at admission -- the directory
21+
# moved, or restored elsewhere -- is no record: the build compiles the
22+
# object again rather than failing.
23+
set -e
24+
25+
TMP=$(mktemp -d)
26+
trap "rm -rf $TMP" EXIT
27+
export MCPP_HOME="$TMP/mcpp-home"
28+
source "$(dirname "$0")/_inherit_toolchain.sh"
29+
fail() { echo "FAIL: $1"; shift; for f in "$@"; do echo "--- $f ---"; cat "$f" 2>/dev/null; done; exit 1; }
30+
31+
cd "$TMP"
32+
mkdir -p app/src && cd app
33+
printf '[package]\nname = "app"\nversion = "0.1.0"\n\n[build]\nbmi_schedule = "on"\n' > mcpp.toml
34+
printf 'export module greet;\nexport int answer() { return 42; }\n' > src/greet.cppm
35+
printf 'import greet;\nint main() { return answer() == 42 ? 0 : 1; }\n' > src/main.cpp
36+
config() { ls -d target/*/*/ | grep -E '/[0-9a-f]{16}/$' | head -1 | sed 's#/$##'; }
37+
38+
"$MCPP" build --release > r0.log 2>&1 || fail "the first release build failed" r0.log
39+
release=$(config); cp "$release/lineage" release.lineage; rm -rf "$release"
40+
"$MCPP" build > d0.log 2>&1 || fail "the dev build failed" d0.log
41+
dev=$(config)
42+
ls "$dev"/obj/*.sched.completed > /dev/null 2>&1 || fail "the split compile left no certificate" <(find "$dev/obj")
43+
pred="$(dirname "$dev")/0000000000000000"
44+
mv "$dev" "$pred"; cp release.lineage "$pred/lineage"
45+
46+
# A
47+
printf 'import greet;\nint main() { return answer() == 42 ? 0 : 2; }\n' > src/main.cpp
48+
"$MCPP" build --release > a.log 2>&1 || fail "the build that took the predecessor over failed" a.log
49+
[ ! -d "$pred" ] || fail "the predecessor was not taken over" <(ls "$(dirname "$pred")")
50+
taken=$(config)
51+
echo "ok: the release build took the predecessor over and built"
52+
53+
# B
54+
if grep -rl "/0000000000000000/" "$taken"/obj --include='*.sched*' > /dev/null 2>&1; then
55+
fail "a record of the predecessor was left beside the objects" <(grep -rl "/0000000000000000/" "$taken"/obj)
56+
fi
57+
echo "ok: no record of the predecessor is left"
58+
59+
# C
60+
moved="$TMP/moved-app"; cp -a "$TMP/app" "$moved"; cd "$moved"
61+
printf 'export module greet;\nexport int answer() { return 41 + 1; }\n' > src/greet.cppm
62+
"$MCPP" build --release > c.log 2>&1 || fail "the build of a moved directory failed" c.log
63+
echo "ok: a certificate of another directory is no record"
64+
65+
echo "PASS: 1022 a taken over directory keeps no compiler record of another"

0 commit comments

Comments
 (0)