Skip to content

Commit 490169e

Browse files
committed
fix 1 and 3 task for issue#110087
modify import llvm Correcting Writing Errors fmt code
1 parent 09df610 commit 490169e

File tree

4 files changed

+95
-14
lines changed

4 files changed

+95
-14
lines changed

config.example.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ change-id = 115898
4242
# Unless you're developing for a target where Rust CI doesn't build a compiler
4343
# toolchain or changing LLVM locally, you probably want to leave this enabled.
4444
#
45-
# All tier 1 targets are currently supported; set this to `"if-available"` if
46-
# you are not sure whether you're on a tier 1 target.
45+
# Set this to `"if-available"` if you are not sure whether you're on a tier 1
46+
# target. All tier 1 targets are currently supported;
4747
#
4848
# We also currently only support this when building LLVM for the build triple.
4949
#
50+
# Set this to `"if-unchanged"` to only download if the llvm-project have not
51+
# been modified. (if no changes, the logic is the same as `"if-available"`)
52+
#
5053
# Note that many of the LLVM options are not currently supported for
5154
# downloading. Currently only the "assertions" option can be toggled.
5255
#download-ci-llvm = if rust.channel == "dev" { "if-available" } else { false }

src/bootstrap/defaults/config.codegen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ assertions = true
1010
# enable warnings during the llvm compilation
1111
enable-warnings = true
1212
# build llvm from source
13-
download-ci-llvm = false
13+
download-ci-llvm = "if-unchanged"
1414

1515
[rust]
1616
# This enables `RUSTC_LOG=debug`, avoiding confusing situations

src/bootstrap/src/core/build_steps/setup.rs

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ impl Step for Profile {
147147
}
148148

149149
fn run(self, builder: &Builder<'_>) {
150+
if self == Profile::Codegen {
151+
builder.update_submodule(&Path::new("src/llvm-project"));
152+
}
150153
setup(&builder.build.config, self)
151154
}
152155
}

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

+86-11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::process::Command;
1919
use std::str::FromStr;
2020

2121
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
22+
use crate::core::build_steps::llvm;
2223
use crate::core::config::flags::{Color, Flags, Warnings};
2324
use crate::utils::cache::{Interned, INTERNER};
2425
use crate::utils::cc_detect::{ndk_compiler, Language};
@@ -1526,17 +1527,7 @@ impl Config {
15261527
config.llvm_build_config = llvm.build_config.clone().unwrap_or(Default::default());
15271528

15281529
let asserts = llvm_assertions.unwrap_or(false);
1529-
config.llvm_from_ci = match llvm.download_ci_llvm {
1530-
Some(StringOrBool::String(s)) => {
1531-
assert_eq!(s, "if-available", "unknown option `{s}` for download-ci-llvm");
1532-
crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
1533-
}
1534-
Some(StringOrBool::Bool(b)) => b,
1535-
None => {
1536-
config.channel == "dev"
1537-
&& crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
1538-
}
1539-
};
1530+
config.llvm_from_ci = config.parse_download_ci_llvm(llvm.download_ci_llvm, asserts);
15401531

15411532
if config.llvm_from_ci {
15421533
// None of the LLVM options, except assertions, are supported
@@ -2107,6 +2098,90 @@ impl Config {
21072098

21082099
Some(commit.to_string())
21092100
}
2101+
2102+
fn parse_download_ci_llvm(
2103+
&self,
2104+
download_ci_llvm: Option<StringOrBool>,
2105+
asserts: bool,
2106+
) -> bool {
2107+
match download_ci_llvm {
2108+
None => self.channel == "dev" && llvm::is_ci_llvm_available(&self, asserts),
2109+
Some(StringOrBool::Bool(b)) => b,
2110+
Some(StringOrBool::String(s)) if s == "if-available" => {
2111+
llvm::is_ci_llvm_available(&self, asserts)
2112+
}
2113+
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
2114+
if self
2115+
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
2116+
.is_none()
2117+
{
2118+
// there are some untracked changes in the the given paths.
2119+
false
2120+
} else {
2121+
llvm::is_ci_llvm_available(&self, asserts)
2122+
}
2123+
}
2124+
Some(StringOrBool::String(other)) => {
2125+
panic!("unrecognized option for download-ci-llvm: {:?}", other)
2126+
}
2127+
}
2128+
}
2129+
2130+
/// Returns the last commit in which any of `modified_paths` were changed,
2131+
/// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
2132+
pub fn last_modified_commit(
2133+
&self,
2134+
modified_paths: &[&str],
2135+
option_name: &str,
2136+
if_unchanged: bool,
2137+
) -> Option<String> {
2138+
// Handle running from a directory other than the top level
2139+
let top_level = output(self.git().args(&["rev-parse", "--show-toplevel"]));
2140+
let top_level = top_level.trim_end();
2141+
2142+
// Look for a version to compare to based on the current commit.
2143+
// Only commits merged by bors will have CI artifacts.
2144+
let merge_base = output(
2145+
self.git()
2146+
.arg("rev-list")
2147+
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
2148+
.args(&["-n1", "--first-parent", "HEAD"]),
2149+
);
2150+
let commit = merge_base.trim_end();
2151+
if commit.is_empty() {
2152+
println!("error: could not find commit hash for downloading components from CI");
2153+
println!("help: maybe your repository history is too shallow?");
2154+
println!("help: consider disabling `{option_name}`");
2155+
println!("help: or fetch enough history to include one upstream commit");
2156+
crate::exit!(1);
2157+
}
2158+
2159+
// Warn if there were changes to the compiler or standard library since the ancestor commit.
2160+
let mut git = self.git();
2161+
git.args(&["diff-index", "--quiet", &commit, "--"]);
2162+
2163+
for path in modified_paths {
2164+
git.arg(format!("{top_level}/{path}"));
2165+
}
2166+
2167+
let has_changes = !t!(git.status()).success();
2168+
if has_changes {
2169+
if if_unchanged {
2170+
if self.verbose > 0 {
2171+
println!(
2172+
"warning: saw changes to one of {modified_paths:?} since {commit}; \
2173+
ignoring `{option_name}`"
2174+
);
2175+
}
2176+
return None;
2177+
}
2178+
println!(
2179+
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
2180+
);
2181+
}
2182+
2183+
Some(commit.to_string())
2184+
}
21102185
}
21112186

21122187
fn set<T>(field: &mut T, val: Option<T>) {

0 commit comments

Comments
 (0)