Skip to content

Commit

Permalink
Change coverage metadata code and remove dependency on serde_json
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed May 7, 2024
1 parent e45f079 commit d74bb86
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ honggfuzz = { package = "ziggy-honggfuzz-2", version = "0.5.55", optional = true
libc = { version = "0.2.154", optional = true }
log = { version = "0.4.21", optional = true }
semver = { version = "1.0.23", optional = true }
serde_json = { version = "1.0.116", optional = true }
strip-ansi-escapes = { version = "0.2.0", optional = true }
time-humanize = { version = "0.1.3", optional = true }
toml = { version = "0.8.12", optional = true }
Expand All @@ -42,7 +41,6 @@ cli = [
"toml",
"semver",
"anyhow",
"serde_json",
"log",
"env_logger",
"strip-ansi-escapes",
Expand Down
17 changes: 2 additions & 15 deletions src/bin/cargo-ziggy/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,8 @@ impl Cover {
let source_or_workspace_root = match &self.source {
Some(s) => s.display().to_string(),
None => {
// TODO use cargo_metadata
let metadata_output = std::process::Command::new("cargo")
.arg("metadata")
.output()
.context("Failed to run cargo metadata")?;

let stdout =
String::from_utf8(metadata_output.stdout).context("Failed to read stdout")?;
let metadata: serde_json::Value =
serde_json::from_str(&stdout).context("Failed to parse JSON")?;

metadata["workspace_root"]
.as_str()
.context("Failed to get workspace root")?
.to_string()
let metadata = cargo_metadata::MetadataCommand::new().exec().unwrap();
metadata.workspace_root.into()
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/bin/cargo-ziggy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ pub fn find_target(target: &String) -> Result<String, anyhow::Error> {
}

fn guess_target() -> Result<String> {
// TODO Use cargo-metadata and remove toml dependency

let cargo_toml_string = fs::read_to_string("Cargo.toml")
.context("⚠️ couldn't find Cargo.toml in this folder, cannot guess target")?;
let cargo_toml = cargo_toml_string.parse::<toml::Value>().context(
Expand Down

0 comments on commit d74bb86

Please sign in to comment.