Skip to content

Commit 69a7495

Browse files
committed
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`.
1 parent 494cb47 commit 69a7495

File tree

2 files changed

+84
-21
lines changed

2 files changed

+84
-21
lines changed

src/tools/build-manifest/src/main.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,28 +283,15 @@ impl Builder {
283283
}
284284

285285
fn add_packages_to(&mut self, manifest: &mut Manifest) {
286-
macro_rules! package {
287-
($name:expr, $targets:expr) => {
288-
self.package($name, &mut manifest.pkg, $targets, &[])
289-
};
286+
for pkg in PkgType::all() {
287+
let fallback = if pkg.use_docs_fallback() { DOCS_FALLBACK } else { &[] };
288+
self.package(
289+
&pkg.manifest_component_name(),
290+
&mut manifest.pkg,
291+
pkg.targets(),
292+
fallback,
293+
);
290294
}
291-
package!("rustc", HOSTS);
292-
package!("rustc-dev", HOSTS);
293-
package!("reproducible-artifacts", HOSTS);
294-
package!("rustc-docs", HOSTS);
295-
package!("cargo", HOSTS);
296-
package!("rust-mingw", MINGW);
297-
package!("rust-std", TARGETS);
298-
self.package("rust-docs", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
299-
self.package("rust-docs-json-preview", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
300-
package!("rust-src", &["*"]);
301-
package!("rls-preview", HOSTS);
302-
package!("rust-analyzer-preview", HOSTS);
303-
package!("clippy-preview", HOSTS);
304-
package!("miri-preview", HOSTS);
305-
package!("rustfmt-preview", HOSTS);
306-
package!("rust-analysis", TARGETS);
307-
package!("llvm-tools-preview", TARGETS);
308295
}
309296

310297
fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
@@ -500,6 +487,12 @@ impl Builder {
500487
targets: &[&str],
501488
fallback: &[(&str, &str)],
502489
) {
490+
if pkgname == "rust" {
491+
// This is handled specially by `rust_package` later.
492+
// Order is important, so don't call `rust_package` here.
493+
return;
494+
}
495+
503496
let version_info = self
504497
.versions
505498
.version(&PkgType::from_component(pkgname))

src/tools/build-manifest/src/versions.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ macro_rules! pkg_type {
1717
}
1818

1919
impl PkgType {
20+
fn is_preview(&self) -> bool {
21+
match self {
22+
$( $( $($is_preview)? PkgType::$variant => true, )? )+
23+
_ => false,
24+
}
25+
}
26+
2027
pub(crate) fn from_component(component: &str) -> Self {
2128
match component {
2229
$( $component $( | concat!($($is_preview)? $component, "-preview") )? => PkgType::$variant,)+
@@ -31,6 +38,11 @@ macro_rules! pkg_type {
3138
PkgType::Other(component) => component,
3239
}
3340
}
41+
42+
/// Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
43+
pub(crate) fn all() -> &'static [PkgType] {
44+
&[ $(PkgType::$variant),+ ]
45+
}
3446
}
3547
}
3648
}
@@ -39,7 +51,14 @@ pkg_type! {
3951
Rust = "rust",
4052
RustSrc = "rust-src",
4153
Rustc = "rustc",
54+
RustcDev = "rustc-dev",
55+
RustcDocs = "rustc-docs",
56+
ReproducibleArtifacts = "reproducible-artifacts",
57+
RustMingw = "rust-mingw",
58+
RustStd = "rust-std",
4259
Cargo = "cargo",
60+
HtmlDocs = "rust-docs",
61+
RustAnalysis = "rust-analysis",
4362
Rls = "rls"; preview = true,
4463
RustAnalyzer = "rust-analyzer"; preview = true,
4564
Clippy = "clippy"; preview = true,
@@ -50,6 +69,15 @@ pkg_type! {
5069
}
5170

5271
impl PkgType {
72+
// / Component name in the manifest. In particular, this includes the `-preview` suffix where appropriate.
73+
pub(crate) fn manifest_component_name(&self) -> String {
74+
if self.is_preview() {
75+
format!("{}-preview", self.tarball_component_name())
76+
} else {
77+
self.tarball_component_name().to_string()
78+
}
79+
}
80+
5381
/// Whether this package has the same version as Rust itself, or has its own `version` and
5482
/// `git-commit-hash` files inside the tarball.
5583
fn should_use_rust_version(&self) -> bool {
@@ -63,17 +91,59 @@ impl PkgType {
6391
PkgType::Miri => false,
6492

6593
PkgType::Rust => true,
94+
PkgType::RustStd => true,
6695
PkgType::RustSrc => true,
6796
PkgType::Rustc => true,
6897
PkgType::JsonDocs => true,
98+
PkgType::HtmlDocs => true,
99+
PkgType::RustcDev => true,
100+
PkgType::RustcDocs => true,
101+
PkgType::ReproducibleArtifacts => true,
102+
PkgType::RustMingw => true,
103+
PkgType::RustAnalysis => true,
69104
PkgType::Other(_) => true,
70105
}
71106
}
72107

108+
pub(crate) fn targets(&self) -> &[&str] {
109+
use crate::{HOSTS, MINGW, TARGETS};
110+
use PkgType::*;
111+
112+
match self {
113+
Rust => HOSTS, // doesn't matter in practice, but return something to avoid panicking
114+
Rustc => HOSTS,
115+
RustcDev => HOSTS,
116+
ReproducibleArtifacts => HOSTS,
117+
RustcDocs => HOSTS,
118+
Cargo => HOSTS,
119+
RustMingw => MINGW,
120+
RustStd => TARGETS,
121+
HtmlDocs => HOSTS,
122+
JsonDocs => HOSTS,
123+
RustSrc => &["*"],
124+
Rls => HOSTS,
125+
RustAnalyzer => HOSTS,
126+
Clippy => HOSTS,
127+
Miri => HOSTS,
128+
Rustfmt => HOSTS,
129+
RustAnalysis => TARGETS,
130+
LlvmTools => TARGETS,
131+
Other(pkg) => panic!("add {pkg} to the list of known `PkgType`s"),
132+
}
133+
}
134+
73135
/// Whether this package is target-independent or not.
74136
fn target_independent(&self) -> bool {
75137
*self == PkgType::RustSrc
76138
}
139+
140+
/// Whether to package these target-specific docs for another similar target.
141+
pub(crate) fn use_docs_fallback(&self) -> bool {
142+
match self {
143+
PkgType::JsonDocs | PkgType::HtmlDocs => true,
144+
_ => false,
145+
}
146+
}
77147
}
78148

79149
#[derive(Debug, Default, Clone)]

0 commit comments

Comments
 (0)