Skip to content

Commit

Permalink
Adjust link_order_callback API
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Dec 31, 2024
1 parent 8e17caa commit 5476f3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
11 changes: 8 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import argparse
import sys
from pathlib import Path
from typing import List
from typing import List, Sequence, Union

from tools.project import (
BuildConfigUnit,
Object,
ProgressCategory,
ProjectConfig,
Expand Down Expand Up @@ -1409,9 +1410,13 @@ def MatchingFor(*versions):
obj.options["extra_clang_flags"].append("-Wno-return-type")


def link_order_callback(module_id: int, units: List[str]) -> List[str]:
def link_order_callback(
module_id: int, units: List[str]
) -> Sequence[Union[str, BuildConfigUnit]]:
if module_id == 0: # DOL
return units + ["dummy.c"]
return units + [
{"object": "dummy.o", "name": "dummy.c", "autogenerated": False}
]
return units


Expand Down
28 changes: 16 additions & 12 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import (
Any,
Callable,
Sequence,
cast,
Dict,
IO,
Expand Down Expand Up @@ -192,9 +193,9 @@ def __init__(self) -> None:
self.scratch_preset_id: Optional[int] = (
None # Default decomp.me preset ID for scratches
)
self.link_order_callback: Optional[Callable[[int, List[str]], List[str]]] = (
None # Callback to add/remove/reorder units within a module
)
self.link_order_callback: Optional[
Callable[[int, List[str]], Sequence[Union[str, BuildConfigUnit]]]
] = None # Callback to add/remove/reorder units within a module

# Progress output, progress.json and report.json config
self.progress = True # Enable report.json generation and CLI progress output
Expand Down Expand Up @@ -371,16 +372,19 @@ def versiontuple(v: str) -> Tuple[int, ...]:
modules: List[BuildConfigModule] = [build_config, *build_config["modules"]]
for module in modules:
unit_names = list(map(lambda u: u["name"], module["units"]))
unit_names = config.link_order_callback(module["module_id"], unit_names)
new_units = config.link_order_callback(module["module_id"], unit_names)
units: List[BuildConfigUnit] = []
for unit_name in unit_names:
# Find existing unit or create a new one
unit = next(
(u for u in module["units"] if u["name"] == unit_name), None
)
if not unit:
unit = {"object": None, "name": unit_name, "autogenerated": False}
units.append(unit)
for new_unit in new_units:
if isinstance(new_unit, str):
units.append(
# Find existing unit or create a new one
next(
(u for u in module["units"] if u["name"] == new_unit),
{"object": None, "name": new_unit, "autogenerated": False},
)
)
else:
units.append(new_unit)
module["units"] = units

return build_config
Expand Down

0 comments on commit 5476f3b

Please sign in to comment.