Skip to content
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

Do not list dependency packages by MetadataCommand #356

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

kdarkhan
Copy link
Contributor

@kdarkhan kdarkhan commented Jan 6, 2024

When following cargo-fuzz tutorial at
https://rust-fuzz.github.io/book/cargo-fuzz/tutorial.html, after executing cargo fuzz init, fuzz/Cargo.toml contains entry [dependencies.matches] instead of [dependencies.url]. This is caused by MetadataCommand listing dependency packages in addition to main packages which is not desired.

Current implementation does work as expected if result of MetadataCommand contains the first package as the non-dep package but that does not seem to work all the time.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

I don't really follow what is going on here -- to calm my nerves, would you mind adding a regression test that fails without this change and passes after it is introduced?

@kdarkhan
Copy link
Contributor Author

kdarkhan commented Jan 8, 2024

I don't really follow what is going on here -- to calm my nerves, would you mind adding a regression test that fails without this change and passes after it is introduced?

@fitzgen, just pushed a commit with a failing test case that is fixed by my change.

assert!(project.fuzz_cargo_toml().is_file());
let cargo_toml = fs::read_to_string(project.fuzz_cargo_toml()).unwrap();
let expected_dependency_attrs =
&format!("[dependencies.{name}]\npath = \"..\"", name = project_name);
Copy link
Contributor Author

@kdarkhan kdarkhan Jan 8, 2024

Choose a reason for hiding this comment

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

Based on my tests, CargoMetadata crate calls cargo metadata with or without --no-deps.
When called without --no-deps, the result contains all packages including dependency packages which are sorted alphabetically. In order to create a failing example, I had to create a sample cargo project which has the name alphabetically greater than one of its dependencies (project_with_some_dep > matches).

When following `cargo-fuzz` tutorial at
https://rust-fuzz.github.io/book/cargo-fuzz/tutorial.html,
after executing `cargo fuzz init`, `fuzz/Cargo.toml`
contains entry `[dependencies.matches]` instead of
`[dependencies.url]`. This is caused by `MetadataCommand`
listing dependency packages in addition to main packages
which is not desired.

This does work as expected if result of `MetadataCommand`
contains the first package as the non-dep package but that does
not seem to work all the time.
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks!

@fitzgen fitzgen merged commit cdd6e41 into rust-fuzz:main Jan 9, 2024
1 check passed
@kdarkhan kdarkhan deleted the no-dep branch January 9, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants