replace get_closest_merge_base_commit with get_closest_merge_commit

Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
onur-ozkan 2024-09-09 20:19:29 +03:00
parent dc9c5f251c
commit 9aa823cc67
5 changed files with 15 additions and 53 deletions

View File

@ -15,6 +15,7 @@
use std::process::Stdio;
use std::{env, fs, str};
use build_helper::git::get_closest_merge_commit;
use serde_derive::Deserialize;
use crate::core::build_steps::tool::SourceType;
@ -26,8 +27,7 @@
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::utils::exec::command;
use crate::utils::helpers::{
self, exe, get_clang_cl_resource_dir, get_closest_merge_base_commit, is_debug_info, is_dylib,
symlink_dir, t, up_to_date,
self, exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
};
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode, LLVM_TOOLS};
@ -127,12 +127,8 @@ fn make_run(run: RunConfig<'_>) {
// the `rust.download-rustc=true` option.
let force_recompile =
if builder.rust_info().is_managed_git_subrepository() && builder.download_rustc() {
let closest_merge_commit = get_closest_merge_base_commit(
Some(&builder.src),
&builder.config.git_config(),
&builder.config.stage0_metadata.config.git_merge_commit_email,
&[],
)
let closest_merge_commit =
get_closest_merge_commit(Some(&builder.src), &builder.config.git_config(), &[])
.unwrap();
// Check if `library` has changes (returns false otherwise)

View File

@ -16,6 +16,7 @@
use std::{env, io};
use build_helper::ci::CiEnv;
use build_helper::git::get_closest_merge_commit;
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection};
@ -153,10 +154,9 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
/// This retrieves the LLVM sha we *want* to use, according to git history.
pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
let llvm_sha = if is_git {
helpers::get_closest_merge_base_commit(
get_closest_merge_commit(
Some(&config.src),
&config.git_config(),
&config.stage0_metadata.config.git_merge_commit_email,
&[
config.src.join("src/llvm-project"),
config.src.join("src/bootstrap/download-ci-llvm-stamp"),

View File

@ -1,6 +1,8 @@
use std::path::PathBuf;
use std::{env, fs};
use build_helper::git::get_closest_merge_commit;
use crate::core::build_steps::compile;
use crate::core::build_steps::toolstate::ToolState;
use crate::core::builder;
@ -8,7 +10,7 @@
use crate::core::config::TargetSelection;
use crate::utils::channel::GitInfo;
use crate::utils::exec::{command, BootstrapCommand};
use crate::utils::helpers::{add_dylib_path, exe, get_closest_merge_base_commit, git, t};
use crate::utils::helpers::{add_dylib_path, exe, git, t};
use crate::{gha, Compiler, Kind, Mode};
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@ -576,10 +578,9 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
&& target_compiler.stage > 0
&& builder.rust_info().is_managed_git_subrepository()
{
let commit = get_closest_merge_base_commit(
let commit = get_closest_merge_commit(
Some(&builder.config.src),
&builder.config.git_config(),
&builder.config.stage0_metadata.config.git_merge_commit_email,
&[],
)
.unwrap();

View File

@ -14,7 +14,7 @@
use std::{cmp, env, fs};
use build_helper::exit;
use build_helper::git::{output_result, GitConfig};
use build_helper::git::{get_closest_merge_commit, output_result, GitConfig};
use serde::{Deserialize, Deserializer};
use serde_derive::Deserialize;
@ -24,7 +24,7 @@
use crate::core::config::flags::{Color, Flags, Warnings};
use crate::utils::cache::{Interned, INTERNER};
use crate::utils::channel::{self, GitInfo};
use crate::utils::helpers::{self, exe, get_closest_merge_base_commit, output, t};
use crate::utils::helpers::{self, exe, output, t};
macro_rules! check_ci_llvm {
($name:expr) => {
@ -2686,13 +2686,7 @@ fn download_ci_rustc_commit(&self, download_rustc: Option<StringOrBool>) -> Opti
// Look for a version to compare to based on the current commit.
// Only commits merged by bors will have CI artifacts.
let commit = get_closest_merge_base_commit(
Some(&self.src),
&self.git_config(),
&self.stage0_metadata.config.git_merge_commit_email,
&[],
)
.unwrap();
let commit = get_closest_merge_commit(Some(&self.src), &self.git_config(), &[]).unwrap();
if commit.is_empty() {
println!("ERROR: could not find commit hash for downloading rustc");
println!("HELP: maybe your repository history is too shallow?");
@ -2783,13 +2777,7 @@ pub fn last_modified_commit(
) -> Option<String> {
// Look for a version to compare to based on the current commit.
// Only commits merged by bors will have CI artifacts.
let commit = get_closest_merge_base_commit(
Some(&self.src),
&self.git_config(),
&self.stage0_metadata.config.git_merge_commit_email,
&[],
)
.unwrap();
let commit = get_closest_merge_commit(Some(&self.src), &self.git_config(), &[]).unwrap();
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?");

View File

@ -10,7 +10,6 @@
use std::time::{Instant, SystemTime, UNIX_EPOCH};
use std::{env, fs, io, str};
use build_helper::git::{get_git_merge_base, output_result, GitConfig};
use build_helper::util::fail;
use crate::core::builder::Builder;
@ -523,28 +522,6 @@ pub fn git(source_dir: Option<&Path>) -> BootstrapCommand {
git
}
/// Returns the closest commit available from upstream for the given `author` and `target_paths`.
///
/// If it fails to find the commit from upstream using `git merge-base`, fallbacks to HEAD.
pub fn get_closest_merge_base_commit(
source_dir: Option<&Path>,
config: &GitConfig<'_>,
author: &str,
target_paths: &[PathBuf],
) -> Result<String, String> {
let mut git = git(source_dir);
let merge_base = get_git_merge_base(config, source_dir).unwrap_or_else(|_| "HEAD".into());
git.args(["rev-list", &format!("--author={author}"), "-n1", "--first-parent", &merge_base]);
if !target_paths.is_empty() {
git.arg("--").args(target_paths);
}
Ok(output_result(git.as_command_mut())?.trim().to_owned())
}
/// Sets the file times for a given file at `path`.
pub fn set_file_times<P: AsRef<Path>>(path: P, times: fs::FileTimes) -> io::Result<()> {
// Windows requires file to be writable to modify file times. But on Linux CI the file does not