]> git.lizzy.rs Git - rust.git/blob - src/tools/build-manifest/src/main.rs
Add a profiles section to the manifest
[rust.git] / src / tools / build-manifest / src / main.rs
1 extern crate toml;
2 #[macro_use]
3 extern crate serde_derive;
4
5 use std::collections::BTreeMap;
6 use std::env;
7 use std::fs;
8 use std::io::{self, Read, Write};
9 use std::path::{PathBuf, Path};
10 use std::process::{Command, Stdio};
11
12 static HOSTS: &'static [&'static str] = &[
13     "aarch64-unknown-linux-gnu",
14     "arm-unknown-linux-gnueabi",
15     "arm-unknown-linux-gnueabihf",
16     "armv7-unknown-linux-gnueabihf",
17     "i686-apple-darwin",
18     "i686-pc-windows-gnu",
19     "i686-pc-windows-msvc",
20     "i686-unknown-linux-gnu",
21     "mips-unknown-linux-gnu",
22     "mips64-unknown-linux-gnuabi64",
23     "mips64el-unknown-linux-gnuabi64",
24     "mipsel-unknown-linux-gnu",
25     "powerpc-unknown-linux-gnu",
26     "powerpc64-unknown-linux-gnu",
27     "powerpc64le-unknown-linux-gnu",
28     "s390x-unknown-linux-gnu",
29     "x86_64-apple-darwin",
30     "x86_64-pc-windows-gnu",
31     "x86_64-pc-windows-msvc",
32     "x86_64-unknown-freebsd",
33     "x86_64-unknown-linux-gnu",
34     "x86_64-unknown-netbsd",
35 ];
36
37 static TARGETS: &'static [&'static str] = &[
38     "aarch64-apple-ios",
39     "aarch64-fuchsia",
40     "aarch64-linux-android",
41     "aarch64-pc-windows-msvc",
42     "aarch64-unknown-cloudabi",
43     "aarch64-unknown-linux-gnu",
44     "aarch64-unknown-linux-musl",
45     "arm-linux-androideabi",
46     "arm-unknown-linux-gnueabi",
47     "arm-unknown-linux-gnueabihf",
48     "arm-unknown-linux-musleabi",
49     "arm-unknown-linux-musleabihf",
50     "armv5te-unknown-linux-gnueabi",
51     "armv5te-unknown-linux-musleabi",
52     "armv7-apple-ios",
53     "armv7-linux-androideabi",
54     "thumbv7neon-linux-androideabi",
55     "armv7-unknown-linux-gnueabihf",
56     "thumbv7neon-unknown-linux-gnueabihf",
57     "armv7-unknown-linux-musleabihf",
58     "armebv7r-none-eabi",
59     "armebv7r-none-eabihf",
60     "armv7r-none-eabi",
61     "armv7r-none-eabihf",
62     "armv7s-apple-ios",
63     "asmjs-unknown-emscripten",
64     "i386-apple-ios",
65     "i586-pc-windows-msvc",
66     "i586-unknown-linux-gnu",
67     "i586-unknown-linux-musl",
68     "i686-apple-darwin",
69     "i686-linux-android",
70     "i686-pc-windows-gnu",
71     "i686-pc-windows-msvc",
72     "i686-unknown-freebsd",
73     "i686-unknown-linux-gnu",
74     "i686-unknown-linux-musl",
75     "mips-unknown-linux-gnu",
76     "mips-unknown-linux-musl",
77     "mips64-unknown-linux-gnuabi64",
78     "mips64el-unknown-linux-gnuabi64",
79     "mipsel-unknown-linux-gnu",
80     "mipsel-unknown-linux-musl",
81     "powerpc-unknown-linux-gnu",
82     "powerpc64-unknown-linux-gnu",
83     "powerpc64le-unknown-linux-gnu",
84     "riscv32imc-unknown-none-elf",
85     "riscv32imac-unknown-none-elf",
86     "s390x-unknown-linux-gnu",
87     "sparc64-unknown-linux-gnu",
88     "sparcv9-sun-solaris",
89     "thumbv6m-none-eabi",
90     "thumbv7em-none-eabi",
91     "thumbv7em-none-eabihf",
92     "thumbv7m-none-eabi",
93     "wasm32-unknown-emscripten",
94     "wasm32-unknown-unknown",
95     "x86_64-apple-darwin",
96     "x86_64-apple-ios",
97     "x86_64-fuchsia",
98     "x86_64-linux-android",
99     "x86_64-pc-windows-gnu",
100     "x86_64-pc-windows-msvc",
101     "x86_64-rumprun-netbsd",
102     "x86_64-sun-solaris",
103     "x86_64-unknown-cloudabi",
104     "x86_64-unknown-freebsd",
105     "x86_64-unknown-linux-gnu",
106     "x86_64-unknown-linux-gnux32",
107     "x86_64-unknown-linux-musl",
108     "x86_64-unknown-netbsd",
109     "x86_64-unknown-redox",
110 ];
111
112 static DOCS_TARGETS: &'static [&'static str] = &[
113     "i686-apple-darwin",
114     "i686-pc-windows-gnu",
115     "i686-pc-windows-msvc",
116     "i686-unknown-linux-gnu",
117     "x86_64-apple-darwin",
118     "x86_64-pc-windows-gnu",
119     "x86_64-pc-windows-msvc",
120     "x86_64-unknown-linux-gnu",
121 ];
122
123 static MINGW: &'static [&'static str] = &[
124     "i686-pc-windows-gnu",
125     "x86_64-pc-windows-gnu",
126 ];
127
128 #[derive(Serialize)]
129 #[serde(rename_all = "kebab-case")]
130 struct Manifest {
131     manifest_version: String,
132     date: String,
133     pkg: BTreeMap<String, Package>,
134     renames: BTreeMap<String, Rename>,
135     profiles: BTreeMap<String, Vec<String>>,
136 }
137
138 #[derive(Serialize)]
139 struct Package {
140     version: String,
141     git_commit_hash: Option<String>,
142     target: BTreeMap<String, Target>,
143 }
144
145 #[derive(Serialize)]
146 struct Rename {
147     to: String,
148 }
149
150 #[derive(Serialize)]
151 struct Target {
152     available: bool,
153     url: Option<String>,
154     hash: Option<String>,
155     xz_url: Option<String>,
156     xz_hash: Option<String>,
157     components: Option<Vec<Component>>,
158     extensions: Option<Vec<Component>>,
159 }
160
161 impl Target {
162     fn unavailable() -> Target {
163         Target {
164             available: false,
165             url: None,
166             hash: None,
167             xz_url: None,
168             xz_hash: None,
169             components: None,
170             extensions: None,
171         }
172     }
173 }
174
175 #[derive(Serialize)]
176 struct Component {
177     pkg: String,
178     target: String,
179 }
180
181 macro_rules! t {
182     ($e:expr) => (match $e {
183         Ok(e) => e,
184         Err(e) => panic!("{} failed with {}", stringify!($e), e),
185     })
186 }
187
188 struct Builder {
189     rust_release: String,
190     cargo_release: String,
191     rls_release: String,
192     clippy_release: String,
193     rustfmt_release: String,
194     llvm_tools_release: String,
195     lldb_release: String,
196     miri_release: String,
197
198     input: PathBuf,
199     output: PathBuf,
200     gpg_passphrase: String,
201     digests: BTreeMap<String, String>,
202     s3_address: String,
203     date: String,
204
205     rust_version: Option<String>,
206     cargo_version: Option<String>,
207     rls_version: Option<String>,
208     clippy_version: Option<String>,
209     rustfmt_version: Option<String>,
210     llvm_tools_version: Option<String>,
211     lldb_version: Option<String>,
212     miri_version: Option<String>,
213
214     rust_git_commit_hash: Option<String>,
215     cargo_git_commit_hash: Option<String>,
216     rls_git_commit_hash: Option<String>,
217     clippy_git_commit_hash: Option<String>,
218     rustfmt_git_commit_hash: Option<String>,
219     llvm_tools_git_commit_hash: Option<String>,
220     lldb_git_commit_hash: Option<String>,
221     miri_git_commit_hash: Option<String>,
222
223     should_sign: bool,
224 }
225
226 fn main() {
227     // Avoid signing packages while manually testing
228     // Do NOT set this envvar in CI
229     let should_sign = env::var("BUILD_MANIFEST_DISABLE_SIGNING").is_err();
230
231     // Safety check to ensure signing is always enabled on CI
232     // The CI environment variable is set by both Travis and AppVeyor
233     if !should_sign && env::var("CI").is_ok() {
234         println!("The 'BUILD_MANIFEST_DISABLE_SIGNING' env var can't be enabled on CI.");
235         println!("If you're not running this on CI, unset the 'CI' env var.");
236         panic!();
237     }
238
239     let mut args = env::args().skip(1);
240     let input = PathBuf::from(args.next().unwrap());
241     let output = PathBuf::from(args.next().unwrap());
242     let date = args.next().unwrap();
243     let rust_release = args.next().unwrap();
244     let s3_address = args.next().unwrap();
245     let cargo_release = args.next().unwrap();
246     let rls_release = args.next().unwrap();
247     let clippy_release = args.next().unwrap();
248     let miri_release = args.next().unwrap();
249     let rustfmt_release = args.next().unwrap();
250     let llvm_tools_release = args.next().unwrap();
251     let lldb_release = args.next().unwrap();
252
253     // Do not ask for a passphrase while manually testing
254     let mut passphrase = String::new();
255     if should_sign {
256         t!(io::stdin().read_to_string(&mut passphrase));
257     }
258
259     Builder {
260         rust_release,
261         cargo_release,
262         rls_release,
263         clippy_release,
264         rustfmt_release,
265         llvm_tools_release,
266         lldb_release,
267         miri_release,
268
269         input,
270         output,
271         gpg_passphrase: passphrase,
272         digests: BTreeMap::new(),
273         s3_address,
274         date,
275
276         rust_version: None,
277         cargo_version: None,
278         rls_version: None,
279         clippy_version: None,
280         rustfmt_version: None,
281         llvm_tools_version: None,
282         lldb_version: None,
283         miri_version: None,
284
285         rust_git_commit_hash: None,
286         cargo_git_commit_hash: None,
287         rls_git_commit_hash: None,
288         clippy_git_commit_hash: None,
289         rustfmt_git_commit_hash: None,
290         llvm_tools_git_commit_hash: None,
291         lldb_git_commit_hash: None,
292         miri_git_commit_hash: None,
293
294         should_sign,
295     }.build();
296 }
297
298 impl Builder {
299     fn build(&mut self) {
300         self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
301         self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
302         self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
303         self.clippy_version = self.version("clippy", "x86_64-unknown-linux-gnu");
304         self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");
305         self.llvm_tools_version = self.version("llvm-tools", "x86_64-unknown-linux-gnu");
306         // lldb is only built for macOS.
307         self.lldb_version = self.version("lldb", "x86_64-apple-darwin");
308         self.miri_version = self.version("miri", "x86_64-unknown-linux-gnu");
309
310         self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
311         self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
312         self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
313         self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu");
314         self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
315         self.llvm_tools_git_commit_hash = self.git_commit_hash("llvm-tools",
316                                                                "x86_64-unknown-linux-gnu");
317         self.lldb_git_commit_hash = self.git_commit_hash("lldb", "x86_64-unknown-linux-gnu");
318         self.miri_git_commit_hash = self.git_commit_hash("miri", "x86_64-unknown-linux-gnu");
319
320         self.digest_and_sign();
321         let manifest = self.build_manifest();
322         self.write_channel_files(&self.rust_release, &manifest);
323
324         if self.rust_release != "beta" && self.rust_release != "nightly" {
325             self.write_channel_files("stable", &manifest);
326         }
327     }
328
329     fn digest_and_sign(&mut self) {
330         for file in t!(self.input.read_dir()).map(|e| t!(e).path()) {
331             let filename = file.file_name().unwrap().to_str().unwrap();
332             let digest = self.hash(&file);
333             self.sign(&file);
334             assert!(self.digests.insert(filename.to_string(), digest).is_none());
335         }
336     }
337
338     fn build_manifest(&mut self) -> Manifest {
339         let mut manifest = Manifest {
340             manifest_version: "2".to_string(),
341             date: self.date.to_string(),
342             pkg: BTreeMap::new(),
343             renames: BTreeMap::new(),
344             profiles: BTreeMap::new(),
345         };
346
347         self.package("rustc", &mut manifest.pkg, HOSTS);
348         self.package("cargo", &mut manifest.pkg, HOSTS);
349         self.package("rust-mingw", &mut manifest.pkg, MINGW);
350         self.package("rust-std", &mut manifest.pkg, TARGETS);
351         self.package("rust-docs", &mut manifest.pkg, DOCS_TARGETS);
352         self.package("rust-src", &mut manifest.pkg, &["*"]);
353         self.package("rls-preview", &mut manifest.pkg, HOSTS);
354         self.package("clippy-preview", &mut manifest.pkg, HOSTS);
355         self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
356         self.package("rust-analysis", &mut manifest.pkg, TARGETS);
357         self.package("llvm-tools-preview", &mut manifest.pkg, TARGETS);
358         self.package("lldb-preview", &mut manifest.pkg, TARGETS);
359
360         self.profile("minimal",
361                      &mut manifest.profiles,
362                      &["rustc", "cargo", "rust-std", "rust-mingw"]);
363         self.profile("default",
364                      &mut manifest.profiles,
365                      &["rustc", "cargo", "rust-std", "rust-mingw",
366                        "rust-docs", "rustfmt-preview", "clippy-preview"]);
367         self.profile("complete",
368                      &mut manifest.profiles,
369                      &["rustc", "cargo", "rust-std", "rust-mingw",
370                        "rust-docs", "rustfmt-preview", "clippy-preview",
371                        "rls-preview", "rust-src", "llvm-tools-preview",
372                        "lldb-preview", "rust-analysis"]);
373
374         manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
375         manifest.renames.insert("rustfmt".to_owned(), Rename { to: "rustfmt-preview".to_owned() });
376         manifest.renames.insert("clippy".to_owned(), Rename { to: "clippy-preview".to_owned() });
377
378         let mut pkg = Package {
379             version: self.cached_version("rust")
380                          .as_ref()
381                          .expect("Couldn't find Rust version")
382                          .clone(),
383             git_commit_hash: self.cached_git_commit_hash("rust").clone(),
384             target: BTreeMap::new(),
385         };
386         for host in HOSTS {
387             let filename = self.filename("rust", host);
388             let digest = match self.digests.remove(&filename) {
389                 Some(digest) => digest,
390                 None => {
391                     pkg.target.insert(host.to_string(), Target::unavailable());
392                     continue
393                 }
394             };
395             let xz_filename = filename.replace(".tar.gz", ".tar.xz");
396             let xz_digest = self.digests.remove(&xz_filename);
397             let mut components = Vec::new();
398             let mut extensions = Vec::new();
399
400             // rustc/rust-std/cargo/docs are all required, and so is rust-mingw
401             // if it's available for the target.
402             components.extend(vec![
403                 Component { pkg: "rustc".to_string(), target: host.to_string() },
404                 Component { pkg: "rust-std".to_string(), target: host.to_string() },
405                 Component { pkg: "cargo".to_string(), target: host.to_string() },
406                 Component { pkg: "rust-docs".to_string(), target: host.to_string() },
407             ]);
408             if host.contains("pc-windows-gnu") {
409                 components.push(Component {
410                     pkg: "rust-mingw".to_string(),
411                     target: host.to_string(),
412                 });
413             }
414
415             // Tools are always present in the manifest, but might be marked as unavailable if they
416             // weren't built
417             extensions.extend(vec![
418                 Component { pkg: "clippy-preview".to_string(), target: host.to_string() },
419                 Component { pkg: "rls-preview".to_string(), target: host.to_string() },
420                 Component { pkg: "rustfmt-preview".to_string(), target: host.to_string() },
421                 Component { pkg: "llvm-tools-preview".to_string(), target: host.to_string() },
422                 Component { pkg: "lldb-preview".to_string(), target: host.to_string() },
423                 Component { pkg: "rust-analysis".to_string(), target: host.to_string() },
424             ]);
425
426             for target in TARGETS {
427                 if target != host {
428                     extensions.push(Component {
429                         pkg: "rust-std".to_string(),
430                         target: target.to_string(),
431                     });
432                 }
433             }
434             extensions.push(Component {
435                 pkg: "rust-src".to_string(),
436                 target: "*".to_string(),
437             });
438
439             // If the components/extensions don't actually exist for this
440             // particular host/target combination then nix it entirely from our
441             // lists.
442             {
443                 let has_component = |c: &Component| {
444                     if c.target == "*" {
445                         return true
446                     }
447                     let pkg = match manifest.pkg.get(&c.pkg) {
448                         Some(p) => p,
449                         None => return false,
450                     };
451                     pkg.target.get(&c.target).is_some()
452                 };
453                 extensions.retain(&has_component);
454                 components.retain(&has_component);
455             }
456
457             pkg.target.insert(host.to_string(), Target {
458                 available: true,
459                 url: Some(self.url(&filename)),
460                 hash: Some(digest),
461                 xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
462                 xz_hash: xz_digest,
463                 components: Some(components),
464                 extensions: Some(extensions),
465             });
466         }
467         manifest.pkg.insert("rust".to_string(), pkg);
468
469         return manifest;
470     }
471
472     fn profile(&mut self,
473                profile_name: &str,
474                dst: &mut BTreeMap<String, Vec<String>>,
475                pkgs: &[&str]) {
476         dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
477     }
478
479     fn package(&mut self,
480                pkgname: &str,
481                dst: &mut BTreeMap<String, Package>,
482                targets: &[&str]) {
483         let (version, is_present) = match *self.cached_version(pkgname) {
484             Some(ref version) => (version.clone(), true),
485             None => (String::new(), false),
486         };
487
488         let targets = targets.iter().map(|name| {
489             if is_present {
490                 let filename = self.filename(pkgname, name);
491                 let digest = match self.digests.remove(&filename) {
492                     Some(digest) => digest,
493                     None => return (name.to_string(), Target::unavailable()),
494                 };
495                 let xz_filename = filename.replace(".tar.gz", ".tar.xz");
496                 let xz_digest = self.digests.remove(&xz_filename);
497
498                 (name.to_string(), Target {
499                     available: true,
500                     url: Some(self.url(&filename)),
501                     hash: Some(digest),
502                     xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)),
503                     xz_hash: xz_digest,
504                     components: None,
505                     extensions: None,
506                 })
507             } else {
508                 // If the component is not present for this build add it anyway but mark it as
509                 // unavailable -- this way rustup won't allow upgrades without --force
510                 (name.to_string(), Target {
511                     available: false,
512                     url: None,
513                     hash: None,
514                     xz_url: None,
515                     xz_hash: None,
516                     components: None,
517                     extensions: None,
518                 })
519             }
520         }).collect();
521
522         dst.insert(pkgname.to_string(), Package {
523             version,
524             git_commit_hash: self.cached_git_commit_hash(pkgname).clone(),
525             target: targets,
526         });
527     }
528
529     fn url(&self, filename: &str) -> String {
530         format!("{}/{}/{}",
531                 self.s3_address,
532                 self.date,
533                 filename)
534     }
535
536     fn filename(&self, component: &str, target: &str) -> String {
537         if component == "rust-src" {
538             format!("rust-src-{}.tar.gz", self.rust_release)
539         } else if component == "cargo" {
540             format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
541         } else if component == "rls" || component == "rls-preview" {
542             format!("rls-{}-{}.tar.gz", self.rls_release, target)
543         } else if component == "clippy" || component == "clippy-preview" {
544             format!("clippy-{}-{}.tar.gz", self.clippy_release, target)
545         } else if component == "rustfmt" || component == "rustfmt-preview" {
546             format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
547         } else if component == "llvm-tools" || component == "llvm-tools-preview" {
548             format!("llvm-tools-{}-{}.tar.gz", self.llvm_tools_release, target)
549         } else if component == "lldb" || component == "lldb-preview" {
550             format!("lldb-{}-{}.tar.gz", self.lldb_release, target)
551         } else if component == "miri" || component == "miri-preview" {
552             format!("miri-{}-{}.tar.gz", self.miri_release, target)
553         } else {
554             format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
555         }
556     }
557
558     fn cached_version(&self, component: &str) -> &Option<String> {
559         if component == "cargo" {
560             &self.cargo_version
561         } else if component == "rls" || component == "rls-preview" {
562             &self.rls_version
563         } else if component == "clippy" || component == "clippy-preview" {
564             &self.clippy_version
565         } else if component == "rustfmt" || component == "rustfmt-preview" {
566             &self.rustfmt_version
567         } else if component == "llvm-tools" || component == "llvm-tools-preview" {
568             &self.llvm_tools_version
569         } else if component == "lldb" || component == "lldb-preview" {
570             &self.lldb_version
571         } else if component == "miri" || component == "miri-preview" {
572             &self.miri_version
573         } else {
574             &self.rust_version
575         }
576     }
577
578     fn cached_git_commit_hash(&self, component: &str) -> &Option<String> {
579         if component == "cargo" {
580             &self.cargo_git_commit_hash
581         } else if component == "rls" || component == "rls-preview" {
582             &self.rls_git_commit_hash
583         } else if component == "clippy" || component == "clippy-preview" {
584             &self.clippy_git_commit_hash
585         } else if component == "rustfmt" || component == "rustfmt-preview" {
586             &self.rustfmt_git_commit_hash
587         } else if component == "llvm-tools" || component == "llvm-tools-preview" {
588             &self.llvm_tools_git_commit_hash
589         } else if component == "lldb" || component == "lldb-preview" {
590             &self.lldb_git_commit_hash
591         } else if component == "miri" || component == "miri-preview" {
592             &self.miri_git_commit_hash
593         } else {
594             &self.rust_git_commit_hash
595         }
596     }
597
598     fn version(&self, component: &str, target: &str) -> Option<String> {
599         let mut cmd = Command::new("tar");
600         let filename = self.filename(component, target);
601         cmd.arg("xf")
602            .arg(self.input.join(&filename))
603            .arg(format!("{}/version", filename.replace(".tar.gz", "")))
604            .arg("-O");
605         let output = t!(cmd.output());
606         if output.status.success() {
607             Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
608         } else {
609             // Perhaps we didn't build this package.
610             None
611         }
612     }
613
614     fn git_commit_hash(&self, component: &str, target: &str) -> Option<String> {
615         let mut cmd = Command::new("tar");
616         let filename = self.filename(component, target);
617         cmd.arg("xf")
618            .arg(self.input.join(&filename))
619            .arg(format!("{}/git-commit-hash", filename.replace(".tar.gz", "")))
620            .arg("-O");
621         let output = t!(cmd.output());
622         if output.status.success() {
623             Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
624         } else {
625             None
626         }
627     }
628
629     fn hash(&self, path: &Path) -> String {
630         let sha = t!(Command::new("shasum")
631                         .arg("-a").arg("256")
632                         .arg(path.file_name().unwrap())
633                         .current_dir(path.parent().unwrap())
634                         .output());
635         assert!(sha.status.success());
636
637         let filename = path.file_name().unwrap().to_str().unwrap();
638         let sha256 = self.output.join(format!("{}.sha256", filename));
639         t!(fs::write(&sha256, &sha.stdout));
640
641         let stdout = String::from_utf8_lossy(&sha.stdout);
642         stdout.split_whitespace().next().unwrap().to_string()
643     }
644
645     fn sign(&self, path: &Path) {
646         if !self.should_sign {
647             return;
648         }
649
650         let filename = path.file_name().unwrap().to_str().unwrap();
651         let asc = self.output.join(format!("{}.asc", filename));
652         println!("signing: {:?}", path);
653         let mut cmd = Command::new("gpg");
654         cmd.arg("--pinentry-mode=loopback")
655             .arg("--no-tty")
656             .arg("--yes")
657             .arg("--batch")
658             .arg("--passphrase-fd").arg("0")
659             .arg("--personal-digest-preferences").arg("SHA512")
660             .arg("--armor")
661             .arg("--output").arg(&asc)
662             .arg("--detach-sign").arg(path)
663             .stdin(Stdio::piped());
664         let mut child = t!(cmd.spawn());
665         t!(child.stdin.take().unwrap().write_all(self.gpg_passphrase.as_bytes()));
666         assert!(t!(child.wait()).success());
667     }
668
669     fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) {
670         self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
671         self.write(&manifest.date, channel_name, "-date.txt");
672         self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(),
673                    channel_name, "-git-commit-hash.txt");
674     }
675
676     fn write(&self, contents: &str, channel_name: &str, suffix: &str) {
677         let dst = self.output.join(format!("channel-rust-{}{}", channel_name, suffix));
678         t!(fs::write(&dst, contents));
679         self.hash(&dst);
680         self.sign(&dst);
681     }
682 }