@@ -195,6 +195,21 @@ impl RunArgs {
195195 }
196196}
197197
198+ use crate :: project_config:: Target ;
199+ use crate :: project_config:: WalltimeOptions ;
200+ /// Determines the execution mode based on CLI args and project config
201+ enum RunTarget < ' a > {
202+ /// Single command from CLI args
203+ SingleCommand ( RunArgs ) ,
204+ /// Multiple targets from project config
205+ /// Note: for now, only `codspeed exec` targets are supported in the project config
206+ ConfigTargets {
207+ args : RunArgs ,
208+ targets : & ' a [ Target ] ,
209+ default_walltime : Option < & ' a WalltimeOptions > ,
210+ } ,
211+ }
212+
198213pub async fn run (
199214 args : RunArgs ,
200215 api_client : & CodSpeedAPIClient ,
@@ -204,35 +219,75 @@ pub async fn run(
204219) -> Result < ( ) > {
205220 let output_json = args. message_format == Some ( MessageFormat :: Json ) ;
206221
207- let merged_args = args. merge_with_project_config ( project_config) ;
208-
209- let config = Config :: try_from ( merged_args) ?;
222+ let args = args. merge_with_project_config ( project_config) ;
223+
224+ let run_target = if args. command . is_empty ( ) {
225+ // No command provided - check for targets in project config
226+ let targets = project_config
227+ . and_then ( |c| c. targets . as_ref ( ) )
228+ . filter ( |t| !t. is_empty ( ) )
229+ . ok_or_else ( || {
230+ anyhow ! ( "No command provided and no targets defined in codspeed.yaml" )
231+ } ) ?;
232+
233+ let default_walltime = project_config
234+ . and_then ( |c| c. options . as_ref ( ) )
235+ . and_then ( |o| o. walltime . as_ref ( ) ) ;
236+
237+ RunTarget :: ConfigTargets {
238+ args,
239+ targets,
240+ default_walltime,
241+ }
242+ } else {
243+ RunTarget :: SingleCommand ( args)
244+ } ;
210245
211- // Create execution context
212- let mut execution_context = executor:: ExecutionContext :: try_from ( ( config, codspeed_config) ) ?;
246+ match run_target {
247+ RunTarget :: SingleCommand ( args) => {
248+ let config = Config :: try_from ( args) ?;
249+
250+ // Create execution context
251+ let mut execution_context =
252+ executor:: ExecutionContext :: try_from ( ( config, codspeed_config) ) ?;
253+
254+ if !execution_context. is_local ( ) {
255+ show_banner ( ) ;
256+ }
257+ debug ! ( "config: {:#?}" , execution_context. config) ;
258+
259+ // Execute benchmarks
260+ let executor = executor:: get_executor_from_mode (
261+ & execution_context. config . mode ,
262+ executor:: ExecutorCommand :: Run ,
263+ ) ;
264+
265+ let poll_results_fn = async |upload_result : & UploadResult | {
266+ poll_results:: poll_results ( api_client, upload_result, output_json) . await
267+ } ;
268+ executor:: execute_benchmarks (
269+ executor. as_ref ( ) ,
270+ & mut execution_context,
271+ setup_cache_dir,
272+ poll_results_fn,
273+ api_client,
274+ )
275+ . await ?;
276+ }
213277
214- if !execution_context. is_local ( ) {
215- show_banner ( ) ;
278+ RunTarget :: ConfigTargets {
279+ mut args,
280+ targets,
281+ default_walltime,
282+ } => {
283+ args. command =
284+ crate :: exec:: multi_targets:: build_pipe_command ( targets, default_walltime) ?;
285+ let config = Config :: try_from ( args) ?;
286+
287+ crate :: exec:: execute_with_harness ( config, api_client, codspeed_config, setup_cache_dir)
288+ . await ?;
289+ }
216290 }
217- debug ! ( "config: {:#?}" , execution_context. config) ;
218-
219- // Execute benchmarks
220- let executor = executor:: get_executor_from_mode (
221- & execution_context. config . mode ,
222- executor:: ExecutorCommand :: Run ,
223- ) ;
224-
225- let poll_results_fn = async |upload_result : & UploadResult | {
226- poll_results:: poll_results ( api_client, upload_result, output_json) . await
227- } ;
228- executor:: execute_benchmarks (
229- executor. as_ref ( ) ,
230- & mut execution_context,
231- setup_cache_dir,
232- poll_results_fn,
233- api_client,
234- )
235- . await ?;
236291
237292 Ok ( ( ) )
238293}
0 commit comments