aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDoug Goldstein <cardoe@cardoe.com>2019-12-23 20:21:08 -0600
committerDoug Goldstein <cardoe@cardoe.com>2020-01-26 09:20:17 -0600
commitbf34b38ed191c9ecb6d405f372e6ccb4d0625cb2 (patch)
treec9ef4daac86f196ef3bb572b67314e91f7a4ae41 /src
parentswitch to cargo_metadata for dep info (diff)
downloadcargo-ebuild-bf34b38ed191c9ecb6d405f372e6ccb4d0625cb2.tar.gz
cargo-ebuild-bf34b38ed191c9ecb6d405f372e6ccb4d0625cb2.tar.bz2
cargo-ebuild-bf34b38ed191c9ecb6d405f372e6ccb4d0625cb2.zip
include license info for depends
Since dependencies are compiled into the final binary, those licenses must be included in the ebuild generated by the tool. Gather up the licenses from each of the dependencies and include them in an AND pattern since computing the OR pattern as well is a bit more effort but this is an improvement.
Diffstat (limited to 'src')
-rw-r--r--src/ebuild.template4
-rw-r--r--src/lib.rs22
-rw-r--r--src/metadata.rs16
3 files changed, 32 insertions, 10 deletions
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=""
diff --git a/src/lib.rs b/src/lib.rs
index 3258dbc..2699cbb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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,