From 13dedab2049ce03b8e0d952e52b2c25ba493b1a5 Mon Sep 17 00:00:00 2001 From: Stu Date: Sun, 4 Oct 2020 09:40:00 +0200 Subject: [PATCH] Implement standalone feature (#243) --- .github/workflows/ci.yaml | 2 +- Cargo.lock | 535 +++++++++++++++++++++++++++++++++++++- Cargo.toml | 2 + README.md | 4 + src/cargo-deny/common.rs | 91 +++++-- 5 files changed, 611 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0caa5a70..e62c7d71 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -100,7 +100,7 @@ jobs: # Also, build and run with musl, this lets us ensure that # musl still works, which is important for the linux binaries # we release, but wasn't exercised until now - args: --path . --debug --target ${{ matrix.target }} + args: --path . --debug --target ${{ matrix.target }} --features standalone - name: self check uses: actions-rs/cargo@v1 with: diff --git a/Cargo.lock b/Cargo.lock index 4d462461..ec925891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -103,6 +103,15 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + [[package]] name = "bitvec" version = "0.17.4" @@ -113,12 +122,88 @@ dependencies = [ "radium", ] +[[package]] +name = "bstr" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31accafdb70df7871592c058eca3985b71104e15ac32f64706022c58867da931" +dependencies = [ + "memchr", +] + [[package]] name = "byteorder" version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" +[[package]] +name = "bytesize" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a18687293a1546b67c246452202bbbf143d239cb43494cc163da14979082da" + +[[package]] +name = "cargo" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd9c4b3682fcfa94d46cca36d93c93d068cd83a025b64d4bbb3fd7389a8b3d8c" +dependencies = [ + "anyhow", + "atty", + "bytesize", + "cargo-platform", + "clap", + "core-foundation", + "crates-io", + "crossbeam-utils", + "crypto-hash", + "curl", + "curl-sys", + "env_logger", + "filetime", + "flate2", + "fwdansi", + "git2", + "git2-curl", + "glob", + "hex 0.4.2", + "home", + "humantime 2.0.1", + "ignore", + "im-rc", + "jobserver", + "lazy_static", + "lazycell", + "libc", + "libgit2-sys", + "log", + "memchr", + "miow", + "num_cpus", + "opener", + "percent-encoding", + "remove_dir_all", + "rustc-workspace-hack", + "rustfix", + "same-file", + "semver 0.10.0", + "serde", + "serde_ignored", + "serde_json", + "shell-escape", + "strip-ansi-escapes", + "tar", + "tempfile", + "termcolor", + "toml", + "unicode-width", + "unicode-xid", + "url", + "walkdir", + "winapi", +] + [[package]] name = "cargo-deny" version = "0.7.3" @@ -128,6 +213,7 @@ dependencies = [ "askalono", "atty", "bitvec", + "cargo", "chrono", "clap", "codespan", @@ -167,6 +253,15 @@ dependencies = [ "url", ] +[[package]] +name = "cargo-platform" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0226944a63d1bf35a3b5f948dd7c59e263db83695c9e8bffc4037de02e30f1d7" +dependencies = [ + "serde", +] + [[package]] name = "cargo_metadata" version = "0.11.1" @@ -249,6 +344,40 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "commoncrypto" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007" +dependencies = [ + "commoncrypto-sys", +] + +[[package]] +name = "commoncrypto-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2" +dependencies = [ + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" + [[package]] name = "crates-index" version = "0.15.0" @@ -257,7 +386,7 @@ checksum = "15467291e8911aa3e73b0e77d988362da1df7ac974c7189ab38b94b6f7edfa7e" dependencies = [ "git2", "glob", - "hex", + "hex 0.4.2", "home", "serde", "serde_derive", @@ -265,6 +394,30 @@ dependencies = [ "smol_str", ] +[[package]] +name = "crates-io" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f977948a46e9edf93eb3dc2d7a8dd4ce3105d36de63300befed37cdf051d4a" +dependencies = [ + "anyhow", + "curl", + "percent-encoding", + "serde", + "serde_derive", + "serde_json", + "url", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam" version = "0.7.3" @@ -337,6 +490,49 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-hash" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a77162240fd97248d19a564a565eb563a3f592b386e4136fb300909e67dddca" +dependencies = [ + "commoncrypto", + "hex 0.3.2", + "openssl", + "winapi", +] + +[[package]] +name = "curl" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9447ad28eee2a5cfb031c329d46bef77487244fff6a724b378885b8691a35f78" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.34+curl-7.71.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4eff0be6985b7e709f64b5a541f700e9ad1407190a29f4884319eb663ed1d6" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + [[package]] name = "cvss" version = "1.0.0" @@ -358,6 +554,19 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd56b59865bce947ac5958779cfa508f6c3b9497cc762b7e24a12d11ccde2c4f" +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + [[package]] name = "failure" version = "0.1.8" @@ -389,12 +598,68 @@ dependencies = [ "log", ] +[[package]] +name = "filetime" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed85775dcc68644b5c950ac06a2b23768d3bc9390464151aaf27136998dcf9e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "fixedbitset" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" +[[package]] +name = "flate2" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" +dependencies = [ + "cfg-if", + "crc32fast", + "libc", + "libz-sys", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "fwdansi" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c1f5787fe85505d1f7777268db5103d80a7a374d2316a7ce262e57baf8f208" +dependencies = [ + "memchr", + "termcolor", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -427,12 +692,37 @@ dependencies = [ "url", ] +[[package]] +name = "git2-curl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502d532a2d06184beb3bc869d4d90236e60934e3382c921b203fa3c33e212bd7" +dependencies = [ + "curl", + "git2", + "log", + "url", +] + [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "globset" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ad1da430bd7281dde2576f44c84cc3f0f7b475e7202cd503042dff01a8c8120" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + [[package]] name = "hashbrown" version = "0.8.2" @@ -460,6 +750,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + [[package]] name = "hex" version = "0.4.2" @@ -478,6 +774,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "humantime" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" + [[package]] name = "idna" version = "0.2.0" @@ -489,6 +800,38 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "ignore" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22dcbf2a4a289528dbef21686354904e1c694ac642610a9bff9e7df730d9ec72" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "im-rc" +version = "15.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ca8957e71f04a205cb162508f9326aea04676c8dfd0711220190d6b83664f3f" +dependencies = [ + "bitmaps", + "rand_core", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", +] + [[package]] name = "indexmap" version = "1.5.1" @@ -541,6 +884,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" + [[package]] name = "libc" version = "0.2.76" @@ -561,6 +910,16 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libnghttp2-sys" +version = "0.1.4+1.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03624ec6df166e79e139a2310ca213283d6b3c30810c54844f307086d4488df1" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "libssh2-sys" version = "0.2.19" @@ -632,6 +991,16 @@ dependencies = [ "adler", ] +[[package]] +name = "miow" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b88fb9795d4d36d62a012dfbf49a8f5cf12751f36d31a9dbe66d528e58979e" +dependencies = [ + "socket2", + "winapi", +] + [[package]] name = "num-integer" version = "0.1.43" @@ -667,6 +1036,29 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" +[[package]] +name = "opener" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13117407ca9d0caf3a0e74f97b490a7e64c0ae3aa90a8b7085544d0c37b6f3ae" +dependencies = [ + "winapi", +] + +[[package]] +name = "openssl" +version = "0.10.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d575eff3665419f9b83678ff2815858ad9d11567e082f5ac1814baba4e2bcb4" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "lazy_static", + "libc", + "openssl-sys", +] + [[package]] name = "openssl-probe" version = "0.1.2" @@ -766,6 +1158,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.7" @@ -822,6 +1220,15 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rand_xoshiro" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9fcdd2e881d02f1d9390ae47ad8e5696a9e4be7b547a1da2afbc61973217004" +dependencies = [ + "rand_core", +] + [[package]] name = "rayon" version = "1.4.0" @@ -907,6 +1314,24 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +[[package]] +name = "rustc-workspace-hack" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" + +[[package]] +name = "rustfix" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2c50b74badcddeb8f7652fa8323ce440b95286f8e4b64ebfd871c609672704e" +dependencies = [ + "anyhow", + "log", + "serde", + "serde_json", +] + [[package]] name = "rustsec" version = "0.21.0" @@ -933,6 +1358,25 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -991,6 +1435,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_ignored" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c2c7d39d14f2f2ea82239de71594782f186fd03501ac81f0ce08e674819ff2f" +dependencies = [ + "serde", +] + [[package]] name = "serde_json" version = "1.0.57" @@ -1002,6 +1455,22 @@ dependencies = [ "serde", ] +[[package]] +name = "shell-escape" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" + +[[package]] +name = "sized-chunks" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec31ceca5644fa6d444cc77548b88b67f46db6f7c71683b0f9336e671830d2f" +dependencies = [ + "bitmaps", + "typenum", +] + [[package]] name = "smallvec" version = "1.4.2" @@ -1017,6 +1486,18 @@ dependencies = [ "serde", ] +[[package]] +name = "socket2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi", +] + [[package]] name = "spdx" version = "0.3.4" @@ -1028,6 +1509,15 @@ dependencies = [ "smallvec", ] +[[package]] +name = "strip-ansi-escapes" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d63676e2abafa709460982ddc02a3bb586b6d15a49b75c212e06edd3933acee" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.8.0" @@ -1081,6 +1571,17 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "tar" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8a4c1d0bee3230179544336c15eefb563cf0302955d962e456542323e8c2e8a" +dependencies = [ + "filetime", + "libc", + "redox_syscall", +] + [[package]] name = "target-lexicon" version = "0.11.0" @@ -1180,6 +1681,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + [[package]] name = "unicode-bidi" version = "0.3.4" @@ -1227,6 +1734,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" + [[package]] name = "vcpkg" version = "0.2.10" @@ -1245,6 +1758,26 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "vte" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f42f536e22f7fcbb407639765c8fd78707a33109301f834a594758bedd6e8cf" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 0f9c95a1..bffd7878 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ path = "src/cargo-deny/main.rs" [features] default = ["vendored-openssl"] vendored-openssl = ["rustsec/vendored-openssl"] +standalone = ["cargo"] [dependencies] ansi_term = "0.12.1" @@ -33,6 +34,7 @@ anyhow = "1.0" askalono = "0.4" atty = "0.2" bitvec = { version = "0.17", features = ["alloc"] } +cargo = { version = "0.46.1", optional = true } chrono = "0.4" clap = "2.33" codespan = { version = "0.9", features = ["reporting"] } diff --git a/README.md b/README.md index 0b9c757a..b1447ebf 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ cargo install cargo-deny && cargo deny init && cargo deny check ### [Install](https://embarkstudios.github.io/cargo-deny/cli/index.html) cargo-deny +If you want to use `cargo-deny` without having `cargo` installed, +build `cargo-deny` with the `standalone1 feature. +This can be useful in Docker Images. + ```bash cargo install cargo-deny diff --git a/src/cargo-deny/common.rs b/src/cargo-deny/common.rs index c43ca803..b00e2c70 100644 --- a/src/cargo-deny/common.rs +++ b/src/cargo-deny/common.rs @@ -94,18 +94,12 @@ impl KrateContext { log::info!("gathering crates for {}", self.manifest_path.display()); let start = std::time::Instant::now(); - let mut mdc = krates::Cmd::new(); - - if self.no_default_features { - mdc.no_default_features(); - } - - if self.all_features { - mdc.all_features(); - } - - mdc.features(self.features); - mdc.manifest_path(self.manifest_path); + let metadata = get_metadata( + self.no_default_features, + self.all_features, + self.features, + self.manifest_path, + )?; use krates::{Builder, DepKind}; @@ -135,16 +129,21 @@ impl KrateContext { }), ); } - let graph = gb.build(mdc, |filtered: krates::cm::Package| match filtered.source { - Some(src) => { - if src.is_crates_io() { - log::debug!("filtered {} {}", filtered.name, filtered.version); - } else { - log::debug!("filtered {} {} {}", filtered.name, filtered.version, src); + + let graph = + gb.build_with_metadata(metadata, |filtered: krates::cm::Package| { + match filtered.source { + Some(src) => { + if src.is_crates_io() { + log::debug!("filtered {} {}", filtered.name, filtered.version); + } else { + log::debug!("filtered {} {} {}", filtered.name, filtered.version, src); + } + } + None => log::debug!("filtered {} {}", filtered.name, filtered.version), } - } - None => log::debug!("filtered {} {}", filtered.name, filtered.version), - }); + }); + if let Ok(ref krates) = graph { let end = std::time::Instant::now(); log::info!( @@ -158,6 +157,56 @@ impl KrateContext { } } +#[cfg(not(feature = "standalone"))] +fn get_metadata( + no_default_features: bool, + all_features: bool, + features: Vec, + manifest_path: PathBuf, +) -> Result { + let mut mdc = krates::Cmd::new(); + + if no_default_features { + mdc.no_default_features(); + } + + if all_features { + mdc.all_features(); + } + + mdc.features(features); + mdc.manifest_path(manifest_path); + + let mdc: krates::cm::MetadataCommand = mdc.into(); + Ok(mdc.exec()?) +} + +#[cfg(feature = "standalone")] +fn get_metadata( + no_default_features: bool, + all_features: bool, + features: Vec, + manifest_path: PathBuf, +) -> Result { + use cargo::{core, ops, util}; + + let config = util::Config::default()?; + let ws = core::Workspace::new(&manifest_path, &config)?; + let options = ops::OutputMetadataOptions { + features, + no_default_features, + all_features, + no_deps: false, + version: 1, + filter_platforms: vec![], + }; + + let md = ops::output_metadata(&ws, &options)?; + let md_value = serde_json::to_value(md)?; + + Ok(serde_json::from_value(md_value)?) +} + pub fn log_level_to_severity(log_level: log::LevelFilter) -> Option { match log_level { log::LevelFilter::Off => None,