Skip to content

Commit 1e9d218

Browse files
committed
Use PkgType in more places
In particular, this avoids serializing and parsing the pkg to a string, which allows getting rid of `PkgType::Other` altogether
1 parent 6cbf079 commit 1e9d218

File tree

4 files changed

+27
-47
lines changed

4 files changed

+27
-47
lines changed

src/tools/build-manifest/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
This tool generates the manifests uploaded to static.rust-lang.org and used by rustup.
44
You can see a full list of all manifests at <https://static.rust-lang.org/manifests.txt>.
5+
This listing is updated by <https://github.com/rust-lang/generate-manifest-list> every 7 days.
56

67
This gets called by `promote-release` <https://github.com/rust-lang/promote-release> via `x.py dist hash-and-sign`.
78

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

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"
180180

181181
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
182182

183-
static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-docs-json-preview"];
183+
static NIGHTLY_ONLY_COMPONENTS: &[PkgType] = &[PkgType::Miri, PkgType::JsonDocs];
184184

185185
macro_rules! t {
186186
($e:expr) => {
@@ -285,12 +285,7 @@ impl Builder {
285285
fn add_packages_to(&mut self, manifest: &mut Manifest) {
286286
for pkg in PkgType::all() {
287287
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-
);
288+
self.package(pkg, &mut manifest.pkg, fallback);
294289
}
295290
}
296291

@@ -401,26 +396,27 @@ impl Builder {
401396
let mut components = Vec::new();
402397
let mut extensions = Vec::new();
403398

404-
let host_component = |pkg: &_| Component::from_str(pkg, host);
399+
let host_component = |pkg: &_| Component::from_pkg(pkg, host);
405400

406401
for pkg in PkgType::all() {
407402
match pkg {
408403
// rustc/rust-std/cargo/docs are all required
409404
PkgType::Rustc | PkgType::Cargo | PkgType::HtmlDocs => {
410-
components.push(host_component(&pkg.manifest_component_name()));
405+
components.push(host_component(pkg));
411406
}
412407
PkgType::RustStd => {
413-
components.push(host_component(&pkg.manifest_component_name()));
408+
components.push(host_component(pkg));
414409
extensions.extend(
415-
TARGETS.iter().filter(|&&target| target != host).map(|target| {
416-
Component::from_str(&pkg.manifest_component_name(), target)
417-
}),
410+
TARGETS
411+
.iter()
412+
.filter(|&&target| target != host)
413+
.map(|target| Component::from_pkg(pkg, target)),
418414
);
419415
}
420416
// so is rust-mingw if it's available for the target
421417
PkgType::RustMingw => {
422418
if host.contains("pc-windows-gnu") {
423-
components.push(host_component("rust-mingw"));
419+
components.push(host_component(pkg));
424420
}
425421
}
426422
// Tools are always present in the manifest,
@@ -433,20 +429,16 @@ impl Builder {
433429
| PkgType::LlvmTools
434430
| PkgType::RustAnalysis
435431
| PkgType::JsonDocs => {
436-
extensions.push(host_component(&pkg.manifest_component_name()));
432+
extensions.push(host_component(pkg));
437433
}
438434
PkgType::RustcDev | PkgType::RustcDocs => {
439-
extensions.extend(
440-
HOSTS.iter().map(|target| {
441-
Component::from_str(&pkg.manifest_component_name(), target)
442-
}),
443-
);
435+
extensions.extend(HOSTS.iter().map(|target| Component::from_pkg(pkg, target)));
444436
}
445437
PkgType::RustSrc => {
446-
extensions.push(Component::from_str(&pkg.manifest_component_name(), "*"));
438+
extensions.push(Component::from_pkg(pkg, "*"));
447439
}
448-
PkgType::Rust | PkgType::Other(_) => {}
449-
// FIXME: is this correct? maybe we should add it so rustup knows about it ...
440+
PkgType::Rust => {}
441+
// NOTE: this is intentional, these artifacts aren't intended to be used with rustup
450442
PkgType::ReproducibleArtifacts => {}
451443
}
452444
}
@@ -494,31 +486,27 @@ impl Builder {
494486

495487
fn package(
496488
&mut self,
497-
pkgname: &str,
489+
pkg: &PkgType,
498490
dst: &mut BTreeMap<String, Package>,
499-
targets: &[&str],
500491
fallback: &[(&str, &str)],
501492
) {
502-
if pkgname == "rust" {
493+
if *pkg == PkgType::Rust {
503494
// This is handled specially by `rust_package` later.
504495
// Order is important, so don't call `rust_package` here.
505496
return;
506497
}
507498

508-
let version_info = self
509-
.versions
510-
.version(&PkgType::from_component(pkgname))
511-
.expect("failed to load package version");
499+
let version_info = self.versions.version(&pkg).expect("failed to load package version");
512500
let mut is_present = version_info.present;
513501

514502
// Never ship nightly-only components for other trains.
515-
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkgname) {
503+
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkg) {
516504
is_present = false; // Pretend the component is entirely missing.
517505
}
518506

519507
macro_rules! tarball_name {
520508
($target_name:expr) => {
521-
self.versions.tarball_name(&PkgType::from_component(pkgname), $target_name).unwrap()
509+
self.versions.tarball_name(pkg, $target_name).unwrap()
522510
};
523511
}
524512
let mut target_from_compressed_tar = |target_name| {
@@ -547,7 +535,8 @@ impl Builder {
547535
Target::unavailable()
548536
};
549537

550-
let targets = targets
538+
let targets = pkg
539+
.targets()
551540
.iter()
552541
.map(|name| {
553542
let target = if is_present {
@@ -562,7 +551,7 @@ impl Builder {
562551
.collect();
563552

564553
dst.insert(
565-
pkgname.to_string(),
554+
pkg.manifest_component_name(),
566555
Package {
567556
version: version_info.version.unwrap_or_default(),
568557
git_commit_hash: version_info.git_commit,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::versions::PkgType;
12
use crate::Builder;
23
use serde::{Serialize, Serializer};
34
use std::collections::BTreeMap;
@@ -116,8 +117,8 @@ pub(crate) struct Component {
116117
}
117118

118119
impl Component {
119-
pub(crate) fn from_str(pkg: &str, target: &str) -> Self {
120-
Self { pkg: pkg.to_string(), target: target.to_string() }
120+
pub(crate) fn from_pkg(pkg: &PkgType, target: &str) -> Self {
121+
Self { pkg: pkg.manifest_component_name(), target: target.to_string() }
121122
}
122123
}
123124

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ macro_rules! pkg_type {
1313
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
1414
pub(crate) enum PkgType {
1515
$($variant,)+
16-
Other(String),
1716
}
1817

1918
impl PkgType {
@@ -24,18 +23,10 @@ macro_rules! pkg_type {
2423
}
2524
}
2625

27-
pub(crate) fn from_component(component: &str) -> Self {
28-
match component {
29-
$( $component $( | concat!($($is_preview)? $component, "-preview") )? => PkgType::$variant,)+
30-
_ => PkgType::Other(component.into()),
31-
}
32-
}
33-
3426
/// First part of the tarball name.
3527
pub(crate) fn tarball_component_name(&self) -> &str {
3628
match self {
3729
$( PkgType::$variant => $component,)+
38-
PkgType::Other(component) => component,
3930
}
4031
}
4132

@@ -100,7 +91,6 @@ impl PkgType {
10091
PkgType::ReproducibleArtifacts => true,
10192
PkgType::RustMingw => true,
10293
PkgType::RustAnalysis => true,
103-
PkgType::Other(_) => true,
10494
}
10595
}
10696

@@ -127,7 +117,6 @@ impl PkgType {
127117
Rustfmt => HOSTS,
128118
RustAnalysis => TARGETS,
129119
LlvmTools => TARGETS,
130-
Other(pkg) => panic!("add {pkg} to the list of known `PkgType`s"),
131120
}
132121
}
133122

0 commit comments

Comments
 (0)