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

fix: use cargo-metadata to support init command in workspace #349

Merged
merged 5 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions src/options/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub struct Add {
impl RunCommand for Add {
fn run_command(&mut self) -> Result<()> {
let project = FuzzProject::new(self.fuzz_dir_wrapper.fuzz_dir.to_owned())?;
let fuzz_manifest_path = project.fuzz_dir().join("Cargo.toml");
let manifest = Manifest::parse(&fuzz_manifest_path)?;
let manifest = Manifest::parse()?;
project.add_target(self, &manifest)
}
}
14 changes: 3 additions & 11 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ impl FuzzProject {
pub fn init(init: &options::Init, fuzz_dir_opt: Option<PathBuf>) -> Result<Self> {
let project = Self::manage_initial_instance(fuzz_dir_opt)?;
let fuzz_project = project.fuzz_dir();
let root_project_manifest_path = project.project_dir.join("Cargo.toml");
let manifest = Manifest::parse(&root_project_manifest_path)?;
let manifest = Manifest::parse()?;

// TODO: check if the project is already initialized
fs::create_dir(fuzz_project)
Expand Down Expand Up @@ -931,16 +930,9 @@ pub struct Manifest {
}

impl Manifest {
pub fn parse(path: &Path) -> Result<Self> {
pub fn parse() -> Result<Self> {
let metatdata = MetadataCommand::new().exec()?;
let package = metatdata
.packages
.iter()
.find(|p| p.manifest_path == path)
.expect({
let path = path.display();
&format!("could not find package for {}", path)
});
let package = metatdata.packages.first().expect("at least one package");
fitzgen marked this conversation as resolved.
Show resolved Hide resolved
let crate_name = package.name.clone();
let edition = Some(String::from(package.edition.as_str()));

Expand Down