Skip to content

Commit

Permalink
fix 1 and 3 task for issue#110087
Browse files Browse the repository at this point in the history
modify import llvm

Correcting Writing Errors

fmt code
  • Loading branch information
LuuuXXX committed Oct 18, 2023
1 parent 09df610 commit 490169e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 14 deletions.
7 changes: 5 additions & 2 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ change-id = 115898
# Unless you're developing for a target where Rust CI doesn't build a compiler
# toolchain or changing LLVM locally, you probably want to leave this enabled.
#
# All tier 1 targets are currently supported; set this to `"if-available"` if
# you are not sure whether you're on a tier 1 target.
# Set this to `"if-available"` if you are not sure whether you're on a tier 1
# target. All tier 1 targets are currently supported;
#
# We also currently only support this when building LLVM for the build triple.
#
# Set this to `"if-unchanged"` to only download if the llvm-project have not
# been modified. (if no changes, the logic is the same as `"if-available"`)
#
# Note that many of the LLVM options are not currently supported for
# downloading. Currently only the "assertions" option can be toggled.
#download-ci-llvm = if rust.channel == "dev" { "if-available" } else { false }
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/defaults/config.codegen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ assertions = true
# enable warnings during the llvm compilation
enable-warnings = true
# build llvm from source
download-ci-llvm = false
download-ci-llvm = "if-unchanged"

[rust]
# This enables `RUSTC_LOG=debug`, avoiding confusing situations
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ impl Step for Profile {
}

fn run(self, builder: &Builder<'_>) {
if self == Profile::Codegen {
builder.update_submodule(&Path::new("src/llvm-project"));
}
setup(&builder.build.config, self)
}
}
Expand Down
97 changes: 86 additions & 11 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::process::Command;
use std::str::FromStr;

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

let asserts = llvm_assertions.unwrap_or(false);
config.llvm_from_ci = match llvm.download_ci_llvm {
Some(StringOrBool::String(s)) => {
assert_eq!(s, "if-available", "unknown option `{s}` for download-ci-llvm");
crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
}
Some(StringOrBool::Bool(b)) => b,
None => {
config.channel == "dev"
&& crate::core::build_steps::llvm::is_ci_llvm_available(&config, asserts)
}
};
config.llvm_from_ci = config.parse_download_ci_llvm(llvm.download_ci_llvm, asserts);

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

Some(commit.to_string())
}

fn parse_download_ci_llvm(
&self,
download_ci_llvm: Option<StringOrBool>,
asserts: bool,
) -> bool {
match download_ci_llvm {
None => self.channel == "dev" && llvm::is_ci_llvm_available(&self, asserts),
Some(StringOrBool::Bool(b)) => b,
Some(StringOrBool::String(s)) if s == "if-available" => {
llvm::is_ci_llvm_available(&self, asserts)
}
Some(StringOrBool::String(s)) if s == "if-unchanged" => {
if self
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
.is_none()
{
// there are some untracked changes in the the given paths.
false
} else {
llvm::is_ci_llvm_available(&self, asserts)
}
}
Some(StringOrBool::String(other)) => {
panic!("unrecognized option for download-ci-llvm: {:?}", other)
}
}
}

/// Returns the last commit in which any of `modified_paths` were changed,
/// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
pub fn last_modified_commit(
&self,
modified_paths: &[&str],
option_name: &str,
if_unchanged: bool,
) -> Option<String> {
// Handle running from a directory other than the top level
let top_level = output(self.git().args(&["rev-parse", "--show-toplevel"]));
let top_level = top_level.trim_end();

// Look for a version to compare to based on the current commit.
// Only commits merged by bors will have CI artifacts.
let merge_base = output(
self.git()
.arg("rev-list")
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
.args(&["-n1", "--first-parent", "HEAD"]),
);
let commit = merge_base.trim_end();
if commit.is_empty() {
println!("error: could not find commit hash for downloading components from CI");
println!("help: maybe your repository history is too shallow?");
println!("help: consider disabling `{option_name}`");
println!("help: or fetch enough history to include one upstream commit");
crate::exit!(1);
}

// Warn if there were changes to the compiler or standard library since the ancestor commit.
let mut git = self.git();
git.args(&["diff-index", "--quiet", &commit, "--"]);

for path in modified_paths {
git.arg(format!("{top_level}/{path}"));
}

let has_changes = !t!(git.status()).success();
if has_changes {
if if_unchanged {
if self.verbose > 0 {
println!(
"warning: saw changes to one of {modified_paths:?} since {commit}; \
ignoring `{option_name}`"
);
}
return None;
}
println!(
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
);
}

Some(commit.to_string())
}
}

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

0 comments on commit 490169e

Please sign in to comment.