diff --git a/synapse-api b/synapse-api index de75a2c..60bdb2f 160000 --- a/synapse-api +++ b/synapse-api @@ -1 +1 @@ -Subproject commit de75a2cb1d9159994bf9a0f2d2c601757c400b09 +Subproject commit 60bdb2fdc8af14f19cef3b324232f1125ce33ead diff --git a/synapse/cli/build.py b/synapse/cli/build.py index 67ded54..00803db 100644 --- a/synapse/cli/build.py +++ b/synapse/cli/build.py @@ -109,7 +109,9 @@ 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]") @@ -117,7 +119,7 @@ def build_app(app_dir: str, app_name: str, force_rebuild: bool = False) -> bool: 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]" ) @@ -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", @@ -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." ) @@ -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)