6868_INDEXER_THREADS_PER_MERGE_QUEUE = 16
6969_INDEXER_PER_THREAD_MEMORY = 2 * 1024 ** 3 # 2 GiB
7070
71+ _CDB_FRAGMENT_DELIMITER = ",\n "
72+
7173SRC = Path (os .getenv ("SRC" , "/src" ))
7274# On OSS-Fuzz build infra, $OUT is not /out.
7375OUT = Path (os .getenv ("OUT" , "/out" ))
@@ -177,13 +179,13 @@ def files_by_creation_time(folder_path: Path) -> Sequence[Path]:
177179 return files
178180
179181
180- def _wait_for_cdb_fragment (file : Path ) -> str | None :
182+ def _wait_for_cdb_fragment (file : Path ) -> Sequence [ str ] :
181183 """Returns the CDB fragment from the given file, waiting if needed."""
182184 num_retries = 3
183185 for i in range (1 + num_retries ):
184186 data = file .read_text ()
185- if data .endswith (", \n " ):
186- return data .rstrip (). rstrip ( "," )
187+ if data .endswith (_CDB_FRAGMENT_DELIMITER ):
188+ return data .split ( _CDB_FRAGMENT_DELIMITER )[: - 1 ]
187189
188190 if i < num_retries :
189191 print (
@@ -202,7 +204,7 @@ def _wait_for_cdb_fragment(file: Path) -> str | None:
202204 else :
203205 raise RuntimeError (error )
204206
205- return None
207+ return ()
206208
207209
208210def read_cdb_fragments (cdb_path : Path ) -> Any :
@@ -216,11 +218,10 @@ def read_cdb_fragments(cdb_path: Path) -> Any:
216218 if not file .name .endswith (".json" ):
217219 continue
218220
219- fragment = _wait_for_cdb_fragment (file )
220- if fragment :
221- contents .append (fragment )
221+ fragments = _wait_for_cdb_fragment (file )
222+ contents .extend (fragments )
222223
223- contents = ", \n " .join (contents )
224+ contents = _CDB_FRAGMENT_DELIMITER .join (contents )
224225 contents = "[" + contents + "]"
225226 return json .loads (contents )
226227
@@ -514,15 +515,13 @@ def load_cdbs(directory: Path) -> Iterator[tuple[Path, dict[str, Any]]]:
514515 if file .name .endswith ("_linker_commands.json" ):
515516 continue
516517
517- fragment_data = _wait_for_cdb_fragment (file )
518- if not fragment_data :
519- continue
520-
521- fragment = json .loads (fragment_data )
522- if "output" not in fragment :
523- continue
518+ fragments_data = _wait_for_cdb_fragment (file )
519+ for fragment_data in fragments_data :
520+ fragment = json .loads (fragment_data )
521+ if "output" not in fragment :
522+ continue
524523
525- yield file , fragment
524+ yield file , fragment
526525
527526 # We could be running multiple linking steps in parallel, so serialize merges.
528527 with _file_lock (merged_cdb_path / ".lock" ):
0 commit comments