Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/dist/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,18 @@ impl ComponentBuilder {
utils::write_line("component", &mut file, &abs_path, &part.encode())?;
}

// Add component to components file
// Add component to components file, sorting it to avoid depending
// on the order components were installed in.
let names = self.components.list()?;
let mut names: Vec<_> = names.into_iter().map(|c| c.name).collect();
names.push(self.name.clone());
names.sort();
let mut contents = names.join("\n");
contents.push('\n');
let path = self.components.rel_components_file();
let abs_path = self.components.prefix.abs_path(&path);
self.tx.modify_file(path)?;
utils::append_file("components", &abs_path, &self.name)?;
utils::write_file("components", &abs_path, &contents)?;

// Drop in the version file for future use
self.components.write_version(&mut self.tx)?;
Expand Down
26 changes: 26 additions & 0 deletions tests/suite/dist_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ fn multiple_component_install() {
assert!(components.find("mycomponent2").unwrap().is_some());
}

#[test]
fn components_file_is_independent_of_install_order() {
// Deliberately not in sorted order.
let names = ["rustc", "cargo", "rust-std"];
let mock = MockInstallerBuilder {
components: names
.iter()
.map(|name| MockComponentBuilder {
name: name.to_string(),
files: vec![MockFile::new(format!("bin/{name}"), b"data")],
})
.collect(),
};

let cx = DistContext::new(Some(mock)).unwrap();
let (mut tx, components, pkg) = cx.start().unwrap();
for name in names {
tx = pkg.install(&components, name, None, tx).unwrap();
}
tx.commit();

let components_path = cx.prefix.manifest_file("components");
let contents = utils::read_file("components", &components_path).unwrap();
assert_eq!(contents, "cargo\nrust-std\nrustc\n");
}

#[test]
fn uninstall() {
let mock = MockInstallerBuilder {
Expand Down
Loading