Rollup merge of #124553 - ferrocene:pa-cargo-git-info, r=onur-ozkan

Write `git-commit-{sha,info}` for Cargo in source tarballs

Right now Cargo doesn't populate the commit hash or date in its version output when it's built from the plain source tarball. That's because we don't include the git information for it, and Cargo's build script doesn't pick it up.

This PR *partially* solves the problem by storing the git information for Cargo in `src/tools/cargo` in the plain source tarball. We store separate information because even when built in CI Cargo uses its own git information rather than Rust's.

This PR will also require a change in the Cargo repository to consume this information (https://github.com/rust-lang/cargo/pull/13832), but it doesn't have to be blocked on the Cargo PR being merged.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-04-30 19:29:52 +01:00 committed by GitHub
commit 9ef81e0146
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,7 +25,7 @@
use crate::core::build_steps::tool::{self, Tool};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::channel;
use crate::utils::channel::{self, Info};
use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit};
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
@ -991,10 +991,17 @@ fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
// Create the version file
builder.create(&plain_dst_src.join("version"), &builder.rust_version());
if let Some(info) = builder.rust_info().info() {
channel::write_commit_hash_file(plain_dst_src, &info.sha);
channel::write_commit_info_file(plain_dst_src, info);
}
// Create the files containing git info, to ensure --version outputs the same.
let write_git_info = |info: Option<&Info>, path: &Path| {
if let Some(info) = info {
t!(std::fs::create_dir_all(path));
channel::write_commit_hash_file(path, &info.sha);
channel::write_commit_info_file(path, info);
}
};
write_git_info(builder.rust_info().info(), plain_dst_src);
write_git_info(builder.cargo_info.info(), &plain_dst_src.join("./src/tools/cargo"));
// If we're building from git or tarball sources, we need to vendor
// a complete distribution.