1- use crate :: executor:: { ExecutorSupport , ToolInstallStatus , get_all_executors} ;
1+ use crate :: executor:: {
2+ Executor , ExecutorSupport , ToolInstallStatus , get_all_executors, get_executor_from_mode,
3+ } ;
24use crate :: prelude:: * ;
5+ use crate :: runner_mode:: RunnerMode ;
36use crate :: system:: SystemInfo ;
47use clap:: { Args , Subcommand } ;
58use console:: style;
@@ -9,6 +12,16 @@ use super::status::{check_mark, cross_mark, warn_mark};
912
1013#[ derive( Debug , Default , Args ) ]
1114pub struct SetupArgs {
15+ /// The modes to set up. If omitted, the environment is set up for all supported executors.
16+ #[ arg(
17+ short,
18+ long,
19+ value_enum,
20+ env = "CODSPEED_RUNNER_MODE" ,
21+ value_delimiter = ','
22+ ) ]
23+ mode : Vec < RunnerMode > ,
24+
1225 #[ command( subcommand) ]
1326 command : Option < SetupCommands > ,
1427}
@@ -21,49 +34,76 @@ enum SetupCommands {
2134
2235pub async fn run ( args : SetupArgs , setup_cache_dir : Option < & Path > ) -> Result < ( ) > {
2336 match args. command {
24- None => setup ( setup_cache_dir) . await ,
25- Some ( SetupCommands :: Status ) => status ( ) ,
37+ Some ( SetupCommands :: Status ) => status ( & args. mode ) ,
38+ None => setup ( & args. mode , setup_cache_dir) . await ,
39+ }
40+ }
41+
42+ /// Resolve the executors to operate on from the requested modes.
43+ ///
44+ /// An empty list of modes means "every executor".
45+ fn get_executors_from_modes ( modes : & [ RunnerMode ] ) -> Vec < Box < dyn Executor > > {
46+ if modes. is_empty ( ) {
47+ get_all_executors ( )
48+ } else {
49+ modes
50+ . iter ( )
51+ . map ( |mode| get_executor_from_mode ( mode, None ) )
52+ . collect ( )
2653 }
2754}
2855
29- async fn setup ( setup_cache_dir : Option < & Path > ) -> Result < ( ) > {
56+ async fn setup ( modes : & [ RunnerMode ] , setup_cache_dir : Option < & Path > ) -> Result < ( ) > {
3057 let system_info = SystemInfo :: new ( ) ?;
31- let executors = get_all_executors ( ) ;
32- start_group ! ( "Setting up the environment for all executors " ) ;
58+ let executors = get_executors_from_modes ( modes ) ;
59+ start_group ! ( "Setting up the environment" ) ;
3360 for executor in executors {
34- match executor. support_level ( & system_info) {
35- ExecutorSupport :: Unsupported => {
36- info ! (
37- "Skipping setup for the {} executor: not supported on {}" ,
38- executor. name( ) ,
39- system_info. os
40- ) ;
41- }
42- ExecutorSupport :: RequiresManualInstallation => {
43- info ! (
44- "Skipping automatic setup for the {} executor on {}; install required tooling manually." ,
45- executor. name( ) ,
46- system_info. os
47- ) ;
48- }
49- ExecutorSupport :: FullySupported => {
50- info ! (
51- "Setting up the environment for the executor: {}" ,
52- executor. name( )
53- ) ;
54- executor. setup ( & system_info, setup_cache_dir) . await ?;
55- }
56- }
61+ setup_executor ( executor. as_ref ( ) , & system_info, setup_cache_dir) . await ?;
5762 }
5863 info ! ( "Environment setup completed" ) ;
5964 end_group ! ( ) ;
6065 Ok ( ( ) )
6166}
6267
63- pub fn status ( ) -> Result < ( ) > {
68+ /// Set up a single executor based on its support level on the current system.
69+ ///
70+ /// Unsupported executors or executors that require manual installation are
71+ /// skipped, not treated as fatal.
72+ async fn setup_executor (
73+ executor : & dyn Executor ,
74+ system_info : & SystemInfo ,
75+ setup_cache_dir : Option < & Path > ,
76+ ) -> Result < ( ) > {
77+ match executor. support_level ( system_info) {
78+ ExecutorSupport :: Unsupported => {
79+ info ! (
80+ "Skipping setup for the {} executor: not supported on {}" ,
81+ executor. name( ) ,
82+ system_info. os
83+ ) ;
84+ }
85+ ExecutorSupport :: RequiresManualInstallation => {
86+ info ! (
87+ "Skipping automatic setup for the {} executor on {}; install required tooling manually." ,
88+ executor. name( ) ,
89+ system_info. os
90+ ) ;
91+ }
92+ ExecutorSupport :: FullySupported => {
93+ info ! (
94+ "Setting up the environment for the executor: {}" ,
95+ executor. name( )
96+ ) ;
97+ executor. setup ( system_info, setup_cache_dir) . await ?;
98+ }
99+ }
100+ Ok ( ( ) )
101+ }
102+
103+ pub fn status ( modes : & [ RunnerMode ] ) -> Result < ( ) > {
64104 let system_info = SystemInfo :: new ( ) ?;
65105 info ! ( "{}" , style( "Tools" ) . bold( ) ) ;
66- for executor in get_all_executors ( ) {
106+ for executor in get_executors_from_modes ( modes ) {
67107 // Don't probe for tooling that can't be used on this OS anyway.
68108 if executor. support_level ( & system_info) == ExecutorSupport :: Unsupported {
69109 continue ;
0 commit comments