@@ -20,12 +20,16 @@ mod runner;
2020mod template;
2121mod translator;
2222
23+ use std:: env;
24+
2325pub use ast:: { Abi , Const , Field , Fn , Parameter , Static , Struct , Type , Union } ;
2426pub use generator:: TestGenerator ;
2527pub use macro_expansion:: expand;
2628pub use runner:: { __compile_test, __run_test, generate_test} ;
2729pub use translator:: TranslationError ;
2830
31+ use crate :: generator:: GenerationError ;
32+
2933/// A possible error that can be encountered in our library.
3034pub type Error = Box < dyn std:: error:: Error > ;
3135/// A type alias for `std::result::Result` that defaults to our error type.
@@ -74,6 +78,23 @@ pub(crate) enum MapInput<'a> {
7478 UnionFieldType ( & ' a Union , & ' a Field ) ,
7579}
7680
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+
7798/* The From impls make it easier to write code in the test templates. */
7899
79100impl < ' a > From < & ' a Const > for MapInput < ' a > {
0 commit comments