|
7 | 7 | use std::collections::VecDeque;
|
8 | 8 | use std::num::NonZeroUsize;
|
9 | 9 | use std::path::PathBuf;
|
| 10 | +use std::process::Command; |
10 | 11 | use std::str::FromStr;
|
11 | 12 | use std::sync::atomic::{AtomicBool, Ordering};
|
12 | 13 | use std::thread::{self, ScopedJoinHandle, scope};
|
13 | 14 | use std::{env, process};
|
14 | 15 |
|
15 | 16 | use tidy::*;
|
16 | 17 |
|
| 18 | +// We set the `BASE_COMMIT` environment variable |
| 19 | +fn set_env_base_commit() { |
| 20 | + if env::var("BASE_COMMIT").is_ok() { |
| 21 | + // Nothing to be done! |
| 22 | + return; |
| 23 | + } |
| 24 | + // If first commit is from `[email protected]`, then we need to skip it as it means we're in |
| 25 | + // the CI and it's the merge commit generated to test the PR. |
| 26 | + let output = Command::new("git") |
| 27 | + .args(&["log", "-n", "1", "--pretty=format:%ae"]) |
| 28 | + .output() |
| 29 | + .expect("Failed to run `git` command to retrieve base commit"); |
| 30 | + let output = String::from_utf8_lossy(&output.stdout); |
| 31 | + let skip = if output .trim() == "[email protected]" { "--skip=1" } else { "--skip=0" }; |
| 32 | + |
| 33 | + // Now we find the last merge commit from bors to know what base commit to use. |
| 34 | + let output = Command::new("git") |
| 35 | + .args(&["log", "[email protected]", "-n", "1", "--pretty=format:%H", skip ]) |
| 36 | + .output() |
| 37 | + .expect("Failed to run `git` command to retrieve base commit"); |
| 38 | + let output = String::from_utf8_lossy(&output.stdout); |
| 39 | + |
| 40 | + let base_commit = output.trim(); |
| 41 | + eprintln!("setting base commit: {base_commit}"); |
| 42 | + env::set_var("BASE_COMMIT", base_commit); |
| 43 | +} |
| 44 | + |
17 | 45 | fn main() {
|
18 | 46 | // Running Cargo will read the libstd Cargo.toml
|
19 | 47 | // which uses the unstable `public-dependency` feature.
|
20 | 48 | //
|
21 | 49 | // `setenv` might not be thread safe, so run it before using multiple threads.
|
22 | 50 | env::set_var("RUSTC_BOOTSTRAP", "1");
|
| 51 | + set_env_base_commit(); |
23 | 52 |
|
24 | 53 | let root_path: PathBuf = env::args_os().nth(1).expect("need path to root of repo").into();
|
25 | 54 | let cargo: PathBuf = env::args_os().nth(2).expect("need path to cargo").into();
|
|
0 commit comments