diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index c485481b9a1eb..9fc12468f3fca 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -28,7 +28,7 @@ use crate::core::config::TargetSelection; use crate::utils::cache::{Interned, INTERNER}; use crate::utils::channel; use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit}; -use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball}; +use crate::utils::tarball::{OverlayKind, Tarball, TarballResult}; use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS}; pub fn pkgname(builder: &Builder<'_>, component: &str) -> String { @@ -56,7 +56,7 @@ pub struct Docs { } impl Step for Docs { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -69,7 +69,7 @@ impl Step for Docs { } /// Builds the `rust-docs` installer component. - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let host = self.host; builder.default_doc(&[]); @@ -89,7 +89,7 @@ pub struct JsonDocs { } impl Step for JsonDocs { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -102,7 +102,7 @@ impl Step for JsonDocs { } /// Builds the `rust-docs-json` installer component. - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let host = self.host; builder.ensure(crate::core::build_steps::doc::Std::new( builder.top_stage, @@ -127,7 +127,7 @@ pub struct RustcDocs { } impl Step for RustcDocs { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -140,7 +140,7 @@ impl Step for RustcDocs { } /// Builds the `rustc-docs` installer component. - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let host = self.host; builder.default_doc(&[]); @@ -314,7 +314,7 @@ pub struct Mingw { } impl Step for Mingw { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -329,7 +329,7 @@ impl Step for Mingw { /// /// This contains all the bits and pieces to run the MinGW Windows targets /// without any extra installed software (e.g., we bundle gcc, libraries, etc). - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let host = self.host; if !host.ends_with("pc-windows-gnu") || !builder.config.dist_include_mingw_linker { return None; @@ -354,7 +354,7 @@ pub struct Rustc { } impl Step for Rustc { - type Output = GeneratedTarball; + type Output = TarballResult; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -368,7 +368,7 @@ impl Step for Rustc { } /// Creates the `rustc` installer component. - fn run(self, builder: &Builder<'_>) -> GeneratedTarball { + fn run(self, builder: &Builder<'_>) -> TarballResult { let compiler = self.compiler; let host = self.compiler.host; @@ -623,7 +623,7 @@ pub struct Std { } impl Step for Std { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -641,7 +641,7 @@ impl Step for Std { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -670,7 +670,7 @@ pub struct RustcDev { } impl Step for RustcDev { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -689,7 +689,7 @@ impl Step for RustcDev { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; if skip_host_target_lib(builder, compiler) { @@ -729,7 +729,7 @@ pub struct Analysis { } impl Step for Analysis { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -752,7 +752,7 @@ impl Step for Analysis { } /// Creates a tarball of (degenerate) save-analysis metadata, if available. - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; if compiler.host != builder.config.build { @@ -874,7 +874,7 @@ pub struct Src; impl Step for Src { /// The output path of the src installer tarball - type Output = GeneratedTarball; + type Output = TarballResult; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -887,7 +887,7 @@ impl Step for Src { } /// Creates the `rust-src` installer component - fn run(self, builder: &Builder<'_>) -> GeneratedTarball { + fn run(self, builder: &Builder<'_>) -> TarballResult { if !builder.config.dry_run() { builder.update_submodule(&Path::new("src/llvm-project")); } @@ -935,7 +935,7 @@ pub struct PlainSourceTarball; impl Step for PlainSourceTarball { /// Produces the location of the tarball generated - type Output = GeneratedTarball; + type Output = TarballResult; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -949,7 +949,7 @@ impl Step for PlainSourceTarball { } /// Creates the plain source tarball - fn run(self, builder: &Builder<'_>) -> GeneratedTarball { + fn run(self, builder: &Builder<'_>) -> TarballResult { // NOTE: This is a strange component in a lot of ways. It uses `src` as the target, which // means neither rustup nor rustup-toolchain-install-master know how to download it. // It also contains symbolic links, unlike other any other dist tarball. @@ -1037,7 +1037,7 @@ pub struct Cargo { } impl Step for Cargo { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1057,7 +1057,7 @@ impl Step for Cargo { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -1086,7 +1086,7 @@ pub struct Rls { } impl Step for Rls { - type Output = Option; + type Output = Option; const ONLY_HOSTS: bool = true; const DEFAULT: bool = true; @@ -1106,7 +1106,7 @@ impl Step for Rls { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -1130,7 +1130,7 @@ pub struct RustAnalyzer { } impl Step for RustAnalyzer { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1150,7 +1150,7 @@ impl Step for RustAnalyzer { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -1174,7 +1174,7 @@ pub struct Clippy { } impl Step for Clippy { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1194,7 +1194,7 @@ impl Step for Clippy { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -1225,7 +1225,7 @@ pub struct Miri { } impl Step for Miri { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1245,7 +1245,7 @@ impl Step for Miri { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { // This prevents miri from being built for "dist" or "install" // on the stable/beta channels. It is a nightly-only tool and should // not be included. @@ -1276,7 +1276,7 @@ pub struct CodegenBackend { } impl Step for CodegenBackend { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1297,7 +1297,7 @@ impl Step for CodegenBackend { } } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { if builder.config.dry_run() { return None; } @@ -1372,7 +1372,7 @@ pub struct Rustfmt { } impl Step for Rustfmt { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1392,7 +1392,7 @@ impl Step for Rustfmt { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -1419,7 +1419,7 @@ pub struct RustDemangler { } impl Step for RustDemangler { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -1444,7 +1444,7 @@ impl Step for RustDemangler { }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let compiler = self.compiler; let target = self.target; @@ -2126,7 +2126,7 @@ pub struct LlvmTools { } impl Step for LlvmTools { - type Output = Option; + type Output = Option; const ONLY_HOSTS: bool = true; const DEFAULT: bool = true; @@ -2140,7 +2140,7 @@ impl Step for LlvmTools { run.builder.ensure(LlvmTools { target: run.target }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let target = self.target; /* run only if llvm-config isn't used */ @@ -2184,7 +2184,7 @@ pub struct RustDev { } impl Step for RustDev { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; @@ -2196,7 +2196,7 @@ impl Step for RustDev { run.builder.ensure(RustDev { target: run.target }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let target = self.target; /* run only if llvm-config isn't used */ @@ -2266,7 +2266,7 @@ pub struct Bootstrap { } impl Step for Bootstrap { - type Output = Option; + type Output = Option; const DEFAULT: bool = false; const ONLY_HOSTS: bool = true; @@ -2278,7 +2278,7 @@ impl Step for Bootstrap { run.builder.ensure(Bootstrap { target: run.target }); } - fn run(self, builder: &Builder<'_>) -> Option { + fn run(self, builder: &Builder<'_>) -> Option { let target = self.target; let tarball = Tarball::new(builder, "bootstrap", &target.triple); @@ -2302,7 +2302,7 @@ pub struct BuildManifest { } impl Step for BuildManifest { - type Output = GeneratedTarball; + type Output = TarballResult; const DEFAULT: bool = false; const ONLY_HOSTS: bool = true; @@ -2314,7 +2314,7 @@ impl Step for BuildManifest { run.builder.ensure(BuildManifest { target: run.target }); } - fn run(self, builder: &Builder<'_>) -> GeneratedTarball { + fn run(self, builder: &Builder<'_>) -> TarballResult { let build_manifest = builder.tool_exe(Tool::BuildManifest); let tarball = Tarball::new(builder, "build-manifest", &self.target.triple); @@ -2334,7 +2334,7 @@ pub struct ReproducibleArtifacts { } impl Step for ReproducibleArtifacts { - type Output = Option; + type Output = Option; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; diff --git a/src/bootstrap/src/core/build_steps/install.rs b/src/bootstrap/src/core/build_steps/install.rs index 6b4a8f597eab5..fbf2b8b5aefc5 100644 --- a/src/bootstrap/src/core/build_steps/install.rs +++ b/src/bootstrap/src/core/build_steps/install.rs @@ -12,7 +12,7 @@ use crate::core::build_steps::dist; use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::core::config::{Config, TargetSelection}; use crate::utils::helpers::t; -use crate::utils::tarball::GeneratedTarball; +use crate::utils::tarball::TarballResult; use crate::INTERNER; use crate::{Compiler, Kind}; @@ -66,7 +66,7 @@ fn install_sh( package: &str, stage: u32, host: Option, - tarball: &GeneratedTarball, + tarball: &TarballResult, ) { let _guard = builder.msg(Kind::Install, stage, package, host, host); @@ -105,7 +105,7 @@ fn install_sh( let mut cmd = Command::new(SHELL); cmd.current_dir(&empty_dir) - .arg(sanitize_sh(&tarball.decompressed_output().join("install.sh"))) + .arg(sanitize_sh(&tarball.prepared_output().join("install.sh"))) .arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix))) .arg(format!("--sysconfdir={}", prepare_dir(&destdir_env, sysconfdir))) .arg(format!("--datadir={}", prepare_dir(&destdir_env, datadir))) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 77a4f2c4cb201..2aae64a21d0e2 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2788,7 +2788,7 @@ impl Step for Distcheck { let mut cmd = Command::new("tar"); cmd.arg("-xf") - .arg(builder.ensure(dist::PlainSourceTarball).tarball()) + .arg(builder.ensure(dist::PlainSourceTarball).tarball().unwrap()) .arg("--strip-components=1") .current_dir(&dir); builder.run(&mut cmd); @@ -2812,7 +2812,7 @@ impl Step for Distcheck { let mut cmd = Command::new("tar"); cmd.arg("-xf") - .arg(builder.ensure(dist::Src).tarball()) + .arg(builder.ensure(dist::Src).tarball().unwrap()) .arg("--strip-components=1") .current_dir(&dir); builder.run(&mut cmd); diff --git a/src/bootstrap/src/utils/tarball.rs b/src/bootstrap/src/utils/tarball.rs index 2508a95247531..657aae77c4684 100644 --- a/src/bootstrap/src/utils/tarball.rs +++ b/src/bootstrap/src/utils/tarball.rs @@ -218,7 +218,7 @@ impl<'a> Tarball<'a> { self.add_dir(src, dest); } - pub(crate) fn generate(self) -> GeneratedTarball { + pub(crate) fn generate(self) -> TarballResult { let mut component_name = self.component.clone(); if self.is_preview { component_name.push_str("-preview"); @@ -257,11 +257,11 @@ impl<'a> Tarball<'a> { }) } - pub(crate) fn combine(self, tarballs: &[GeneratedTarball]) -> GeneratedTarball { - let mut input_tarballs = tarballs[0].path.as_os_str().to_os_string(); + pub(crate) fn combine(self, tarballs: &[TarballResult]) -> TarballResult { + let mut input_tarballs = tarballs[0].path.as_ref().unwrap().as_os_str().to_os_string(); for tarball in &tarballs[1..] { input_tarballs.push(","); - input_tarballs.push(&tarball.path); + input_tarballs.push(&tarball.path.as_ref().unwrap()); } self.run(|this, cmd| { @@ -270,7 +270,7 @@ impl<'a> Tarball<'a> { }) } - pub(crate) fn bare(self) -> GeneratedTarball { + pub(crate) fn bare(self) -> TarballResult { // Bare tarballs should have the top level directory match the package // name, not "image". We rename the image directory just before passing // into rust-installer. @@ -308,7 +308,7 @@ impl<'a> Tarball<'a> { .arg(distdir(self.builder)); } - fn run(self, build_cli: impl FnOnce(&Tarball<'a>, &mut Command)) -> GeneratedTarball { + fn run(self, build_cli: impl FnOnce(&Tarball<'a>, &mut Command)) -> TarballResult { t!(std::fs::create_dir_all(&self.overlay_dir)); self.builder.create(&self.overlay_dir.join("version"), &self.overlay.version(self.builder)); if let Some(info) = self.builder.rust_info().info() { @@ -336,9 +336,9 @@ impl<'a> Tarball<'a> { // Ensure there are no symbolic links in the tarball. In particular, // rustup-toolchain-install-master and most versions of Windows can't handle symbolic links. - let decompressed_output = self.temp_dir.join(&package_name); + let prepared_output = self.temp_dir.join(&package_name); if !self.builder.config.dry_run() && !self.permit_symlinks { - for entry in walkdir::WalkDir::new(&decompressed_output) { + for entry in walkdir::WalkDir::new(&prepared_output) { let entry = t!(entry); if entry.path_is_symlink() { panic!("generated a symlink in a tarball: {}", entry.path().display()); @@ -356,28 +356,33 @@ impl<'a> Tarball<'a> { .map(|s| s.as_str()) .unwrap_or("gz"); - GeneratedTarball { - path: distdir(self.builder).join(format!("{package_name}.tar.{ext}")), - decompressed_output, + TarballResult { + path: if self.builder.kind == Kind::Install { + None + } else { + Some(distdir(self.builder).join(format!("{package_name}.tar.{ext}"))) + }, + prepared_output, work: self.temp_dir, } } } #[derive(Debug, Clone)] -pub struct GeneratedTarball { - path: PathBuf, - decompressed_output: PathBuf, +pub struct TarballResult { + /// None if `--prepare-only` was used. + path: Option, + prepared_output: PathBuf, work: PathBuf, } -impl GeneratedTarball { - pub(crate) fn tarball(&self) -> &Path { - &self.path +impl TarballResult { + pub(crate) fn tarball(&self) -> Option<&Path> { + self.path.as_deref() } - pub(crate) fn decompressed_output(&self) -> &Path { - &self.decompressed_output + pub(crate) fn prepared_output(&self) -> &Path { + &self.prepared_output } pub(crate) fn work_dir(&self) -> &Path {