Skip to content

Commit

Permalink
Remove online build
Browse files Browse the repository at this point in the history
  • Loading branch information
evenorog committed Apr 13, 2024
1 parent 333d3fd commit 50d095c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 60 deletions.
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ categories = ["no-std"]
exclude = ["/license-list-data", "!/license-list-data/json"]
edition = "2021"

[features]
default = []
offline = []

[dependencies]
serde = { version = "1", default-features = false, optional = true }

Expand All @@ -29,6 +25,3 @@ serde_json = "1"

[badges]
maintenance = { status = "actively-developed" }

[package.metadata.docs.rs]
features = ["offline"]
67 changes: 18 additions & 49 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::error::Error;
use std::fs::{self, File};
use std::io::{BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::process::Command;

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -60,54 +59,6 @@ impl Exception {
}
}

fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);
let licenses_output = out_dir.join("licenses.rs");
let exceptions_output = out_dir.join("exceptions.rs");

if cfg!(feature = "offline") {
// If unable to clone the latest version from git we use the offline files.
build_licenses_from_json(
Path::new("license-list-data/json/details"),
&licenses_output,
)
.unwrap();
build_exceptions_from_json(
Path::new("license-list-data/json/exceptions"),
&exceptions_output,
)
.unwrap();
} else {
let json_dir = Path::new(&out_dir).join("license-list-data/json");

if json_dir.exists() {
build_licenses_from_json(&json_dir.join("details"), &licenses_output).unwrap();
build_exceptions_from_json(&json_dir.join("exceptions"), &exceptions_output).unwrap();
} else {
let status = Command::new("git")
.arg("clone")
.arg("--depth")
.arg("1")
.arg("https://github.com/spdx/license-list-data.git")
.current_dir(&out_dir)
.status()
.expect("`git` not found");

if status.success() {
build_licenses_from_json(&json_dir.join("details"), &licenses_output).unwrap();
build_exceptions_from_json(&json_dir.join("exceptions"), &exceptions_output)
.unwrap();
} else {
match status.code() {
Some(code) => panic!("`git clone --depth 1` failed with exit code `{}`", code),
None => panic!("`git clone --depth 1` was terminated by signal"),
}
}
}
}
}

fn build_licenses_from_json(input: &Path, output: &Path) -> Result<(), Box<dyn Error>> {
let inner = File::create(output)?;
let mut f = BufWriter::with_capacity(4_194_304, inner);
Expand Down Expand Up @@ -190,5 +141,23 @@ fn build_exceptions_from_json(input: &Path, output: &Path) -> Result<(), Box<dyn
see_also = exception.see_also,
)?;
}

Ok(())
}

fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);

build_licenses_from_json(
Path::new("license-list-data/json/details"),
&out_dir.join("licenses.rs"),
)
.expect("failed to build licenses.rs");

build_exceptions_from_json(
Path::new("license-list-data/json/exceptions"),
&out_dir.join("exceptions.rs"),
)
.expect("failed to build exceptions.rs");
}
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
//! assert_eq!(gcc.name(), "GCC Runtime Library exception 3.1");
//! ```
//!
//! By default, this library downloads the latest licenses from
//! [github.com/spdx](https://github.com/spdx/license-list-data.git).
//! If you want to build it offline instead, you can enable the `offline` feature.
//!
//! [Serde](https://crates.io/crates/serde) is supported with the `serde` feature.
#![no_std]
Expand Down

0 comments on commit 50d095c

Please sign in to comment.