@@ -873,7 +873,8 @@ impl Xtasks {
873873 context : & str ,
874874 add_args : I ,
875875 dir : Option < & Path > ,
876- ) -> Result < ( ) > {
876+ capture_streams_in_output : bool ,
877+ ) -> Result < Output > {
877878 info ! ( "Running system command: {command}" ) ;
878879
879880 let working_dir = match dir {
@@ -882,18 +883,25 @@ impl Xtasks {
882883 } ;
883884
884885 let mut cmd = Command :: new ( command) ;
885- cmd. args ( add_args)
886- . stdout ( std:: process:: Stdio :: inherit ( ) )
887- . stderr ( std:: process:: Stdio :: inherit ( ) )
888- . current_dir ( working_dir) ;
886+ cmd. args ( add_args) . current_dir ( working_dir) ;
887+
888+ if !capture_streams_in_output {
889+ cmd. stdout ( std:: process:: Stdio :: inherit ( ) )
890+ . stderr ( std:: process:: Stdio :: inherit ( ) ) ;
891+ }
889892
890893 info ! ( "Using command: {cmd:?}" ) ;
891894
892895 let output = cmd. output ( ) ;
893- info ! ( "Command output: {output:?}" ) ;
896+ if !capture_streams_in_output {
897+ info ! ( "Command status: {:?}" , output. as_ref( ) . map( |o| o. status) ) ;
898+ } else {
899+ info ! ( "Command output: {output:?}" ) ;
900+ }
901+
894902 let output = output. with_context ( || context. to_owned ( ) ) ?;
895903 match output. status . code ( ) {
896- Some ( 0 ) => Ok ( ( ) ) ,
904+ Some ( 0 ) => Ok ( output ) ,
897905 _ => bail ! (
898906 "{} failed with exit code: {}" ,
899907 context,
@@ -1139,6 +1147,7 @@ impl Xtasks {
11391147 "Failed to install bevy_api_gen" ,
11401148 vec ! [ "install" , "--path" , "." ] ,
11411149 None ,
1150+ false ,
11421151 ) ?;
11431152
11441153 let metadata = Self :: main_workspace_cargo_metadata ( ) ?;
@@ -1168,6 +1177,7 @@ impl Xtasks {
11681177 "." ,
11691178 ] ,
11701179 None ,
1180+ false ,
11711181 ) ;
11721182
11731183 // fetch the tags
@@ -1177,6 +1187,7 @@ impl Xtasks {
11771187 "Failed to fetch bevy tags" ,
11781188 vec ! [ "fetch" , "--tags" ] ,
11791189 Some ( & bevy_dir) ,
1190+ false ,
11801191 ) ?;
11811192
11821193 // checkout the version tag
@@ -1186,6 +1197,7 @@ impl Xtasks {
11861197 "Failed to checkout bevy tag" ,
11871198 vec ! [ "checkout" , format!( "v{bevy_version}" ) . as_str( ) ] ,
11881199 Some ( & bevy_dir) ,
1200+ false ,
11891201 ) ?;
11901202
11911203 // run bevy_api_gen
@@ -1237,6 +1249,51 @@ impl Xtasks {
12371249 false ,
12381250 ) ?;
12391251
1252+ // now expand the macros and replace the files in place
1253+ // by running cargo expand --features crate_name and capturing the output
1254+ let functions_crate_dir = Self :: relative_workspace_dir (
1255+ & main_workspace_app_settings,
1256+ "crates/bevy_mod_scripting_functions" ,
1257+ ) ?;
1258+
1259+ let expand_crates = std:: fs:: read_dir ( & output_dir) ?;
1260+ for entry in expand_crates {
1261+ let entry = entry?;
1262+ let path = entry. path ( ) ;
1263+ if path. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "rs" ) || path. ends_with ( "mod.rs" ) {
1264+ continue ;
1265+ }
1266+
1267+ let without_extension = path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
1268+ let args = vec ! [
1269+ String :: from( "expand" ) ,
1270+ format!( "bevy_bindings::{without_extension}" ) ,
1271+ String :: from( "--features" ) ,
1272+ String :: from( without_extension) ,
1273+ ] ;
1274+ let expand_cmd = Self :: run_system_command (
1275+ & main_workspace_app_settings,
1276+ "cargo" ,
1277+ "pre-expanding generated code" ,
1278+ args,
1279+ Some ( & functions_crate_dir) ,
1280+ true ,
1281+ ) ?;
1282+
1283+ let output = String :: from_utf8 ( expand_cmd. stdout ) ?;
1284+ // remove the first mod <mod name> { .. } wrapper
1285+ let output = output
1286+ . lines ( )
1287+ . skip ( 1 )
1288+ . take ( output. lines ( ) . count ( ) - 2 )
1289+ . collect :: < Vec < _ > > ( )
1290+ . join ( "\n " ) ;
1291+
1292+ std:: fs:: write ( & path, output)
1293+ . with_context ( || format ! ( "writing expanded code to {path:?}" ) ) ?;
1294+ info ! ( "Wrote expanded code to {path:?}" ) ;
1295+ }
1296+
12401297 Ok ( ( ) )
12411298 }
12421299
@@ -1347,6 +1404,7 @@ impl Xtasks {
13471404 "Failed to build or serve mdbook docs" ,
13481405 args,
13491406 Some ( Path :: new ( "docs" ) ) ,
1407+ false ,
13501408 ) ?;
13511409
13521410 Ok ( ( ) )
@@ -1686,6 +1744,7 @@ impl Xtasks {
16861744 "target/coverage/html" ,
16871745 ] ,
16881746 None ,
1747+ false ,
16891748 ) ?;
16901749
16911750 Self :: run_system_command (
@@ -1708,6 +1767,7 @@ impl Xtasks {
17081767 "target/coverage/lcov.info" ,
17091768 ] ,
17101769 None ,
1770+ false ,
17111771 ) ?;
17121772 }
17131773 Ok ( ( ) )
@@ -1843,6 +1903,7 @@ impl Xtasks {
18431903 "Failed to install Linux dependencies" ,
18441904 vec ! [ "-c" , install_cmd. as_str( ) ] ,
18451905 None ,
1906+ false ,
18461907 ) ?;
18471908 }
18481909
@@ -1864,6 +1925,7 @@ impl Xtasks {
18641925 "bencher_cli" ,
18651926 ] ,
18661927 None ,
1928+ false ,
18671929 ) ?;
18681930 // install cargo mdbook
18691931 Self :: run_system_command (
@@ -1872,6 +1934,7 @@ impl Xtasks {
18721934 "Failed to install mdbook" ,
18731935 vec ! [ "install" , "mdbook" ] ,
18741936 None ,
1937+ false ,
18751938 ) ?;
18761939
18771940 // install grcov
@@ -1881,6 +1944,17 @@ impl Xtasks {
18811944 "Failed to install grcov" ,
18821945 vec ! [ "install" , "grcov" ] ,
18831946 None ,
1947+ false ,
1948+ ) ?;
1949+
1950+ // install cargo expand
1951+ Self :: run_system_command (
1952+ & app_settings,
1953+ "cargo" ,
1954+ "Failed to install cargo expand" ,
1955+ vec ! [ "install" , "cargo-expand" ] ,
1956+ None ,
1957+ false ,
18841958 ) ?;
18851959
18861960 // install nightly toolchaing for bevy api gen
@@ -1891,6 +1965,7 @@ impl Xtasks {
18911965 "Failed to install nightly toolchain" ,
18921966 vec ! [ "toolchain" , "install" , toolchain. as_str( ) ] ,
18931967 None ,
1968+ false ,
18941969 ) ?;
18951970
18961971 let rustup_components_args = [
@@ -1910,6 +1985,7 @@ impl Xtasks {
19101985 "Failed to install rust components" ,
19111986 rustup_components_args,
19121987 None ,
1988+ false ,
19131989 ) ?;
19141990
19151991 // add components on nightly toolchain
@@ -1921,6 +1997,7 @@ impl Xtasks {
19211997 . iter ( )
19221998 . chain ( [ "--toolchain" , toolchain. as_str ( ) ] . iter ( ) ) ,
19231999 Some ( Path :: new ( "." ) ) ,
2000+ false ,
19242001 ) ?;
19252002
19262003 // create .vscode settings
@@ -2018,6 +2095,7 @@ impl Xtasks {
20182095 "Failed to install binary" ,
20192096 vec ! [ "install" , "--path" , binary_path. to_str( ) . unwrap( ) ] ,
20202097 None ,
2098+ false ,
20212099 ) ?;
20222100
20232101 Ok ( ( ) )
@@ -2030,7 +2108,7 @@ impl Xtasks {
20302108fn pop_cargo_env ( ) -> Result < ( ) > {
20312109 let env = std:: env:: vars ( ) . collect :: < Vec < _ > > ( ) ;
20322110 // RUSTUP TOOLCHAIN exclude is a temporary fix, it might make deving the api codegen crate not work
2033- let exclude_list = [ ] ;
2111+ let exclude_list = [ "CARGO_HOME" ] ;
20342112
20352113 for ( key, value) in env. iter ( ) {
20362114 if key. starts_with ( "CARGO_" ) && !exclude_list. contains ( & ( key. as_str ( ) ) ) {
0 commit comments