Skip to content

Guard against crate id collisions #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2023
Merged
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
30 changes: 17 additions & 13 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,24 @@ pub fn build_dependencies(config: &mut Config) -> Result<Dependencies> {
let artifact_output = output.stdout;
let artifact_output = String::from_utf8(artifact_output)?;
let mut import_paths: HashSet<PathBuf> = HashSet::new();
let mut artifacts: HashMap<_, _> = artifact_output
.lines()
.filter_map(|line| {
let message = serde_json::from_str::<cargo_metadata::Message>(line).ok()?;
if let cargo_metadata::Message::CompilerArtifact(artifact) = message {
for filename in &artifact.filenames {
import_paths.insert(filename.parent().unwrap().into());
}
Some((artifact.package_id, artifact.filenames))
} else {
None
let mut artifacts = HashMap::new();
for line in artifact_output.lines() {
let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(line) else {
continue
};
if let cargo_metadata::Message::CompilerArtifact(artifact) = message {
for filename in &artifact.filenames {
import_paths.insert(filename.parent().unwrap().into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this assert that no existing entry is overwritten?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this doesn't matter, it is just about import paths, and these are the same for most dependencies.

}
let package_id = artifact.package_id;
if artifacts
.insert(package_id.clone(), artifact.filenames)
.is_some()
{
bail!("`ui_test` does not support crates that appear as both build-dependencies and core dependencies: {package_id}")
}
})
.collect();
}
}

// Check which crates are mentioned in the crate itself
let mut metadata = cargo_metadata::MetadataCommand::new().cargo_command();
Expand Down