Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1906c42

Browse files
committed
bootstrap: convert rust-src to use Tarball
1 parent 2e0a16c commit 1906c42

File tree

2 files changed

+28
-33
lines changed

2 files changed

+28
-33
lines changed

src/bootstrap/dist.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,7 @@ impl Step for Src {
814814

815815
/// Creates the `rust-src` installer component
816816
fn run(self, builder: &Builder<'_>) -> PathBuf {
817-
let name = pkgname(builder, "rust-src");
818-
let image = tmpdir(builder).join(format!("{}-image", name));
819-
let _ = fs::remove_dir_all(&image);
817+
let tarball = Tarball::new_targetless(builder, "rust-src");
820818

821819
// A lot of tools expect the rust-src component to be entirely in this directory, so if you
822820
// change that (e.g. by adding another directory `lib/rustlib/src/foo` or
@@ -825,8 +823,7 @@ impl Step for Src {
825823
//
826824
// NOTE: if you update the paths here, you also should update the "virtual" path
827825
// translation code in `imported_source_files` in `src/librustc_metadata/rmeta/decoder.rs`
828-
let dst_src = image.join("lib/rustlib/src/rust");
829-
t!(fs::create_dir_all(&dst_src));
826+
let dst_src = tarball.image_dir().join("lib/rustlib/src/rust");
830827

831828
let src_files = ["Cargo.lock"];
832829
// This is the reduced set of paths which will become the rust-src component
@@ -846,28 +843,7 @@ impl Step for Src {
846843
builder.copy(&builder.src.join(file), &dst_src.join(file));
847844
}
848845

849-
// Create source tarball in rust-installer format
850-
let mut cmd = rust_installer(builder);
851-
cmd.arg("generate")
852-
.arg("--product-name=Rust")
853-
.arg("--rel-manifest-dir=rustlib")
854-
.arg("--success-message=Awesome-Source.")
855-
.arg("--image-dir")
856-
.arg(&image)
857-
.arg("--work-dir")
858-
.arg(&tmpdir(builder))
859-
.arg("--output-dir")
860-
.arg(&distdir(builder))
861-
.arg(format!("--package-name={}", name))
862-
.arg("--component-name=rust-src")
863-
.arg("--legacy-manifest-dirs=rustlib,cargo");
864-
865-
builder.info("Dist src");
866-
let _time = timeit(builder);
867-
builder.run(&mut cmd);
868-
869-
builder.remove_dir(&image);
870-
distdir(builder).join(&format!("{}.tar.gz", name))
846+
tarball.generate()
871847
}
872848
}
873849

src/bootstrap/tarball.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub(crate) struct Tarball<'a> {
8484

8585
pkgname: String,
8686
component: String,
87-
target: String,
87+
target: Option<String>,
8888
product_name: String,
8989
overlay: OverlayKind,
9090

@@ -99,6 +99,14 @@ pub(crate) struct Tarball<'a> {
9999

100100
impl<'a> Tarball<'a> {
101101
pub(crate) fn new(builder: &'a Builder<'a>, component: &str, target: &str) -> Self {
102+
Self::new_inner(builder, component, Some(target.into()))
103+
}
104+
105+
pub(crate) fn new_targetless(builder: &'a Builder<'a>, component: &str) -> Self {
106+
Self::new_inner(builder, component, None)
107+
}
108+
109+
fn new_inner(builder: &'a Builder<'a>, component: &str, target: Option<String>) -> Self {
102110
let pkgname = crate::dist::pkgname(builder, component);
103111

104112
let temp_dir = builder.out.join("tmp").join("tarball").join(component);
@@ -113,7 +121,7 @@ impl<'a> Tarball<'a> {
113121

114122
pkgname,
115123
component: component.into(),
116-
target: target.into(),
124+
target,
117125
product_name: "Rust".into(),
118126
overlay: OverlayKind::Rust,
119127

@@ -197,7 +205,14 @@ impl<'a> Tarball<'a> {
197205

198206
let mut cmd = self.builder.tool_cmd(crate::tool::Tool::RustInstaller);
199207

200-
self.builder.info(&format!("Dist {} ({})", self.component, self.target));
208+
let package_name = if let Some(target) = &self.target {
209+
self.builder.info(&format!("Dist {} ({})", self.component, target));
210+
format!("{}-{}", self.pkgname, target)
211+
} else {
212+
self.builder.info(&format!("Dist {}", self.component));
213+
self.pkgname.clone()
214+
};
215+
201216
let _time = crate::util::timeit(self.builder);
202217

203218
let mut component_name = self.component.clone();
@@ -206,7 +221,11 @@ impl<'a> Tarball<'a> {
206221
}
207222
if self.include_target_in_component_name {
208223
component_name.push('-');
209-
component_name.push_str(&self.target);
224+
component_name.push_str(
225+
&self
226+
.target
227+
.expect("include_target_in_component_name used in a targetless tarball"),
228+
);
210229
}
211230

212231
let distdir = crate::dist::distdir(self.builder);
@@ -222,12 +241,12 @@ impl<'a> Tarball<'a> {
222241
.arg(&distdir)
223242
.arg("--non-installed-overlay")
224243
.arg(self.overlay_dir)
225-
.arg(format!("--package-name={}-{}", self.pkgname, self.target))
244+
.arg(format!("--package-name={}", package_name))
226245
.arg("--legacy-manifest-dirs=rustlib,cargo")
227246
.arg(format!("--component-name={}", component_name));
228247
self.builder.run(&mut cmd);
229248
t!(std::fs::remove_dir_all(&self.temp_dir));
230249

231-
distdir.join(format!("{}-{}.tar.gz", self.pkgname, self.target))
250+
distdir.join(format!("{}.tar.gz", package_name))
232251
}
233252
}

0 commit comments

Comments
 (0)