Skip to content

Commit f912d77

Browse files
committed
Make git commit info optional and per-package in channel manifests
At the moment it is always missing for Cargo and RLS. Their respective build systems need to be modified to include `git-commit-hash` files in their "dist" tarballs.
1 parent 9412fd7 commit f912d77

File tree

1 file changed

+33
-10
lines changed
  • src/tools/build-manifest/src

1 file changed

+33
-10
lines changed

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ static MINGW: &'static [&'static str] = &[
107107
struct Manifest {
108108
manifest_version: String,
109109
date: String,
110-
git_commit_hash: String,
111110
pkg: BTreeMap<String, Package>,
112111
}
113112

114113
#[derive(Serialize)]
115114
struct Package {
116115
version: String,
116+
git_commit_hash: Option<String>,
117117
target: BTreeMap<String, Target>,
118118
}
119119

@@ -168,6 +168,9 @@ struct Builder {
168168
rust_version: String,
169169
cargo_version: String,
170170
rls_version: String,
171+
rust_git_commit_hash: Option<String>,
172+
cargo_git_commit_hash: Option<String>,
173+
rls_git_commit_hash: Option<String>,
171174
}
172175

173176
fn main() {
@@ -195,6 +198,9 @@ fn main() {
195198
rust_version: String::new(),
196199
cargo_version: String::new(),
197200
rls_version: String::new(),
201+
rust_git_commit_hash: None,
202+
cargo_git_commit_hash: None,
203+
rls_git_commit_hash: None,
198204
}.build();
199205
}
200206

@@ -203,6 +209,9 @@ impl Builder {
203209
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
204210
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
205211
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");
206215

207216
self.digest_and_sign();
208217
let manifest = self.build_manifest();
@@ -226,7 +235,6 @@ impl Builder {
226235
let mut manifest = Manifest {
227236
manifest_version: "2".to_string(),
228237
date: self.date.to_string(),
229-
git_commit_hash: self.git_commit_hash("rust", "x86_64-unknown-linux-gnu"),
230238
pkg: BTreeMap::new(),
231239
};
232240

@@ -246,6 +254,7 @@ impl Builder {
246254

247255
let mut pkg = Package {
248256
version: self.cached_version("rust").to_string(),
257+
git_commit_hash: self.cached_git_commit_hash("rust").clone(),
249258
target: BTreeMap::new(),
250259
};
251260
for host in HOSTS {
@@ -339,6 +348,7 @@ impl Builder {
339348

340349
dst.insert(pkgname.to_string(), Package {
341350
version: self.cached_version(pkgname).to_string(),
351+
git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
342352
target: targets,
343353
});
344354
}
@@ -372,6 +382,16 @@ impl Builder {
372382
}
373383
}
374384

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+
375395
fn version(&self, component: &str, target: &str) -> String {
376396
let mut cmd = Command::new("tar");
377397
let filename = self.filename(component, target);
@@ -389,21 +409,23 @@ impl Builder {
389409
String::from_utf8_lossy(&output.stdout).trim().to_string()
390410
}
391411

392-
fn git_commit_hash(&self, component: &str, target: &str) -> String {
412+
fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
393413
let mut cmd = Command::new("tar");
394414
let filename = self.filename(component, target);
395415
cmd.arg("xf")
396416
.arg(self.input.join(&filename))
397417
.arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
398418
.arg("-O");
399419
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));
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
405428
}
406-
String::from_utf8_lossy(&output.stdout).trim().to_string()
407429
}
408430

409431
fn hash(&self, path: &Path) -> String {
@@ -442,7 +464,8 @@ impl Builder {
442464
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
443465
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
444466
self.write(&manifest.date, channel_name, "-date.txt");
445-
self.write(&manifest.git_commit_hash, channel_name, "-git-commit-hash.txt");
467+
self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
468+
channel_name, "-git-commit-hash.txt");
446469
}
447470

448471
fn write(&self, contents: &str, channel_name: &str, suffix: &str) {

0 commit comments

Comments
 (0)