@@ -53,7 +53,7 @@ def run_bash(self, script):
5353 return subprocess .run (["bash" , "-ec" , script ], env = self .env ,
5454 cwd = self .work , text = True , capture_output = True )
5555
56- def check_install (self , system , missing , clean = 0 ):
56+ def check_install (self , system , missing , clean = 0 , empty = None , expect_rebuild = False ):
5757 script = (ROOT / "build.sh" ).read_text ()
5858 gate = script [script .index ("# build thirdparty libraries if necessary." ):
5959 script .index ("update_submodule() {" )]
@@ -64,15 +64,15 @@ def check_install(self, system, missing, clean=0):
6464 "include/paimon_rust/paimon.h" ]
6565 for name in files :
6666 if name != missing :
67- self .write ("installed/" + name )
67+ self .write ("installed/" + name , "" if name == empty else "complete" )
6868 # Execute the real installation gate, replacing only the expensive build.
6969 self .executable ("build-thirdparty.sh" , 'printf "%s\\ n" "$*" > "$BUILD_LOG"\n ' )
7070 self .env .update (DORIS_THIRDPARTY = str (self .work ), TARGET_SYSTEM = system ,
7171 CLEAN = str (clean ), PARALLEL = "2" , BUILD_LOG = str (self .work / "build.log" ))
7272 result = self .run_bash (gate )
7373 self .assertEqual (result .returncode , 0 , result .stderr )
74- self .assertEqual ((self .work / "build.log" ).exists (), missing is not None )
75- if missing is not None :
74+ self .assertEqual ((self .work / "build.log" ).exists (), missing is not None or expect_rebuild )
75+ if missing is not None or expect_rebuild :
7676 args = (self .work / "build.log" ).read_text ().strip ()
7777 self .assertEqual (args , "-j 2" + (" --clean" if clean else "" ))
7878 # A full rebuild also replaces Lance built with the previous Rust version.
@@ -96,9 +96,70 @@ def test_clean_option_is_preserved(self):
9696 def test_complete_install_is_reused (self ):
9797 self .check_install ("Linux" , None )
9898
99+ def test_incomplete_pair_rebuilds (self ):
100+ self .write ("installed/lib64/.paimon-installing" )
101+ self .check_install ("Linux" , None , expect_rebuild = True )
102+
103+ def test_empty_header_rebuilds (self ):
104+ self .check_install ("Linux" , None , empty = "include/paimon_rust/paimon.h" , expect_rebuild = True )
105+
106+ def test_empty_archive_rebuilds (self ):
107+ self .check_install ("Linux" , None , empty = "lib64/libpaimon_c.a" , expect_rebuild = True )
108+
99109 def archive_installer (self ):
100110 script = (ROOT / "thirdparty/build-thirdparty.sh" ).read_text ()
101- return re .search (r"^install_rust_archive\(\) \{\n.*?^\}" , script , re .M | re .S )[0 ]
111+ return "\n " .join (re .search (r"^" + name + r"\(\) \{\n.*?^\}" , script , re .M | re .S )[0 ]
112+ for name in ("install_rust_archive" , "install_paimon_rust" ))
113+
114+ def test_header_archive_pair_publication (self ):
115+ archive = self .write ("build/libpaimon_c.a" , "new archive" )
116+ header = self .write ("build/paimon.h" , "new header" )
117+ target_archive = self .work / "installed/lib64/libpaimon_c.a"
118+ target_header = self .work / "installed/include/paimon_rust/paimon.h"
119+ marker = target_archive .parent / ".paimon-installing"
120+ self .env .update (TP_INSTALL_DIR = str (self .work / "installed" ), STRIP_TP_LIB = "OFF" ,
121+ KERNEL = "Linux" , ARCHIVE = str (archive ), HEADER = str (header ))
122+ failures = {
123+ "header-copy" : 'cp() { if [[ "$1" = -p && "$2" = "$HEADER" ]]; then '
124+ 'printf partial > "${@: -1}"; return 1; fi; command cp "$@"; }' ,
125+ "archive-publish" : 'mv() { if [[ "${@: -1}" = */libpaimon_c.a ]]; then return 1; fi; '
126+ 'command mv "$@"; }' ,
127+ "header-publish" : 'mv() { if [[ "${@: -1}" = */paimon.h ]]; then return 1; fi; '
128+ 'command mv "$@"; }' ,
129+ "success" : "" ,
130+ }
131+ for replacement in (False , True ):
132+ for stage , injection in failures .items ():
133+ with self .subTest (replacement = replacement , stage = stage ):
134+ for path in (target_archive , target_header , marker ):
135+ if path .exists ():
136+ path .unlink ()
137+ path .parent .mkdir (parents = True , exist_ok = True )
138+ if replacement :
139+ target_archive .write_text ("old archive" )
140+ target_header .write_text ("old header" )
141+ result = self .run_bash (self .archive_installer () + "\n " + injection
142+ + '\n install_paimon_rust "$ARCHIVE" "$HEADER"' )
143+ if stage == "success" :
144+ self .assertEqual (result .returncode , 0 , result .stderr )
145+ self .assertEqual (target_header .read_text (), "new header" )
146+ self .assertEqual (target_archive .read_text (), "new archive" )
147+ self .assertFalse (marker .exists ())
148+ else :
149+ self .assertNotEqual (result .returncode , 0 )
150+ if replacement :
151+ self .assertEqual (target_header .read_text (), "old header" )
152+ else :
153+ self .assertFalse (target_header .exists ())
154+ self .assertEqual (marker .exists (), stage != "header-copy" )
155+ # A retry must repair the pair and clear its incomplete marker.
156+ retry = self .run_bash (self .archive_installer ()
157+ + '\n install_paimon_rust "$ARCHIVE" "$HEADER"' )
158+ self .assertEqual (retry .returncode , 0 , retry .stderr )
159+ self .assertEqual (target_header .read_text (), "new header" )
160+ self .assertEqual (target_archive .read_text (), "new archive" )
161+ self .assertFalse (marker .exists ())
162+ self .assertEqual (list (target_header .parent .glob ("*.tmp.*" )), [])
102163
103164 def check_archive_publication (self , name ):
104165 source = self .write ("build/" + name , "new archive" )
@@ -150,7 +211,7 @@ def check_header(self, offline, inherited_offline="", cargo_override=True):
150211 --version) echo 'cargo 1.94.0' ;;
151212 build)
152213 mkdir -p "$CARGO_TARGET_DIR/release"
153- touch "$CARGO_TARGET_DIR/release/libpaimon_c.a"
214+ printf 'archive' > "$CARGO_TARGET_DIR/release/libpaimon_c.a"
154215 ;;
155216 metadata) printf '%s' "${CARGO_NET_OFFLINE:-unset}" > "$METADATA_LOG" ;;
156217 *) exit 90 ;;
0 commit comments