Skip to content

Commit 77bfde0

Browse files
committed
Auto merge of #4293 - Turbo87:spdx, r=ehuss
Replace `license-exprs` crate with `spdx` Resolves #2595 tl;dr you can now use parenthesis (e.g. `X AND (Y OR Z)`) in license expressions. the custom `/` operator is still supported for now, though not directly compatible with the use of parenthesis.
2 parents b78d35c + 87bce69 commit 77bfde0

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

Cargo.lock

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ hyper = { version = "=0.14.16", features = ["client", "http1"] }
6363
indexmap = { version = "=1.7.0", features = ["serde-1"] }
6464
tikv-jemallocator = { version = "=0.4.1", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] }
6565
lettre = { version = "=0.10.0-rc.4", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] }
66-
license-exprs = "=1.6.0"
6766
minijinja = "=0.8.2"
6867
moka = "=0.6.2"
6968
oauth2 = { version = "=4.1.0", default-features = false, features = ["reqwest"] }
@@ -78,6 +77,7 @@ sentry-conduit = { version = "=0.4.0", default-features = false }
7877
serde = { version = "=1.0.131", features = ["derive"] }
7978
serde_json = "=1.0.73"
8079
sha2 = "=0.10.0"
80+
spdx = "=0.8.0"
8181
swirl = { git = "https://github.com/sgrif/swirl.git", rev = "e87cf37" }
8282
tar = "=0.4.38"
8383
tempfile = "=3.2.0"

src/models/version.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,16 @@ impl NewVersion {
189189
}
190190

191191
fn validate_license_expr(s: &str) -> AppResult<()> {
192-
for part in s.split('/') {
193-
license_exprs::validate_license_expr(part).map_err(|e| {
194-
cargo_err(&format_args!("{}; see http://opensource.org/licenses for options, and http://spdx.org/licenses/ for their identifiers", e))
195-
})?;
196-
}
192+
pub const PARSE_MODE: spdx::ParseMode = spdx::ParseMode {
193+
allow_lower_case_operators: false,
194+
allow_slash_as_or_operator: true,
195+
allow_imprecise_license_names: false,
196+
allow_postfix_plus_on_gpl: true,
197+
};
198+
199+
spdx::Expression::parse_mode(s, PARSE_MODE).map_err(|_| {
200+
cargo_err("unknown or invalid license expression; see http://opensource.org/licenses for options, and http://spdx.org/licenses/ for their identifiers")
201+
})?;
197202

198203
Ok(())
199204
}
@@ -277,13 +282,11 @@ mod tests {
277282
assert_ok!(validate_license_expr("MIT OR Apache-2.0"));
278283
assert_ok!(validate_license_expr("MIT/Apache-2.0"));
279284
assert_ok!(validate_license_expr("MIT AND Apache-2.0"));
285+
assert_ok!(validate_license_expr("MIT OR (Apache-2.0 AND MIT)"));
286+
assert_ok!(validate_license_expr("GPL-3.0+"));
280287

281288
let error = assert_err!(validate_license_expr("apache 2.0"));
282289
let error = format!("{}", error);
283-
assert!(error.starts_with("unknown license or other term: apache; see http"));
284-
285-
let error = assert_err!(validate_license_expr("MIT OR (Apache-2.0 AND MIT)"));
286-
let error = format!("{}", error);
287-
assert!(error.starts_with("unknown license or other term: (Apache-2.0; see http"));
290+
assert!(error.starts_with("unknown or invalid license expression; see http"));
288291
}
289292
}

0 commit comments

Comments
 (0)