From 4c23ddd9504e3ba5babad123752230de181e224f Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Sat, 25 Feb 2023 04:31:28 +0300 Subject: [PATCH] Initial git support --- Cargo.lock | 997 ++++++++++++++++++++++++++++++++++++- cargo-marker/Cargo.toml | 1 + cargo-marker/src/config.rs | 164 +++--- cargo-marker/src/lints.rs | 160 ++++-- cargo-marker/src/main.rs | 47 +- 5 files changed, 1242 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 925ef9bc..71af56f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.20" @@ -17,32 +23,193 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f0778972c64420fdedc63f09919c8a88bda7b25135357fd25a5d9f3257e832" +dependencies = [ + "memchr", + "once_cell", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "bytesize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" + +[[package]] +name = "cargo" +version = "0.68.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df5e8070173cd407a849cb3d231542f6781fe09cf52ae1c58fbb4d3ae01cf24d" +dependencies = [ + "anyhow", + "base64", + "bytesize", + "cargo-platform", + "cargo-util", + "clap", + "crates-io", + "curl", + "curl-sys", + "env_logger", + "filetime", + "flate2", + "fwdansi", + "git2", + "git2-curl", + "glob", + "hex 0.4.3", + "hmac", + "home", + "http-auth", + "humantime", + "ignore", + "im-rc", + "indexmap", + "is-terminal", + "itertools", + "jobserver", + "lazy_static", + "lazycell", + "libc", + "libgit2-sys", + "log", + "memchr", + "opener", + "os_info", + "pathdiff", + "percent-encoding", + "rustc-workspace-hack", + "rustfix", + "semver", + "serde", + "serde-value", + "serde_ignored", + "serde_json", + "sha1", + "shell-escape", + "strip-ansi-escapes", + "tar", + "tempfile", + "termcolor", + "toml_edit 0.15.0", + "unicode-width", + "unicode-xid", + "url", + "walkdir", + "winapi", +] + +[[package]] +name = "cargo-platform" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-util" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4e0cd00582e110eb8d99de768521d36fce9e24a286babf3cea68824ae09948f" +dependencies = [ + "anyhow", + "core-foundation", + "crypto-hash", + "filetime", + "hex 0.4.3", + "jobserver", + "libc", + "log", + "miow 0.5.0", + "same-file", + "shell-escape", + "tempfile", + "walkdir", + "winapi", +] + +[[package]] +name = "cargo_fetch" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce9709e3d591a17d00a9a39428ae772a3dfbef88b2ca5f17c4088a83339e51e6" +dependencies = [ + "cargo", + "semver", + "url", +] + [[package]] name = "cargo_marker" version = "0.1.0" dependencies = [ + "cargo_fetch", "clap", "once_cell", "serde", - "toml_edit", + "toml_edit 0.17.1", ] [[package]] @@ -50,6 +217,9 @@ name = "cc" version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +dependencies = [ + "jobserver", +] [[package]] name = "cfg-if" @@ -79,6 +249,34 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + +[[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 = "compiletest_rs" version = "0.9.0" @@ -91,7 +289,7 @@ dependencies = [ "lazy_static", "libc", "log", - "miow", + "miow 0.3.7", "regex", "rustfix", "serde", @@ -102,12 +300,124 @@ dependencies = [ "winapi", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crates-io" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "848493b0d668efbe713dcddcde49f1e5d4b6d542337262660c198336db47977e" +dependencies = [ + "anyhow", + "curl", + "percent-encoding", + "serde", + "serde_json", + "url", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[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.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.59+curl-7.86.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cfce34829f448b08f55b7db6d0009e23e2e86a34e8c2b366269bf5799b4a407" +dependencies = [ + "cc", + "libc", + "libnghttp2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -135,6 +445,19 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + [[package]] name = "errno" version = "0.2.8" @@ -177,6 +500,67 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "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 = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fwdansi" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c1f5787fe85505d1f7777268db5103d80a7a374d2316a7ce262e57baf8f208" +dependencies = [ + "memchr", + "termcolor", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getopts" version = "0.2.21" @@ -197,6 +581,52 @@ dependencies = [ "wasi", ] +[[package]] +name = "git2" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf7f68c2995f392c49fffb4f95ae2c873297830eb25c6bc4c114ce8f4562acc" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "git2-curl" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7577f4e6341ba7c90d883511130a45b956c274ba5f4d205d9f9da990f654cd33" +dependencies = [ + "curl", + "git2", + "log", + "url", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "globset" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -212,6 +642,92 @@ 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.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747309b4b440c06d57b0b25f2aee03ee9b5e5397d288c60e21fc709bb98a7408" +dependencies = [ + "winapi", +] + +[[package]] +name = "http-auth" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5430cacd7a1f9a02fbeb350dfc81a0e5ed42d81f3398cb0ba184017f85bdcfbc" +dependencies = [ + "memchr", +] + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" +dependencies = [ + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "im-rc" +version = "15.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1955a75fa080c677d3972822ec4bad316169ab1cfc6c257a942c2265dbe5fe" +dependencies = [ + "bitmaps", + "rand_core", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", +] + [[package]] name = "indexmap" version = "1.9.2" @@ -268,6 +784,24 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "jobserver" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" +dependencies = [ + "libc", +] + +[[package]] +name = "kstring" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" +dependencies = [ + "static_assertions", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -275,19 +809,75 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "libc" -version = "0.2.139" +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "libgit2-sys" +version = "0.14.2+1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libnghttp2-sys" +version = "0.1.7+1.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ed28aba195b38d5ff02b9170cbff627e336a20925e43b4945390401c5dc93f" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "libssh2-sys" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] [[package]] -name = "libloading" -version = "0.7.4" +name = "libz-sys" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" dependencies = [ - "cfg-if", - "winapi", + "cc", + "libc", + "pkg-config", + "vcpkg", ] [[package]] @@ -345,6 +935,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + [[package]] name = "miow" version = "0.3.7" @@ -354,6 +953,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "miow" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123" +dependencies = [ + "windows-sys", +] + [[package]] name = "nom8" version = "0.2.0" @@ -363,6 +971,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.15.0" @@ -379,12 +996,105 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +[[package]] +name = "opener" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "293c15678e37254c15bd2f092314abb4e51d7fdde05c2021279c12631b54f005" +dependencies = [ + "bstr", + "winapi", +] + +[[package]] +name = "openssl" +version = "0.10.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "ordered-float" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +dependencies = [ + "num-traits", +] + +[[package]] +name = "os_info" +version = "3.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c424bc68d15e0778838ac013b5b3449544d8133633d8016319e7e05a820b8c0" +dependencies = [ + "log", + "serde", + "winapi", +] + [[package]] name = "os_str_bytes" version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + [[package]] name = "proc-macro2" version = "1.0.49" @@ -403,6 +1113,21 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -434,6 +1159,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.28" @@ -449,6 +1180,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-workspace-hack" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc71d2faa173b74b232dedc235e3ee1696581bb132fc116fa3626d6151a1a8fb" + [[package]] name = "rustc_tools_util" version = "0.3.0" @@ -493,6 +1230,33 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +[[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.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "semver" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.152" @@ -502,6 +1266,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.152" @@ -513,6 +1287,15 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_ignored" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94eb4a4087ba8bdf14a9208ac44fddbf55c01a6195f7edfc511ddaff6cae45a6" +dependencies = [ + "serde", +] + [[package]] name = "serde_json" version = "1.0.91" @@ -524,12 +1307,70 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" +dependencies = [ + "bitmaps", + "typenum", +] + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strip-ansi-escapes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "011cbb39cf7c1f62871aea3cc46e5817b0937b49e9447370c93cacbe93a766d8" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + [[package]] name = "syn" version = "1.0.107" @@ -541,6 +1382,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", +] + [[package]] name = "tempfile" version = "3.3.0" @@ -608,6 +1459,30 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml_datetime" version = "0.5.0" @@ -617,6 +1492,20 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_edit" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1541ba70885967e662f69d31ab3aeca7b1aaecfcd58679590b893e9239c3646" +dependencies = [ + "combine", + "indexmap", + "itertools", + "kstring", + "serde", + "toml_datetime", +] + [[package]] name = "toml_edit" version = "0.17.1" @@ -630,18 +1519,74 @@ dependencies = [ "toml_datetime", ] +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "unicode-bidi" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf8parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936e4b492acfd135421d8dca4b1aa80a7bfc26e702ef3af710e0752684df5372" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "visibility" version = "0.0.1" @@ -653,6 +1598,38 @@ dependencies = [ "syn", ] +[[package]] +name = "vte" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cbce692ab4ca2f1f3047fcf732430249c0e971bfdd2b234cf2c47ad93af5983" +dependencies = [ + "arrayvec", + "utf8parse", + "vte_generate_state_changes", +] + +[[package]] +name = "vte_generate_state_changes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d257817081c7dffcdbab24b9e62d2def62e2ff7d00b1c20062551e6cccc145ff" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/cargo-marker/Cargo.toml b/cargo-marker/Cargo.toml index 5bcc3b7d..02ecaf15 100644 --- a/cargo-marker/Cargo.toml +++ b/cargo-marker/Cargo.toml @@ -16,6 +16,7 @@ clap = { version = "4.0.26", features = ["string"] } serde = { version = "1.0", features = ["derive"] } toml_edit = { version = "0.17.1", features = ["easy"] } once_cell = "1.16.0" +cargo_fetch = "0.1.2" [features] default = [] diff --git a/cargo-marker/src/config.rs b/cargo-marker/src/config.rs index 3caee562..19a29b16 100644 --- a/cargo-marker/src/config.rs +++ b/cargo-marker/src/config.rs @@ -2,24 +2,27 @@ use std::{ collections::HashMap, fs::File, io::{self, Read}, + path::PathBuf, }; +use cargo_fetch::{GitReference, PackageSource}; use serde::Deserialize; use toml_edit::easy::{from_str, Value}; -use crate::{lints::LintCrateSpec, ExitStatus}; +use crate::{ + lints::{LintCrateSpec, PackageName}, + ExitStatus, +}; const CARGO_TOML: &str = "Cargo.toml"; #[derive(Deserialize, Debug)] -#[serde(deny_unknown_fields)] pub struct Config { lints: HashMap, } #[derive(Deserialize, Debug)] -#[serde(deny_unknown_fields)] #[serde(untagged)] pub enum LintDependency { /// Version string like: `lint = "0.0.1"` @@ -30,25 +33,50 @@ pub enum LintDependency { } #[derive(Deserialize, Debug)] -#[serde(deny_unknown_fields)] +#[serde(rename_all = "lowercase")] +pub enum GitRef { + Rev(String), + Tag(String), + Branch(String), +} + +impl From for GitReference { + fn from(value: GitRef) -> Self { + match value { + GitRef::Rev(rev) => GitReference::Revision(rev), + GitRef::Tag(tag) => GitReference::Tag(tag), + GitRef::Branch(branch) => GitReference::Branch(branch), + } + } +} + +#[derive(Deserialize, Debug)] +#[serde(untagged)] +pub enum Source { + // TODO: Registries are not supported yet, see https://github.com/rust-marker/marker/issues/87 + Registry { + version: String, + registry: Option, + }, + Git { + git: String, + #[serde(flatten)] + git_ref: Option, + }, + Path { + path: String, + }, +} + +#[derive(Deserialize, Debug)] pub struct LintDependencyEntry { - path: Option, + #[serde(flatten)] + source: Source, package: Option, - // TODO: Everything below is not yet supported - // Registry fetching: - version: Option, - registry: Option, - // Git source fetching: - git: Option, - rev: Option, - branch: Option, - // Features: + // TODO: Features are not supported yet, see https://github.com/rust-marker/marker/issues/81 #[serde(rename = "default-features")] default_features: Option, features: Option>, - optional: Option, - // TODO: do we want lint configuration here too? - // configuration: Option } #[derive(Debug)] @@ -81,16 +109,6 @@ impl ConfigFetchError { } } -macro_rules! unsupported_fields { - ($name:expr, $dep:expr => [$($i:ident),+]) => { - $( - if let Some(ref $i) = $dep.$i { - eprintln!(concat!("warning: {} ({:?}): marker doesn't yet support `", stringify!($i), "` field"), $name, $i); - } - )+ - } -} - impl Config { fn get_raw_manifest() -> Result { let Ok(mut config_file) = File::open(CARGO_TOML) else { @@ -123,37 +141,65 @@ impl Config { Ok(marker_config) } - pub fn collect_crates(&self) -> Result, ExitStatus> { - self.lints - .iter() - .map(|(name, dep)| match dep { - LintDependency::Simple(v) => { - eprintln!("{name} ({v}): marker doesn't yet support registries"); - Err(ExitStatus::InvalidValue) - }, - LintDependency::Full(dep) => { - unsupported_fields!( - name, dep => [ - version, - registry, - git, - rev, - branch, - default_features, - features, - optional - ] - ); - if let Some(ref path) = dep.path { - if let Some(ref package) = dep.package { - return Ok(LintCrateSpec::new(Some(package), path.as_ref())); - } - return Ok(LintCrateSpec::new(Some(name), path.as_ref())); - } - eprintln!("No `path` field found for lint crate {name}"); - Err(ExitStatus::BadConfiguration) - }, - }) - .collect() + pub fn collect_crates(self) -> Result, ExitStatus> { + self.lints.into_iter().map(dep_to_spec).collect() + } +} + +macro_rules! unsupported_fields { + ($name:expr, $dep:expr => [$($i:ident),+]) => { + $( + if let Some(ref $i) = $dep.$i { + eprintln!(concat!("warning: {} ({:?}): marker doesn't yet support `", stringify!($i), "` field"), $name, $i); + } + )+ + } +} + +fn dep_to_spec((name, dep): (String, LintDependency)) -> Result { + let dep = match dep { + LintDependency::Simple(ver) => { + eprintln!("{name} ({ver}): marker does not yet support registries"); + return Err(ExitStatus::InvalidValue); + }, + LintDependency::Full(dep) => dep, + }; + + unsupported_fields!( + name, dep => [ + default_features, + features + ] + ); + + let pkg_name = if let Some(package) = dep.package { + PackageName::Renamed { + orig: package, + new: name.clone(), + } + } else { + PackageName::Named(name.clone()) + }; + + match dep.source { + Source::Registry { version, .. } => { + eprintln!("{name} ({version}): marker does not yet support registries"); + Err(ExitStatus::BadConfiguration) + }, + Source::Git { git, git_ref } => { + let src = PackageSource::git(&git, git_ref.map(Into::into)).map_err(|e| { + eprintln!("{name}: {git} is not a valid git repository url ({e})"); + ExitStatus::InvalidValue + })?; + Ok(LintCrateSpec::new(pkg_name, None, src)) + }, + Source::Path { path } => { + let path: PathBuf = path.into(); + let src = PackageSource::path(path.clone()).map_err(|e| { + eprintln!("{name}: {} is not a valid lint crate path ({e})", path.display()); + ExitStatus::LintCrateNotFound + })?; + Ok(LintCrateSpec::new(pkg_name, None, src)) + }, } } diff --git a/cargo-marker/src/lints.rs b/cargo-marker/src/lints.rs index 5abbe240..a7885d22 100644 --- a/cargo-marker/src/lints.rs +++ b/cargo-marker/src/lints.rs @@ -1,57 +1,143 @@ use std::{ - ffi::OsStr, + ffi::OsString, path::{Path, PathBuf}, process::Command, }; use crate::{cli::Flags, ExitStatus}; -pub struct LintCrateSpec<'a> { - /// Optional package name (this is always UTF-8, as opposed to `dir`), exists if supplied from - /// config: - /// +use cargo_fetch::{PackageFetcher, PackageSource}; + +/// Holds the "cargo name", and optionally the real name, of the package which contains the lint +/// crate. +/// +/// This struct is parsed from `Cargo.toml`, see variant documentation for more info. +pub enum PackageName { + /// Renamed - stores both "cargo name" and the real package name + /// ```toml + /// lint_b = { path = "...", package = "lint_c" } + /// ``` + /// Results in: + /// ```rust,no_run + /// PackageName::Renamed { orig: "lint_c", new: "lint_b" } + /// ``` + Renamed { orig: String, new: String }, + /// Not renamed - "cargo name" is the package name. /// ```toml - /// lint_a = { path = "" } - /// # `lint_a` is the package_name - /// lint_b = { path = "", package = "lint_c"} - /// # `lint_c` is the package name + /// lint_a = { path = "..." } + /// ``` + /// Results in: + /// ```rust,no_run + /// PackageName::Named("lint_a") /// ``` - /// if the lint crate was supplied only from path, this is `None`, for example in case of + Named(String), +} + +/// Represents a downloaded package +struct DownloadedPackage { + /// Path to the package + path: PathBuf, + /// Optional package name, to specify during building. + /// + /// This is [`None`] if we don't rename the package. + package_name: Option, +} + +impl DownloadedPackage { + fn new(path: PathBuf, package_name: Option) -> Self { + Self { path, package_name } + } +} + +pub struct LintCrateSpec { + /// Name of the package which contains the lint crate. + /// + /// if the lint crate was supplied only from path, this is taken from + /// [`Path::file_name`], for example in case of /// command-line arguments: /// /// `--lints ./marker_lints` /// - /// where `./marker_lints` is `dir`, and `package_name` in this case is empty. - /// - /// Setting this to `None` won't validate the package name when building the package with - /// [`build()`](`Self::build`) - package_name: Option<&'a str>, - /// Path to lint crate - dir: &'a Path, + /// `marker_lints` is the `package_name`. + package_name: PackageName, + /// Version requirement of the package, [`None`] is a wildcard requirement, aka "*". + version_req: Option, + /// Source to fetch the lint crate from. + source: PackageSource, } -impl<'a> LintCrateSpec<'a> { - pub fn new(package_name: Option<&'a str>, dir: &'a Path) -> Self { - Self { package_name, dir } +impl LintCrateSpec { + pub fn new(package_name: PackageName, version_req: Option, source: PackageSource) -> Self { + Self { + package_name, + version_req, + source, + } } - /// Currently only checks for semicolons, can be extended in the future - pub fn is_valid(&self) -> bool { - !self.dir.to_string_lossy().contains(';') + fn fetch_many(specs: Vec) -> Result, String> { + let mut fetcher = PackageFetcher::new()?; + + // Packages which we don't need to identify, they just need to be downloaded and built. + // Basically: set of pkgs goes in - set of pathbufs goes out + let mut auto_fetch = vec![]; + + // Packages which we care to identify, because they need some special building flags + // like `--package=...` + let mut manual_fetch = vec![]; + + for spec in specs { + match spec.package_name { + PackageName::Named(s) => { + auto_fetch.push(fetcher.resolve_first(s, spec.version_req.as_deref(), &spec.source, None)?); + }, + PackageName::Renamed { orig, new } => manual_fetch.push(( + fetcher.resolve_first(orig, spec.version_req.as_deref(), &spec.source, None)?, + new, + )), + } + } + + let mut v: Vec<_> = fetcher + .fetch_many(&auto_fetch)? + .into_iter() + .map(|path| DownloadedPackage::new(path, None)) + .collect(); + + for package in manual_fetch { + let pkg = fetcher.fetch(package.0)?; + v.push(DownloadedPackage::new(pkg, Some(package.1))); + } + + Ok(v) } - /// Creates a debug build for this crate. The path of the build library - /// will be returned, if the operation was successful. - pub fn build(&self, target_dir: &Path, flags: &Flags) -> Result { - build_local_lint_crate(self, target_dir, flags) + /// Fetches and debug builds crates. The paths of built libraries + /// will be returned, if the operations were successful. + pub fn build_many(specs: Vec, target_dir: &Path, flags: &Flags) -> Result, ExitStatus> { + let pkg_paths = match Self::fetch_many(specs) { + Ok(p) => p, + Err(e) => { + eprintln!("Failed fetching lint crates: {e}"); + return Err(ExitStatus::LintCrateFetchFailed); + }, + }; + + pkg_paths + .into_iter() + .map(|p| build_local_lint_crate(&p.path, p.package_name, target_dir, flags)) + .collect() } } -/// This creates a debug build for a local crate. The path of the build library -/// will be returned, if the operation was successful. -fn build_local_lint_crate(krate: &LintCrateSpec<'_>, target_dir: &Path, flags: &Flags) -> Result { - if !krate.dir.exists() { - eprintln!("The given lint can't be found, searched at: `{}`", krate.dir.display()); +fn build_local_lint_crate( + krate: &Path, + pkg_name: Option, + target_dir: &Path, + flags: &Flags, +) -> Result { + if !krate.exists() { + eprintln!("The given lint can't be found, searched at: `{}`", krate.display()); return Err(ExitStatus::LintCrateNotFound); } @@ -68,12 +154,12 @@ fn build_local_lint_crate(krate: &LintCrateSpec<'_>, target_dir: &Path, flags: & if flags.verbose { cmd.arg("--verbose"); } - if let Some(name) = krate.package_name { + if let Some(name) = pkg_name { cmd.arg("--package"); cmd.arg(name); } let exit_status = cmd - .current_dir(std::fs::canonicalize(krate.dir).unwrap()) + .current_dir(std::fs::canonicalize(krate).unwrap()) .args(["--lib", "--target-dir"]) .arg(target_dir.as_os_str()) .env("RUSTFLAGS", rustc_flags) @@ -94,10 +180,8 @@ fn build_local_lint_crate(krate: &LintCrateSpec<'_>, target_dir: &Path, flags: & // FIXME: currently this expect, that the lib name is the same as the crate dir. // See marker#60 - let file_name = format!( - "{lib_file_prefix}{}", - krate.dir.file_name().and_then(OsStr::to_str).unwrap_or_default() - ); + let mut file_name = OsString::from(lib_file_prefix); + file_name.push(krate.file_name().unwrap_or_default()); // Here `debug` is attached as the crate is build with the `cargo build` command let mut krate_path = target_dir.join("debug").join(file_name); diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index 44564666..9cbf8bd2 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -15,10 +15,11 @@ use std::{ process::exit, }; +use cargo_fetch::PackageSource; use cli::{get_clap_config, Flags}; use config::Config; use driver::{get_driver_path, run_driver}; -use lints::LintCrateSpec; +use lints::{LintCrateSpec, PackageName}; use once_cell::sync::Lazy; use crate::driver::print_driver_version; @@ -51,6 +52,8 @@ pub enum ExitStatus { LintCrateNotFound = 501, /// The lint crate has been build, but the resulting binary could not be found. LintCrateLibNotFound = 502, + /// Failed to fetch the lint crate + LintCrateFetchFailed = 550, /// General "bad config" error BadConfiguration = 600, /// No lint crates were specified -> nothing to do @@ -84,12 +87,22 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String { .to_string() } -fn choose_lint_crates<'a>( - args: &'a clap::ArgMatches, - config: Option<&'a Config>, -) -> Result>, ExitStatus> { +fn choose_lint_crates(args: &clap::ArgMatches, config: Option) -> Result, ExitStatus> { match args.get_many::("lints") { - Some(v) => Ok(v.map(|v| LintCrateSpec::new(None, v.as_ref())).collect()), + Some(v) => v + .map(|s| { + let p = Path::new(s); + let src = PackageSource::path(p).map_err(|e| { + eprintln!("{}: {e}", p.display()); + ExitStatus::LintCrateNotFound + })?; + Ok(LintCrateSpec::new( + PackageName::Named(p.file_name().unwrap_or_default().to_string_lossy().to_string()), + None, + src, + )) + }) + .collect::>(), None => { if let Some(config) = config { config.collect_crates() @@ -126,13 +139,13 @@ fn main() -> Result<(), ExitStatus> { match matches.subcommand() { Some(("setup", _args)) => driver::install_driver(&flags), - Some(("check", args)) => run_check(&choose_lint_crates(args, config.as_ref())?, &flags), - None => run_check(&choose_lint_crates(&matches, config.as_ref())?, &flags), + Some(("check", args)) => run_check(choose_lint_crates(args, config)?, &flags), + None => run_check(choose_lint_crates(&matches, config)?, &flags), _ => unreachable!(), } } -fn run_check(crate_entries: &[LintCrateSpec], flags: &Flags) -> Result<(), ExitStatus> { +fn run_check(crate_entries: Vec, flags: &Flags) -> Result<(), ExitStatus> { // If this is a dev build, we want to recompile the driver before checking if flags.dev_build { driver::install_driver(flags)?; @@ -143,20 +156,14 @@ fn run_check(crate_entries: &[LintCrateSpec], flags: &Flags) -> Result<(), ExitS return Err(ExitStatus::NoLints); } - if !crate_entries.iter().all(LintCrateSpec::is_valid) { - eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); - return Err(ExitStatus::InvalidValue); - } - - let mut lint_crates = Vec::with_capacity(crate_entries.len()); - println!(); println!("Compiling Lints:"); let target_dir = Path::new(&*MARKER_LINT_DIR); - for krate in crate_entries { - let crate_file = krate.build(target_dir, flags)?; - lint_crates.push(crate_file.as_os_str().to_os_string()); - } + + let lint_crates: Vec = LintCrateSpec::build_many(crate_entries, target_dir, flags)? + .into_iter() + .map(OsString::from) + .collect(); #[rustfmt::skip] let env = vec![