@@ -20,6 +20,8 @@ fn main() -> anyhow::Result<()> {
2020}
2121
2222fn test ( params : test:: Params ) -> anyhow:: Result < ( ) > {
23+ init_env ( params. ci ) ?;
24+
2325 build:: build ( params. build ) ?;
2426
2527 // the variables must be kept alive and not dropped
@@ -39,6 +41,42 @@ fn test(params: test::Params) -> anyhow::Result<()> {
3941 Ok ( ( ) )
4042}
4143
44+ // Set up environment variables needed by the compilation and testing process.
45+ //
46+ // If ci flag is specified, all binaries are added to PATH env variable
47+ // and the sovereign constant manifest position is specified through the
48+ // CONSTANTS_MANIFEST new env variable
49+ fn init_env ( ci : bool ) -> anyhow:: Result < ( ) > {
50+ if ci {
51+ #[ rustfmt:: skip]
52+ let project_dir = duct:: cmd!(
53+ "sh" , "-c" ,
54+ "cargo locate-project | jq -r '.root' | grep -oE '^.*/'"
55+ )
56+ . stdout_capture ( )
57+ . run ( ) ?;
58+ let project_dir = std:: str:: from_utf8 ( & project_dir. stdout ) ?. trim ( ) ;
59+
60+ let path = std:: env:: var ( "PATH" ) . unwrap_or_else ( |_| "" . to_string ( ) ) ;
61+
62+ // `cargo_target` is the target used in ci by cargo as destination
63+ // for all intermediate and final artifacts
64+ let new_path = format ! ( "/cargo_target/release/:{}" , path) ;
65+ std:: env:: set_var ( "PATH" , new_path) ;
66+
67+ let path = std:: path:: Path :: new ( project_dir) . join ( "demo/sovereign/constants.json" ) ;
68+ if !path. exists ( ) {
69+ anyhow:: bail!(
70+ "The `constants.json` file for Sovereign does not exist,\n \
71+ or it is not in the expected position, `demo/sovereign/constants.json`"
72+ )
73+ }
74+ std:: env:: set_var ( "CONSTANTS_MANIFEST" , path) ;
75+ }
76+
77+ Ok ( ( ) )
78+ }
79+
4280fn init_logging ( ) -> anyhow:: Result < ( ) > {
4381 use tracing_subscriber:: fmt;
4482 use tracing_subscriber:: prelude:: * ;
0 commit comments