Skip to content

Commit 22f2be6

Browse files
committed
clitools: Fix generation of multiarch channels
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
1 parent 1907b12 commit 22f2be6

File tree

1 file changed

+89
-78
lines changed

1 file changed

+89
-78
lines changed

tests/mock/clitools.rs

Lines changed: 89 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,15 @@ enum RlsStatus {
479479
Unavailable,
480480
}
481481

482+
impl RlsStatus {
483+
fn pkg_name(self) -> &'static str {
484+
match self {
485+
Self::Renamed => "rls-preview",
486+
_ => "rls",
487+
}
488+
}
489+
}
490+
482491
struct Release {
483492
// Either "nightly", "stable", "beta", or an explicit version number
484493
channel: String,
@@ -690,6 +699,36 @@ fn create_mock_dist_server(path: &Path, s: Scenario) {
690699
}
691700
}
692701

702+
#[derive(Default)]
703+
struct MockChannelContent {
704+
std: Vec<(MockInstallerBuilder, String)>,
705+
rustc: Vec<(MockInstallerBuilder, String)>,
706+
cargo: Vec<(MockInstallerBuilder, String)>,
707+
rls: Vec<(MockInstallerBuilder, String)>,
708+
docs: Vec<(MockInstallerBuilder, String)>,
709+
src: Vec<(MockInstallerBuilder, String)>,
710+
analysis: Vec<(MockInstallerBuilder, String)>,
711+
combined: Vec<(MockInstallerBuilder, String)>,
712+
}
713+
714+
impl MockChannelContent {
715+
fn into_packages(
716+
self,
717+
rls_name: &'static str,
718+
) -> Vec<(&'static str, Vec<(MockInstallerBuilder, String)>)> {
719+
vec![
720+
("rust-std", self.std),
721+
("rustc", self.rustc),
722+
("cargo", self.cargo),
723+
(rls_name, self.rls),
724+
("rust-docs", self.docs),
725+
("rust-src", self.src),
726+
("rust-analysis", self.analysis),
727+
("rust", self.combined),
728+
]
729+
}
730+
}
731+
693732
fn build_mock_channel(
694733
channel: &str,
695734
date: &str,
@@ -717,85 +756,61 @@ fn build_mock_channel(
717756

718757
// Convert the mock installers to mock package definitions for the
719758
// mock dist server
720-
let mut all = vec![
721-
(
722-
"rust-std",
723-
vec![
724-
(std, host_triple.clone()),
725-
(cross_std1, CROSS_ARCH1.to_string()),
726-
(cross_std2, CROSS_ARCH2.to_string()),
727-
],
728-
),
729-
("rustc", vec![(rustc, host_triple.clone())]),
730-
("cargo", vec![(cargo, host_triple.clone())]),
731-
];
759+
let mut all = MockChannelContent::default();
760+
all.std.extend(
761+
vec![
762+
(std, host_triple.clone()),
763+
(cross_std1, CROSS_ARCH1.to_string()),
764+
(cross_std2, CROSS_ARCH2.to_string()),
765+
]
766+
.into_iter(),
767+
);
768+
all.rustc.push((rustc, host_triple.clone()));
769+
all.cargo.push((cargo, host_triple.clone()));
732770

733-
if rls == RlsStatus::Renamed {
734-
let rls = build_mock_rls_installer(version, version_hash, true);
735-
all.push(("rls-preview", vec![(rls, host_triple.clone())]));
736-
} else if rls == RlsStatus::Available {
737-
let rls = build_mock_rls_installer(version, version_hash, false);
738-
all.push(("rls", vec![(rls, host_triple.clone())]));
771+
if rls != RlsStatus::Unavailable {
772+
let rls = build_mock_rls_installer(version, version_hash, rls.pkg_name());
773+
all.rls.push((rls, host_triple.clone()));
739774
} else {
740-
all.push((
741-
"rls",
742-
vec![(
743-
MockInstallerBuilder { components: vec![] },
744-
host_triple.clone(),
745-
)],
746-
))
775+
all.rls.push((
776+
MockInstallerBuilder { components: vec![] },
777+
host_triple.clone(),
778+
));
747779
}
748780

749-
let more = vec![
750-
("rust-docs", vec![(rust_docs, host_triple.clone())]),
751-
("rust-src", vec![(rust_src, "*".to_string())]),
752-
("rust-analysis", vec![(rust_analysis, "*".to_string())]),
753-
("rust", vec![(rust, host_triple)]),
754-
];
755-
all.extend(more);
781+
all.docs.push((rust_docs, host_triple.clone()));
782+
all.src.push((rust_src, "*".to_string()));
783+
all.analysis.push((rust_analysis, "*".to_string()));
784+
all.combined.push((rust, host_triple));
756785

757786
if multi_arch {
758787
let std = build_mock_std_installer(MULTI_ARCH1);
759788
let rustc = build_mock_rustc_installer(MULTI_ARCH1, version, version_hash);
760789
let cargo = build_mock_cargo_installer(version, version_hash);
761790
let rust_docs = build_mock_rust_doc_installer();
762791
let rust = build_combined_installer(&[&std, &rustc, &cargo, &rust_docs]);
763-
let cross_std1 = build_mock_cross_std_installer(CROSS_ARCH1, date);
764-
let cross_std2 = build_mock_cross_std_installer(CROSS_ARCH2, date);
765-
let rust_src = build_mock_rust_src_installer();
766792

767793
let triple = MULTI_ARCH1.to_string();
768-
let more = vec![
769-
(
770-
"rust-std",
771-
vec![
772-
(std, triple.clone()),
773-
(cross_std1, CROSS_ARCH1.to_string()),
774-
(cross_std2, CROSS_ARCH2.to_string()),
775-
],
776-
),
777-
("rustc", vec![(rustc, triple.clone())]),
778-
("cargo", vec![(cargo, triple.clone())]),
779-
];
780-
all.extend(more);
781-
782-
if rls == RlsStatus::Renamed {
783-
let rls = build_mock_rls_installer(version, version_hash, true);
784-
all.push(("rls-preview", vec![(rls, triple.clone())]));
785-
} else if rls == RlsStatus::Available {
786-
let rls = build_mock_rls_installer(version, version_hash, false);
787-
all.push(("rls", vec![(rls, triple.clone())]));
788-
}
794+
all.std.push((std, triple.clone()));
795+
all.rustc.push((rustc, triple.clone()));
796+
all.cargo.push((cargo, triple.clone()));
789797

790-
let more = vec![
791-
("rust-docs", vec![(rust_docs, triple.clone())]),
792-
("rust-src", vec![(rust_src, "*".to_string())]),
793-
("rust", vec![(rust, triple)]),
794-
];
798+
if rls != RlsStatus::Unavailable {
799+
let rls = build_mock_rls_installer(version, version_hash, rls.pkg_name());
800+
all.rls.push((rls, triple.clone()));
801+
} else {
802+
all.rls
803+
.push((MockInstallerBuilder { components: vec![] }, triple.clone()));
804+
}
795805

796-
all.extend(more);
806+
all.docs.push((rust_docs, triple.to_string()));
807+
all.combined.push((rust, triple));
797808
}
798809

810+
let all_std_archs: Vec<String> = all.std.iter().map(|(_, arch)| arch).cloned().collect();
811+
812+
let all = all.into_packages(rls.pkg_name());
813+
799814
let packages = all.into_iter().map(|(name, target_pkgs)| {
800815
let target_pkgs = target_pkgs
801816
.into_iter()
@@ -858,16 +873,16 @@ fn build_mock_channel(
858873
is_extension: true,
859874
})
860875
}
861-
target_pkg.components.push(MockComponent {
862-
name: "rust-std".to_string(),
863-
target: CROSS_ARCH1.to_string(),
864-
is_extension: false,
865-
});
866-
target_pkg.components.push(MockComponent {
867-
name: "rust-std".to_string(),
868-
target: CROSS_ARCH2.to_string(),
869-
is_extension: false,
870-
});
876+
for other_target in &all_std_archs {
877+
if other_target != target {
878+
target_pkg.components.push(MockComponent {
879+
name: "rust-std".to_string(),
880+
target: other_target.to_string(),
881+
is_extension: false,
882+
});
883+
}
884+
}
885+
871886
target_pkg.components.push(MockComponent {
872887
name: "rust-src".to_string(),
873888
target: "*".to_string(),
@@ -1027,15 +1042,11 @@ fn build_mock_cargo_installer(version: &str, version_hash: &str) -> MockInstalle
10271042
fn build_mock_rls_installer(
10281043
version: &str,
10291044
version_hash: &str,
1030-
preview: bool,
1045+
pkg_name: &str,
10311046
) -> MockInstallerBuilder {
10321047
MockInstallerBuilder {
10331048
components: vec![MockComponentBuilder {
1034-
name: if preview {
1035-
"rls-preview".to_string()
1036-
} else {
1037-
"rls".to_string()
1038-
},
1049+
name: pkg_name.to_string(),
10391050
files: mock_bin("rls", version, version_hash),
10401051
}],
10411052
}

0 commit comments

Comments
 (0)