Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion synapse-api
39 changes: 36 additions & 3 deletions synapse/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ def build_docker_image(app_dir: str, app_name: str | None = None) -> str:
return image_tag


def build_app(app_dir: str, app_name: str, force_rebuild: bool = False) -> bool:
def build_app(
app_dir: str, app_name: str, force_rebuild: bool = False, clean: bool = False
) -> bool:
"""Cross-compile *app_name* inside its SDK container."""

console.print(f"[yellow]Building application: {app_name}...[/yellow]")

binary_path = os.path.join(app_dir, "build/aarch64", app_name)

# Skip if binary already exists unless a rebuild was requested
if (not force_rebuild) and os.path.exists(binary_path):
if (not force_rebuild) and (not clean) and os.path.exists(binary_path):
console.print(
f"[green]Binary already exists at: {binary_path} (skipping rebuild) [/green]"
)
Expand All @@ -137,6 +139,31 @@ def build_app(app_dir: str, app_name: str, force_rebuild: bool = False) -> bool:
)
return False

# Perform clean if requested - do this inside Docker container to avoid permission issues
if clean:
console.print(
"[yellow]Cleaning build directories in Docker container...[/yellow]"
)
clean_cmd = [
"docker",
"run",
"--rm",
"-v",
f"{os.path.abspath(app_dir)}:/home/workspace",
image_tag,
"/bin/bash",
"-c",
"cd /home/workspace && rm -rf build/ || true",
]

try:
subprocess.run(clean_cmd, check=True, cwd=app_dir)
console.print("[green]Successfully cleaned build directories[/green]")
except subprocess.CalledProcessError:
console.print(
"[yellow]Warning: Failed to clean build directories. Continuing with build...[/yellow]"
)

console.print("[blue]Installing dependencies...[/blue]")
vcpkg_cmd = [
"docker",
Expand Down Expand Up @@ -488,7 +515,7 @@ def build_cmd(args) -> None:

# 1. Build phase (unless explicitly skipped)
if not args.skip_build:
if not build_app(app_dir, app_name, force_rebuild=True):
if not build_app(app_dir, app_name, force_rebuild=True, clean=args.clean):
console.print(
"[bold red]Error:[/bold red] Failed to build the application."
)
Expand Down Expand Up @@ -536,4 +563,10 @@ def add_commands(subparsers) -> None:
default=False,
help="Skip compilation phase; assume the binary already exists and only build the .deb package.",
)
build_parser.add_argument(
"--clean",
action="store_true",
default=False,
help="Clean build directories and force a complete rebuild from scratch.",
)
build_parser.set_defaults(func=build_cmd)