1use anyhow::Result;
2use serde::{Deserialize, Serialize};
3use std::collections::{HashMap, HashSet};
4use std::fs::{File, OpenOptions};
5use std::path::{Path, PathBuf};
6
7pub mod cargo;
8pub mod git;
9
10pub const GITIGNORE: &str = "audit_build.log";
11pub const JSON_CACHE: &str = "trust_store.json";
12
13pub fn log_file(repo_root: &Path) -> Result<File> {
15 Ok(OpenOptions::new()
16 .create(true)
17 .append(true)
18 .open(repo_root.join("audit_build.log"))?)
19}
20
21pub fn repository() -> Result<PathBuf> {
23 Ok(home::cargo_home()?.join("audits").join("build_scripts"))
24}
25
26#[derive(Default, Debug, Serialize, Deserialize)]
27pub struct BuildTrustStore(pub HashMap<String, (bool, HashSet<String>)>);
28
29#[derive(Debug, Serialize, Deserialize)]
30pub struct Metadata {
31 pub packages: Vec<PackageMetadata>,
32}
33
34#[derive(Debug, Serialize, Deserialize)]
35pub struct PackageMetadata {
36 pub name: String,
37 pub version: String,
38 pub targets: Vec<PackageTarget>,
39}
40
41impl PackageMetadata {
42 pub fn build_script(&self) -> PathBuf {
43 self.targets
44 .iter()
45 .find_map(|t| {
46 if t.kind.contains(&"custom-build".to_owned()) {
47 Some(PathBuf::from(&t.src_path))
48 } else {
49 None
50 }
51 })
52 .expect("to find build script in src_path")
53 }
54}
55
56#[derive(Debug, Serialize, Deserialize)]
57pub struct PackageTarget {
58 pub kind: Vec<String>,
59 pub src_path: String,
60}