Skip to content

Commit 9ca5570

Browse files
committed
Refactor locking and BCASL integration in CLI
1 parent 6b2db53 commit 9ca5570

3 files changed

Lines changed: 80 additions & 3 deletions

File tree

Core/Locking/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def load_yaml_file(path: Path) -> dict[str, Any]:
4242

4343

4444
def engine_config_path(workspace: Path, engine_id: str) -> Path:
45-
return workspace / ".ark" / "config" / engine_id / "config.json"
45+
return workspace / ".ark" / engine_id / "config.json"
4646

4747

4848
def read_engine_config(workspace: Path, engine_id: str) -> dict[str, Any]:

Ui/Cli/app.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ def _build_impl(
8686
"--engine cannot be used with --lock\nIf you need a different engine, create a new lock with: ark build --engine <engine_id>"
8787
)
8888

89+
# 1. BCASL Pre-compile check (Point 1 of mutation plan)
90+
from .helpers import run_bcasl_before_compile_sync
91+
if not run_bcasl_before_compile_sync(workspace):
92+
return 1
93+
8994
if lock_file is None:
9095
config = load_ark_config(workspace)
9196
validated = validate_ark_config(workspace, config)
9297
engine_id = engine_override or str(validated.config["build"]["engine"])
9398
_ensure_engine_known(engine_id)
99+
# Point 3 alignment: build_lock_payload now correctly loads engine config via fixed path
94100
lock_payload = build_lock_payload(workspace, validated.config, engine_id=engine_id)
95101
lock_paths = write_lock_files(workspace, lock_payload)
96102
context = build_context_object_from_ark_config(validated.config)

Ui/Cli/helpers.py

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,80 @@ def scaffold_plugin_payload(name: str, root_dir: str | None = None) -> dict[str,
295295
return scaffold_plugin(name, root_dir=root_dir)
296296

297297

298+
def run_bcasl_before_compile_sync(workspace: Path) -> bool:
299+
"""Run BCASL pre-compile stage synchronously for the CLI.
300+
301+
Returns:
302+
True if compilation can proceed (success or BCASL disabled), False otherwise.
303+
"""
304+
from .output import info, error, success, log
305+
from bcasl.Loader import run_pre_compile
306+
307+
class CliBcaslHost:
308+
def __init__(self, ws_dir: Path):
309+
self.workspace_dir = str(ws_dir)
310+
class Logger:
311+
def append(self, msg: str):
312+
# Strip trailing newline as our log() adds one
313+
log("BCASL", msg.rstrip())
314+
self.log = Logger()
315+
316+
host = CliBcaslHost(workspace)
317+
info("Running BCASL pre-compile checks...")
318+
try:
319+
report = run_pre_compile(host)
320+
except Exception as exc:
321+
error(f"BCASL execution failed: {exc}")
322+
return False
323+
324+
if report is None:
325+
# report is None if BCASL is disabled or failed silently
326+
return True
327+
328+
if hasattr(report, "ok"):
329+
if not getattr(report, "ok"):
330+
error("BCASL reported security or validation failures.")
331+
return False
332+
success("BCASL checks passed.")
333+
return True
334+
335+
return True
336+
337+
298338
def run_bcasl_headless(args: list[str]) -> int:
299-
# À Connecter à BCASL depuis bcasl/
300-
return print("Pas encore implémenter en Cli")
339+
"""Run BCASL in headless mode for the current workspace."""
340+
from .output import error, success
341+
from bcasl.Loader import run_pre_compile
342+
343+
workspace = Path.cwd()
344+
if "run" in args:
345+
# If workspace path is provided in args, use it
346+
for i, arg in enumerate(args):
347+
if arg == "run" and i + 1 < len(args):
348+
candidate = Path(args[i+1])
349+
if candidate.is_dir():
350+
workspace = candidate.resolve()
351+
break
352+
353+
class CliBcaslHost:
354+
def __init__(self, ws_dir: Path):
355+
self.workspace_dir = str(ws_dir)
356+
class Logger:
357+
def append(self, msg: str):
358+
print(msg, end="", flush=True)
359+
self.log = Logger()
360+
361+
host = CliBcaslHost(workspace)
362+
try:
363+
report = run_pre_compile(host)
364+
if report and hasattr(report, "ok") and not getattr(report, "ok"):
365+
error("\nBCASL found issues.")
366+
return 1
367+
success("\nBCASL completed successfully.")
368+
return 0
369+
except Exception as exc:
370+
error(f"BCASL failed: {exc}")
371+
return 1
301372

302373
def launch_gui(*, legacy: bool = False) -> int:
303374
return launch_main_application(

0 commit comments

Comments
 (0)