Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cargo-sbom/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ struct Opt {

fn main() {
if let Err(err) = try_main() {
eprintln!("ERROR: {}", err);
eprintln!("ERROR: {err}");
err
.chain()
.skip(1)
.for_each(|cause| eprintln!("because: {}", cause));
.for_each(|cause| eprintln!("because: {cause}"));
std::process::exit(1);
}
}
Expand Down
23 changes: 18 additions & 5 deletions cargo-sbom/src/util/spdx/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn normalize_license_string<S: AsRef<str> + ToString>(
for node in license_expr.iter() {
match node {
spdx::expression::ExprNode::Req(req) => {
string_stack.push(req.req.license.to_string());
string_stack.push(req.req.to_string());
op_stack.push(None);
}
spdx::expression::ExprNode::Op(spdx::expression::Operator::Or) => {
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn normalize_license_string<S: AsRef<str> + ToString>(
})?;

op_stack.push(Some(spdx::expression::Operator::Or));
string_stack.push(format!("{} OR {}", b, a));
string_stack.push(format!("{b} OR {a}"));
}
spdx::expression::ExprNode::Op(spdx::expression::Operator::And) => {
let mut a = string_stack.pop().ok_or_else(|| {
Expand Down Expand Up @@ -81,14 +81,14 @@ pub fn normalize_license_string<S: AsRef<str> + ToString>(

// AND takes precedence, so parenthesize the OR expressions before applying AND
if matches!(a_op, Some(spdx::expression::Operator::Or)) {
a = format!("({})", a);
a = format!("({a})");
}
if matches!(b_op, Some(spdx::expression::Operator::Or)) {
b = format!("({})", b);
b = format!("({b})");
}

op_stack.push(Some(spdx::expression::Operator::And));
string_stack.push(format!("{} AND {}", b, a));
string_stack.push(format!("{b} AND {a}"));
}
}
}
Expand All @@ -104,6 +104,19 @@ pub fn normalize_license_string<S: AsRef<str> + ToString>(
mod tests {
use super::*;

#[test]
fn test_exceptions() {
assert_eq!(
normalize_license_string("Apache-2.0 WITH LLVM-exception").unwrap(),
"Apache-2.0 WITH LLVM-exception"
);

assert_eq!(
normalize_license_string("Apache-2.0 WITH LLVM-exception/MIT").unwrap(),
"Apache-2.0 WITH LLVM-exception OR MIT"
);
}

#[test]
fn test_quotation() {
assert_eq!(
Expand Down
5 changes: 1 addition & 4 deletions cargo-sbom/src/util/spdx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ pub fn convert(
.spdxid("SPDXRef-DOCUMENT")
.creation_info(creation_info)
.data_license("CC0-1.0")
.document_namespace(format!(
"https://spdx.org/spdxdocs/{}-{}",
name, uuid
))
.document_namespace(format!("https://spdx.org/spdxdocs/{name}-{uuid}"))
.files(files)
.name(name)
.spdx_version("SPDX-2.3")
Expand Down
9 changes: 3 additions & 6 deletions serde-cyclonedx/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,8 @@ fn process_token_stream(input: proc_macro2::TokenStream) -> syn::File {
}

fn generate_schema(version_str: &str) -> Result<()> {
println!(
"cargo:rerun-if-changed=schemas/cyclonedx_{}.json",
version_str
);
let path_str = format!("schemas/cyclonedx_{}.json", version_str);
println!("cargo:rerun-if-changed=schemas/cyclonedx_{version_str}.json",);
let path_str = format!("schemas/cyclonedx_{version_str}.json",);
let path = Path::new(&path_str);

// Generate the Rust schema struct
Expand All @@ -105,7 +102,7 @@ fn generate_schema(version_str: &str) -> Result<()> {
// Write the struct to the $OUT_DIR/cyclonedx.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut file =
File::create(out_path.join(format!("cyclonedx_{}.rs", version_str)))?;
File::create(out_path.join(format!("cyclonedx_{version_str}.rs",)))?;
file.write_all(prettyplease::unparse(&generated).as_bytes())?;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions serde-spdx/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ fn process_token_stream(input: proc_macro2::TokenStream) -> syn::File {
}

fn generate_schema(version_str: &str) -> Result<()> {
println!("cargo:rerun-if-changed=schemas/spdx_{}.json", version_str);
let path_str = format!("schemas/spdx_{}.json", version_str);
println!("cargo:rerun-if-changed=schemas/spdx_{version_str}.json",);
let path_str = format!("schemas/spdx_{version_str}.json",);
let path = Path::new(&path_str);

// Generate the Rust schema struct
Expand All @@ -91,7 +91,7 @@ fn generate_schema(version_str: &str) -> Result<()> {
// Write the struct to the $OUT_DIR/spdx.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut file =
File::create(out_path.join(format!("spdx_{}.rs", version_str)))?;
File::create(out_path.join(format!("spdx_{version_str}.rs",)))?;
file.write_all(prettyplease::unparse(&generated).as_bytes())?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions tests/examples_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn test_cargo_binary_cyclonedx_1_6_example() -> Result<()> {
// Ensure we have components and metadata
assert!(output_sbom.components.is_some());
assert!(output_sbom.metadata.is_some());
assert!(output_sbom.components.unwrap().len() > 0);
assert!(!output_sbom.components.unwrap().is_empty());

Ok(())
}
Expand Down Expand Up @@ -177,7 +177,7 @@ fn test_cargo_binary_cyclonedx_1_5_example() -> Result<()> {
// Ensure we have components and metadata
assert!(output_sbom.components.is_some());
assert!(output_sbom.metadata.is_some());
assert!(output_sbom.components.unwrap().len() > 0);
assert!(!output_sbom.components.unwrap().is_empty());

Ok(())
}
Loading