(
config: ProjectConfig, build_config_path: Path
)
| 396 | |
| 397 | # Load decomp-toolkit generated config.json |
| 398 | def load_build_config( |
| 399 | config: ProjectConfig, build_config_path: Path |
| 400 | ) -> Optional[BuildConfig]: |
| 401 | if not build_config_path.is_file(): |
| 402 | return None |
| 403 | |
| 404 | def versiontuple(v: str) -> Tuple[int, ...]: |
| 405 | return tuple(map(int, (v.split(".")))) |
| 406 | |
| 407 | f = open(build_config_path, "r", encoding="utf-8") |
| 408 | build_config: BuildConfig = json.load(f) |
| 409 | config_version = build_config.get("version") |
| 410 | if config_version is None: |
| 411 | print("Invalid config.json, regenerating...") |
| 412 | f.close() |
| 413 | os.remove(build_config_path) |
| 414 | return None |
| 415 | |
| 416 | dtk_version = str(config.dtk_tag)[1:] # Strip v |
| 417 | if versiontuple(config_version) < versiontuple(dtk_version): |
| 418 | print("Outdated config.json, regenerating...") |
| 419 | f.close() |
| 420 | os.remove(build_config_path) |
| 421 | return None |
| 422 | |
| 423 | f.close() |
| 424 | |
| 425 | # Apply link order callback |
| 426 | if config.link_order_callback: |
| 427 | modules: List[BuildConfigModule] = [build_config, *build_config["modules"]] |
| 428 | for module in modules: |
| 429 | unit_names = list(map(lambda u: u["name"], module["units"])) |
| 430 | unit_names = config.link_order_callback(module["module_id"], unit_names) |
| 431 | units: List[BuildConfigUnit] = [] |
| 432 | for unit_name in unit_names: |
| 433 | units.append( |
| 434 | # Find existing unit or create a new one |
| 435 | next( |
| 436 | (u for u in module["units"] if u["name"] == unit_name), |
| 437 | {"object": None, "name": unit_name, "autogenerated": False}, |
| 438 | ) |
| 439 | ) |
| 440 | module["units"] = units |
| 441 | |
| 442 | return build_config |
| 443 | |
| 444 | |
| 445 | # Generate build.ninja, objdiff.json and compile_commands.json |
no test coverage detected