Skip to content

Commit

Permalink
Fix "local crate" detection
Browse files Browse the repository at this point in the history
`PackageId` is an opaque identifier whose internal format is subject to
change, so looking up the names of local crates by ID is more robust
than parsing the ID.

Resolves rust-lang#3643.
  • Loading branch information
narpfel authored and lcnr committed Jun 10, 2024
1 parent 1ec6779 commit ca91401
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/tools/miri/cargo-miri/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::env;
use std::ffi::OsString;
use std::fs::File;
Expand Down Expand Up @@ -233,21 +234,18 @@ pub fn get_cargo_metadata() -> Metadata {
}

/// Pulls all the crates in this workspace from the cargo metadata.
/// Workspace members are emitted like "miri 0.1.0 (path+file:///path/to/miri)"
/// Additionally, somewhere between cargo metadata and TyCtxt, '-' gets replaced with '_' so we
/// make that same transformation here.
pub fn local_crates(metadata: &Metadata) -> String {
assert!(!metadata.workspace_members.is_empty());
let mut local_crates = String::new();
for member in &metadata.workspace_members {
let name = member.repr.split(' ').next().unwrap();
let name = name.replace('-', "_");
local_crates.push_str(&name);
local_crates.push(',');
}
local_crates.pop(); // Remove the trailing ','

local_crates
let package_name_by_id: HashMap<_, _> =
metadata.packages.iter().map(|package| (&package.id, package.name.as_str())).collect();
metadata
.workspace_members
.iter()
.map(|id| package_name_by_id[id].replace('-', "_"))
.collect::<Vec<_>>()
.join(",")
}

/// Debug-print a command that is going to be run.
Expand Down

0 comments on commit ca91401

Please sign in to comment.