Skip to content

Commit c768ce1

Browse files
committed
bootstrap: convert rust-docs to use Tarball
1 parent 7be8570 commit c768ce1

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

src/bootstrap/dist.rs

+11-34
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub struct Docs {
5555
}
5656

5757
impl Step for Docs {
58-
type Output = PathBuf;
58+
type Output = Option<PathBuf>;
5959
const DEFAULT: bool = true;
6060

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

6969
/// Builds the `rust-docs` installer component.
70-
fn run(self, builder: &Builder<'_>) -> PathBuf {
70+
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
7171
let host = self.host;
72-
73-
let name = pkgname(builder, "rust-docs");
74-
7572
if !builder.config.docs {
76-
return distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple));
73+
return None;
7774
}
7875

7976
builder.default_doc(None);
8077

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

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

87-
let dst = image.join("share/doc/rust/html");
88-
t!(fs::create_dir_all(&dst));
89-
let src = builder.doc_out(host);
90-
builder.cp_r(&src, &dst);
91-
builder.install(&builder.src.join("src/doc/robots.txt"), &dst, 0o644);
92-
93-
let mut cmd = rust_installer(builder);
94-
cmd.arg("generate")
95-
.arg("--product-name=Rust-Documentation")
96-
.arg("--rel-manifest-dir=rustlib")
97-
.arg("--success-message=Rust-documentation-is-installed.")
98-
.arg("--image-dir")
99-
.arg(&image)
100-
.arg("--work-dir")
101-
.arg(&tmpdir(builder))
102-
.arg("--output-dir")
103-
.arg(&distdir(builder))
104-
.arg(format!("--package-name={}-{}", name, host.triple))
105-
.arg("--component-name=rust-docs")
106-
.arg("--legacy-manifest-dirs=rustlib,cargo")
107-
.arg("--bulk-dirs=share/doc/rust/html");
108-
builder.run(&mut cmd);
109-
builder.remove_dir(&image);
83+
let mut tarball = Tarball::new(builder, "rust-docs", &host.triple);
84+
tarball.set_product_name("Rust Documentation");
85+
tarball.add_dir(&builder.doc_out(host), dest);
86+
tarball.add_file(&builder.src.join("src/doc/robots.txt"), dest, 0o644);
11087

111-
distdir(builder).join(format!("{}-{}.tar.gz", name, host.triple))
88+
Some(tarball.generate())
11289
}
11390
}
11491

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

25142491
// Copy libLLVM.so to the target lib dir as well, so the RPATH like
25152492
// `$ORIGIN/../lib` can find it. It may also be used as a dependency

src/bootstrap/tarball.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) struct Tarball<'a> {
2727
pkgname: String,
2828
component: String,
2929
target: String,
30+
product_name: String,
3031
overlay: OverlayKind,
3132

3233
temp_dir: PathBuf,
@@ -54,6 +55,7 @@ impl<'a> Tarball<'a> {
5455
pkgname,
5556
component: component.into(),
5657
target: target.into(),
58+
product_name: "Rust".into(),
5759
overlay: OverlayKind::Rust,
5860

5961
temp_dir,
@@ -69,6 +71,10 @@ impl<'a> Tarball<'a> {
6971
self.overlay = overlay;
7072
}
7173

74+
pub(crate) fn set_product_name(&mut self, name: &str) {
75+
self.product_name = name.into();
76+
}
77+
7278
pub(crate) fn is_preview(&mut self, is: bool) {
7379
self.is_preview = is;
7480
}
@@ -91,12 +97,11 @@ impl<'a> Tarball<'a> {
9197
self.builder.install(src.as_ref(), &destdir, perms);
9298
}
9399

94-
pub(crate) fn add_dir(&self, src: impl AsRef<Path>, destdir: impl AsRef<Path>) {
95-
t!(std::fs::create_dir_all(destdir.as_ref()));
96-
self.builder.cp_r(
97-
src.as_ref(),
98-
&self.image_dir.join(destdir.as_ref()).join(src.as_ref().file_name().unwrap()),
99-
);
100+
pub(crate) fn add_dir(&self, src: impl AsRef<Path>, dest: impl AsRef<Path>) {
101+
let dest = self.image_dir.join(dest.as_ref());
102+
103+
t!(std::fs::create_dir_all(&dest));
104+
self.builder.cp_r(src.as_ref(), &dest);
100105
}
101106

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

0 commit comments

Comments
 (0)