about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJoshua Nelson <jnelson@cloudflare.com>2022-10-02 00:25:08 -0500
committerJoshua Nelson <jnelson@cloudflare.com>2022-10-27 12:16:15 -0500
commit69a74955fd9dfd28647b8a4c18abc3dcecb5696d (patch)
tree3157c110590bb7b77291ce081f910247d7e839c2 /src
parent494cb47852ef7bb2cc14f1f440d77722bf0f759b (diff)
downloadrust-69a74955fd9dfd28647b8a4c18abc3dcecb5696d.tar.gz
rust-69a74955fd9dfd28647b8a4c18abc3dcecb5696d.zip
Use `PkgType` to determine which packages to add to the manifest
Previously, these had to be hard-coded (i.e. specified in both `PkgType` and `fn package`). Now they only have to be specified in `PkgType`.
Diffstat (limited to 'src')
-rw-r--r--src/tools/build-manifest/src/main.rs35
-rw-r--r--src/tools/build-manifest/src/versions.rs70
2 files changed, 84 insertions, 21 deletions
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index 983f4ca7138..726275988e0 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -283,28 +283,15 @@ impl Builder {
     }
 
     fn add_packages_to(&mut self, manifest: &mut Manifest) {
-        macro_rules! package {
-            ($name:expr, $targets:expr) => {
-                self.package($name, &mut manifest.pkg, $targets, &[])
-            };
+        for pkg in PkgType::all() {
+            let fallback = if pkg.use_docs_fallback() { DOCS_FALLBACK } else { &[] };
+            self.package(
+                &pkg.manifest_component_name(),
+                &mut manifest.pkg,
+                pkg.targets(),
+                fallback,
+            );
         }
-        package!("rustc", HOSTS);
-        package!("rustc-dev", HOSTS);
-        package!("reproducible-artifacts", HOSTS);
-        package!("rustc-docs", HOSTS);
-        package!("cargo", HOSTS);
-        package!("rust-mingw", MINGW);
-        package!("rust-std", TARGETS);
-        self.package("rust-docs", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
-        self.package("rust-docs-json-preview", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
-        package!("rust-src", &["*"]);
-        package!("rls-preview", HOSTS);
-        package!("rust-analyzer-preview", HOSTS);
-        package!("clippy-preview", HOSTS);
-        package!("miri-preview", HOSTS);
-        package!("rustfmt-preview", HOSTS);
-        package!("rust-analysis", TARGETS);
-        package!("llvm-tools-preview", TARGETS);
     }
 
     fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
@@ -500,6 +487,12 @@ impl Builder {
         targets: &[&str],
         fallback: &[(&str, &str)],
     ) {
+        if pkgname == "rust" {
+            // This is handled specially by `rust_package` later.
+            // Order is important, so don't call `rust_package` here.
+            return;
+        }
+
         let version_info = self
             .versions
             .version(&PkgType::from_component(pkgname))
diff --git a/src/tools/build-manifest/src/versions.rs b/src/tools/build-manifest/src/versions.rs
index 61e8825753c..5aef232d7ab 100644
--- a/src/tools/build-manifest/src/versions.rs
+++ b/src/tools/build-manifest/src/versions.rs
@@ -17,6 +17,13 @@ macro_rules! pkg_type {
         }
 
         impl PkgType {
+            fn is_preview(&self) -> bool {
+                match self {
+                    $( $( $($is_preview)? PkgType::$variant => true, )? )+
+                    _ => false,
+                }
+            }
+
             pub(crate) fn from_component(component: &str) -> Self {
                 match component {
                     $( $component  $( | concat!($($is_preview)? $component, "-preview") )? => PkgType::$variant,)+
@@ -31,6 +38,11 @@ macro_rules! pkg_type {
                     PkgType::Other(component) => component,
                 }
             }
+
+            /// Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
+            pub(crate) fn all() -> &'static [PkgType] {
+                &[ $(PkgType::$variant),+ ]
+            }
         }
     }
 }
@@ -39,7 +51,14 @@ pkg_type! {
     Rust = "rust",
     RustSrc = "rust-src",
     Rustc = "rustc",
+    RustcDev = "rustc-dev",
+    RustcDocs = "rustc-docs",
+    ReproducibleArtifacts = "reproducible-artifacts",
+    RustMingw = "rust-mingw",
+    RustStd = "rust-std",
     Cargo = "cargo",
+    HtmlDocs = "rust-docs",
+    RustAnalysis = "rust-analysis",
     Rls = "rls"; preview = true,
     RustAnalyzer = "rust-analyzer"; preview = true,
     Clippy = "clippy"; preview = true,
@@ -50,6 +69,15 @@ pkg_type! {
 }
 
 impl PkgType {
+    // / Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
+    pub(crate) fn manifest_component_name(&self) -> String {
+        if self.is_preview() {
+            format!("{}-preview", self.tarball_component_name())
+        } else {
+            self.tarball_component_name().to_string()
+        }
+    }
+
     /// Whether this package has the same version as Rust itself, or has its own `version` and
     /// `git-commit-hash` files inside the tarball.
     fn should_use_rust_version(&self) -> bool {
@@ -63,17 +91,59 @@ impl PkgType {
             PkgType::Miri => false,
 
             PkgType::Rust => true,
+            PkgType::RustStd => true,
             PkgType::RustSrc => true,
             PkgType::Rustc => true,
             PkgType::JsonDocs => true,
+            PkgType::HtmlDocs => true,
+            PkgType::RustcDev => true,
+            PkgType::RustcDocs => true,
+            PkgType::ReproducibleArtifacts => true,
+            PkgType::RustMingw => true,
+            PkgType::RustAnalysis => true,
             PkgType::Other(_) => true,
         }
     }
 
+    pub(crate) fn targets(&self) -> &[&str] {
+        use crate::{HOSTS, MINGW, TARGETS};
+        use PkgType::*;
+
+        match self {
+            Rust => HOSTS, // doesn't matter in practice, but return something to avoid panicking
+            Rustc => HOSTS,
+            RustcDev => HOSTS,
+            ReproducibleArtifacts => HOSTS,
+            RustcDocs => HOSTS,
+            Cargo => HOSTS,
+            RustMingw => MINGW,
+            RustStd => TARGETS,
+            HtmlDocs => HOSTS,
+            JsonDocs => HOSTS,
+            RustSrc => &["*"],
+            Rls => HOSTS,
+            RustAnalyzer => HOSTS,
+            Clippy => HOSTS,
+            Miri => HOSTS,
+            Rustfmt => HOSTS,
+            RustAnalysis => TARGETS,
+            LlvmTools => TARGETS,
+            Other(pkg) => panic!("add {pkg} to the list of known `PkgType`s"),
+        }
+    }
+
     /// Whether this package is target-independent or not.
     fn target_independent(&self) -> bool {
         *self == PkgType::RustSrc
     }
+
+    /// Whether to package these target-specific docs for another similar target.
+    pub(crate) fn use_docs_fallback(&self) -> bool {
+        match self {
+            PkgType::JsonDocs | PkgType::HtmlDocs => true,
+            _ => false,
+        }
+    }
 }
 
 #[derive(Debug, Default, Clone)]