Skip to content

Commit 04868fa

Browse files
authored
Unrolled build for rust-lang#138743
Rollup merge of rust-lang#138743 - onur-ozkan:override-is-ci-behaviour, r=Kobzol bootstrap: add `--ci` flag To make bootstrap act like it's running on CI, we had to override the `GITHUB_ACTIONS` environment variable which is a hidden detail of `CiEnv::is_ci`. Now, we can use the `--ci` flag directly on bootstrap which will be documented automatically from `x --help`. This also helps us to avoid race conditions on bootstrap (overriding `GITHUB_ACTIONS` env in each test can cause that if we run the tests in parallel) tests.
2 parents 5d85a71 + b5eaeaf commit 04868fa

File tree

18 files changed

+415
-74
lines changed

18 files changed

+415
-74
lines changed

src/bootstrap/src/bin/main.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use bootstrap::{
1414
Build, CONFIG_CHANGE_HISTORY, Config, Flags, Subcommand, debug, find_recent_config_change_ids,
1515
human_readable_changes, t,
1616
};
17-
use build_helper::ci::CiEnv;
1817
#[cfg(feature = "tracing")]
1918
use tracing::instrument;
2019

@@ -70,12 +69,14 @@ fn main() {
7069
}
7170

7271
// check_version warnings are not printed during setup, or during CI
73-
let changelog_suggestion =
74-
if matches!(config.cmd, Subcommand::Setup { .. }) || CiEnv::is_ci() || config.dry_run() {
75-
None
76-
} else {
77-
check_version(&config)
78-
};
72+
let changelog_suggestion = if matches!(config.cmd, Subcommand::Setup { .. })
73+
|| config.is_running_on_ci
74+
|| config.dry_run()
75+
{
76+
None
77+
} else {
78+
check_version(&config)
79+
};
7980

8081
// NOTE: Since `./configure` generates a `bootstrap.toml`, distro maintainers will see the
8182
// changelog warning, not the `x.py setup` message.

src/bootstrap/src/core/build_steps/format.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::process::Command;
66
use std::sync::Mutex;
77
use std::sync::mpsc::SyncSender;
88

9-
use build_helper::ci::CiEnv;
109
use build_helper::git::get_git_modified_files;
1110
use ignore::WalkBuilder;
1211

@@ -104,7 +103,7 @@ struct RustfmtConfig {
104103

105104
// Prints output describing a collection of paths, with lines such as "formatted modified file
106105
// foo/bar/baz" or "skipped 20 untracked files".
107-
fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
106+
fn print_paths(build: &Builder<'_>, verb: &str, adjective: Option<&str>, paths: &[String]) {
108107
let len = paths.len();
109108
let adjective =
110109
if let Some(adjective) = adjective { format!("{adjective} ") } else { String::new() };
@@ -115,7 +114,7 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
115114
} else {
116115
println!("fmt: {verb} {len} {adjective}files");
117116
}
118-
if len > 1000 && !CiEnv::is_ci() {
117+
if len > 1000 && !build.config.is_running_on_ci {
119118
println!("hint: if this number seems too high, try running `git fetch origin master`");
120119
}
121120
}
@@ -135,7 +134,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
135134
// `--all` is specified or we are in CI. We check all files in CI to avoid bugs in
136135
// `get_modified_rs_files` letting regressions slip through; we also care about CI time less
137136
// since this is still very fast compared to building the compiler.
138-
let all = all || CiEnv::is_ci();
137+
let all = all || build.config.is_running_on_ci;
139138

140139
let mut builder = ignore::types::TypesBuilder::new();
141140
builder.add_defaults();
@@ -190,7 +189,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
190189
)
191190
.map(|x| x.to_string())
192191
.collect();
193-
print_paths("skipped", Some("untracked"), &untracked_paths);
192+
print_paths(build, "skipped", Some("untracked"), &untracked_paths);
194193

195194
for untracked_path in untracked_paths {
196195
// The leading `/` makes it an exact match against the
@@ -319,7 +318,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
319318
});
320319
let mut paths = formatted_paths.into_inner().unwrap();
321320
paths.sort();
322-
print_paths(if check { "checked" } else { "formatted" }, adjective, &paths);
321+
print_paths(build, if check { "checked" } else { "formatted" }, adjective, &paths);
323322

324323
drop(tx);
325324

src/bootstrap/src/core/build_steps/gcc.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use std::fs;
1212
use std::path::{Path, PathBuf};
1313
use std::sync::OnceLock;
1414

15-
use build_helper::ci::CiEnv;
16-
1715
use crate::core::builder::{Builder, Cargo, Kind, RunConfig, ShouldRun, Step};
1816
use crate::core::config::TargetSelection;
1917
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
@@ -202,7 +200,7 @@ fn build_gcc(metadata: &Meta, builder: &Builder<'_>, target: TargetSelection) {
202200
// source directories as read-only on Linux.
203201
// Therefore, as a part of the build in CI, we first copy the whole source directory
204202
// to the build directory, and perform the build from there.
205-
let src_dir = if CiEnv::is_ci() {
203+
let src_dir = if builder.config.is_running_on_ci {
206204
let src_dir = builder.gcc_out(target).join("src");
207205
if src_dir.exists() {
208206
builder.remove_dir(&src_dir);

src/bootstrap/src/core/build_steps/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
266266
/// Returns true if we're running in CI with modified LLVM (and thus can't download it)
267267
pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
268268
// If not running in a CI environment, return false.
269-
if !CiEnv::is_ci() {
269+
if !config.is_running_on_ci {
270270
return false;
271271
}
272272

src/bootstrap/src/core/builder/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ fn ci_rustc_if_unchanged_logic() {
264264
let mut paths = vec!["compiler"];
265265

266266
// Handle library tree the same way as in `Config::download_ci_rustc_commit`.
267-
if build_helper::ci::CiEnv::is_ci() {
267+
if builder.config.is_running_on_ci {
268268
paths.push("library");
269269
}
270270

src/bootstrap/src/core/config/config.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ pub struct Config {
415415

416416
/// Command for visual diff display, e.g. `diff-tool --color=always`.
417417
pub compiletest_diff_tool: Option<String>,
418+
419+
pub is_running_on_ci: bool,
418420
}
419421

420422
#[derive(Clone, Debug, Default)]
@@ -1422,6 +1424,7 @@ impl Config {
14221424
config.llvm_profile_generate = flags.llvm_profile_generate;
14231425
config.enable_bolt_settings = flags.enable_bolt_settings;
14241426
config.bypass_bootstrap_lock = flags.bypass_bootstrap_lock;
1427+
config.is_running_on_ci = flags.ci.unwrap_or(CiEnv::is_ci());
14251428

14261429
// Infer the rest of the configuration.
14271430

@@ -2425,7 +2428,7 @@ impl Config {
24252428

24262429
// CI should always run stage 2 builds, unless it specifically states otherwise
24272430
#[cfg(not(test))]
2428-
if flags.stage.is_none() && build_helper::ci::CiEnv::is_ci() {
2431+
if flags.stage.is_none() && config.is_running_on_ci {
24292432
match config.cmd {
24302433
Subcommand::Test { .. }
24312434
| Subcommand::Miri { .. }
@@ -2647,7 +2650,7 @@ impl Config {
26472650
if !self.llvm_from_ci {
26482651
// This happens when LLVM submodule is updated in CI, we should disable ci-rustc without an error
26492652
// to not break CI. For non-CI environments, we should return an error.
2650-
if CiEnv::is_ci() {
2653+
if self.is_running_on_ci {
26512654
println!("WARNING: LLVM submodule has changes, `download-rustc` will be disabled.");
26522655
return None;
26532656
} else {
@@ -3036,7 +3039,7 @@ impl Config {
30363039
//
30373040
// If you update "library" logic here, update `builder::tests::ci_rustc_if_unchanged_logic` test
30383041
// logic accordingly.
3039-
if !CiEnv::is_ci() {
3042+
if !self.is_running_on_ci {
30403043
allowed_paths.push(":!library");
30413044
}
30423045

@@ -3064,7 +3067,7 @@ impl Config {
30643067
.expect("git-commit-info is missing in the project root")
30653068
};
30663069

3067-
if CiEnv::is_ci() && {
3070+
if self.is_running_on_ci && {
30683071
let head_sha =
30693072
output(helpers::git(Some(&self.src)).arg("rev-parse").arg("HEAD").as_command_mut());
30703073
let head_sha = head_sha.trim();

src/bootstrap/src/core/config/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pub struct Flags {
179179
/// arguments passed to subcommands
180180
#[arg(global = true, last(true), value_name = "ARGS")]
181181
pub free_args: Vec<String>,
182+
/// Make bootstrap to behave as it's running on the CI environment or not.
183+
#[arg(global = true, long, value_name = "bool")]
184+
pub ci: Option<bool>,
182185
}
183186

184187
impl Flags {

src/bootstrap/src/core/config/tests.rs

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fs::{File, remove_file};
44
use std::io::Write;
55
use std::path::Path;
66

7+
use build_helper::ci::CiEnv;
78
use clap::CommandFactory;
89
use serde::Deserialize;
910

@@ -532,3 +533,19 @@ fn test_exclude() {
532533

533534
assert_eq!(first_excluded, exclude_path);
534535
}
536+
537+
#[test]
538+
fn test_ci_flag() {
539+
let config = Config::parse_inner(Flags::parse(&["check".into(), "--ci=false".into()]), |&_| {
540+
toml::from_str("")
541+
});
542+
assert!(!config.is_running_on_ci);
543+
544+
let config = Config::parse_inner(Flags::parse(&["check".into(), "--ci=true".into()]), |&_| {
545+
toml::from_str("")
546+
});
547+
assert!(config.is_running_on_ci);
548+
549+
let config = Config::parse_inner(Flags::parse(&["check".into()]), |&_| toml::from_str(""));
550+
assert_eq!(config.is_running_on_ci, CiEnv::is_ci());
551+
}

src/bootstrap/src/core/download.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::path::{Path, PathBuf};
66
use std::process::{Command, Stdio};
77
use std::sync::OnceLock;
88

9-
use build_helper::ci::CiEnv;
109
use xz2::bufread::XzDecoder;
1110

1211
use crate::core::config::BUILDER_CONFIG_FILENAME;
@@ -262,7 +261,7 @@ impl Config {
262261
"--fail",
263262
]);
264263
// Don't print progress in CI; the \r wrapping looks bad and downloads don't take long enough for progress to be useful.
265-
if CiEnv::is_ci() {
264+
if self.is_running_on_ci {
266265
curl.arg("--silent");
267266
} else {
268267
curl.arg("--progress-bar");

src/bootstrap/src/utils/render_tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::io::{BufRead, BufReader, Read, Write};
1010
use std::process::{ChildStdout, Stdio};
1111
use std::time::Duration;
1212

13-
use build_helper::ci::CiEnv;
1413
use termcolor::{Color, ColorSpec, WriteColor};
1514

1615
use crate::core::builder::Builder;
@@ -187,7 +186,7 @@ impl<'a> Renderer<'a> {
187186

188187
if self.builder.config.verbose_tests {
189188
self.render_test_outcome_verbose(outcome, test);
190-
} else if CiEnv::is_ci() {
189+
} else if self.builder.config.is_running_on_ci {
191190
self.render_test_outcome_ci(outcome, test);
192191
} else {
193192
self.render_test_outcome_terse(outcome, test);

0 commit comments

Comments
 (0)