@@ -52,97 +52,127 @@ def resolve_default_engine_id() -> str:
5252
5353
5454def run_bcasl_before_compile (
55- gui_instance , on_done , build_context : Optional [Any ] = None
55+ gui_instance , on_done , build_context : Optional [Any ] = None , ark_config : Optional [ dict ] = None
5656) -> None :
57- """Run BCASL pre-compile stage, then invoke `on_done(report)`."""
57+ """
58+ Run BCASL pre-compile stage, then invoke `on_done(report)`.
59+ Optimized: Checks activation state before launching the async thread.
60+ """
5861 try :
62+ from bcasl .Loader import BCASL_DISABLED_REPORT , _is_bcasl_enabled
5963 from Ui .Gui .Dialogs .BcaslDialog import run_pre_compile_async
64+ from pathlib import Path
6065 except Exception :
6166 if callable (on_done ):
62- try :
63- on_done (None )
64- except Exception :
65- pass
67+ on_done (None )
68+ return
69+
70+ ws = getattr (gui_instance , "workspace_dir" , None )
71+ if not ws :
72+ if callable (on_done ):
73+ on_done (None )
6674 return
75+
76+ # Optimization: Short-circuit if BCASL is disabled to avoid thread overhead
77+ enabled = True
78+ try :
79+ if ark_config :
80+ enabled = bool (ark_config .get ("plugins" , {}).get ("bcasl_enabled" , True ))
81+ else :
82+ enabled = _is_bcasl_enabled (Path (ws ))
83+ except Exception :
84+ pass
85+
86+ if not enabled :
87+ try :
88+ log_i18n_level (
89+ gui_instance ,
90+ "info" ,
91+ "BCASL désactivé dans ark.yml. Exécution ignorée." ,
92+ "BCASL disabled in ark.yml. Skipping execution." ,
93+ )
94+ except Exception :
95+ pass
96+ if callable (on_done ):
97+ on_done (dict (BCASL_DISABLED_REPORT ))
98+ return
99+
67100 try :
68101 log_i18n_level (
69102 gui_instance ,
70103 "info" ,
71- "Pré-compilation (BCASL) si activée ..." ,
72- "Pre-compilation (BCASL) if enabled ..." ,
104+ "Pré-compilation (BCASL)..." ,
105+ "Pre-compilation (BCASL)..." ,
73106 )
74107 except Exception :
75108 pass
109+
76110 try :
77111 run_pre_compile_async (gui_instance , on_done , build_context = build_context )
78112 except Exception :
79113 if callable (on_done ):
80- try :
81- on_done (None )
82- except Exception :
83- pass
114+ on_done (None )
84115
85116
86117def bcasl_report_allows_compile (gui_instance , report ) -> bool :
87- """Return True when BCASL pre-compile report allows compilation to continue."""
118+ """
119+ Return True when BCASL pre-compile report allows compilation to continue.
120+ Robustly handles dicts, objects, and lists.
121+ """
88122 try :
89123 if report is None :
124+ # Fallback check if the thread returned nothing
90125 try :
91126 from pathlib import Path
92-
93127 from bcasl .Loader import _is_bcasl_enabled
94-
95128 ws = getattr (gui_instance , "workspace_dir" , None )
96129 if ws and not _is_bcasl_enabled (Path (ws ).resolve ()):
97130 return True
98131 except Exception :
99132 pass
100- log_i18n_level (
101- gui_instance ,
102- "error" ,
103- "BCASL a échoué ou n'a pas retourné de rapport. Compilation bloquée." ,
104- "BCASL failed or returned no report. Compilation blocked." ,
105- )
106133 return False
107134
135+ # 1. Handle Disabled Report (Dict)
108136 if isinstance (report , dict ):
109137 try :
110138 from bcasl .Loader import is_bcasl_disabled_report
111-
112139 if is_bcasl_disabled_report (report ):
113140 return True
114141 except Exception :
115- status = str ( report . get ( "status" , "" )). strip (). lower ()
116- if status in { "disabled" , "skipped" }:
117- return True
142+ pass
143+
144+ # Simple check for 'ok' key
118145 if "ok" in report :
119- ok = any (report .get ("ok" ))
120- if not ok :
121- log_i18n_level (
122- gui_instance ,
123- "error" ,
124- "BCASL a signalé un échec. Compilation bloquée." ,
125- "BCASL reported a failure. Compilation blocked." ,
126- )
127- return ok
146+ res = report .get ("ok" )
147+ return bool (res ) if not isinstance (res , (list , tuple , set )) else all (res )
128148 return True
129149
150+ # 2. Handle ExecutionReport object
130151 if hasattr (report , "ok" ):
131- ok = any (getattr (report , "ok" ))
132- if not ok :
133- log_i18n_level (
134- gui_instance ,
135- "error" ,
136- "BCASL a signalé des erreurs plugins. Compilation bloquée." ,
137- "BCASL reported plugin errors. Compilation blocked." ,
138- )
139- return ok
152+ ok_val = getattr (report , "ok" )
153+ # If it's a property returning bool, use it directly
154+ if isinstance (ok_val , bool ):
155+ return ok_val
156+ # If it's a list (legacy/compat), check all
157+ try :
158+ return all (ok_val )
159+ except Exception :
160+ return bool (ok_val )
161+
162+ # 3. Handle List of Results
163+ if isinstance (report , (list , tuple )):
164+ return all (getattr (item , "success" , True ) for item in report )
165+
140166 except Exception :
141- log_i18n_level (
142- gui_instance ,
143- "error" ,
144- "Erreur lors de la validation du rapport BCASL. Compilation bloquée." ,
145- "Error while validating BCASL report. Compilation blocked." ,
146- )
167+ try :
168+ log_i18n_level (
169+ gui_instance ,
170+ "error" ,
171+ "Erreur lors de la validation du rapport BCASL. Compilation bloquée." ,
172+ "Error while validating BCASL report. Compilation blocked." ,
173+ )
174+ except Exception :
175+ pass
147176 return False
177+
148178 return True
0 commit comments