Skip to content

Commit de038b7

Browse files
committed
Add full git commit hash to release channel manifests
The full hash is necessary to build the download URL for "alternate" compiler builds. This is a first step for rust-lang/rustup#1099
1 parent 97b01ab commit de038b7

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

src/bootstrap/dist.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ impl Step for Rustc {
364364
cp("README.md");
365365
// tiny morsel of metadata is used by rust-packaging
366366
let version = build.rust_version();
367+
let sha = build.rust_sha().unwrap_or("");
367368
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
369+
t!(t!(File::create(overlay.join("git-commit-hash"))).write_all(sha.as_bytes()));
368370

369371
// On MinGW we've got a few runtime DLL dependencies that we need to
370372
// include. The first argument to this script is where to put these DLLs

src/bootstrap/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,11 @@ impl Build {
797797
self.rust_info.version(self, channel::CFG_RELEASE_NUM)
798798
}
799799

800+
/// Return the full commit hash
801+
fn rust_sha(&self) -> Option<&str> {
802+
self.rust_info.sha()
803+
}
804+
800805
/// Returns the `a.b.c` version that the given package is at.
801806
fn release_num(&self, package: &str) -> String {
802807
let mut toml = String::new();

src/tools/build-manifest/src/main.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static MINGW: &'static [&'static str] = &[
107107
struct Manifest {
108108
manifest_version: String,
109109
date: String,
110+
git_commit_hash: String,
110111
pkg: BTreeMap<String, Package>,
111112
}
112113

@@ -205,15 +206,10 @@ impl Builder {
205206

206207
self.digest_and_sign();
207208
let manifest = self.build_manifest();
208-
let filename = format!("channel-rust-{}.toml", self.rust_release);
209-
self.write_manifest(&toml::to_string(&manifest).unwrap(), &filename);
210-
211-
let filename = format!("channel-rust-{}-date.txt", self.rust_release);
212-
self.write_date_stamp(&manifest.date, &filename);
209+
self.write_channel_files(&self.rust_release, &manifest);
213210

214211
if self.rust_release != "beta" && self.rust_release != "nightly" {
215-
self.write_manifest(&toml::to_string(&manifest).unwrap(), "channel-rust-stable.toml");
216-
self.write_date_stamp(&manifest.date, "channel-rust-stable-date.txt");
212+
self.write_channel_files("stable", &manifest);
217213
}
218214
}
219215

@@ -230,6 +226,7 @@ impl Builder {
230226
let mut manifest = Manifest {
231227
manifest_version: "2".to_string(),
232228
date: self.date.to_string(),
229+
git_commit_hash: self.git_commit_hash("rust", "x86_64-unknown-linux-gnu"),
233230
pkg: BTreeMap::new(),
234231
};
235232

@@ -382,14 +379,31 @@ impl Builder {
382379
.arg(self.input.join(&filename))
383380
.arg(format!("{}/version", filename.replace(".tar.gz", "")))
384381
.arg("-O");
385-
let version = t!(cmd.output());
386-
if !version.status.success() {
382+
let output = t!(cmd.output());
383+
if !output.status.success() {
387384
panic!("failed to learn version:\n\n{:?}\n\n{}\n\n{}",
388385
cmd,
389-
String::from_utf8_lossy(&version.stdout),
390-
String::from_utf8_lossy(&version.stderr));
386+
String::from_utf8_lossy(&output.stdout),
387+
String::from_utf8_lossy(&output.stderr));
388+
}
389+
String::from_utf8_lossy(&output.stdout).trim().to_string()
390+
}
391+
392+
fn git_commit_hash(&self, component: &str, target: &str) -> String {
393+
let mut cmd = Command::new("tar");
394+
let filename = self.filename(component, target);
395+
cmd.arg("xf")
396+
.arg(self.input.join(&filename))
397+
.arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
398+
.arg("-O");
399+
let output = t!(cmd.output());
400+
if !output.status.success() {
401+
panic!("failed to learn git commit hash:\n\n{:?}\n\n{}\n\n{}",
402+
cmd,
403+
String::from_utf8_lossy(&output.stdout),
404+
String::from_utf8_lossy(&output.stderr));
391405
}
392-
String::from_utf8_lossy(&version.stdout).trim().to_string()
406+
String::from_utf8_lossy(&output.stdout).trim().to_string()
393407
}
394408

395409
fn hash(&self, path: &Path) -> String {
@@ -425,16 +439,15 @@ impl Builder {
425439
assert!(t!(child.wait()).success());
426440
}
427441

428-
fn write_manifest(&self, manifest: &str, name: &str) {
429-
let dst = self.output.join(name);
430-
t!(t!(File::create(&dst)).write_all(manifest.as_bytes()));
431-
self.hash(&dst);
432-
self.sign(&dst);
442+
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
443+
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
444+
self.write(&manifest.date, channel_name, "-date.txt");
445+
self.write(&manifest.git_commit_hash, channel_name, "-git-commit-hash.txt");
433446
}
434447

435-
fn write_date_stamp(&self, date: &str, name: &str) {
436-
let dst = self.output.join(name);
437-
t!(t!(File::create(&dst)).write_all(date.as_bytes()));
448+
fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
449+
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
450+
t!(t!(File::create(&dst)).write_all(contents.as_bytes()));
438451
self.hash(&dst);
439452
self.sign(&dst);
440453
}

0 commit comments

Comments
 (0)