Skip to content

Commit

Permalink
Speed up builds by spawning the SLC daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Jun 4, 2024
1 parent 74545a0 commit df69429
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions tools/build_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
# There are only a few components whose filename doesn't match the component name
"freertos": "freertos_kernel",
}

SLC = ["slc", "--daemon", "--daemon-timeout", "1"]

LOGGER = logging.getLogger(__name__)


yaml = YAML(typ="safe")


Expand Down Expand Up @@ -137,11 +141,18 @@ def git(*args: str) -> str:


def determine_chip_specific_config_filenames(
slcp_path: pathlib.Path, sdk: pathlib.Path, slc: str
slcp_path: pathlib.Path, sdk: pathlib.Path
) -> list[str]:
"""Determine the chip-specific config files to remove."""
proc = subprocess.run(
[slc, "graph", "-p", str(slcp_path.absolute()), "--sdk", str(sdk.absolute())],
SLC
+ [
"graph",
"--project-file",
str(slcp_path.absolute()),
"--sdk",
str(sdk.absolute()),
],
cwd=str(slcp_path.parent),
check=True,
text=True,
Expand Down Expand Up @@ -250,6 +261,13 @@ def main():
default=[],
help="Override config key with JSON.",
)
parser.add_argument(
"--keep-slc-daemon",
action="store_true",
dest="keep_slc_daemon",
default=False,
help="Do not shut down the SLC daemon after the build",
)

args = parser.parse_args()

Expand Down Expand Up @@ -368,13 +386,6 @@ def main():
cmake_build_root = args.build_dir / f"{base_project_name}_cmake"
shutil.rmtree(cmake_build_root, ignore_errors=True)

# On macOS `slc` doesn't execute properly
slc = shutil.which("slc-cli") or shutil.which("slc")

if not slc:
LOGGER.error("`slc` and/or `slc-cli` not found in PATH")
sys.exit(1)

# Find the SDK version required by the project
for sdk in args.sdks:
try:
Expand All @@ -396,7 +407,7 @@ def main():

LOGGER.info("Building component graph and identifying board-specific files")
for name in determine_chip_specific_config_filenames(
slcp_path=base_project_slcp, sdk=sdk, slc=slc
slcp_path=base_project_slcp, sdk=sdk
):
try:
(args.build_dir / f"config/{name}").unlink()
Expand Down Expand Up @@ -449,8 +460,8 @@ def main():
sys.exit(1)

subprocess.run(
[
slc,
SLC
+ [
"generate",
"--project-file",
(args.build_dir / f"{base_project_name}.slcp").resolve(),
Expand Down Expand Up @@ -609,6 +620,9 @@ def main():
with contextlib.suppress(OSError):
shutil.rmtree(args.build_dir)

if not args.keep_slc_daemon:
subprocess.run(SLC + ["daemon-shutdown"], check=True)


if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
Expand Down

0 comments on commit df69429

Please sign in to comment.