@@ -109,15 +109,17 @@ def build_docker_image(app_dir: str, app_name: str | None = None) -> str:
109109 return image_tag
110110
111111
112- def build_app (app_dir : str , app_name : str , force_rebuild : bool = False ) -> bool :
112+ def build_app (
113+ app_dir : str , app_name : str , force_rebuild : bool = False , clean : bool = False
114+ ) -> bool :
113115 """Cross-compile *app_name* inside its SDK container."""
114116
115117 console .print (f"[yellow]Building application: { app_name } ...[/yellow]" )
116118
117119 binary_path = os .path .join (app_dir , "build/aarch64" , app_name )
118120
119121 # Skip if binary already exists unless a rebuild was requested
120- if (not force_rebuild ) and os .path .exists (binary_path ):
122+ if (not force_rebuild ) and ( not clean ) and os .path .exists (binary_path ):
121123 console .print (
122124 f"[green]Binary already exists at: { binary_path } (skipping rebuild) [/green]"
123125 )
@@ -137,6 +139,31 @@ def build_app(app_dir: str, app_name: str, force_rebuild: bool = False) -> bool:
137139 )
138140 return False
139141
142+ # Perform clean if requested - do this inside Docker container to avoid permission issues
143+ if clean :
144+ console .print (
145+ "[yellow]Cleaning build directories in Docker container...[/yellow]"
146+ )
147+ clean_cmd = [
148+ "docker" ,
149+ "run" ,
150+ "--rm" ,
151+ "-v" ,
152+ f"{ os .path .abspath (app_dir )} :/home/workspace" ,
153+ image_tag ,
154+ "/bin/bash" ,
155+ "-c" ,
156+ "cd /home/workspace && rm -rf build/ || true" ,
157+ ]
158+
159+ try :
160+ subprocess .run (clean_cmd , check = True , cwd = app_dir )
161+ console .print ("[green]Successfully cleaned build directories[/green]" )
162+ except subprocess .CalledProcessError :
163+ console .print (
164+ "[yellow]Warning: Failed to clean build directories. Continuing with build...[/yellow]"
165+ )
166+
140167 console .print ("[blue]Installing dependencies...[/blue]" )
141168 vcpkg_cmd = [
142169 "docker" ,
@@ -488,7 +515,7 @@ def build_cmd(args) -> None:
488515
489516 # 1. Build phase (unless explicitly skipped)
490517 if not args .skip_build :
491- if not build_app (app_dir , app_name , force_rebuild = True ):
518+ if not build_app (app_dir , app_name , force_rebuild = True , clean = args . clean ):
492519 console .print (
493520 "[bold red]Error:[/bold red] Failed to build the application."
494521 )
@@ -536,4 +563,10 @@ def add_commands(subparsers) -> None:
536563 default = False ,
537564 help = "Skip compilation phase; assume the binary already exists and only build the .deb package." ,
538565 )
566+ build_parser .add_argument (
567+ "--clean" ,
568+ action = "store_true" ,
569+ default = False ,
570+ help = "Clean build directories and force a complete rebuild from scratch." ,
571+ )
539572 build_parser .set_defaults (func = build_cmd )
0 commit comments