diff options
-rw-r--r-- | Cargo.lock | 16 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/ebuild.template | 4 | ||||
-rw-r--r-- | src/lib.rs | 22 | ||||
-rw-r--r-- | src/metadata.rs | 16 |
5 files changed, 49 insertions, 10 deletions
@@ -160,6 +160,7 @@ dependencies = [ "cargo 0.37.0 (registry+https://github.com/rust-lang/crates.io-index)", "cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -309,6 +310,11 @@ dependencies = [ ] [[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "env_logger" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -537,6 +543,14 @@ dependencies = [ ] [[package]] +name = "itertools" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "itoa" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1230,6 +1244,7 @@ dependencies = [ "checksum crypto-hash 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca" "checksum curl 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)" = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" "checksum curl-sys 0.4.23 (registry+https://github.com/rust-lang/crates.io-index)" = "f71cd2dbddb49c744c1c9e0b96106f50a634e8759ec51bcd5399a578700a3ab3" +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum env_logger 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" @@ -1254,6 +1269,7 @@ dependencies = [ "checksum ignore 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0ec16832258409d571aaef8273f3c3cc5b060d784e159d1a0f3b0017308f84a7" "checksum im-rc 12.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e882e6e7cd335baacae574b56aa3ce74844ec82fc6777def7c0ac368837dc3d5" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" @@ -32,5 +32,6 @@ maintenance = { status = "passively-maintained" } cargo = "^0.37" cargo_metadata = "^0.9" failure = "^0.1" +itertools = "^0.8" structopt = "^0.3" time = "^0.1" diff --git a/src/ebuild.template b/src/ebuild.template index 37c4433..4e527ae 100644 --- a/src/ebuild.template +++ b/src/ebuild.template @@ -14,7 +14,9 @@ DESCRIPTION="{description}" HOMEPAGE="{homepage}" SRC_URI="$(cargo_crate_uris ${{CRATES}})" RESTRICT="mirror" -LICENSE="{license}" # Update to proper Gentoo format +# License set may be more restrictive as OR is not respected +# use cargo-license for a more accurate license picture +LICENSE="{license}" SLOT="0" KEYWORDS="~amd64" IUSE="" @@ -17,6 +17,7 @@ use cargo::core::Workspace; use cargo::util::{important_paths, CargoResult}; use cargo::{CliResult, Config}; use failure::format_err; +use std::collections::BTreeSet; use std::fs::OpenOptions; use std::io::Write; use std::path::{Path, PathBuf}; @@ -29,6 +30,15 @@ fn workspace(config: &Config, manifest: impl AsRef<Path>) -> CargoResult<Workspa Workspace::new(&root, config) } +fn parse_license<'a>(lic_str: &'a str) -> Vec<&'a str> { + lic_str + .split('/') + .flat_map(|l| l.split(" OR ")) + .flat_map(|l| l.split(" AND ")) + .map(str::trim) + .collect() +} + pub fn run(verbose: u32, quiet: bool, manifest_path: Option<PathBuf>) -> CliResult { let mut cmd = cargo_metadata::MetadataCommand::new(); @@ -41,8 +51,18 @@ pub fn run(verbose: u32, quiet: bool, manifest_path: Option<PathBuf>) -> CliResu .map_err(|e| format_err!("cargo metadata failed: {}", e))?; let mut crates = Vec::with_capacity(metadata.packages.len()); + let mut licenses = BTreeSet::new(); for pkg in metadata.packages { crates.push(format!("{}-{}\n", pkg.name, pkg.version)); + + if let Some(lic_list) = pkg.license.as_ref().map(|l| parse_license(&l)) { + for lic in lic_list.iter() { + licenses.insert(lic.to_string()); + } + } + if pkg.license_file.is_some() { + println!("WARNING: {} uses a license-file, not handled", pkg.name); + } } // sort the crates @@ -72,7 +92,7 @@ pub fn run(verbose: u32, quiet: bool, manifest_path: Option<PathBuf>) -> CliResu let workspace = workspace(&config, &metadata.workspace_root)?; let package = workspace.current()?; - let ebuild_data = EbuildConfig::from_package(package, crates); + let ebuild_data = EbuildConfig::from_package(package, crates, licenses); // build up the ebuild path let ebuild_path = PathBuf::from(format!("{}-{}.ebuild", package.name(), package.version())); diff --git a/src/metadata.rs b/src/metadata.rs index 2caadbe..72ea920 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -9,6 +9,8 @@ */ use cargo::core::Package; +use itertools::Itertools; +use std::collections::BTreeSet; pub struct EbuildConfig { pub inherit: Option<String>, @@ -27,7 +29,11 @@ pub struct EbuildConfig { } impl EbuildConfig { - pub fn from_package(package: &Package, crates: Vec<String>) -> Self { + pub fn from_package( + package: &Package, + crates: Vec<String>, + licenses: BTreeSet<String>, + ) -> Self { // root package metadata let metadata = package.manifest().metadata(); @@ -47,17 +53,11 @@ impl EbuildConfig { .unwrap_or_else(|| String::from("")) }); - let license = metadata - .license - .as_ref() - .cloned() - .unwrap_or_else(|| String::from("unknown license")); - EbuildConfig { inherit: None, homepage, description: desc, - license, + license: licenses.iter().format(" ").to_string(), restrict: None, slot: None, keywords: None, |