Skip to content

Commit

Permalink
Make git commit info optional and per-package in channel manifests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SimonSapin committed Sep 5, 2017
1 parent 9412fd7 commit f912d77
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/tools/build-manifest/src/main.rs
Expand Up @@ -107,13 +107,13 @@ static MINGW: &'static [&'static str] = &[
struct Manifest {
manifest_version: String,
date: String,
git_commit_hash: String,
pkg: BTreeMap<String, Package>,
}

#[derive(Serialize)]
struct Package {
version: String,
git_commit_hash: Option<String>,
target: BTreeMap<String, Target>,
}

Expand Down Expand Up @@ -168,6 +168,9 @@ struct Builder {
rust_version: String,
cargo_version: String,
rls_version: String,
rust_git_commit_hash: Option<String>,
cargo_git_commit_hash: Option<String>,
rls_git_commit_hash: Option<String>,
}

fn main() {
Expand Down Expand Up @@ -195,6 +198,9 @@ fn main() {
rust_version: String::new(),
cargo_version: String::new(),
rls_version: String::new(),
rust_git_commit_hash: None,
cargo_git_commit_hash: None,
rls_git_commit_hash: None,
}.build();
}

Expand All @@ -203,6 +209,9 @@ impl Builder {
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");

self.digest_and_sign();
let manifest = self.build_manifest();
Expand All @@ -226,7 +235,6 @@ impl Builder {
let mut manifest = Manifest {
manifest_version: "2".to_string(),
date: self.date.to_string(),
git_commit_hash: self.git_commit_hash("rust", "x86_64-unknown-linux-gnu"),
pkg: BTreeMap::new(),
};

Expand All @@ -246,6 +254,7 @@ impl Builder {

let mut pkg = Package {
version: self.cached_version("rust").to_string(),
git_commit_hash: self.cached_git_commit_hash("rust").clone(),
target: BTreeMap::new(),
};
for host in HOSTS {
Expand Down Expand Up @@ -339,6 +348,7 @@ impl Builder {

dst.insert(pkgname.to_string(), Package {
version: self.cached_version(pkgname).to_string(),
git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
target: targets,
});
}
Expand Down Expand Up @@ -372,6 +382,16 @@ impl Builder {
}
}

fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
if component == "cargo" {
&self.cargo_git_commit_hash
} else if component == "rls" || component == "rls-preview" {
&self.rls_git_commit_hash
} else {
&self.rust_git_commit_hash
}
}

fn version(&self, component: &str, target: &str) -> String {
let mut cmd = Command::new("tar");
let filename = self.filename(component, target);
Expand All @@ -389,21 +409,23 @@ impl Builder {
String::from_utf8_lossy(&output.stdout).trim().to_string()
}

fn git_commit_hash(&self, component: &str, target: &str) -> String {
fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
let mut cmd = Command::new("tar");
let filename = self.filename(component, target);
cmd.arg("xf")
.arg(self.input.join(&filename))
.arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
.arg("-O");
let output = t!(cmd.output());
if !output.status.success() {
panic!("failed to learn git commit hash:\n\n{:?}\n\n{}\n\n{}",
cmd,
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr));
if output.status.success() {
Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
} else {
// This is always called after `.version()`.
// So if that didn’t fail but this does,
// that’s very probably because the tarball is valid
// but does not contain a `git-commit-hash` file.
None
}
String::from_utf8_lossy(&output.stdout).trim().to_string()
}

fn hash(&self, path: &Path) -> String {
Expand Down Expand Up @@ -442,7 +464,8 @@ impl Builder {
fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
self.write(&manifest.date, channel_name, "-date.txt");
self.write(&manifest.git_commit_hash, channel_name, "-git-commit-hash.txt");
self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
channel_name, "-git-commit-hash.txt");
}

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

0 comments on commit f912d77

Please sign in to comment.