diff options
author | Doug Goldstein <cardoe@cardoe.com> | 2018-08-25 12:36:38 -0500 |
---|---|---|
committer | Doug Goldstein <cardoe@cardoe.com> | 2018-08-26 17:05:06 -0500 |
commit | a7d158dc07f8c5bdf0ab14bbecadb632c5ef7c4b (patch) | |
tree | bd46400827dfa79c947d23e73ead6d7ed67687e1 | |
parent | add ebuild specific metadata to the Cargo.toml (diff) | |
download | cargo-ebuild-a7d158dc07f8c5bdf0ab14bbecadb632c5ef7c4b.tar.gz cargo-ebuild-a7d158dc07f8c5bdf0ab14bbecadb632c5ef7c4b.tar.bz2 cargo-ebuild-a7d158dc07f8c5bdf0ab14bbecadb632c5ef7c4b.zip |
split metadata parsing and ebuild generation
Split away the metadata parsing into its own module.
-rw-r--r-- | src/lib.rs | 37 | ||||
-rw-r--r-- | src/metadata.rs | 72 |
2 files changed, 81 insertions, 28 deletions
@@ -11,6 +11,8 @@ extern crate cargo; extern crate time; +mod metadata; + use cargo::core::registry::PackageRegistry; use cargo::core::resolver::Method; use cargo::core::{Package, PackageSet, Resolve, Workspace}; @@ -21,6 +23,8 @@ use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; +use metadata::EbuildConfig; + /// Finds the root Cargo.toml of the workspace fn workspace(config: &Config, manifest_path: Option<String>) -> CargoResult<Workspace> { let root = important_paths::find_root_manifest_for_wd(manifest_path, config.cwd())?; @@ -92,30 +96,7 @@ pub fn run(verbose: u32, quiet: bool) -> CliResult { // sort the crates crates.sort(); - // root package metadata - let metadata = package.manifest().metadata(); - - // package description - let desc = metadata - .description - .as_ref() - .cloned() - .unwrap_or_else(|| String::from(package.name())); - - // package homepage - let homepage = metadata.homepage.as_ref().cloned().unwrap_or( - metadata - .repository - .as_ref() - .cloned() - .unwrap_or_else(|| String::from("")), - ); - - let license = metadata - .license - .as_ref() - .cloned() - .unwrap_or_else(|| String::from("unknown license")); + let ebuild_data = EbuildConfig::from_package(package, crates); // build up the ebuild path let ebuild_path = PathBuf::from(format!("{}-{}.ebuild", package.name(), package.version())); @@ -132,10 +113,10 @@ pub fn run(verbose: u32, quiet: bool) -> CliResult { write!( file, include_str!("ebuild.template"), - description = desc.trim(), - homepage = homepage.trim(), - license = license.trim(), - crates = crates.join(""), + description = ebuild_data.description.trim(), + homepage = ebuild_data.homepage.trim(), + license = ebuild_data.license.trim(), + crates = ebuild_data.crates.join(""), cargo_ebuild_ver = env!("CARGO_PKG_VERSION"), this_year = 1900 + time::now().tm_year, ).chain_err(|| "unable to write ebuild to disk")?; diff --git a/src/metadata.rs b/src/metadata.rs new file mode 100644 index 0000000..d81b6c0 --- /dev/null +++ b/src/metadata.rs @@ -0,0 +1,72 @@ +/* + * Copyright 2016-2018 Doug Goldstein <cardoe@cardoe.com> + * + * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or + * http://www.apache.org/licenses/LICENSE-2.0> or the MIT license + * <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your + * option. This file may not be copied, modified, or distributed + * except according to those terms. + */ + +use cargo::core::Package; + +pub struct EbuildConfig { + pub inherit: Option<String>, + pub homepage: String, + pub description: String, + pub license: String, + pub restrict: Option<String>, + pub slot: Option<String>, + pub keywords: Option<String>, + pub iuse: Option<String>, + pub depend: Option<String>, + pub rdepend: Option<String>, + pub pdepend: Option<String>, + pub depend_is_rdepend: bool, + pub crates: Vec<String>, +} + +impl EbuildConfig { + pub fn from_package(package: &Package, crates: Vec<String>) -> Self { + // root package metadata + let metadata = package.manifest().metadata(); + + // package description + let desc = metadata + .description + .as_ref() + .cloned() + .unwrap_or_else(|| String::from(package.name())); + + // package homepage + let homepage = metadata.homepage.as_ref().cloned().unwrap_or( + metadata + .repository + .as_ref() + .cloned() + .unwrap_or_else(|| String::from("")), + ); + + let license = metadata + .license + .as_ref() + .cloned() + .unwrap_or_else(|| String::from("unknown license")); + + EbuildConfig { + inherit: None, + homepage: homepage, + description: desc, + license: license, + restrict: None, + slot: None, + keywords: None, + iuse: None, + depend: None, + rdepend: None, + pdepend: None, + depend_is_rdepend: true, + crates: crates, + } + } +} |