@@ -8,10 +8,8 @@ use std::collections::{BTreeSet, HashMap};
8
8
/// Environment configuration
9
9
#[ derive( Debug , Deserialize , PartialEq , Eq , Default ) ]
10
10
pub struct CrossEnvConfig {
11
- #[ serde( default ) ]
12
- volumes : Vec < String > ,
13
- #[ serde( default ) ]
14
- passthrough : Vec < String > ,
11
+ volumes : Option < Vec < String > > ,
12
+ passthrough : Option < Vec < String > > ,
15
13
}
16
14
17
15
/// Build configuration
@@ -88,23 +86,23 @@ impl CrossToml {
88
86
}
89
87
90
88
/// Returns the list of environment variables to pass through for `build`,
91
- pub fn env_passthrough_build ( & self ) -> & [ String ] {
92
- & self . build . env . passthrough
89
+ pub fn env_passthrough_build ( & self ) -> Option < & [ String ] > {
90
+ self . build . env . passthrough . as_deref ( )
93
91
}
94
92
95
93
/// Returns the list of environment variables to pass through for `target`,
96
- pub fn env_passthrough_target ( & self , target : & Target ) -> & [ String ] {
97
- self . get_vec ( target, |e| & e. passthrough )
94
+ pub fn env_passthrough_target ( & self , target : & Target ) -> Option < & [ String ] > {
95
+ self . get_vec ( target, |e| e. passthrough . as_deref ( ) )
98
96
}
99
97
100
98
/// Returns the list of environment variables to pass through for `build`,
101
- pub fn env_volumes_build ( & self ) -> & [ String ] {
102
- & self . build . env . volumes
99
+ pub fn env_volumes_build ( & self ) -> Option < & [ String ] > {
100
+ self . build . env . volumes . as_deref ( )
103
101
}
104
102
105
103
/// Returns the list of environment variables to pass through for `target`,
106
- pub fn env_volumes_target ( & self , target : & Target ) -> & [ String ] {
107
- self . get_vec ( target, |e| & e. volumes )
104
+ pub fn env_volumes_target ( & self , target : & Target ) -> Option < & [ String ] > {
105
+ self . get_vec ( target, |e| e. volumes . as_deref ( ) )
108
106
}
109
107
110
108
/// Returns the default target to build,
@@ -140,8 +138,12 @@ impl CrossToml {
140
138
( build, target)
141
139
}
142
140
143
- fn get_vec ( & self , target : & Target , get : impl Fn ( & CrossEnvConfig ) -> & [ String ] ) -> & [ String ] {
144
- self . get_target ( target) . map_or ( & [ ] , |t| get ( & t. env ) )
141
+ fn get_vec (
142
+ & self ,
143
+ target : & Target ,
144
+ get : impl Fn ( & CrossEnvConfig ) -> Option < & [ String ] > ,
145
+ ) -> Option < & [ String ] > {
146
+ self . get_target ( target) . and_then ( |t| get ( & t. env ) )
145
147
}
146
148
}
147
149
@@ -169,8 +171,8 @@ mod tests {
169
171
targets : HashMap :: new ( ) ,
170
172
build : CrossBuildConfig {
171
173
env : CrossEnvConfig {
172
- volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
173
- passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
174
+ volumes : Some ( vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ) ,
175
+ passthrough : Some ( vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ) ,
174
176
} ,
175
177
xargo : Some ( true ) ,
176
178
build_std : None ,
@@ -203,8 +205,8 @@ mod tests {
203
205
} ,
204
206
CrossTargetConfig {
205
207
env : CrossEnvConfig {
206
- passthrough : vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ,
207
- volumes : vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ,
208
+ passthrough : Some ( vec ! [ "VAR1" . to_string( ) , "VAR2" . to_string( ) ] ) ,
209
+ volumes : Some ( vec ! [ "VOL1_ARG" . to_string( ) , "VOL2_ARG" . to_string( ) ] ) ,
208
210
} ,
209
211
xargo : Some ( false ) ,
210
212
build_std : Some ( true ) ,
@@ -234,4 +236,57 @@ mod tests {
234
236
235
237
Ok ( ( ) )
236
238
}
239
+
240
+ #[ test]
241
+ pub fn parse_mixed_toml ( ) -> Result < ( ) > {
242
+ let mut target_map = HashMap :: new ( ) ;
243
+ target_map. insert (
244
+ Target :: BuiltIn {
245
+ triple : "aarch64-unknown-linux-gnu" . to_string ( ) ,
246
+ } ,
247
+ CrossTargetConfig {
248
+ env : CrossEnvConfig {
249
+ passthrough : None ,
250
+ volumes : Some ( vec ! [ "VOL" . to_string( ) ] ) ,
251
+ } ,
252
+ xargo : Some ( false ) ,
253
+ build_std : None ,
254
+ image : None ,
255
+ runner : None ,
256
+ } ,
257
+ ) ;
258
+
259
+ let cfg = CrossToml {
260
+ targets : target_map,
261
+ build : CrossBuildConfig {
262
+ env : CrossEnvConfig {
263
+ volumes : None ,
264
+ passthrough : Some ( vec ! [ ] ) ,
265
+ } ,
266
+ xargo : Some ( true ) ,
267
+ build_std : None ,
268
+ default_target : None ,
269
+ } ,
270
+ } ;
271
+
272
+ let test_str = r#"
273
+ [build]
274
+ xargo = true
275
+
276
+ [build.env]
277
+ passthrough = []
278
+
279
+ [target.aarch64-unknown-linux-gnu]
280
+ xargo = false
281
+
282
+ [target.aarch64-unknown-linux-gnu.env]
283
+ volumes = ["VOL"]
284
+ "# ;
285
+ let ( parsed_cfg, unused) = CrossToml :: parse ( test_str) ?;
286
+
287
+ assert_eq ! ( parsed_cfg, cfg) ;
288
+ assert ! ( unused. is_empty( ) ) ;
289
+
290
+ Ok ( ( ) )
291
+ }
237
292
}
0 commit comments