Skip to content

Commit

Permalink
bootstrap: convert rust-docs to use Tarball
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Dec 23, 2020
1 parent 7be8570 commit c768ce1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 41 deletions.
45 changes: 11 additions & 34 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Docs {
}

impl Step for Docs {
type Output = PathBuf;
type Output = Option<PathBuf>;
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand All @@ -67,48 +67,25 @@ impl Step for Docs {
}

/// Builds the `rust-docs` installer component.
fn run(self, builder: &Builder<'_>) -> PathBuf {
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
let host = self.host;

let name = pkgname(builder, "rust-docs");

if !builder.config.docs {
return distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple));
return None;
}

builder.default_doc(None);

builder.info(&format!("Dist docs ({})", host));
let _time = timeit(builder);

let image = tmpdir(builder).join(format!("{}-{}-image", name, host.triple));
let _ = fs::remove_dir_all(&image);
let dest = "share/doc/rust/html";

let dst = image.join("share/doc/rust/html");
t!(fs::create_dir_all(&dst));
let src = builder.doc_out(host);
builder.cp_r(&src, &dst);
builder.install(&builder.src.join("src/doc/robots.txt"), &dst, 0o644);

let mut cmd = rust_installer(builder);
cmd.arg("generate")
.arg("--product-name=Rust-Documentation")
.arg("--rel-manifest-dir=rustlib")
.arg("--success-message=Rust-documentation-is-installed.")
.arg("--image-dir")
.arg(&image)
.arg("--work-dir")
.arg(&tmpdir(builder))
.arg("--output-dir")
.arg(&distdir(builder))
.arg(format!("--package-name={}-{}", name, host.triple))
.arg("--component-name=rust-docs")
.arg("--legacy-manifest-dirs=rustlib,cargo")
.arg("--bulk-dirs=share/doc/rust/html");
builder.run(&mut cmd);
builder.remove_dir(&image);
let mut tarball = Tarball::new(builder, "rust-docs", &host.triple);
tarball.set_product_name("Rust Documentation");
tarball.add_dir(&builder.doc_out(host), dest);
tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);

distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple))
Some(tarball.generate())
}
}

Expand Down Expand Up @@ -1826,7 +1803,7 @@ impl Step for Extended {
tarballs.extend(llvm_tools_installer);
tarballs.push(analysis_installer);
tarballs.push(std_installer);
if builder.config.docs {
if let Some(docs_installer) = docs_installer {
tarballs.push(docs_installer);
}
if target.contains("pc-windows-gnu") {
Expand Down Expand Up @@ -2509,7 +2486,7 @@ impl Step for RustDev {
// Copy the include directory as well; needed mostly to build
// librustc_llvm properly (e.g., llvm-config.h is in here). But also
// just broadly useful to be able to link against the bundled LLVM.
tarball.add_dir(&builder.llvm_out(target).join("include"), ".");
tarball.add_dir(&builder.llvm_out(target).join("include"), "include");

// Copy libLLVM.so to the target lib dir as well, so the RPATH like
// `$ORIGIN/../lib` can find it. It may also be used as a dependency
Expand Down
19 changes: 12 additions & 7 deletions src/bootstrap/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) struct Tarball<'a> {
pkgname: String,
component: String,
target: String,
product_name: String,
overlay: OverlayKind,

temp_dir: PathBuf,
Expand Down Expand Up @@ -54,6 +55,7 @@ impl<'a> Tarball<'a> {
pkgname,
component: component.into(),
target: target.into(),
product_name: "Rust".into(),
overlay: OverlayKind::Rust,

temp_dir,
Expand All @@ -69,6 +71,10 @@ impl<'a> Tarball<'a> {
self.overlay = overlay;
}

pub(crate) fn set_product_name(&mut self, name: &str) {
self.product_name = name.into();
}

pub(crate) fn is_preview(&mut self, is: bool) {
self.is_preview = is;
}
Expand All @@ -91,12 +97,11 @@ impl<'a> Tarball<'a> {
self.builder.install(src.as_ref(), &destdir, perms);
}

pub(crate) fn add_dir(&self, src: impl AsRef<Path>, destdir: impl AsRef<Path>) {
t!(std::fs::create_dir_all(destdir.as_ref()));
self.builder.cp_r(
src.as_ref(),
&self.image_dir.join(destdir.as_ref()).join(src.as_ref().file_name().unwrap()),
);
pub(crate) fn add_dir(&self, src: impl AsRef<Path>, dest: impl AsRef<Path>) {
let dest = self.image_dir.join(dest.as_ref());

t!(std::fs::create_dir_all(&dest));
self.builder.cp_r(src.as_ref(), &dest);
}

pub(crate) fn generate(self) -> PathBuf {
Expand All @@ -114,7 +119,7 @@ impl<'a> Tarball<'a> {
let distdir = crate::dist::distdir(self.builder);
let mut cmd = self.builder.tool_cmd(crate::tool::Tool::RustInstaller);
cmd.arg("generate")
.arg("--product-name=Rust")
.arg(format!("--product-name={}", self.product_name))
.arg("--rel-manifest-dir=rustlib")
.arg(format!("--success-message={} installed.", self.component))
.arg("--image-dir")
Expand Down

0 comments on commit c768ce1

Please sign in to comment.