Skip to content

Commit 3a4099b

Browse files
committed
[fix](thirdparty) Publish Rust archives after copy and strip succeed
1 parent f805ff3 commit 3a4099b

2 files changed

Lines changed: 69 additions & 11 deletions

File tree

‎thirdparty/build-thirdparty.sh‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,24 @@ build_pugixml() {
23722372
}
23732373

23742374
# lance-c
2375+
# Publish a complete archive with one rename. Copy/strip must not damage an installed library
2376+
# or expose a partial first installation if either command fails or the build is interrupted.
2377+
install_rust_archive() {
2378+
(
2379+
set -e
2380+
local archive="$1"
2381+
local destination="${TP_INSTALL_DIR}/lib64/${archive##*/}"
2382+
local staged
2383+
staged="$(mktemp "${destination}.tmp.XXXXXX")"
2384+
trap 'rm -f "${staged}"' EXIT
2385+
cp -p "${archive}" "${staged}"
2386+
if [[ "${STRIP_TP_LIB}" = "ON" && "${KERNEL}" != 'Darwin' ]]; then
2387+
strip --strip-debug --strip-unneeded "${staged}"
2388+
fi
2389+
mv -f "${staged}" "${destination}"
2390+
)
2391+
}
2392+
23752393
build_lance_c() {
23762394
check_if_source_exist "${LANCE_C_SOURCE}"
23772395
cd "${TP_SOURCE_DIR}/${LANCE_C_SOURCE}"
@@ -2446,11 +2464,7 @@ build_lance_c() {
24462464
mkdir -p "${TP_INSTALL_DIR}/include" "${TP_INSTALL_DIR}/lib64"
24472465
rm -rf "${TP_INSTALL_DIR}/include/lance"
24482466
cp -av include/lance "${TP_INSTALL_DIR}/include/"
2449-
cp -v "${BUILD_DIR}/release/liblance_c.a" "${TP_INSTALL_DIR}/lib64/"
2450-
2451-
if [[ "${STRIP_TP_LIB}" = "ON" && "${KERNEL}" != 'Darwin' ]]; then
2452-
strip --strip-debug --strip-unneeded "${TP_INSTALL_DIR}/lib64/liblance_c.a"
2453-
fi
2467+
install_rust_archive "${BUILD_DIR}/release/liblance_c.a"
24542468
}
24552469

24562470
build_paimon_rust() {
@@ -2575,11 +2589,7 @@ EOF
25752589
rm -rf "${TP_INSTALL_DIR}/include/paimon_rust"
25762590
mkdir -p "${TP_INSTALL_DIR}/include/paimon_rust"
25772591
cp -v "${BUILD_DIR}/release/paimon.h" "${TP_INSTALL_DIR}/include/paimon_rust/"
2578-
cp -v "${BUILD_DIR}/release/libpaimon_c.a" "${TP_INSTALL_DIR}/lib64/"
2579-
2580-
if [[ "${STRIP_TP_LIB}" = "ON" && "${KERNEL}" != 'Darwin' ]]; then
2581-
strip --strip-debug --strip-unneeded "${TP_INSTALL_DIR}/lib64/libpaimon_c.a"
2582-
fi
2592+
install_rust_archive "${BUILD_DIR}/release/libpaimon_c.a"
25832593
}
25842594

25852595
if [[ "${#packages[@]}" -eq 0 ]]; then

‎thirdparty/test/paimon-build-test.py‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,53 @@ def test_clean_option_is_preserved(self):
9696
def test_complete_install_is_reused(self):
9797
self.check_install("Linux", None)
9898

99+
def archive_installer(self):
100+
script = (ROOT / "thirdparty/build-thirdparty.sh").read_text()
101+
return re.search(r"^install_rust_archive\(\) \{\n.*?^\}", script, re.M | re.S)[0]
102+
103+
def check_archive_publication(self, name):
104+
source = self.write("build/" + name, "new archive")
105+
source.chmod(0o644)
106+
destination = self.work / "installed/lib64" / name
107+
destination.parent.mkdir(parents=True, exist_ok=True)
108+
self.env.update(TP_INSTALL_DIR=str(self.work / "installed"),
109+
STRIP_TP_LIB="ON", KERNEL="Linux", ARCHIVE=str(source))
110+
failures = {
111+
"copy": 'cp() { printf partial > "${@: -1}"; return 1; }',
112+
"strip": 'strip() { printf damaged > "${@: -1}"; return 1; }',
113+
"publish": 'mv() { return 1; }',
114+
"success": '',
115+
}
116+
for replacement in (False, True):
117+
for stage, injection in failures.items():
118+
with self.subTest(archive=name, replacement=replacement, stage=stage):
119+
if destination.exists():
120+
destination.unlink()
121+
if replacement:
122+
destination.write_text("old archive")
123+
# Execute the production publisher with failures after partial copy/strip;
124+
# neither a first install nor a replacement may expose those bytes.
125+
result = self.run_bash(self.archive_installer() +
126+
'\nstrip() { :; }\n' + injection +
127+
'\ninstall_rust_archive "$ARCHIVE"')
128+
if stage == "success":
129+
self.assertEqual(result.returncode, 0, result.stderr)
130+
self.assertEqual(destination.read_text(), "new archive")
131+
self.assertEqual(destination.stat().st_mode & 0o777, 0o644)
132+
else:
133+
self.assertNotEqual(result.returncode, 0)
134+
if replacement:
135+
self.assertEqual(destination.read_text(), "old archive")
136+
else:
137+
self.assertFalse(destination.exists())
138+
self.assertEqual(list(destination.parent.glob(name + ".tmp.*")), [])
139+
140+
def test_atomic_lance_archive_publication(self):
141+
self.check_archive_publication("liblance_c.a")
142+
143+
def test_atomic_paimon_archive_publication(self):
144+
self.check_archive_publication("libpaimon_c.a")
145+
99146
def check_header(self, offline, inherited_offline="", cargo_override=True):
100147
script = (ROOT / "thirdparty/build-thirdparty.sh").read_text()
101148
function = re.search(r"^build_paimon_rust\(\) \{\n.*?^\}", script, re.M | re.S)[0]
@@ -130,7 +177,8 @@ def check_header(self, offline, inherited_offline="", cargo_override=True):
130177
self.env["CARGO"] = str(cargo)
131178
if inherited_offline:
132179
self.env["CARGO_NET_OFFLINE"] = inherited_offline
133-
result = self.run_bash("check_if_source_exist() { :; }\n" + function + "\nbuild_paimon_rust")
180+
result = self.run_bash("check_if_source_exist() { :; }\n" + self.archive_installer()
181+
+ "\n" + function + "\nbuild_paimon_rust")
134182
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
135183
expected = "true" if offline.upper() == "ON" else inherited_offline or "unset"
136184
self.assertEqual((self.work / "metadata.log").read_text(), expected)

0 commit comments

Comments
 (0)