Skip to content

Commit bf310d5

Browse files
committed
chore: avoid problems with locking xtask executable on windows
1 parent 517a08c commit bf310d5

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

crates/xtask/src/main.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,10 @@ impl Xtasks {
752752
Xtasks::Bench {
753753
name,
754754
enable_profiling,
755-
} => Self::bench(app_settings, enable_profiling, name),
755+
} => {
756+
let _ = Self::bench(app_settings, enable_profiling, name, false)?;
757+
Ok(())
758+
}
756759
}?;
757760

758761
Ok("".into())
@@ -840,6 +843,7 @@ impl Xtasks {
840843
context: &str,
841844
add_args: I,
842845
dir: Option<&Path>,
846+
capture_streams_in_output: bool,
843847
) -> Result<Output> {
844848
let coverage_mode = app_settings
845849
.coverage
@@ -898,10 +902,12 @@ impl Xtasks {
898902
};
899903

900904
let mut cmd = Command::new("cargo");
901-
cmd.args(args)
902-
.stdout(std::process::Stdio::inherit())
903-
.stderr(std::process::Stdio::inherit())
904-
.current_dir(working_dir);
905+
cmd.args(args).current_dir(working_dir);
906+
907+
if !capture_streams_in_output {
908+
cmd.stdout(std::process::Stdio::inherit())
909+
.stderr(std::process::Stdio::inherit());
910+
}
905911

906912
info!("Using command: {:?}", cmd);
907913

@@ -925,6 +931,7 @@ impl Xtasks {
925931
"Failed to build workspace",
926932
vec!["--all-targets"],
927933
None,
934+
false,
928935
)?;
929936
Ok(())
930937
}
@@ -943,6 +950,7 @@ impl Xtasks {
943950
"Failed to run clippy",
944951
clippy_args,
945952
None,
953+
false,
946954
)?;
947955

948956
if ide_mode {
@@ -956,6 +964,7 @@ impl Xtasks {
956964
"Failed to run cargo fmt",
957965
vec!["--all", "--", "--check"],
958966
None,
967+
false,
959968
)?;
960969

961970
Ok(())
@@ -983,6 +992,7 @@ impl Xtasks {
983992
"Failed to run clippy on codegen crate",
984993
clippy_args,
985994
None,
995+
false,
986996
)?;
987997

988998
// TODO: for now do nothing, it's difficult to get rust analyzer to accept the nightly version
@@ -1124,6 +1134,7 @@ impl Xtasks {
11241134
"-v",
11251135
],
11261136
Some(&bevy_dir),
1137+
false,
11271138
)?;
11281139

11291140
// collect
@@ -1142,6 +1153,7 @@ impl Xtasks {
11421153
"-v",
11431154
],
11441155
Some(&bevy_dir),
1156+
false,
11451157
)?;
11461158

11471159
Ok(())
@@ -1234,6 +1246,7 @@ impl Xtasks {
12341246
"Failed to build crates.io docs",
12351247
args,
12361248
None,
1249+
false,
12371250
)?;
12381251
}
12391252

@@ -1252,7 +1265,12 @@ impl Xtasks {
12521265
Ok(())
12531266
}
12541267

1255-
fn bench(app_settings: GlobalArgs, profile: bool, name: Option<String>) -> Result<()> {
1268+
fn bench(
1269+
app_settings: GlobalArgs,
1270+
profile: bool,
1271+
name: Option<String>,
1272+
capture_streams_in_output: bool,
1273+
) -> Result<Output> {
12561274
log::info!("Profiling enabled: {profile}");
12571275

12581276
let mut features = vec![
@@ -1274,17 +1292,18 @@ impl Xtasks {
12741292
vec![]
12751293
};
12761294

1277-
Self::run_workspace_command(
1295+
let output = Self::run_workspace_command(
12781296
// run with just lua54
12791297
&app_settings.with_features(Features::new(features)),
12801298
"bench",
12811299
"Failed to run benchmarks",
12821300
args,
12831301
None,
1302+
capture_streams_in_output,
12841303
)
12851304
.with_context(|| "when executing criterion benchmarks")?;
12861305

1287-
Ok(())
1306+
Ok(output)
12881307
}
12891308

12901309
fn bencher(app_settings: GlobalArgs, publish: bool) -> Result<()> {
@@ -1320,6 +1339,13 @@ impl Xtasks {
13201339

13211340
let token = std::env::var("BENCHER_API_TOKEN").ok();
13221341

1342+
// first of all run bench, and save output to a file
1343+
1344+
let result = Self::bench(app_settings, false, None, true)?;
1345+
let bench_file_path = PathBuf::from("./bencher_output.txt");
1346+
let mut file = std::fs::File::create(&bench_file_path)?;
1347+
file.write_all(&result.stdout)?;
1348+
13231349
let mut bencher_cmd = Command::new("bencher");
13241350
bencher_cmd
13251351
.stdout(std::process::Stdio::inherit())
@@ -1347,7 +1373,8 @@ impl Xtasks {
13471373

13481374
bencher_cmd
13491375
.args(["--adapter", "rust_criterion"])
1350-
.arg("cargo xtask bench");
1376+
.arg("--file")
1377+
.arg(bench_file_path);
13511378

13521379
log::info!("Running bencher command: {:?}", bencher_cmd);
13531380

@@ -1547,6 +1574,7 @@ impl Xtasks {
15471574
"Failed to run tests",
15481575
test_args,
15491576
None,
1577+
false,
15501578
)?;
15511579

15521580
// generate coverage report and lcov file
@@ -1880,6 +1908,7 @@ impl Xtasks {
18801908
"Failed to run example",
18811909
vec!["--example", example.as_str()],
18821910
None,
1911+
false,
18831912
)?;
18841913

18851914
Ok(())

0 commit comments

Comments
 (0)