@@ -16,9 +16,6 @@ fn main() -> Result<(), anyhow::Error> {
1616 let crate_root = PathBuf :: from ( env:: var_os ( "CARGO_MANIFEST_DIR" ) . ok_or ( anyhow:: anyhow!(
1717 "env variable CARGO_MANIFEST_DIR is missing"
1818 ) ) ?) ;
19- let available_mcu_inputs = InputFinder :: find ( & crate_root, & mut cargo_directives)
20- . context ( "failed finding available MCUs" ) ?;
21-
2219 let out_dir = PathBuf :: from (
2320 env:: var_os ( "OUT_DIR" ) . ok_or ( anyhow:: anyhow!( "env variable OUT_DIR is missing" ) ) ?,
2421 ) ;
@@ -28,9 +25,8 @@ fn main() -> Result<(), anyhow::Error> {
2825 let code_generator = CodeGenerator :: from_out_dir ( & out_dir)
2926 . context ( "failed to create codegen output directory" ) ?;
3027
31- let mcu_inputs = available_mcu_inputs
32- . filter_from_features ( )
33- . context ( "failed to select MCUs for code generation" ) ?;
28+ let mcu_inputs = InputFinder :: find ( & crate_root, & mut cargo_directives)
29+ . context ( "failed finding and selecting MCU inputs" ) ?;
3430 let mut svds = BTreeMap :: new ( ) ;
3531 for ( mcu, inputs) in mcu_inputs. get_map ( ) {
3632 let _ = svds. insert (
@@ -73,32 +69,6 @@ impl InputFinder {
7369 & self . inputs
7470 }
7571
76- pub fn filter_from_features ( self ) -> Result < Self , anyhow:: Error > {
77- let ( selected_mcus, other_mcus) =
78- self . inputs
79- . into_iter ( )
80- . partition :: < BTreeMap < _ , _ > , _ > ( |( mcu, _) | {
81- env:: var_os ( format ! ( "CARGO_FEATURE_{}" , mcu. to_uppercase( ) ) ) . is_some ( )
82- } ) ;
83- if !selected_mcus. is_empty ( ) {
84- Ok ( Self {
85- inputs : selected_mcus,
86- } )
87- } else {
88- // In this case `other_mcus` contains all of them, for listing when
89- // printing the error.
90- Err ( anyhow:: anyhow!(
91- "at least one MCU feature must be selected; choose from {}" ,
92- other_mcus
93- . keys( )
94- . map( ToOwned :: to_owned)
95- . collect:: <Vec <_>>( )
96- . join( ", " )
97- ) )
98- . context ( "no crate-features for MCUs were selected" )
99- }
100- }
101-
10272 pub fn find (
10373 crate_root : & Path ,
10474 cargo_directives : & mut Vec < String > ,
@@ -110,6 +80,7 @@ impl InputFinder {
11080 Self :: track_path ( & patches_dir, cargo_directives) ?;
11181
11282 let mut inputs = BTreeMap :: new ( ) ;
83+ let mut all_mcus = Vec :: new ( ) ;
11384 for result in fs:: read_dir ( & packs_dir)
11485 . map_err ( io_error_in_path ( & packs_dir) )
11586 . context ( "could not scan vendor/ directory" ) ?
@@ -133,6 +104,10 @@ impl InputFinder {
133104 atdf_path. display( )
134105 ) ) ?
135106 . to_owned ( ) ;
107+ all_mcus. push ( mcu_name. clone ( ) ) ;
108+ if env:: var_os ( format ! ( "CARGO_FEATURE_{}" , mcu_name. to_uppercase( ) ) ) . is_none ( ) {
109+ continue ;
110+ }
136111
137112 let atdf_file = File :: open ( & atdf_path)
138113 . map_err ( io_error_in_path ( & atdf_path) )
@@ -161,6 +136,13 @@ impl InputFinder {
161136 } ,
162137 ) ;
163138 }
139+ if inputs. is_empty ( ) {
140+ return Err ( anyhow:: anyhow!(
141+ "at least one MCU feature must be selected; choose from {}" ,
142+ all_mcus. join( ", " )
143+ ) )
144+ . context ( "no crate-features for MCUs were selected" ) ;
145+ }
164146
165147 Ok ( Self { inputs } )
166148 }
0 commit comments