Skip to content

Commit

Permalink
crevette: export guix crates
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Nov 20, 2023
1 parent 4b0d33a commit be532d9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crevette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ toml_edit = { version = "0.21.0", features = ["serde"] }
cargo_author = { version = "1.0.6", optional = true }
flate2 = { version = "1.0.28", optional = true }
index-debcargo = { version = "1.1.0", optional = true }
index-guix = { version = "1.0.0", optional = true, path = "../../index-guix" }
reqwest = { version = "0.11.22", features = ["blocking"], optional = true }

[features]
# Ability to export list of crates vetted by Debian
debcargo = ["dep:index-debcargo", "dep:cargo_author", "dep:reqwest", "dep:flate2"]
# Ability to export list of crates included in Guix
guix = ["dep:index-guix"]
13 changes: 13 additions & 0 deletions crevette/src/bin/crevette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ Run with --debcargo to make a vet file from Debian package list.", env!("CARGO_P
return Ok(())
}
},
Some("--guix") => {
if !cfg!(feature = "guix") {
eprintln!("Reinstall with guix enabled:\ncargo install crevette --features=guix");
return Err(Error::UnsupportedVersion(0));
}
#[cfg(feature = "guix")]
{
let dirs = directories_next::BaseDirs::new().unwrap();
let cache_dir = dirs.cache_dir().join("crevette");
println!("{}", Crevette::from_guix_repo(&cache_dir)?);
return Ok(())
}
},
Some(other) => {
eprintln!("unknown argument: {other}");
},
Expand Down
41 changes: 39 additions & 2 deletions crevette/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Crevette {
/// Here's your cargo-vet-compatible `audits.toml` file
pub fn convert_to_toml(&self) -> Result<String, Error> {
let mut toml = toml_edit::ser::to_string_pretty(&self.convert_to_document()?)
.map_err(|toml| Error::IO(std::io::Error::new(std::io::ErrorKind::Other, toml)))?;
.map_err(|toml| Error::IO(io::Error::new(io::ErrorKind::Other, toml)))?;

toml.insert_str(0, &format!("# Automatically generated by https://lib.rs/crevette {} from cargo-crev reviews\n\n", env!("CARGO_PKG_VERSION")));

Expand Down Expand Up @@ -186,13 +186,50 @@ impl Crevette {
};

let mut toml = toml_edit::ser::to_string_pretty(&audits)
.map_err(|toml| Error::IO(std::io::Error::new(std::io::ErrorKind::Other, toml)))?;
.map_err(|toml| Error::IO(io::Error::new(io::ErrorKind::Other, toml)))?;

toml.insert_str(0, &format!("# Automatically generated by https://lib.rs/crevette {} from debcargo-conf repo\n\n", env!("CARGO_PKG_VERSION")));

Ok(toml)
}

#[cfg(feature = "guix")]
pub fn from_guix_repo(temp_dir_path: &std::path::Path) -> Result<String, Error> {
let _ = std::fs::create_dir_all(&temp_dir_path);

let g_err = |e: index_guix::Error| Error::ErrorIteratingLocalProofStore(Box::new((temp_dir_path.into(), e.to_string())));
let g = index_guix::Index::new(temp_dir_path).map_err(g_err)?;

let all = g.list_all().map_err(g_err)?;

let mut audits = BTreeMap::new();
for (category, packages) in all {
for p in packages {
audits.entry(p.name).or_insert_with(Vec::new).push(vet::AuditEntry {
criteria: vec!["safe-to-run"],
aggregated_from: vec![index_guix::GUIX_REPO_URL.to_string()],
notes: Some(format!("Packaged for Guix ({category})")),
delta: None,
version: Some(p.version),
violation: None,
who: vet::StringOrVec::Vec(vec![]),
});
}
}

let audits = vet::AuditsFile {
criteria: Default::default(),
audits,
};

let mut toml = toml_edit::ser::to_string_pretty(&audits)
.map_err(|toml| Error::IO(io::Error::new(io::ErrorKind::Other, toml)))?;

toml.insert_str(0, &format!("# Automatically generated by https://lib.rs/crevette {} from guix repo\n\n", env!("CARGO_PKG_VERSION")));

Ok(toml)
}

pub fn convert_to_document(&self) -> Result<vet::AuditsFile, Error> {
// audits BTreeMap will sort reviews by crate
let mut all = HashMap::new();
Expand Down

0 comments on commit be532d9

Please sign in to comment.