Skip to content

Commit

Permalink
Auto merge of rust-lang#134790 - onur-ozkan:cfg-test, r=clubby789
Browse files Browse the repository at this point in the history
replace bootstrap-self-test feature flag with cfg(test)

This makes it in more rusty way.
  • Loading branch information
bors committed Dec 28, 2024
2 parents 3c1e750 + 485c20d commit ceb0441
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ default-run = "bootstrap"

[features]
build-metrics = ["sysinfo"]
bootstrap-self-test = [] # enabled in the bootstrap unit tests

[lib]
path = "src/lib.rs"
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ fn copy_self_contained_objects(
/// Resolves standard library crates for `Std::run_make` for any build kind (like check, build, clippy, etc.).
pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
// FIXME: Extend builder tests to cover the `crates` field of `Std` instances.
if cfg!(feature = "bootstrap-self-test") {
if cfg!(test) {
return vec![];
}

Expand Down
3 changes: 1 addition & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3152,9 +3152,8 @@ impl Step for Bootstrap {

let mut cmd = command(&builder.initial_cargo);
cmd.arg("test")
.args(["--features", "bootstrap-self-test"])
.current_dir(builder.src.join("src/bootstrap"))
.env("RUSTFLAGS", "-Cdebuginfo=2")
.env("RUSTFLAGS", "--cfg test -Cdebuginfo=2")
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
.env("RUSTC_BOOTSTRAP", "1")
.env("RUSTDOC", builder.rustdoc(compiler))
Expand Down
10 changes: 5 additions & 5 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ impl Config {
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
// but not if `config.toml` hasn't been created.
let mut toml = if !using_default_path || toml_path.exists() {
config.config = Some(if cfg!(not(feature = "bootstrap-self-test")) {
config.config = Some(if cfg!(not(test)) {
toml_path.canonicalize().unwrap()
} else {
toml_path.clone()
Expand Down Expand Up @@ -2793,11 +2793,11 @@ impl Config {
}
}

#[cfg(feature = "bootstrap-self-test")]
#[cfg(test)]
pub fn check_stage0_version(&self, _program_path: &Path, _component_name: &'static str) {}

/// check rustc/cargo version is same or lower with 1 apart from the building one
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
pub fn check_stage0_version(&self, program_path: &Path, component_name: &'static str) {
use build_helper::util::fail;

Expand Down Expand Up @@ -2939,7 +2939,7 @@ impl Config {
}

// Fetching the LLVM submodule is unnecessary for self-tests.
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
self.update_submodule("src/llvm-project");

// Check for untracked changes in `src/llvm-project`.
Expand Down Expand Up @@ -3014,7 +3014,7 @@ impl Config {

/// Compares the current `Llvm` options against those in the CI LLVM builder and detects any incompatible options.
/// It does this by destructuring the `Llvm` instance to make sure every `Llvm` field is covered and not missing.
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
pub(crate) fn check_incompatible_options_for_ci_llvm(
current_config_toml: TomlConfig,
ci_config_toml: TomlConfig,
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,14 @@ impl Config {
cargo_clippy
}

#[cfg(feature = "bootstrap-self-test")]
#[cfg(test)]
pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
None
}

/// NOTE: rustfmt is a completely different toolchain than the bootstrap compiler, so it can't
/// reuse target directories or artifacts
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
use build_helper::stage0_parser::VersionMetadata;

Expand Down Expand Up @@ -534,10 +534,10 @@ impl Config {
);
}

#[cfg(feature = "bootstrap-self-test")]
#[cfg(test)]
pub(crate) fn download_beta_toolchain(&self) {}

#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
pub(crate) fn download_beta_toolchain(&self) {
self.verbose(|| println!("downloading stage0 beta artifacts"));

Expand Down Expand Up @@ -714,10 +714,10 @@ download-rustc = false
self.unpack(&tarball, &bin_root, prefix);
}

#[cfg(feature = "bootstrap-self-test")]
#[cfg(test)]
pub(crate) fn maybe_download_ci_llvm(&self) {}

#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
pub(crate) fn maybe_download_ci_llvm(&self) {
use build_helper::exit;

Expand Down Expand Up @@ -789,7 +789,7 @@ download-rustc = false
};
}

#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
fn download_ci_llvm(&self, llvm_sha: &str) {
let llvm_assertions = self.llvm_assertions;

Expand Down
11 changes: 5 additions & 6 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::path::PathBuf;
use std::{env, fs};

use crate::Build;
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
use crate::builder::Builder;
use crate::builder::Kind;
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
use crate::core::build_steps::tool;
use crate::core::config::Target;
use crate::utils::exec::command;
Expand All @@ -38,7 +38,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
/// from CI (with`llvm.download-ci-llvm` option).
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
const LIBSTDCXX_MIN_VERSION_THRESHOLD: usize = 8;

impl Finder {
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn check(build: &mut Build) {
}

// Ensure that a compatible version of libstdc++ is available on the system when using `llvm.download-ci-llvm`.
#[cfg(not(feature = "bootstrap-self-test"))]
#[cfg(not(test))]
if !build.config.dry_run() && !build.build.is_msvc() && build.config.llvm_from_ci {
let builder = Builder::new(build);
let libcxx_version = builder.ensure(tool::LibcxxVersionTool { target: build.build });
Expand Down Expand Up @@ -226,8 +226,7 @@ than building it.
}

// Ignore fake targets that are only used for unit tests in bootstrap.
if cfg!(not(feature = "bootstrap-self-test")) && !skip_target_sanity && !build.local_rebuild
{
if cfg!(not(test)) && !skip_target_sanity && !build.local_rebuild {
let mut has_target = false;
let target_str = target.to_string();

Expand Down

0 comments on commit ceb0441

Please sign in to comment.