Skip to content

Commit

Permalink
bootstrap: convert rustfmt to use Tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Dec 23, 2020
1 parent 2073ea5 commit 2b54f0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
56 changes: 7 additions & 49 deletions src/bootstrap/dist.rs
Expand Up @@ -1355,17 +1355,6 @@ impl Step for Rustfmt {
let compiler = self.compiler;
let target = self.target;

let src = builder.src.join("src/tools/rustfmt");
let release_num = builder.release_num("rustfmt");
let name = pkgname(builder, "rustfmt");
let version = builder.rustfmt_info.version(builder, &release_num);

let tmp = tmpdir(builder);
let image = tmp.join("rustfmt-image");
drop(fs::remove_dir_all(&image));
builder.create_dir(&image);

// Prepare the image directory
let rustfmt = builder
.ensure(tool::Rustfmt { compiler, target, extra_features: Vec::new() })
.or_else(|| {
Expand All @@ -1379,44 +1368,13 @@ impl Step for Rustfmt {
None
})?;

builder.install(&rustfmt, &image.join("bin"), 0o755);
builder.install(&cargofmt, &image.join("bin"), 0o755);
let doc = image.join("share/doc/rustfmt");
builder.install(&src.join("README.md"), &doc, 0o644);
builder.install(&src.join("LICENSE-MIT"), &doc, 0o644);
builder.install(&src.join("LICENSE-APACHE"), &doc, 0o644);

// Prepare the overlay
let overlay = tmp.join("rustfmt-overlay");
drop(fs::remove_dir_all(&overlay));
builder.create_dir(&overlay);
builder.install(&src.join("README.md"), &overlay, 0o644);
builder.install(&src.join("LICENSE-MIT"), &overlay, 0o644);
builder.install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
builder.create(&overlay.join("version"), &version);

// 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(builder))
.arg("--output-dir")
.arg(&distdir(builder))
.arg("--non-installed-overlay")
.arg(&overlay)
.arg(format!("--package-name={}-{}", name, target.triple))
.arg("--legacy-manifest-dirs=rustlib,cargo")
.arg("--component-name=rustfmt-preview");

builder.info(&format!("Dist Rustfmt stage{} ({})", compiler.stage, target));
let _time = timeit(builder);
builder.run(&mut cmd);
Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
tarball.set_overlay(OverlayKind::Rustfmt);
tarball.is_preview(true);
tarball.add_file(rustfmt, "bin", 0o755);
tarball.add_file(cargofmt, "bin", 0o755);
tarball.add_legal_and_readme_to("share/doc/rustfmt");
Some(tarball.generate())
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap/tarball.rs
Expand Up @@ -11,6 +11,7 @@ pub(crate) enum OverlayKind {
Cargo,
Clippy,
Miri,
Rustfmt,
}

impl OverlayKind {
Expand All @@ -36,6 +37,11 @@ impl OverlayKind {
"src/tools/miri/LICENSE-APACHE",
"src/tools/miri/LICENSE-MIT",
],
OverlayKind::Rustfmt => &[
"src/tools/rustfmt/README.md",
"src/tools/rustfmt/LICENSE-APACHE",
"src/tools/rustfmt/LICENSE-MIT",
],
}
}

Expand All @@ -50,6 +56,9 @@ impl OverlayKind {
builder.clippy_info.version(builder, &builder.release_num("clippy"))
}
OverlayKind::Miri => builder.miri_info.version(builder, &builder.release_num("miri")),
OverlayKind::Rustfmt => {
builder.rustfmt_info.version(builder, &builder.release_num("rustfmt"))
}
}
}
}
Expand Down

0 comments on commit 2b54f0d

Please sign in to comment.