about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-11-13 21:06:11 +0000
committerbors <bors@rust-lang.org>2017-11-13 21:06:11 +0000
commite21df8020d0d1a37d2856117b1be2f1a91d8bc42 (patch)
tree0038b835ec5345473165c868e62aa81ea4228bd6
parent8efbf7a4f0e44a490d3379b102b7b13ee0152ab9 (diff)
parent97d21e29df0ff67bd25fe563a87f5f387d291e5f (diff)
downloadrust-e21df8020d0d1a37d2856117b1be2f1a91d8bc42.tar.gz
rust-e21df8020d0d1a37d2856117b1be2f1a91d8bc42.zip
Auto merge of #45903 - nrc:rustfmt-dist, r=alexcrichton
Distribute Rustfmt

r? @alexcrichton
-rw-r--r--src/bootstrap/builder.rs3
-rw-r--r--src/bootstrap/dist.rs89
-rw-r--r--src/bootstrap/lib.rs8
-rw-r--r--src/tools/build-manifest/src/main.rs30
4 files changed, 129 insertions, 1 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index cf9659350c1..4e2898bd665 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -261,7 +261,8 @@ impl<'a> Builder<'a> {
                 doc::Reference, doc::Rustdoc, doc::CargoBook),
             Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
                 dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
-                dist::Rls, dist::Extended, dist::HashSign, dist::DontDistWithMiriEnabled),
+                dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign,
+                dist::DontDistWithMiriEnabled),
             Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
                 install::Analysis, install::Src, install::Rustc),
         }
diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
index 090fb6c778c..08403833646 100644
--- a/src/bootstrap/dist.rs
+++ b/src/bootstrap/dist.rs
@@ -39,6 +39,8 @@ pub fn pkgname(build: &Build, component: &str) -> String {
         format!("{}-{}", component, build.cargo_package_vers())
     } else if component == "rls" {
         format!("{}-{}", component, build.rls_package_vers())
+    } else if component == "rustfmt" {
+        format!("{}-{}", component, build.rustfmt_package_vers())
     } else {
         assert!(component.starts_with("rust"));
         format!("{}-{}", component, build.rust_package_vers())
@@ -1113,6 +1115,92 @@ impl Step for Rls {
 
 
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct Rustfmt {
+    pub stage: u32,
+    pub target: Interned<String>,
+}
+
+impl Step for Rustfmt {
+    type Output = Option<PathBuf>;
+    const ONLY_BUILD_TARGETS: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun) -> ShouldRun {
+        run.path("rustfmt")
+    }
+
+    fn make_run(run: RunConfig) {
+        run.builder.ensure(Rustfmt {
+            stage: run.builder.top_stage,
+            target: run.target,
+        });
+    }
+
+    fn run(self, builder: &Builder) -> Option<PathBuf> {
+        let build = builder.build;
+        let stage = self.stage;
+        let target = self.target;
+        assert!(build.config.extended);
+
+        if !builder.config.toolstate.rustfmt.testing() {
+            println!("skipping Dist Rustfmt stage{} ({})", stage, target);
+            return None
+        }
+
+        println!("Dist Rustfmt stage{} ({})", stage, target);
+        let src = build.src.join("src/tools/rustfmt");
+        let release_num = build.release_num("rustfmt");
+        let name = pkgname(build, "rustfmt");
+        let version = build.rustfmt_info.version(build, &release_num);
+
+        let tmp = tmpdir(build);
+        let image = tmp.join("rustfmt-image");
+        drop(fs::remove_dir_all(&image));
+        t!(fs::create_dir_all(&image));
+
+        // Prepare the image directory
+        // We expect RLS to build, because we've exited this step above if tool
+        // state for RLS isn't testing.
+        let rustfmt = builder.ensure(tool::Rustfmt {
+            compiler: builder.compiler(stage, build.build),
+            target
+        }).expect("Rustfmt to build: toolstate is testing");
+        install(&rustfmt, &image.join("bin"), 0o755);
+        let doc = image.join("share/doc/rustfmt");
+        install(&src.join("README.md"), &doc, 0o644);
+        install(&src.join("LICENSE-MIT"), &doc, 0o644);
+        install(&src.join("LICENSE-APACHE"), &doc, 0o644);
+
+        // Prepare the overlay
+        let overlay = tmp.join("rustfmt-overlay");
+        drop(fs::remove_dir_all(&overlay));
+        t!(fs::create_dir_all(&overlay));
+        install(&src.join("README.md"), &overlay, 0o644);
+        install(&src.join("LICENSE-MIT"), &overlay, 0o644);
+        install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
+        t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));
+
+        // Generate the installer tarball
+        let mut cmd = rust_installer(builder);
+        cmd.arg("generate")
+           .arg("--product-name=Rust")
+           .arg("--rel-manifest-dir=rustlib")
+           .arg("--success-message=rustfmt-ready-to-fmt.")
+           .arg("--image-dir").arg(&image)
+           .arg("--work-dir").arg(&tmpdir(build))
+           .arg("--output-dir").arg(&distdir(build))
+           .arg("--non-installed-overlay").arg(&overlay)
+           .arg(format!("--package-name={}-{}", name, target))
+           .arg("--legacy-manifest-dirs=rustlib,cargo")
+           .arg("--component-name=rustfmt-preview");
+
+        build.run(&mut cmd);
+        Some(distdir(build).join(format!("{}-{}.tar.gz", name, target)))
+    }
+}
+
+
+#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct DontDistWithMiriEnabled;
 
 impl Step for DontDistWithMiriEnabled {
@@ -1606,6 +1694,7 @@ impl Step for HashSign {
         cmd.arg(build.rust_package_vers());
         cmd.arg(build.package_vers(&build.release_num("cargo")));
         cmd.arg(build.package_vers(&build.release_num("rls")));
+        cmd.arg(build.package_vers(&build.release_num("rustfmt")));
         cmd.arg(addr);
 
         t!(fs::create_dir_all(distdir(build)));
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 479283b3595..68329922592 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -222,6 +222,7 @@ pub struct Build {
     rust_info: channel::GitInfo,
     cargo_info: channel::GitInfo,
     rls_info: channel::GitInfo,
+    rustfmt_info: channel::GitInfo,
     local_rebuild: bool,
     fail_fast: bool,
     verbosity: usize,
@@ -304,6 +305,7 @@ impl Build {
         let rust_info = channel::GitInfo::new(&config, &src);
         let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
         let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
+        let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));
 
         Build {
             initial_rustc: config.initial_rustc.clone(),
@@ -323,6 +325,7 @@ impl Build {
             rust_info,
             cargo_info,
             rls_info,
+            rustfmt_info,
             cc: HashMap::new(),
             cxx: HashMap::new(),
             ar: HashMap::new(),
@@ -814,6 +817,11 @@ impl Build {
         self.package_vers(&self.release_num("rls"))
     }
 
+    /// Returns the value of `package_vers` above for rustfmt
+    fn rustfmt_package_vers(&self) -> String {
+        self.package_vers(&self.release_num("rustfmt"))
+    }
+
     /// Returns the `version` string associated with this compiler for Rust
     /// itself.
     ///
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index 5f680cafcca..524ba7908bd 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -168,18 +168,24 @@ struct Builder {
     rust_release: String,
     cargo_release: String,
     rls_release: String,
+    rustfmt_release: String,
+
     input: PathBuf,
     output: PathBuf,
     gpg_passphrase: String,
     digests: BTreeMap<String, String>,
     s3_address: String,
     date: String,
+
     rust_version: Option<String>,
     cargo_version: Option<String>,
     rls_version: Option<String>,
+    rustfmt_version: Option<String>,
+
     rust_git_commit_hash: Option<String>,
     cargo_git_commit_hash: Option<String>,
     rls_git_commit_hash: Option<String>,
+    rustfmt_git_commit_hash: Option<String>,
 }
 
 fn main() {
@@ -190,6 +196,7 @@ fn main() {
     let rust_release = args.next().unwrap();
     let cargo_release = args.next().unwrap();
     let rls_release = args.next().unwrap();
+    let rustfmt_release = args.next().unwrap();
     let s3_address = args.next().unwrap();
     let mut passphrase = String::new();
     t!(io::stdin().read_to_string(&mut passphrase));
@@ -198,18 +205,24 @@ fn main() {
         rust_release,
         cargo_release,
         rls_release,
+        rustfmt_release,
+
         input,
         output,
         gpg_passphrase: passphrase,
         digests: BTreeMap::new(),
         s3_address,
         date,
+
         rust_version: None,
         cargo_version: None,
         rls_version: None,
+        rustfmt_version: None,
+
         rust_git_commit_hash: None,
         cargo_git_commit_hash: None,
         rls_git_commit_hash: None,
+        rustfmt_git_commit_hash: None,
     }.build();
 }
 
@@ -218,9 +231,12 @@ 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.rustfmt_version = self.version("rustfmt", "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.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");
 
         self.digest_and_sign();
         let manifest = self.build_manifest();
@@ -255,9 +271,11 @@ impl Builder {
         self.package("rust-docs", &mut manifest.pkg, TARGETS);
         self.package("rust-src", &mut manifest.pkg, &["*"]);
         self.package("rls-preview", &mut manifest.pkg, HOSTS);
+        self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
         self.package("rust-analysis", &mut manifest.pkg, TARGETS);
 
         let rls_present = manifest.pkg.contains_key("rls-preview");
+        let rustfmt_present = manifest.pkg.contains_key("rustfmt-preview");
 
         if rls_present {
             manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
@@ -306,6 +324,12 @@ impl Builder {
                     target: host.to_string(),
                 });
             }
+            if rustfmt_present {
+                extensions.push(Component {
+                    pkg: "rustfmt-preview".to_string(),
+                    target: host.to_string(),
+                });
+            }
             extensions.push(Component {
                 pkg: "rust-analysis".to_string(),
                 target: host.to_string(),
@@ -391,6 +415,8 @@ impl Builder {
             format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
         } else if component == "rls" || component == "rls-preview" {
             format!("rls-{}-{}.tar.gz", self.rls_release, target)
+        } else if component == "rustfmt" || component == "rustfmt-preview" {
+            format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
         } else {
             format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
         }
@@ -401,6 +427,8 @@ impl Builder {
             &self.cargo_version
         } else if component == "rls" || component == "rls-preview" {
             &self.rls_version
+        } else if component == "rustfmt" || component == "rustfmt-preview" {
+            &self.rustfmt_version
         } else {
             &self.rust_version
         }
@@ -411,6 +439,8 @@ impl Builder {
             &self.cargo_git_commit_hash
         } else if component == "rls" || component == "rls-preview" {
             &self.rls_git_commit_hash
+        } else if component == "rustfmt" || component == "rustfmt-preview" {
+            &self.rustfmt_git_commit_hash
         } else {
             &self.rust_git_commit_hash
         }