Skip to content

Commit

Permalink
Generate license cache at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroto committed Nov 4, 2019
1 parent dd1e480 commit a1243fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# nix result from nix-build
result

# generated license cache
resources/licenses/cache.bin.gz
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ strum = "0.16.0"
strum_macros = "0.16.0"
image = "0.22.3"

[build-dependencies]
askalono = "0.3.0"

[target.'cfg(windows)'.dependencies]
ansi_term = "0.12"

Expand Down
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extern crate askalono;

use std::fs::File;
use std::path::Path;

use askalono::Store;

const EMBEDDED_CACHE: &str = "resources/licenses/cache.bin.gz";

fn main() {
if Path::new(EMBEDDED_CACHE).exists() {
println!("cargo:warning=onefetch license cache file already exists; not re-building");
return;
}

let mut store = Store::new();
store
.load_spdx(Path::new("resources/licenses/spdx/json/details"), false)
.expect("Couldn't create a store from SPDX data");

let mut cache = File::create(EMBEDDED_CACHE).unwrap();
store.to_cache(&mut cache).unwrap();
}
Binary file removed resources/license-cache.bin.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::Error;

type Result<T> = std::result::Result<T, Error>;

static CACHE_DATA: &[u8] = include_bytes!("../resources/license-cache.bin.gz");
static CACHE_DATA: &[u8] = include_bytes!("../resources/licenses/cache.bin.gz");

pub struct Detector {
store: Store,
Expand Down

0 comments on commit a1243fa

Please sign in to comment.