aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Goldstein <cardoe@cardoe.com>2020-08-29 08:39:04 -0500
committerGitHub <noreply@github.com>2020-08-29 08:39:04 -0500
commitca7dca9ff92304627dcb5b682b090789cfda95f4 (patch)
tree9a67bbe8af7a2e1372aed6ef12da9c96fd9d1026
parent(cargo-release) start next development iteration 0.3.2-alpha.0 (diff)
parentImplemented automatic lockfile generation (diff)
downloadcargo-ebuild-ca7dca9ff92304627dcb5b682b090789cfda95f4.tar.gz
cargo-ebuild-ca7dca9ff92304627dcb5b682b090789cfda95f4.tar.bz2
cargo-ebuild-ca7dca9ff92304627dcb5b682b090789cfda95f4.zip
Merge pull request #39 from leonardohn/dep-resolution-fix
Fixed dependency resolution using Cargo.lock
-rw-r--r--Cargo.lock146
-rw-r--r--Cargo.toml1
-rw-r--r--README.md139
-rw-r--r--src/lib.rs60
4 files changed, 239 insertions, 107 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 99e27df..bba491d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -24,6 +24,11 @@ dependencies = [
]
[[package]]
+name = "autocfg"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -33,6 +38,7 @@ name = "cargo-ebuild"
version = "0.3.2-alpha.0"
dependencies = [
"anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
+ "cargo-lock 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cargo_metadata 0.9.1 (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.15 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -40,6 +46,19 @@ dependencies = [
]
[[package]]
+name = "cargo-lock"
+version = "4.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gumdrop 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "petgraph 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.112 (registry+https://github.com/rust-lang/crates.io-index)",
+ "toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "cargo_metadata"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -70,6 +89,37 @@ version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "fixedbitset"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "gumdrop"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "gumdrop_derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "gumdrop_derive"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -86,6 +136,25 @@ dependencies = [
]
[[package]]
+name = "idna"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "indexmap"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "hashbrown 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "itertools"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -109,6 +178,25 @@ version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "matches"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "percent-encoding"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "petgraph"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "fixedbitset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "indexmap 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "proc-macro-error"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -171,6 +259,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "serde"
version = "1.0.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde_derive 1.0.112 (registry+https://github.com/rust-lang/crates.io-index)",
+]
[[package]]
name = "serde_derive"
@@ -257,6 +348,35 @@ dependencies = [
]
[[package]]
+name = "tinyvec"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "toml"
+version = "0.5.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.112 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-bidi"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "unicode-normalization"
+version = "0.1.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -272,6 +392,16 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "url"
+version = "2.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -304,16 +434,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f"
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
+"checksum cargo-lock 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8504b63dd1249fd1745b7b4ef9b6f7b107ddeb3c95370043c7dbcc38653a2679"
"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
+"checksum fixedbitset 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
+"checksum gumdrop 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee50908bc1beeac1f2902e0b4e0cd0d844e716f5ebdc6f0cfc1163fe5e10bcde"
+"checksum gumdrop_derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "90454ce4de40b7ca6a8968b5ef367bdab48413962588d0d2b1638d60090c35d7"
+"checksum hashbrown 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hermit-abi 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909"
+"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
+"checksum indexmap 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7"
"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484"
"checksum itoa 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)" = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
+"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
+"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
+"checksum petgraph 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
"checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
@@ -331,9 +472,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
"checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
+"checksum tinyvec 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed"
+"checksum toml 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
+"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
+"checksum unicode-normalization 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977"
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
+"checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb"
"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
"checksum version_check 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
diff --git a/Cargo.toml b/Cargo.toml
index 21adbcc..e579d5a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,6 +30,7 @@ maintenance = { status = "passively-maintained" }
[dependencies]
anyhow = "^1"
+cargo-lock = "^4.0"
cargo_metadata = "^0.9"
itertools = "^0.8"
structopt = "^0.3"
diff --git a/README.md b/README.md
index 8e6b775..a860667 100644
--- a/README.md
+++ b/README.md
@@ -34,120 +34,67 @@ ebuild for that crate.
```bash
$ git clone https://github.com/cardoe/cargo-ebuild.git
$ cd cargo-ebuild
-$ git checkout 0.1.5
+$ git checkout v0.3.0
$ cargo ebuild
-$ cat cargo-ebuild-0.1.5.ebuild
+$ cat cargo-ebuild-0.3.0.ebuild
```
```ebuild
-# Copyright 2017-2017 Gentoo Foundation
+# Copyright 2017-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
-# Auto-Generated by cargo-ebuild 0.1.5
+# Auto-Generated by cargo-ebuild 0.3.0
-EAPI=6
+EAPI=7
CRATES="
-advapi32-sys-0.2.0
-aho-corasick-0.6.3
-atty-0.2.3
-backtrace-0.3.3
-backtrace-sys-0.1.16
-bitflags-0.7.0
-bitflags-0.8.2
-cargo-0.21.1
-cargo-ebuild-0.1.5
-cc-1.0.3
-cfg-if-0.1.0
-cmake-0.1.22
-crates-io-0.10.0
-crossbeam-0.2.10
-curl-0.4.6
-curl-sys-0.3.10
-dbghelp-sys-0.2.0
-docopt-0.8.1
-dtoa-0.4.2
-env_logger-0.4.3
-error-chain-0.11.0
-filetime-0.1.10
-flate2-0.2.19
-foreign-types-0.2.0
-fs2-0.4.2
-gcc-0.3.45
-gdi32-sys-0.2.0
-git2-0.6.4
-git2-curl-0.7.0
-glob-0.2.11
-hex-0.2.0
-idna-0.1.1
-itoa-0.3.4
-jobserver-0.1.8
-kernel32-sys-0.2.2
-lazy_static-0.2.8
-libc-0.2.21
-libgit2-sys-0.6.7
-libssh2-sys-0.2.5
-libz-sys-1.0.13
-log-0.3.7
-matches-0.1.4
-memchr-1.0.2
-miniz-sys-0.1.9
-miow-0.2.1
-net2-0.2.27
-num-traits-0.1.40
-num_cpus-1.3.0
-openssl-0.9.11
-openssl-probe-0.1.1
-openssl-sys-0.9.11
-pkg-config-0.3.9
-psapi-sys-0.1.0
-quote-0.3.15
-rand-0.3.15
-redox_syscall-0.1.17
-redox_termios-0.1.1
-regex-0.2.2
-regex-syntax-0.4.1
-rustc-demangle-0.1.5
-scoped-tls-0.1.0
-semver-0.7.0
+ansi_term-0.11.0
+anyhow-1.0.26
+atty-0.2.13
+bitflags-1.2.0
+cargo_metadata-0.9.1
+clap-2.33.0
+either-1.5.3
+heck-0.3.1
+itertools-0.8.2
+itoa-0.4.4
+libc-0.2.62
+proc-macro-error-0.2.6
+proc-macro2-1.0.5
+quote-1.0.2
+redox_syscall-0.1.56
+ryu-1.0.0
+semver-0.9.0
semver-parser-0.7.0
-serde-1.0.16
-serde_derive-1.0.16
-serde_derive_internals-0.16.0
-serde_ignored-0.0.3
-serde_json-1.0.5
-shell-escape-0.1.3
-strsim-0.6.0
-syn-0.11.11
-synom-0.11.3
-tar-0.4.11
-tempdir-0.3.5
-termcolor-0.3.3
-termion-1.5.1
-thread_local-0.3.4
-time-0.1.36
-toml-0.4.5
-unicode-bidi-0.2.5
-unicode-normalization-0.1.4
-unicode-xid-0.0.4
-unreachable-1.0.0
-url-1.4.0
-user32-sys-0.2.0
-utf8-ranges-1.0.0
-void-1.0.2
-winapi-0.2.8
-winapi-build-0.1.1
-wincolor-0.1.4
-ws2_32-sys-0.2.1
+serde-1.0.101
+serde_derive-1.0.101
+serde_json-1.0.41
+strsim-0.8.0
+structopt-0.3.3
+structopt-derive-0.3.3
+syn-1.0.5
+textwrap-0.11.0
+time-0.1.42
+unicode-segmentation-1.3.0
+unicode-width-0.1.6
+unicode-xid-0.2.0
+vec_map-0.8.1
+winapi-0.3.8
+winapi-i686-pc-windows-gnu-0.4.0
+winapi-x86_64-pc-windows-gnu-0.4.0
"
inherit cargo
DESCRIPTION="Generates an ebuild for a package using the in-tree eclasses."
+# Double check the homepage as the cargo_metadata crate
+# does not provide this value so instead repository is used
HOMEPAGE="https://github.com/cardoe/cargo-ebuild"
SRC_URI="$(cargo_crate_uris ${CRATES})"
RESTRICT="mirror"
-LICENSE="MIT/Apache-2.0" # 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="Apache-2.0 BSL-1.0 MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""
diff --git a/src/lib.rs b/src/lib.rs
index 2ee9cf3..b6243bc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,10 +11,13 @@
mod metadata;
use anyhow::{format_err, Context, Result};
+use cargo_lock::Lockfile;
+use cargo_metadata::MetadataCommand;
use std::collections::BTreeSet;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::{Path, PathBuf};
+use std::process::Command;
use metadata::EbuildConfig;
@@ -27,10 +30,33 @@ fn parse_license<'a>(lic_str: &'a str) -> Vec<&'a str> {
.collect()
}
+fn generate_lockfile(manifest_path: Option<PathBuf>) -> Result<()> {
+ let cargo = std::env::var("CARGO")
+ .map(PathBuf::from)
+ .unwrap_or_else(|_| PathBuf::from("cargo"));
+
+ let mut lock_cmd = Command::new(cargo);
+ lock_cmd.arg("generate-lockfile");
+
+ if let Some(path) = manifest_path.as_ref() {
+ lock_cmd.arg("--manifest-path");
+ lock_cmd.arg(path.as_os_str());
+ }
+
+ let lock_output = lock_cmd.output()?;
+
+ if !lock_output.status.success() {
+ let stderr = String::from_utf8_lossy(&lock_output.stderr);
+ return Err(format_err!("unable to generate lockfile:\n{}", stderr));
+ }
+
+ Ok(())
+}
+
pub fn gen_ebuild_data(manifest_path: Option<PathBuf>) -> Result<EbuildConfig> {
- let mut cmd = cargo_metadata::MetadataCommand::new();
+ let mut cmd = MetadataCommand::new();
- if let Some(path) = manifest_path {
+ if let Some(path) = manifest_path.as_ref() {
cmd.manifest_path(path);
}
@@ -42,30 +68,27 @@ pub fn gen_ebuild_data(manifest_path: Option<PathBuf>) -> Result<EbuildConfig> {
.resolve
.as_ref()
.ok_or_else(|| format_err!("cargo metadata did not resolve the depend graph"))?;
+
let root = resolve
.root
.as_ref()
.ok_or_else(|| format_err!("cargo metadata failed to resolve the root package"))?;
- let mut crates = Vec::with_capacity(metadata.packages.len());
let mut licenses = BTreeSet::new();
+ let mut crates = Vec::new();
let mut root_pkg = None;
+
for pkg in metadata.packages {
if &pkg.id == root {
root_pkg = Some(pkg.clone());
}
- if let Some(src) = pkg.source {
- if src.is_crates_io() {
- 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);
}
@@ -74,8 +97,23 @@ pub fn gen_ebuild_data(manifest_path: Option<PathBuf>) -> Result<EbuildConfig> {
let root_pkg = root_pkg
.ok_or_else(|| format_err!("unable to determine package to generate ebuild for"))?;
- // sort the crates
- crates.sort();
+ let lockfile_path = metadata.workspace_root.join("Cargo.lock");
+
+ // Generate lockfile if it doesn't exists
+ if std::fs::metadata(&lockfile_path).is_err() {
+ generate_lockfile(manifest_path)?;
+ }
+
+ // Check for packages that must be fetched from default registry
+ let lockfile = Lockfile::load(lockfile_path)?;
+
+ for pkg in lockfile.packages {
+ if let Some(src) = pkg.source {
+ if src.is_default_registry() {
+ crates.push(format!("{}-{}\n", pkg.name, pkg.version));
+ }
+ }
+ }
Ok(EbuildConfig::from_package(root_pkg, crates, licenses))
}