Skip to content

Commit

Permalink
Don't panic on unrecognised licences (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Apr 13, 2021
1 parent 1edfb53 commit a975c2e
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions impl/src/planning/license.rs
Expand Up @@ -16,7 +16,7 @@ use crate::context::LicenseData;

use spdx::{
expression::{ExprNode, Operator},
Expression,
Expression, LicenseItem,
};

// KEEP ORDERED: The order dictates the preference.
Expand Down Expand Up @@ -155,13 +155,22 @@ pub fn get_license_from_str(cargo_license_str: &str) -> LicenseData {
},
ExprNode::Req(requirement) => {
// Unwrap is safe because there was no parse error so the license type must exist
let req_name = requirement.req.license.id().unwrap().name;
// Push requirement onto stack
license_stack.push(BazelSpdxLicense {
name: req_name.into(),
expression: req_name.into(),
license: get_bazel_license_type(&req_name),
});
match &requirement.req.license {
LicenseItem::SPDX { id, .. } => {
let req_name = id.name;
// Push requirement onto stack
license_stack.push(BazelSpdxLicense {
name: req_name.into(),
expression: req_name.into(),
license: get_bazel_license_type(&req_name),
});
}
LicenseItem::Other { lic_ref, .. } => license_stack.push(BazelSpdxLicense {
name: lic_ref.clone(),
expression: lic_ref.clone(),
license: BazelLicenseType::Restricted,
}),
}
}
};
}
Expand Down

0 comments on commit a975c2e

Please sign in to comment.