55from pathlib import Path
66from typing import Any
77
8- from cli .runtime import install_runtime , should_enable_qt
8+ from .runtime import install_runtime , should_enable_qt
99
1010from .spec_helpers import (
1111 CliSpecError ,
12- build_context_from_ark_config ,
13- build_context_from_lock ,
12+ build_context_object_from_ark_config ,
13+ build_context_object_from_lock ,
1414 build_lock_payload ,
1515 cache_rebuild_lock ,
1616 compare_lock_payloads ,
1717 default_lock_path ,
18+ engine_config_from_lock ,
1819 init_workspace ,
1920 launch_gui ,
2021 list_engines_payload ,
@@ -62,6 +63,17 @@ def _resolve_version() -> str:
6263 return "unknown"
6364
6465
66+ def _ensure_engine_known (engine_id : str ) -> None :
67+ payload = list_engines_payload ()
68+ known_ids = {
69+ str (item .get ("id" ) or "" ).strip ()
70+ for item in payload .get ("engines" , [])
71+ if isinstance (item , dict )
72+ }
73+ if engine_id not in known_ids :
74+ raise CliSpecError (f"build.engine: unknown engine '{ engine_id } '" )
75+
76+
6577def _build_impl (
6678 * ,
6779 workspace : Path ,
@@ -78,19 +90,22 @@ def _build_impl(
7890 config = load_ark_config (workspace )
7991 validated = validate_ark_config (workspace , config )
8092 engine_id = engine_override or str (validated .config ["build" ]["engine" ])
93+ _ensure_engine_known (engine_id )
8194 lock_payload = build_lock_payload (workspace , validated .config , engine_id = engine_id )
8295 lock_paths = write_lock_files (workspace , lock_payload )
96+ context = build_context_object_from_ark_config (validated .config )
8397 result = run_engine_compile (
8498 workspace = workspace ,
8599 engine_id = engine_id ,
86- entry_file = str (validated .config ["project" ]["entry" ]),
100+ context = context ,
101+ engine_config = engine_config_from_lock (lock_payload ),
87102 )
88103 payload = {
89104 "mode" : "build" ,
90105 "engine" : engine_id ,
91106 "warnings" : validated .warnings ,
92107 "lock" : lock_paths ,
93- "build_context" : build_context_from_ark_config ( validated . config ),
108+ "build_context" : context . to_dict ( ),
94109 "result" : result ,
95110 }
96111 if as_json :
@@ -120,11 +135,18 @@ def _build_impl(
120135 entry_file = str (((lock_payload .get ("project" ) or {}).get ("entry" )) or "" ).strip ()
121136 if not engine_id or not entry_file :
122137 raise CliSpecError ("Invalid lock file: missing engine.name or project.entry" )
138+ entry_path = workspace / Path (entry_file )
139+ if not entry_path .is_file ():
140+ raise CliSpecError (
141+ f"Invalid lock file: project.entry '{ entry_file } ' is missing or obsolete"
142+ )
123143
144+ context = build_context_object_from_lock (lock_payload )
124145 result = run_engine_compile (
125146 workspace = workspace ,
126147 engine_id = engine_id ,
127- entry_file = entry_file ,
148+ context = context ,
149+ engine_config = engine_config_from_lock (lock_payload ),
128150 )
129151
130152 comparison = None
@@ -150,7 +172,7 @@ def _build_impl(
150172 "warnings" : warnings ,
151173 "comparison_ok" : comparison ,
152174 "comparison_lock" : rebuild_cache ,
153- "build_context" : build_context_from_lock ( lock_payload ),
175+ "build_context" : context . to_dict ( ),
154176 "result" : result ,
155177 }
156178 if as_json :
@@ -374,4 +396,3 @@ def main(argv: list[str] | None = None) -> int:
374396 exc .show ()
375397 return int (getattr (exc , "exit_code" , 2 ))
376398 raise
377-
0 commit comments