Skip to content

Commit da5e5ef

Browse files
Rollup merge of rust-lang#44218 - SimonSapin:commit-hash, r=alexcrichton
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.
2 parents b8812a2 + f912d77 commit da5e5ef

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

src/bootstrap/dist.rs

+9
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ impl Step for Rustc {
365365
// tiny morsel of metadata is used by rust-packaging
366366
let version = build.rust_version();
367367
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
368+
if let Some(sha) = build.rust_sha() {
369+
t!(t!(File::create(overlay.join("git-commit-hash"))).write_all(sha.as_bytes()));
370+
}
368371

369372
// On MinGW we've got a few runtime DLL dependencies that we need to
370373
// include. The first argument to this script is where to put these DLLs
@@ -844,6 +847,9 @@ impl Step for PlainSourceTarball {
844847

845848
// Create the version file
846849
write_file(&plain_dst_src.join("version"), build.rust_version().as_bytes());
850+
if let Some(sha) = build.rust_sha() {
851+
write_file(&plain_dst_src.join("git-commit-hash"), sha.as_bytes());
852+
}
847853

848854
// If we're building from git sources, we need to vendor a complete distribution.
849855
if build.rust_info.is_git() {
@@ -1157,6 +1163,9 @@ impl Step for Extended {
11571163
install(&build.src.join("LICENSE-MIT"), &overlay, 0o644);
11581164
let version = build.rust_version();
11591165
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
1166+
if let Some(sha) = build.rust_sha() {
1167+
t!(t!(File::create(overlay.join("git-commit-hash"))).write_all(sha.as_bytes()));
1168+
}
11601169
install(&etc.join("README.md"), &overlay, 0o644);
11611170

11621171
// When rust-std package split from rustc, we needed to ensure that during

src/bootstrap/lib.rs

+5
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

+56-20
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct Manifest {
113113
#[derive(Serialize)]
114114
struct Package {
115115
version: String,
116+
git_commit_hash: Option<String>,
116117
target: BTreeMap<String, Target>,
117118
}
118119

@@ -167,6 +168,9 @@ struct Builder {
167168
rust_version: String,
168169
cargo_version: String,
169170
rls_version: String,
171+
rust_git_commit_hash: Option<String>,
172+
cargo_git_commit_hash: Option<String>,
173+
rls_git_commit_hash: Option<String>,
170174
}
171175

172176
fn main() {
@@ -194,6 +198,9 @@ fn main() {
194198
rust_version: String::new(),
195199
cargo_version: String::new(),
196200
rls_version: String::new(),
201+
rust_git_commit_hash: None,
202+
cargo_git_commit_hash: None,
203+
rls_git_commit_hash: None,
197204
}.build();
198205
}
199206

@@ -202,18 +209,16 @@ impl Builder {
202209
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
203210
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
204211
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
212+
self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
213+
self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
214+
self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
205215

206216
self.digest_and_sign();
207217
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);
218+
self.write_channel_files(&self.rust_release, &manifest);
213219

214220
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");
221+
self.write_channel_files("stable", &manifest);
217222
}
218223
}
219224

@@ -249,6 +254,7 @@ impl Builder {
249254

250255
let mut pkg = Package {
251256
version: self.cached_version("rust").to_string(),
257+
git_commit_hash: self.cached_git_commit_hash("rust").clone(),
252258
target: BTreeMap::new(),
253259
};
254260
for host in HOSTS {
@@ -342,6 +348,7 @@ impl Builder {
342348

343349
dst.insert(pkgname.to_string(), Package {
344350
version: self.cached_version(pkgname).to_string(),
351+
git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
345352
target: targets,
346353
});
347354
}
@@ -375,21 +382,50 @@ impl Builder {
375382
}
376383
}
377384

385+
fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
386+
if component == "cargo" {
387+
&self.cargo_git_commit_hash
388+
} else if component == "rls" || component == "rls-preview" {
389+
&self.rls_git_commit_hash
390+
} else {
391+
&self.rust_git_commit_hash
392+
}
393+
}
394+
378395
fn version(&self, component: &str, target: &str) -> String {
379396
let mut cmd = Command::new("tar");
380397
let filename = self.filename(component, target);
381398
cmd.arg("xf")
382399
.arg(self.input.join(&filename))
383400
.arg(format!("{}/version", filename.replace(".tar.gz", "")))
384401
.arg("-O");
385-
let version = t!(cmd.output());
386-
if !version.status.success() {
402+
let output = t!(cmd.output());
403+
if !output.status.success() {
387404
panic!("failed to learn version:\n\n{:?}\n\n{}\n\n{}",
388405
cmd,
389-
String::from_utf8_lossy(&version.stdout),
390-
String::from_utf8_lossy(&version.stderr));
406+
String::from_utf8_lossy(&output.stdout),
407+
String::from_utf8_lossy(&output.stderr));
408+
}
409+
String::from_utf8_lossy(&output.stdout).trim().to_string()
410+
}
411+
412+
fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
413+
let mut cmd = Command::new("tar");
414+
let filename = self.filename(component, target);
415+
cmd.arg("xf")
416+
.arg(self.input.join(&filename))
417+
.arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
418+
.arg("-O");
419+
let output = t!(cmd.output());
420+
if output.status.success() {
421+
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
422+
} else {
423+
// This is always called after `.version()`.
424+
// So if that didn’t fail but this does,
425+
// that’s very probably because the tarball is valid
426+
// but does not contain a `git-commit-hash` file.
427+
None
391428
}
392-
String::from_utf8_lossy(&version.stdout).trim().to_string()
393429
}
394430

395431
fn hash(&self, path: &Path) -> String {
@@ -425,16 +461,16 @@ impl Builder {
425461
assert!(t!(child.wait()).success());
426462
}
427463

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);
464+
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
465+
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
466+
self.write(&manifest.date, channel_name, "-date.txt");
467+
self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
468+
channel_name, "-git-commit-hash.txt");
433469
}
434470

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()));
471+
fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
472+
let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
473+
t!(t!(File::create(&dst)).write_all(contents.as_bytes()));
438474
self.hash(&dst);
439475
self.sign(&dst);
440476
}

0 commit comments

Comments
 (0)