Skip to content

Commit feb1222

Browse files
committed
Remove the hard-wired legacy profile
1 parent 96a7d3e commit feb1222

File tree

9 files changed

+183
-63
lines changed

9 files changed

+183
-63
lines changed

src/cli/rustup_mode.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,11 @@ fn target_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
900900
}
901901

902902
for target in &targets {
903-
let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::new(target)));
903+
let new_component = Component::new(
904+
"rust-std".to_string(),
905+
Some(TargetTriple::new(target)),
906+
false,
907+
);
904908
toolchain.add_component(new_component)?;
905909
}
906910

@@ -911,7 +915,11 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
911915
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
912916

913917
for target in m.values_of("target").expect("") {
914-
let new_component = Component::new("rust-std".to_string(), Some(TargetTriple::new(target)));
918+
let new_component = Component::new(
919+
"rust-std".to_string(),
920+
Some(TargetTriple::new(target)),
921+
false,
922+
);
915923

916924
toolchain.remove_component(new_component)?;
917925
}
@@ -940,7 +948,7 @@ fn component_add(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
940948
});
941949

942950
for component in m.values_of("component").expect("") {
943-
let new_component = Component::new(component.to_string(), target.clone());
951+
let new_component = Component::new(component.to_string(), target.clone(), true);
944952

945953
toolchain.add_component(new_component)?;
946954
}
@@ -959,7 +967,7 @@ fn component_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
959967
});
960968

961969
for component in m.values_of("component").expect("") {
962-
let new_component = Component::new(component.to_string(), target.clone());
970+
let new_component = Component::new(component.to_string(), target.clone(), true);
963971

964972
toolchain.remove_component(new_component)?;
965973
}

src/dist/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Config {
6767
for (i, v) in arr.into_iter().enumerate() {
6868
if let toml::Value::Table(t) = v {
6969
let path = format!("{}[{}]", path, i);
70-
result.push(Component::from_toml(t, &path)?);
70+
result.push(Component::from_toml(t, &path, false)?);
7171
}
7272
}
7373

src/dist/dist.rs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::dist::download::DownloadCfg;
2-
use crate::dist::manifest::Component;
32
use crate::dist::manifest::Manifest as ManifestV2;
43
use crate::dist::manifestation::{Changes, Manifestation, UpdateStatus};
54
use crate::dist::notifications::*;
@@ -490,14 +489,6 @@ impl Profile {
490489
pub fn default_name() -> &'static str {
491490
"default"
492491
}
493-
494-
// Non-required components that were required before profiles exist.
495-
pub fn legacy_profile() -> Vec<String> {
496-
["rust-std", "rustc", "cargo", "rust-docs"]
497-
.into_iter()
498-
.map(|s| (*s).to_owned())
499-
.collect()
500-
}
501492
}
502493

503494
impl Default for Profile {
@@ -619,27 +610,13 @@ fn update_from_dist_<'a>(
619610
m.get_rust_version().ok(),
620611
));
621612

622-
let add_components = profile
623-
.and_then(|profile| {
624-
m.get_profile_components(profile, &toolchain.target)
625-
.ok()
626-
.map(|v| {
627-
v.iter()
628-
.map(|name| {
629-
Component::new(name.to_owned(), Some(toolchain.target.clone()))
630-
})
631-
.collect::<Vec<Component>>()
632-
})
633-
})
634-
.unwrap_or_else(|| {
635-
Profile::legacy_profile()
636-
.into_iter()
637-
.map(|s| Component::new(s, Some(toolchain.target.clone())))
638-
.collect()
639-
});
613+
let implicit_add_components = match profile {
614+
Some(profile) => m.get_profile_components(profile, &toolchain.target)?,
615+
None => Vec::new(),
616+
};
640617

641618
let changes = Changes {
642-
implicit_add_components: add_components,
619+
implicit_add_components,
643620
explicit_add_components: Vec::new(),
644621
remove_components: Vec::new(),
645622
};

src/dist/manifest.rs

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ pub struct PackageBins {
5555
pub xz_hash: Option<String>,
5656
}
5757

58-
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
58+
#[derive(Clone, Debug, Eq, Ord, PartialOrd, Hash)]
5959
pub struct Component {
6060
pkg: String,
6161
pub target: Option<TargetTriple>,
62+
// Older Rustup distinguished between components (which are essential) and
63+
// extensions (which are not).
64+
is_extension: bool,
65+
}
66+
67+
impl PartialEq for Component {
68+
fn eq(&self, other: &Component) -> bool {
69+
self.pkg == other.pkg && self.target == other.target
70+
}
6271
}
6372

6473
impl Manifest {
@@ -165,7 +174,10 @@ impl Manifest {
165174
path: &str,
166175
) -> Result<HashMap<Profile, Vec<String>>> {
167176
let mut result = HashMap::new();
168-
let profile_table = get_table(table, "profiles", path)?;
177+
let profile_table = match get_table(table, "profiles", path) {
178+
Ok(t) => t,
179+
Err(_) => return Ok(result),
180+
};
169181

170182
for (k, v) in profile_table {
171183
if let toml::Value::Array(a) = v {
@@ -201,11 +213,29 @@ impl Manifest {
201213
self.get_package("rust").map(|p| &*p.version)
202214
}
203215

216+
pub fn get_legacy_components(&self, target: &TargetTriple) -> Result<Vec<Component>> {
217+
// Build a profile from the components/extensions.
218+
let result = self
219+
.get_package("rust")?
220+
.get_target(Some(target))?
221+
.components
222+
.iter()
223+
.filter(|c| !c.is_extension && c.target.as_ref().map(|t| t == target).unwrap_or(true))
224+
.map(|c| c.clone())
225+
.collect();
226+
227+
return Ok(result);
228+
}
204229
pub fn get_profile_components(
205230
&self,
206231
profile: Profile,
207232
target: &TargetTriple,
208-
) -> Result<Vec<String>> {
233+
) -> Result<Vec<Component>> {
234+
// An older manifest with no profiles section.
235+
if self.profiles.is_empty() {
236+
return self.get_legacy_components(target);
237+
}
238+
209239
let profile = self
210240
.profiles
211241
.get(&profile)
@@ -214,8 +244,13 @@ impl Manifest {
214244
let rust_pkg = self.get_package("rust")?.get_target(Some(target))?;
215245
let result = profile
216246
.into_iter()
217-
.filter(|s| rust_pkg.components.iter().any(|c| &c.pkg == *s))
218-
.map(|s| s.to_owned())
247+
.filter(|s| {
248+
rust_pkg
249+
.components
250+
.iter()
251+
.any(|c| &c.pkg == *s && c.target.as_ref().map(|t| t == target).unwrap_or(true))
252+
})
253+
.map(|s| Component::new(s.to_owned(), Some(target.clone()), false))
219254
.collect();
220255
Ok(result)
221256
}
@@ -357,10 +392,11 @@ impl TargetedPackage {
357392
let extensions = get_array(&mut table, "extensions", path)?;
358393

359394
let mut components =
360-
Self::toml_to_components(components, &format!("{}{}.", path, "components"))?;
395+
Self::toml_to_components(components, &format!("{}{}.", path, "components"), false)?;
361396
components.append(&mut Self::toml_to_components(
362397
extensions,
363398
&format!("{}{}.", path, "extensions"),
399+
true,
364400
)?);
365401

366402
if get_bool(&mut table, "available", path)? {
@@ -381,11 +417,14 @@ impl TargetedPackage {
381417
}
382418
}
383419
pub fn into_toml(self) -> toml::value::Table {
384-
let components = Self::components_to_toml(self.components);
385420
let mut result = toml::value::Table::new();
421+
let (components, extensions) = Self::components_to_toml(self.components);
386422
if !components.is_empty() {
387423
result.insert("components".to_owned(), toml::Value::Array(components));
388424
}
425+
if !extensions.is_empty() {
426+
result.insert("extensions".to_owned(), toml::Value::Array(extensions));
427+
}
389428
if let Some(bins) = self.bins.clone() {
390429
result.insert("hash".to_owned(), toml::Value::String(bins.hash));
391430
result.insert("url".to_owned(), toml::Value::String(bins.url));
@@ -404,38 +443,56 @@ impl TargetedPackage {
404443
self.bins.is_some()
405444
}
406445

407-
fn toml_to_components(arr: toml::value::Array, path: &str) -> Result<Vec<Component>> {
446+
fn toml_to_components(
447+
arr: toml::value::Array,
448+
path: &str,
449+
is_extension: bool,
450+
) -> Result<Vec<Component>> {
408451
let mut result = Vec::new();
409452

410453
for (i, v) in arr.into_iter().enumerate() {
411454
if let toml::Value::Table(t) = v {
412455
let path = format!("{}[{}]", path, i);
413-
result.push(Component::from_toml(t, &path)?);
456+
result.push(Component::from_toml(t, &path, is_extension)?);
414457
}
415458
}
416459

417460
Ok(result)
418461
}
419-
fn components_to_toml(components: Vec<Component>) -> toml::value::Array {
420-
let mut result = toml::value::Array::new();
421-
for v in components {
422-
result.push(toml::Value::Table(v.into_toml()));
462+
fn components_to_toml(data: Vec<Component>) -> (toml::value::Array, toml::value::Array) {
463+
let mut components = toml::value::Array::new();
464+
let mut extensions = toml::value::Array::new();
465+
for v in data {
466+
if v.is_extension {
467+
extensions.push(toml::Value::Table(v.into_toml()));
468+
} else {
469+
components.push(toml::Value::Table(v.into_toml()));
470+
}
423471
}
424-
result
472+
(components, extensions)
425473
}
426474
}
427475

428476
impl Component {
429-
pub fn new(pkg: String, target: Option<TargetTriple>) -> Component {
430-
Component { pkg, target }
477+
pub fn new(pkg: String, target: Option<TargetTriple>, is_extension: bool) -> Component {
478+
Component {
479+
pkg,
480+
target,
481+
is_extension,
482+
}
431483
}
432484
pub fn wildcard(&self) -> Component {
433485
Component {
434486
pkg: self.pkg.clone(),
435487
target: None,
488+
is_extension: false,
436489
}
437490
}
438-
pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result<Self> {
491+
pub fn from_toml(
492+
mut table: toml::value::Table,
493+
path: &str,
494+
is_extension: bool,
495+
) -> Result<Self> {
439496
Ok(Component {
440497
pkg: get_string(&mut table, "pkg", path)?,
441498
target: get_string(&mut table, "target", path).map(|s| {
@@ -445,6 +502,7 @@ impl Component {
445502
Some(TargetTriple::new(&s))
446503
}
447504
})?,
505+
is_extension,
448506
})
449507
}
450508
pub fn into_toml(self) -> toml::value::Table {

src/dist/manifestation.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ impl Manifestation {
124124
let update = Update::build_update(self, new_manifest, &changes, &config, notify_handler)?;
125125

126126
if update.nothing_changes() {
127-
// TODO changes and ,manifest are empty?
128-
eprintln!("update: {:?}", update);
127+
// TODO
128+
eprintln!("no changes: {:?} {:?}", update, config);
129129
return Ok(UpdateStatus::Unchanged);
130130
}
131131

@@ -488,10 +488,16 @@ impl Update {
488488
changes.check_invariants(&config);
489489

490490
// The list of components already installed, empty if a new install
491-
let starting_list = config
492-
.as_ref()
493-
.map(|c| c.components.clone())
494-
.unwrap_or_default();
491+
let installed_components = manifestation.installation.list()?;
492+
let looks_like_v1 = config.is_none() && !installed_components.is_empty();
493+
let starting_list = if looks_like_v1 {
494+
new_manifest.get_legacy_components(&manifestation.target_triple)?
495+
} else {
496+
config
497+
.as_ref()
498+
.map(|c| c.components.clone())
499+
.unwrap_or_default()
500+
};
495501

496502
let mut result = Update {
497503
components_to_uninstall: vec![],

tests/cli-v2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ fn upgrade_v1_to_v2() {
473473
// Delete the v2 manifest so the first day we install from the v1s
474474
fs::remove_file(config.distdir.join("dist/channel-rust-nightly.toml.sha256")).unwrap();
475475
expect_ok(config, &["rustup", "default", "nightly"]);
476+
expect_stdout_ok(config, &["rustc", "--version"], "hash-n-1");
476477
set_current_dist_date(config, "2015-01-02");
477478
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);
478479
expect_stdout_ok(config, &["rustc", "--version"], "hash-n-2");

0 commit comments

Comments
 (0)