@@ -20,12 +20,16 @@ mod runner;
20
20
mod template;
21
21
mod translator;
22
22
23
+ use std:: env;
24
+
23
25
pub use ast:: { Abi , Const , Field , Fn , Parameter , Static , Struct , Type , Union } ;
24
26
pub use generator:: TestGenerator ;
25
27
pub use macro_expansion:: expand;
26
28
pub use runner:: { __compile_test, __run_test, generate_test} ;
27
29
pub use translator:: TranslationError ;
28
30
31
+ use crate :: generator:: GenerationError ;
32
+
29
33
/// A possible error that can be encountered in our library.
30
34
pub type Error = Box < dyn std:: error:: Error > ;
31
35
/// A type alias for `std::result::Result` that defaults to our error type.
@@ -74,6 +78,23 @@ pub(crate) enum MapInput<'a> {
74
78
UnionFieldType ( & ' a Union , & ' a Field ) ,
75
79
}
76
80
81
+ /// Search for the target to build for, specified manually or through an environment variable.
82
+ ///
83
+ /// This function will check the following places for the target name:
84
+ /// - TestGenerator.target
85
+ /// - TARGET environment variable.
86
+ /// - TARGET_PLATFORM environment variable.
87
+ fn get_build_target ( generator : & TestGenerator ) -> Result < String , GenerationError > {
88
+ generator
89
+ . target
90
+ . clone ( )
91
+ . or_else ( || env:: var ( "TARGET" ) . ok ( ) )
92
+ . or_else ( || env:: var ( "TARGET_PLATFORM" ) . ok ( ) )
93
+ . ok_or ( GenerationError :: EnvVarNotFound (
94
+ "TARGET, TARGET_PLATFORM" . to_string ( ) ,
95
+ ) )
96
+ }
97
+
77
98
/* The From impls make it easier to write code in the test templates. */
78
99
79
100
impl < ' a > From < & ' a Const > for MapInput < ' a > {
0 commit comments