Skip to content

Commit

Permalink
Merge #3819
Browse files Browse the repository at this point in the history
3819: Unique package by name and version. r=matklad a=o0Ignition0o

This commit is a fixup of #3781 I introduced a bug by using a PackageId to refer to a crate when its name conflicts with a dependency.
It turns out the package id currently is `name version path` while cargo expects `name:version` as argument eg:
Cargo command with a `PackageId`:
```
> Executing task: cargo test --package 'config 0.1.0 (path+file:///Users/ignition/Projects/oss/config)' --test default -- test_with_name --exact --nocapture <
```
Cargo command with `name:version`:
```
> Executing task: cargo test --package 'config:0.1.0' --test default -- test_with_name --exact --nocapture <
```

Co-authored-by: o0Ignition0o <jeremy.lempereur@gmail.com>
  • Loading branch information
bors[bot] and o0Ignition0o committed Apr 2, 2020
2 parents f0ba01c + f643b4b commit 2883b29
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/ra_project_model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub type Target = Idx<TargetData>;

#[derive(Debug, Clone)]
pub struct PackageData {
pub id: String,
pub version: String,
pub name: String,
pub manifest: PathBuf,
pub targets: Vec<Target>,
Expand Down Expand Up @@ -174,14 +174,15 @@ impl CargoWorkspace {
let ws_members = &meta.workspace_members;

for meta_pkg in meta.packages {
let cargo_metadata::Package { id, edition, name, manifest_path, .. } = meta_pkg;
let cargo_metadata::Package { id, edition, name, manifest_path, version, .. } =
meta_pkg;
let is_member = ws_members.contains(&id);
let edition = edition
.parse::<Edition>()
.with_context(|| format!("Failed to parse edition {}", edition))?;
let pkg = packages.alloc(PackageData {
name,
id: id.to_string(),
version: version.to_string(),
manifest: manifest_path,
targets: Vec::new(),
is_member,
Expand Down Expand Up @@ -256,7 +257,7 @@ impl CargoWorkspace {
if self.is_unique(&*package.name) {
package.name.clone()
} else {
package.id.clone()
format!("{}:{}", package.name, package.version)
}
}

Expand Down

0 comments on commit 2883b29

Please sign in to comment.