(
config: ProjectConfig, build_config_path: Path
)
| 340 | |
| 341 | # Load decomp-toolkit generated config.json |
| 342 | def load_build_config( |
| 343 | config: ProjectConfig, build_config_path: Path |
| 344 | ) -> Optional[BuildConfig]: |
| 345 | if not build_config_path.is_file(): |
| 346 | return None |
| 347 | |
| 348 | def versiontuple(v: str) -> Tuple[int, ...]: |
| 349 | return tuple(map(int, (v.split(".")))) |
| 350 | |
| 351 | f = open(build_config_path, "r", encoding="utf-8") |
| 352 | build_config: BuildConfig = json.load(f) |
| 353 | config_version = build_config.get("version") |
| 354 | if config_version is None: |
| 355 | print("Invalid config.json, regenerating...") |
| 356 | f.close() |
| 357 | os.remove(build_config_path) |
| 358 | return None |
| 359 | |
| 360 | dtk_version = str(config.dtk_tag)[1:] # Strip v |
| 361 | if versiontuple(config_version) < versiontuple(dtk_version): |
| 362 | print("Outdated config.json, regenerating...") |
| 363 | f.close() |
| 364 | os.remove(build_config_path) |
| 365 | return None |
| 366 | |
| 367 | f.close() |
| 368 | |
| 369 | # Apply link order callback |
| 370 | if config.link_order_callback: |
| 371 | modules: List[BuildConfigModule] = [build_config, *build_config["modules"]] |
| 372 | for module in modules: |
| 373 | unit_names = list(map(lambda u: u["name"], module["units"])) |
| 374 | unit_names = config.link_order_callback(module["module_id"], unit_names) |
| 375 | units: List[BuildConfigUnit] = [] |
| 376 | for unit_name in unit_names: |
| 377 | units.append( |
| 378 | # Find existing unit or create a new one |
| 379 | next( |
| 380 | (u for u in module["units"] if u["name"] == unit_name), |
| 381 | {"object": None, "name": unit_name, "autogenerated": False}, |
| 382 | ) |
| 383 | ) |
| 384 | module["units"] = units |
| 385 | |
| 386 | return build_config |
| 387 | |
| 388 | |
| 389 | # Generate build.ninja, objdiff.json and compile_commands.json |
no test coverage detected