Skip to content

Commit 517fa87

Browse files
committed
Port download-ci-rustc
1 parent a24ea17 commit 517fa87

File tree

8 files changed

+43
-89
lines changed

8 files changed

+43
-89
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::utils::exec::command;
3131
use crate::utils::helpers::{
3232
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3333
};
34-
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode};
34+
use crate::{CLang, Compiler, DependencyType, GitRepo, LLVM_TOOLS, Mode, trace};
3535

3636
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3737
pub struct Std {
@@ -108,7 +108,11 @@ impl Step for Std {
108108
// the `rust.download-rustc=true` option.
109109
let force_recompile = builder.rust_info().is_managed_git_subrepository()
110110
&& builder.download_rustc()
111-
&& builder.config.last_modified_commit(&["library"], "download-rustc", true).is_none();
111+
&& builder.config.has_changes_from_upstream(&["library"]);
112+
113+
trace!("is managed git repo: {}", builder.rust_info().is_managed_git_subrepository());
114+
trace!("download_rustc: {}", builder.download_rustc());
115+
trace!(force_recompile);
112116

113117
run.builder.ensure(Std {
114118
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn get_modified_rs_files(build: &Builder<'_>) -> Result<Option<Vec<String>>, Str
9494
return Ok(None);
9595
}
9696

97-
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"])
97+
get_git_modified_files(&build.config.git_config(), Some(&build.config.src), &["rs"]).map(Some)
9898
}
9999

100100
#[derive(serde_derive::Deserialize)]

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl Step for Llvm {
520520
}
521521

522522
// https://llvm.org/docs/HowToCrossCompileLLVM.html
523-
if !builder.is_builder_target(target) {
523+
if !builder.is_builder_target(&target) {
524524
let LlvmResult { llvm_config, .. } =
525525
builder.ensure(Llvm { target: builder.config.build });
526526
if !builder.config.dry_run() {
@@ -672,7 +672,7 @@ fn configure_cmake(
672672
}
673673
cfg.target(&target.triple).host(&builder.config.build.triple);
674674

675-
if !builder.is_builder_target(target) {
675+
if !builder.is_builder_target(&target) {
676676
cfg.define("CMAKE_CROSSCOMPILING", "True");
677677

678678
if target.contains("netbsd") {
@@ -1097,7 +1097,7 @@ impl Step for Lld {
10971097
.define("LLVM_CMAKE_DIR", llvm_cmake_dir)
10981098
.define("LLVM_INCLUDE_TESTS", "OFF");
10991099

1100-
if !builder.is_builder_target(target) {
1100+
if !builder.is_builder_target(&target) {
11011101
// Use the host llvm-tblgen binary.
11021102
cfg.define(
11031103
"LLVM_TABLEGEN_EXE",

src/bootstrap/src/core/build_steps/tool.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,7 @@ impl Step for Rustdoc {
604604
let files_to_track = &["src/librustdoc", "src/tools/rustdoc"];
605605

606606
// Check if unchanged
607-
if builder.config.last_modified_commit(files_to_track, "download-rustc", true).is_some()
608-
{
607+
if !builder.config.has_changes_from_upstream(files_to_track) {
609608
let precompiled_rustdoc = builder
610609
.config
611610
.ci_rustc_dir()

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,14 @@ fn ci_rustc_if_unchanged_logic() {
261261
// Make sure "if-unchanged" logic doesn't try to use CI rustc while there are changes
262262
// in compiler and/or library.
263263
if config.download_rustc_commit.is_some() {
264-
let has_changes =
265-
config.last_modified_commit(&["compiler", "library"], "download-rustc", true).is_none();
264+
let mut paths = vec!["compiler"];
265+
266+
// Handle library tree the same way as in `Config::download_ci_rustc_commit`.
267+
if build_helper::ci::CiEnv::is_ci() {
268+
paths.push("library");
269+
}
270+
271+
let has_changes = config.has_changes_from_upstream(&paths);
266272

267273
assert!(
268274
!has_changes,

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

+19-74
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ use std::{cmp, env, fs};
1515

1616
use build_helper::ci::CiEnv;
1717
use build_helper::exit;
18-
use build_helper::git::{
19-
GitConfig, PathFreshness, check_path_modifications, get_closest_merge_commit, output_result,
20-
};
18+
use build_helper::git::{GitConfig, PathFreshness, check_path_modifications, output_result};
2119
use serde::{Deserialize, Deserializer};
2220
use serde_derive::Deserialize;
2321
#[cfg(feature = "tracing")]
@@ -2981,17 +2979,22 @@ impl Config {
29812979
let commit = if self.rust_info.is_managed_git_subrepository() {
29822980
// Look for a version to compare to based on the current commit.
29832981
// Only commits merged by bors will have CI artifacts.
2984-
match self.last_modified_commit(&allowed_paths, "download-rustc", if_unchanged) {
2985-
Some(commit) => commit,
2986-
None => {
2982+
match self.check_modifications(&allowed_paths) {
2983+
PathFreshness::LastModifiedUpstream { upstream } => upstream,
2984+
PathFreshness::HasLocalModifications { upstream } => {
29872985
if if_unchanged {
29882986
return None;
29892987
}
2990-
println!("ERROR: could not find commit hash for downloading rustc");
2991-
println!("HELP: maybe your repository history is too shallow?");
2992-
println!("HELP: consider setting `rust.download-rustc=false` in config.toml");
2993-
println!("HELP: or fetch enough history to include one upstream commit");
2994-
crate::exit!(1);
2988+
2989+
if CiEnv::is_ci() {
2990+
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
2991+
eprintln!(
2992+
"`rustc.download-ci` functionality will be skipped as artifacts are not available."
2993+
);
2994+
return None;
2995+
}
2996+
2997+
upstream
29952998
}
29962999
}
29973000
} else {
@@ -3000,19 +3003,6 @@ impl Config {
30003003
.expect("git-commit-info is missing in the project root")
30013004
};
30023005

3003-
if CiEnv::is_ci() && {
3004-
let head_sha =
3005-
output(helpers::git(Some(&self.src)).arg("rev-parse").arg("HEAD").as_command_mut());
3006-
let head_sha = head_sha.trim();
3007-
commit == head_sha
3008-
} {
3009-
eprintln!("CI rustc commit matches with HEAD and we are in CI.");
3010-
eprintln!(
3011-
"`rustc.download-ci` functionality will be skipped as artifacts are not available."
3012-
);
3013-
return None;
3014-
}
3015-
30163006
if debug_assertions_requested {
30173007
eprintln!(
30183008
"WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \
@@ -3068,61 +3058,16 @@ impl Config {
30683058
}
30693059

30703060
/// Returns true if any of the `paths` have been modified locally.
3071-
fn has_changes_from_upstream(&self, paths: &[&str]) -> bool {
3072-
let freshness =
3073-
check_path_modifications(Some(&self.src), &self.git_config(), paths, CiEnv::current())
3074-
.unwrap();
3075-
match freshness {
3061+
pub fn has_changes_from_upstream(&self, paths: &[&str]) -> bool {
3062+
match self.check_modifications(paths) {
30763063
PathFreshness::LastModifiedUpstream { .. } => false,
30773064
PathFreshness::HasLocalModifications { .. } => true,
30783065
}
30793066
}
30803067

3081-
/// Returns the last commit in which any of `modified_paths` were changed,
3082-
/// or `None` if there are untracked changes in the working directory and `if_unchanged` is true.
3083-
pub fn last_modified_commit(
3084-
&self,
3085-
modified_paths: &[&str],
3086-
option_name: &str,
3087-
if_unchanged: bool,
3088-
) -> Option<String> {
3089-
assert!(
3090-
self.rust_info.is_managed_git_subrepository(),
3091-
"Can't run `Config::last_modified_commit` on a non-git source."
3092-
);
3093-
3094-
// Look for a version to compare to based on the current commit.
3095-
// Only commits merged by bors will have CI artifacts.
3096-
let commit = get_closest_merge_commit(Some(&self.src), &self.git_config(), &[]).unwrap();
3097-
if commit.is_empty() {
3098-
println!("error: could not find commit hash for downloading components from CI");
3099-
println!("help: maybe your repository history is too shallow?");
3100-
println!("help: consider disabling `{option_name}`");
3101-
println!("help: or fetch enough history to include one upstream commit");
3102-
crate::exit!(1);
3103-
}
3104-
3105-
// Warn if there were changes to the compiler or standard library since the ancestor commit.
3106-
let mut git = helpers::git(Some(&self.src));
3107-
git.args(["diff-index", "--quiet", &commit, "--"]).args(modified_paths);
3108-
3109-
let has_changes = !t!(git.as_command_mut().status()).success();
3110-
if has_changes {
3111-
if if_unchanged {
3112-
if self.is_verbose() {
3113-
println!(
3114-
"warning: saw changes to one of {modified_paths:?} since {commit}; \
3115-
ignoring `{option_name}`"
3116-
);
3117-
}
3118-
return None;
3119-
}
3120-
println!(
3121-
"warning: `{option_name}` is enabled, but there are changes to one of {modified_paths:?}"
3122-
);
3123-
}
3124-
3125-
Some(commit.to_string())
3068+
fn check_modifications(&self, paths: &[&str]) -> PathFreshness {
3069+
check_path_modifications(Some(&self.src), &self.git_config(), paths, CiEnv::current())
3070+
.unwrap()
31263071
}
31273072
}
31283073

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ fn download_ci_llvm() {
3939

4040
let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\"");
4141
if if_unchanged_config.llvm_from_ci {
42-
let has_changes = if_unchanged_config
43-
.last_modified_commit(&["src/llvm-project"], "download-ci-llvm", true)
44-
.is_none();
42+
let has_changes = if_unchanged_config.has_changes_from_upstream(&["src/llvm-project"]);
4543

4644
assert!(
4745
!has_changes,

src/build_helper/src/git.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(test)]
22
mod tests;
33

4-
use std::path::{Path, PathBuf};
4+
use std::path::Path;
55
use std::process::{Command, Stdio};
66

77
use crate::ci::CiEnv;
@@ -184,10 +184,12 @@ pub enum PathFreshness {
184184

185185
/// This function figures out if a set of paths was last modified upstream or
186186
/// if there are some local modifications made to them.
187-
///
188187
/// It can be used to figure out if we should download artifacts from CI or rather
189188
/// build them locally.
190189
///
190+
/// The function assumes that at least a single upstream bors merge commit is in the
191+
/// local git history.
192+
///
191193
/// `target_paths` should be a non-empty slice of paths (relative to `git_dir` or the
192194
/// current working directory) whose modifications would invalidate the artifact.
193195
/// Each path can also be a negative match, i.e. `:!foo`. This matches changes outside

0 commit comments

Comments
 (0)