From badbdcdfe354b99bfa45f22795f8764968622f16 Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Sat, 7 Jan 2023 20:53:39 +0300 Subject: [PATCH 1/7] cargo-marker: add initial configuration support --- .cargo/config.toml | 2 +- Cargo.lock | 173 +++++++++++++++++++++++++------------ Cargo.toml | 5 +- README.md | 2 +- cargo-marker/Cargo.toml | 4 +- cargo-marker/src/config.rs | 147 +++++++++++++++++++++++++++++++ cargo-marker/src/main.rs | 96 +++++++++++++------- 7 files changed, 340 insertions(+), 89 deletions(-) create mode 100644 cargo-marker/src/config.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 1276b0f1..3cf7359d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] -dogfood = "run --features dev-build --bin cargo-marker -- -l ./marker_lints" +dogfood = "run --features dev-build --bin cargo-marker" uitest = "test --test compile_test" diff --git a/Cargo.lock b/Cargo.lock index b0df521a..e921edba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.66" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -35,13 +41,15 @@ version = "0.1.0" dependencies = [ "clap", "once_cell", + "serde", + "toml_edit", ] [[package]] name = "cc" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cfg-if" @@ -51,9 +59,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.0.27" +version = "4.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0acbd8d28a0a60d7108d7ae850af6ba34cf2d1257fc646980e5f97ce14275966" +checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" dependencies = [ "bitflags", "clap_lex", @@ -121,6 +129,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "either" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" + [[package]] name = "errno" version = "0.2.8" @@ -153,9 +167,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b9663d381d07ae25dc88dbdf27df458faa83a9b25336bcac83d5e452b5fc9d3" +checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9" dependencies = [ "cfg-if", "libc", @@ -184,13 +198,10 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "hashbrown" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" @@ -201,6 +212,16 @@ dependencies = [ "libc", ] +[[package]] +name = "indexmap" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.12" @@ -212,9 +233,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e394faa0efb47f9f227f1cd89978f854542b318a6f64fa695489c9c993056656" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", "windows-sys", @@ -222,21 +243,30 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae5bc6e2eb41c9def29a3e0f1306382807764b9b53112030eff57435667352d" +checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "io-lifetimes", "rustix", "windows-sys", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "lazy_static" @@ -246,9 +276,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.137" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" @@ -262,9 +292,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" @@ -323,21 +353,30 @@ dependencies = [ "winapi", ] +[[package]] +name = "nom8" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" +dependencies = [ + "memchr", +] + [[package]] name = "num_cpus" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", ] [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "os_str_bytes" @@ -347,18 +386,18 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -385,9 +424,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -429,9 +468,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.3" +version = "0.36.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b1fbb4dfc4eb1d390c02df47760bb19a84bb80b301ecc947ab5406394d8223e" +checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" dependencies = [ "bitflags", "errno", @@ -443,30 +482,30 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "serde" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -475,9 +514,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa", "ryu", @@ -492,9 +531,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.103" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -550,29 +589,51 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "toml_datetime" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808b51e57d0ef8f71115d8f3a01e7d3750d01c79cac4b3eda910f4389fdf92fd" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34cc558345efd7e88b9eda9626df2138b80bb46a7606f695e751c892bc7dac6" +dependencies = [ + "indexmap", + "itertools", + "nom8", + "serde", + "toml_datetime", +] + [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-width" diff --git a/Cargo.toml b/Cargo.toml index 45c18261..59ad2fc2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,9 @@ members = [ "marker_adapter", "marker_api", "marker_driver_rustc", - # This is temporary, lint crates like this one will be managed with `cargo-liner` + # This is needed for rust-analyzer, uitests and other tools "marker_lints", ] + +[workspace.metadata.marker.lints] +dogfood = { path = "marker_lints" } diff --git a/README.md b/README.md index 5aefb86e..087cd499 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The internal structure of marker and its components is documented in [`docs/inte ## Running The project is currently only available in this GitHub repo. -For a quick test, checkout the repo and run `cargo run --bin cargo-marker -- -l ./marker_lints`. +For a quick test, clone the repo and run `cargo dogfood`. This will start `cargo-marker`, load [`./marker_lints`](./marker_lints) as a *lint crate* and run it in this repository. ## License diff --git a/cargo-marker/Cargo.toml b/cargo-marker/Cargo.toml index 46dffd6c..5bcc3b7d 100644 --- a/cargo-marker/Cargo.toml +++ b/cargo-marker/Cargo.toml @@ -12,7 +12,9 @@ name = "cargo-marker" path = "src/main.rs" [dependencies] -clap = {version = "4.0.26", features = ["string"]} +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" [features] diff --git a/cargo-marker/src/config.rs b/cargo-marker/src/config.rs new file mode 100644 index 00000000..63dbd029 --- /dev/null +++ b/cargo-marker/src/config.rs @@ -0,0 +1,147 @@ +use std::{ + collections::HashMap, + fs::File, + io::{self, Read}, +}; + +use serde::Deserialize; + +use toml_edit::easy::{from_str, Value}; + +use crate::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"` + Simple(String), + /// Full dependency entry, like: + /// lint = { path = ".", version = "1.0.0" } + Full(LintDependencyEntry), +} + +#[derive(Deserialize, Debug)] +#[serde(deny_unknown_fields)] +pub struct LintDependencyEntry { + path: Option, + // TODO: Everything below is not yet supported + // Registry fetching: + version: Option, + registry: Option, + // Git source fetching: + git: Option, + rev: Option, + branch: Option, + // Features: + features: Option>, + optional: Option, + // TODO: do we want lint configuration here too? + // configuration: Option +} + +#[derive(Debug)] +pub enum ConfigFetchError { + /// `Cargo.toml` wasn't found + FileNotFound, + /// Read failed + IoError(io::Error), + /// Couldn't parse `Cargo.toml` + ParseError(toml_edit::de::Error), + /// `workspace.metadata.marker` has invalid structure + InvalidStructure, + /// `workspace.metadata.marker` doesn't exist + NotFound, +} + +impl ConfigFetchError { + pub fn emit_and_convert(self) -> ExitStatus { + match self { + ConfigFetchError::FileNotFound => eprintln!("`Cargo.toml` wasn't found"), + ConfigFetchError::IoError(err) => eprintln!("IO error reading config: {err:?}"), + ConfigFetchError::ParseError(err) => eprintln!("Can't parse config: {err:?}"), + ConfigFetchError::NotFound => eprintln!("Marker config wasn't found"), + ConfigFetchError::InvalidStructure => { + eprintln!("`workspace.metadata.marker` has invalid structure"); + return ExitStatus::WrongStructure; + }, + }; + ExitStatus::BadConfiguration + } +} + +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 { + pub fn get_marker_config() -> Result { + let Ok(mut config_file) = File::open(CARGO_TOML) else { + return Err(ConfigFetchError::FileNotFound); + }; + + let mut config_str = String::new(); + if let Err(e) = config_file.read_to_string(&mut config_str) { + return Err(ConfigFetchError::IoError(e)); + } + + let cargo_config = match from_str::(&config_str) { + Ok(v) => v, + Err(e) => return Err(ConfigFetchError::ParseError(e)), + }; + + let Some(config_value) = cargo_config.get("workspace").and_then(|v| v.get("metadata")).and_then(|v| v.get("marker")) else { + return Err(ConfigFetchError::NotFound); + }; + + let Some(marker_config) = config_value.clone().try_into::().ok() else { + return Err(ConfigFetchError::InvalidStructure); + }; + + Ok(marker_config) + } + + pub fn collect_paths(&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, + features, + optional + ] + ); + if let Some(ref path) = dep.path { + return Ok(path.clone()); + } + eprintln!("No `path` field found for lint crate {name}"); + Err(ExitStatus::BadConfiguration) + }, + }) + .collect() + } +} diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index 0a38c02c..3293108e 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -3,6 +3,7 @@ #![allow(clippy::module_name_repetitions)] mod cli; +mod config; mod driver; mod lints; @@ -15,6 +16,7 @@ use std::{ }; use cli::get_clap_config; +use config::Config; use driver::{get_driver_path, run_driver}; use lints::build_local_lint_crate; use once_cell::sync::Lazy; @@ -44,23 +46,31 @@ pub enum ExitStatus { LintCrateNotFound = 501, /// The lint crate has been build, but the resulting binary could not be found. LintCrateLibNotFound = 502, + /// General "bad config" error + BadConfiguration = 600, + /// No lint crates were specified -> nothing to do + NoLints = 601, + /// Can't deserialise `workspace.metadata.marker.lints` properly + WrongStructure = 602, + /// An invalid configuration value was specified + InvalidValue = 603, /// Check failed MarkerCheckFailed = 1000, } /// This creates the absolute path for a given build directory. fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String { - if !Path::new("./target").exists() { + if !Path::new("Cargo.toml").exists() { // FIXME: This is a temporary check to ensure that we don't randomly create files. // This should not be part of the release and maybe be replaced by something more // elegant or removed completely. - eprintln!("No `target` directory exists, most likely running in the wrong directory"); + eprintln!("Cargo manifest doesn't exist (`Cargo.toml`), most likely running in the wrong directory"); exit(-1); } let path = Path::new(LINT_KRATES_BASE_DIR).join(dir_name); if !path.exists() { - create_dir_all(&path).unwrap_or_else(|_| panic!("Error while creating lint krate {info_name} directory")); + create_dir_all(&path).unwrap_or_else(|_| panic!("Error while creating lint crate {info_name} directory")); } std::fs::canonicalize(path) @@ -69,6 +79,29 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String { .to_string() } +fn choose_lint_crates(args: &clap::ArgMatches, config: Option) -> Result, ExitStatus> { + let lint_crates: Vec = match args.get_many::("lints") { + Some(v) => v.cloned().collect(), + None => { + if let Some(config) = config { + config.collect_paths()?.iter().map(Into::into).collect() + } else { + eprintln!( + "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" + ); + return Err(ExitStatus::NoLints); + } + }, + }; + if lint_crates.is_empty() { + eprintln!( + "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" + ); + return Err(ExitStatus::NoLints); + } + Ok(lint_crates) +} + fn main() -> Result<(), ExitStatus> { let matches = get_clap_config().get_matches_from( std::env::args() @@ -77,7 +110,16 @@ fn main() -> Result<(), ExitStatus> { .take_while(|s| s != CARGO_ARGS_SEPARATOR), ); + let config = match Config::get_marker_config() { + Ok(v) => Some(v), + Err(e) => match e { + config::ConfigFetchError::NotFound => None, + _ => return Err(e.emit_and_convert()), + }, + }; + let verbose = matches.get_flag("verbose"); + let test_build = matches.get_flag("test-setup"); let dev_build = cfg!(feature = "dev-build"); if matches.get_flag("version") { @@ -87,39 +129,37 @@ fn main() -> Result<(), ExitStatus> { match matches.subcommand() { Some(("setup", _args)) => driver::install_driver(verbose, dev_build), - Some(("check", args)) => run_check(args, verbose, dev_build), - None => run_check(&matches, verbose, dev_build), + Some(("check", args)) => run_check(&choose_lint_crates(args, config)?, verbose, dev_build, test_build), + None => run_check(&choose_lint_crates(&matches, config)?, verbose, dev_build, test_build), _ => unreachable!(), } } -fn run_check(matches: &clap::ArgMatches, verbose: bool, dev_build: bool) -> Result<(), ExitStatus> { +fn run_check( + lint_crate_paths: &[OsString], + verbose: bool, + dev_build: bool, + test_build: bool, +) -> Result<(), ExitStatus> { // If this is a dev build, we want to recompile the driver before checking if dev_build { driver::install_driver(verbose, dev_build)?; } - let mut lint_crates = vec![]; - if let Some(cmd_lint_crates) = matches.get_many::("lints") { - println!(); - println!("Compiling Lints:"); - lint_crates.reserve(cmd_lint_crates.len()); - let target_dir = Path::new(&*MARKER_LINT_DIR); - for krate in cmd_lint_crates { - let src_dir = PathBuf::from(krate); - let crate_file = build_local_lint_crate(src_dir.as_path(), target_dir, verbose)?; - lint_crates.push(crate_file.as_os_str().to_os_string()); - } + if lint_crate_paths.iter().any(|path| path.to_string_lossy().contains(';')) { + eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); + return Err(ExitStatus::InvalidValue); } - if lint_crates.is_empty() { - eprintln!("Please provide at least one valid lint crate, with the `--lints` argument"); - exit(-1); - } + let mut lint_crates = Vec::with_capacity(lint_crate_paths.len()); - if lint_crates.iter().any(|path| path.to_string_lossy().contains(';')) { - eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); - exit(-1); + println!(); + println!("Compiling Lints:"); + let target_dir = Path::new(&*MARKER_LINT_DIR); + for krate in lint_crate_paths { + let src_dir = PathBuf::from(krate); + let crate_file = build_local_lint_crate(src_dir.as_path(), target_dir, verbose)?; + lint_crates.push(crate_file.as_os_str().to_os_string()); } #[rustfmt::skip] @@ -127,7 +167,7 @@ fn run_check(matches: &clap::ArgMatches, verbose: bool, dev_build: bool) -> Resu (OsString::from("RUSTC_WORKSPACE_WRAPPER"), get_driver_path().as_os_str().to_os_string()), (OsString::from("MARKER_LINT_CRATES"), lint_crates.join(OsStr::new(";"))) ]; - if matches.get_flag("test-setup") { + if test_build { print_env(env).unwrap(); Ok(()) } else { @@ -171,8 +211,6 @@ fn print_env(env: Vec<(OsString, OsString)>) -> io::Result<()> { lock.write_all(value.as_bytes())?; writeln!(lock)?; } - - Ok(()) } #[cfg(target_os = "windows")] @@ -184,7 +222,7 @@ fn print_env(env: Vec<(OsString, OsString)>) -> io::Result<()> { unreachable!("Windows requires it's file path to be valid UTF-16 AFAIK"); } } - - Ok(()) } + + Ok(()) } From 31ad510733a3782e6622cd88341c7b8f95d8ec94 Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 00:39:36 +0300 Subject: [PATCH 2/7] Move `NoLints` check --- cargo-marker/src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index 3293108e..a823179a 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -93,12 +93,6 @@ fn choose_lint_crates(args: &clap::ArgMatches, config: Option) -> Result } }, }; - if lint_crates.is_empty() { - eprintln!( - "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" - ); - return Err(ExitStatus::NoLints); - } Ok(lint_crates) } @@ -146,6 +140,13 @@ fn run_check( driver::install_driver(verbose, dev_build)?; } + if lint_crate_paths.is_empty() { + eprintln!( + "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" + ); + return Err(ExitStatus::NoLints); + } + if lint_crate_paths.iter().any(|path| path.to_string_lossy().contains(';')) { eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); return Err(ExitStatus::InvalidValue); From 66c556f914e94074276af1885ff86f00235a7859 Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 00:40:18 +0300 Subject: [PATCH 3/7] Move config fetching *after* version check --- cargo-marker/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index a823179a..5faf8441 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -104,14 +104,6 @@ fn main() -> Result<(), ExitStatus> { .take_while(|s| s != CARGO_ARGS_SEPARATOR), ); - let config = match Config::get_marker_config() { - Ok(v) => Some(v), - Err(e) => match e { - config::ConfigFetchError::NotFound => None, - _ => return Err(e.emit_and_convert()), - }, - }; - let verbose = matches.get_flag("verbose"); let test_build = matches.get_flag("test-setup"); let dev_build = cfg!(feature = "dev-build"); @@ -121,6 +113,14 @@ fn main() -> Result<(), ExitStatus> { return Ok(()); } + let config = match Config::get_marker_config() { + Ok(v) => Some(v), + Err(e) => match e { + config::ConfigFetchError::NotFound => None, + _ => return Err(e.emit_and_convert()), + }, + }; + match matches.subcommand() { Some(("setup", _args)) => driver::install_driver(verbose, dev_build), Some(("check", args)) => run_check(&choose_lint_crates(args, config)?, verbose, dev_build, test_build), From fca490c797fc133dded13a046dbef53696b405ba Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 01:19:33 +0300 Subject: [PATCH 4/7] Add missing dependency fields and follow cargo's dependency renaming rules --- Cargo.toml | 2 +- cargo-marker/src/config.rs | 11 +++++++++-- cargo-marker/src/lints.rs | 14 ++++++++++++-- cargo-marker/src/main.rs | 37 ++++++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 59ad2fc2..ecc7fc1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,4 @@ members = [ ] [workspace.metadata.marker.lints] -dogfood = { path = "marker_lints" } +marker_lints = { path = "marker_lints" } diff --git a/cargo-marker/src/config.rs b/cargo-marker/src/config.rs index 63dbd029..45943a94 100644 --- a/cargo-marker/src/config.rs +++ b/cargo-marker/src/config.rs @@ -33,6 +33,7 @@ pub enum LintDependency { #[serde(deny_unknown_fields)] pub struct LintDependencyEntry { path: Option, + package: Option, // TODO: Everything below is not yet supported // Registry fetching: version: Option, @@ -42,6 +43,8 @@ pub struct LintDependencyEntry { rev: Option, branch: Option, // Features: + #[serde(rename = "default-features")] + default_features: Option, features: Option>, optional: Option, // TODO: do we want lint configuration here too? @@ -115,7 +118,7 @@ impl Config { Ok(marker_config) } - pub fn collect_paths(&self) -> Result, ExitStatus> { + pub fn collect_crates(&self) -> Result, ExitStatus> { self.lints .iter() .map(|(name, dep)| match dep { @@ -131,12 +134,16 @@ impl Config { git, rev, branch, + default_features, features, optional ] ); if let Some(ref path) = dep.path { - return Ok(path.clone()); + if let Some(ref package) = dep.package { + return Ok((package.clone(), path.clone())); + } + return Ok((name.clone(), path.clone())); } eprintln!("No `path` field found for lint crate {name}"); Err(ExitStatus::BadConfiguration) diff --git a/cargo-marker/src/lints.rs b/cargo-marker/src/lints.rs index da7b2f54..4d59d614 100644 --- a/cargo-marker/src/lints.rs +++ b/cargo-marker/src/lints.rs @@ -8,7 +8,12 @@ use crate::ExitStatus; /// This creates a debug build for a local crate. The path of the build library /// will be returned, if the operation was successful. -pub fn build_local_lint_crate(crate_dir: &Path, target_dir: &Path, verbose: bool) -> Result { +pub fn build_local_lint_crate( + package_name: Option<&str>, + crate_dir: &Path, + target_dir: &Path, + verbose: bool, +) -> Result { if !crate_dir.exists() { eprintln!("The given lint can't be found, searched at: `{}`", crate_dir.display()); return Err(ExitStatus::LintCrateNotFound); @@ -16,12 +21,17 @@ pub fn build_local_lint_crate(crate_dir: &Path, target_dir: &Path, verbose: bool // Compile the lint crate let mut cmd = Command::new("cargo"); + cmd.arg("build"); if verbose { cmd.arg("--verbose"); } + if let Some(name) = package_name { + cmd.arg("--package"); + cmd.arg(name); + } let exit_status = cmd .current_dir(std::fs::canonicalize(crate_dir).unwrap()) - .args(["build", "--lib", "--target-dir"]) + .args(["--lib", "--target-dir"]) .arg(target_dir.as_os_str()) .env("RUSTFLAGS", "--cap-lints=allow") .spawn() diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index 5faf8441..6377c186 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -79,12 +79,19 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String { .to_string() } -fn choose_lint_crates(args: &clap::ArgMatches, config: Option) -> Result, ExitStatus> { - let lint_crates: Vec = match args.get_many::("lints") { - Some(v) => v.cloned().collect(), +fn choose_lint_crates( + args: &clap::ArgMatches, + config: Option, +) -> Result, OsString)>, ExitStatus> { + let lint_crates: Vec<(Option, OsString)> = match args.get_many::("lints") { + Some(v) => v.cloned().map(|v| (None, v)).collect(), None => { if let Some(config) = config { - config.collect_paths()?.iter().map(Into::into).collect() + config + .collect_crates()? + .into_iter() + .map(|(name, path)| (Some(name), path.into())) + .collect() } else { eprintln!( "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" @@ -130,7 +137,7 @@ fn main() -> Result<(), ExitStatus> { } fn run_check( - lint_crate_paths: &[OsString], + crate_entries: &[(Option, OsString)], verbose: bool, dev_build: bool, test_build: bool, @@ -140,26 +147,34 @@ fn run_check( driver::install_driver(verbose, dev_build)?; } - if lint_crate_paths.is_empty() { + if crate_entries.is_empty() { eprintln!( "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" ); return Err(ExitStatus::NoLints); } - if lint_crate_paths.iter().any(|path| path.to_string_lossy().contains(';')) { + if crate_entries + .iter() + .any(|(_name, path)| path.to_string_lossy().contains(';')) + { eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); return Err(ExitStatus::InvalidValue); } - let mut lint_crates = Vec::with_capacity(lint_crate_paths.len()); + 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 lint_crate_paths { - let src_dir = PathBuf::from(krate); - let crate_file = build_local_lint_crate(src_dir.as_path(), target_dir, verbose)?; + for (name, path) in crate_entries { + let src_dir = PathBuf::from(path); + let crate_file = build_local_lint_crate( + name.as_ref().map(String::as_str), + src_dir.as_path(), + target_dir, + verbose, + )?; lint_crates.push(crate_file.as_os_str().to_os_string()); } From d0af80d7d43eb7d1661e6b6b9cea782e630d2b2b Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 12:03:08 +0300 Subject: [PATCH 5/7] some refactoring --- cargo-marker/src/config.rs | 8 ++--- cargo-marker/src/lints.rs | 33 ++++++++++++++---- cargo-marker/src/main.rs | 71 ++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 48 deletions(-) diff --git a/cargo-marker/src/config.rs b/cargo-marker/src/config.rs index 45943a94..cba3c3a5 100644 --- a/cargo-marker/src/config.rs +++ b/cargo-marker/src/config.rs @@ -8,7 +8,7 @@ use serde::Deserialize; use toml_edit::easy::{from_str, Value}; -use crate::ExitStatus; +use crate::{lints::LintCrateSpec, ExitStatus}; const CARGO_TOML: &str = "Cargo.toml"; @@ -118,7 +118,7 @@ impl Config { Ok(marker_config) } - pub fn collect_crates(&self) -> Result, ExitStatus> { + pub fn collect_crates(&self) -> Result, ExitStatus> { self.lints .iter() .map(|(name, dep)| match dep { @@ -141,9 +141,9 @@ impl Config { ); if let Some(ref path) = dep.path { if let Some(ref package) = dep.package { - return Ok((package.clone(), path.clone())); + return Ok(LintCrateSpec::new(Some(package), path.as_ref())); } - return Ok((name.clone(), path.clone())); + return Ok(LintCrateSpec::new(Some(name), path.as_ref())); } eprintln!("No `path` field found for lint crate {name}"); Err(ExitStatus::BadConfiguration) diff --git a/cargo-marker/src/lints.rs b/cargo-marker/src/lints.rs index 4d59d614..275bf01e 100644 --- a/cargo-marker/src/lints.rs +++ b/cargo-marker/src/lints.rs @@ -6,16 +6,35 @@ use std::{ use crate::ExitStatus; +pub struct LintCrateSpec<'a> { + package_name: Option<&'a str>, + dir: &'a Path, +} + +impl<'a> LintCrateSpec<'a> { + pub fn new(package_name: Option<&'a str>, dir: &'a Path) -> Self { + Self { package_name, dir } + } + + /// Currently only checks for semicolons, can be extended in the future + pub fn validate(&self) -> bool { + self.dir.to_string_lossy().contains(';') + } + + pub fn build_self(&self, target_dir: &Path, verbose: bool) -> Result { + build_local_lint_crate(self, target_dir, verbose) + } +} + /// This creates a debug build for a local crate. The path of the build library /// will be returned, if the operation was successful. pub fn build_local_lint_crate( - package_name: Option<&str>, - crate_dir: &Path, + krate: &LintCrateSpec<'_>, target_dir: &Path, verbose: bool, ) -> Result { - if !crate_dir.exists() { - eprintln!("The given lint can't be found, searched at: `{}`", crate_dir.display()); + if !krate.dir.exists() { + eprintln!("The given lint can't be found, searched at: `{}`", krate.dir.display()); return Err(ExitStatus::LintCrateNotFound); } @@ -25,12 +44,12 @@ pub fn build_local_lint_crate( if verbose { cmd.arg("--verbose"); } - if let Some(name) = package_name { + if let Some(name) = krate.package_name { cmd.arg("--package"); cmd.arg(name); } let exit_status = cmd - .current_dir(std::fs::canonicalize(crate_dir).unwrap()) + .current_dir(std::fs::canonicalize(krate.dir).unwrap()) .args(["--lib", "--target-dir"]) .arg(target_dir.as_os_str()) .env("RUSTFLAGS", "--cap-lints=allow") @@ -53,7 +72,7 @@ pub fn build_local_lint_crate( // See marker#60 let file_name = format!( "{lib_file_prefix}{}", - crate_dir.file_name().and_then(OsStr::to_str).unwrap_or_default() + krate.dir.file_name().and_then(OsStr::to_str).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 6377c186..0f7f0734 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -11,14 +11,14 @@ use std::{ ffi::{OsStr, OsString}, fs::create_dir_all, io, - path::{Path, PathBuf}, + path::Path, process::exit, }; use cli::get_clap_config; use config::Config; use driver::{get_driver_path, run_driver}; -use lints::build_local_lint_crate; +use lints::LintCrateSpec; use once_cell::sync::Lazy; use crate::driver::print_driver_version; @@ -26,6 +26,11 @@ use crate::driver::print_driver_version; const CARGO_ARGS_SEPARATOR: &str = "--"; const VERSION: &str = concat!("cargo-marker ", env!("CARGO_PKG_VERSION")); const LINT_KRATES_BASE_DIR: &str = "./target/marker"; +const NO_LINTS_ERROR: &str = concat!( + "Please provide at least one valid lint crate, ", + "with the `--lints` argument, ", + "or `[workspace.metadata.marker.lints]` in `Cargo.toml`" +); static MARKER_LINT_DIR: Lazy = Lazy::new(|| prepare_lint_build_dir("marker", "marker")); #[derive(Debug)] @@ -79,28 +84,21 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String { .to_string() } -fn choose_lint_crates( - args: &clap::ArgMatches, - config: Option, -) -> Result, OsString)>, ExitStatus> { - let lint_crates: Vec<(Option, OsString)> = match args.get_many::("lints") { - Some(v) => v.cloned().map(|v| (None, v)).collect(), +fn choose_lint_crates<'a>( + args: &'a clap::ArgMatches, + config: Option<&'a Config>, +) -> Result>, ExitStatus> { + match args.get_many::("lints") { + Some(v) => Ok(v.map(|v| LintCrateSpec::new(None, v.as_ref())).collect()), None => { if let Some(config) = config { - config - .collect_crates()? - .into_iter() - .map(|(name, path)| (Some(name), path.into())) - .collect() + config.collect_crates() } else { - eprintln!( - "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" - ); - return Err(ExitStatus::NoLints); + eprintln!("{NO_LINTS_ERROR}"); + Err(ExitStatus::NoLints) } }, - }; - Ok(lint_crates) + } } fn main() -> Result<(), ExitStatus> { @@ -130,14 +128,24 @@ fn main() -> Result<(), ExitStatus> { match matches.subcommand() { Some(("setup", _args)) => driver::install_driver(verbose, dev_build), - Some(("check", args)) => run_check(&choose_lint_crates(args, config)?, verbose, dev_build, test_build), - None => run_check(&choose_lint_crates(&matches, config)?, verbose, dev_build, test_build), + Some(("check", args)) => run_check( + &choose_lint_crates(args, config.as_ref())?, + verbose, + dev_build, + test_build, + ), + None => run_check( + &choose_lint_crates(&matches, config.as_ref())?, + verbose, + dev_build, + test_build, + ), _ => unreachable!(), } } fn run_check( - crate_entries: &[(Option, OsString)], + crate_entries: &[LintCrateSpec], verbose: bool, dev_build: bool, test_build: bool, @@ -148,16 +156,11 @@ fn run_check( } if crate_entries.is_empty() { - eprintln!( - "Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`" - ); + eprintln!("{NO_LINTS_ERROR}"); return Err(ExitStatus::NoLints); } - if crate_entries - .iter() - .any(|(_name, path)| path.to_string_lossy().contains(';')) - { + if crate_entries.iter().any(LintCrateSpec::validate) { eprintln!("The absolute paths of lint crates are not allowed to contain a `;`"); return Err(ExitStatus::InvalidValue); } @@ -167,14 +170,8 @@ fn run_check( println!(); println!("Compiling Lints:"); let target_dir = Path::new(&*MARKER_LINT_DIR); - for (name, path) in crate_entries { - let src_dir = PathBuf::from(path); - let crate_file = build_local_lint_crate( - name.as_ref().map(String::as_str), - src_dir.as_path(), - target_dir, - verbose, - )?; + for krate in crate_entries { + let crate_file = krate.build_self(target_dir, verbose)?; lint_crates.push(crate_file.as_os_str().to_os_string()); } From a96c13e60b1f2b262539cce637cb5bd8e51bdb9e Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 13:16:09 +0300 Subject: [PATCH 6/7] Address review comments --- cargo-marker/src/config.rs | 7 ++++++- cargo-marker/src/lints.rs | 31 +++++++++++++++++++++++-------- cargo-marker/src/main.rs | 4 ++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/cargo-marker/src/config.rs b/cargo-marker/src/config.rs index cba3c3a5..3caee562 100644 --- a/cargo-marker/src/config.rs +++ b/cargo-marker/src/config.rs @@ -92,7 +92,7 @@ macro_rules! unsupported_fields { } impl Config { - pub fn get_marker_config() -> Result { + fn get_raw_manifest() -> Result { let Ok(mut config_file) = File::open(CARGO_TOML) else { return Err(ConfigFetchError::FileNotFound); }; @@ -101,6 +101,11 @@ impl Config { if let Err(e) = config_file.read_to_string(&mut config_str) { return Err(ConfigFetchError::IoError(e)); } + Ok(config_str) + } + + pub fn get_marker_config() -> Result { + let config_str = Self::get_raw_manifest()?; let cargo_config = match from_str::(&config_str) { Ok(v) => v, diff --git a/cargo-marker/src/lints.rs b/cargo-marker/src/lints.rs index 275bf01e..3580aaad 100644 --- a/cargo-marker/src/lints.rs +++ b/cargo-marker/src/lints.rs @@ -7,7 +7,24 @@ use std::{ use crate::ExitStatus; pub struct LintCrateSpec<'a> { + /// Optional package name, exists if supplied from config: + /// ```toml + /// lint_a = { path = "" } + /// # `lint_a` is the package_name + /// lint_b = { path = "", package = "lint_c"} + /// # `lint_c` is the package name + /// ``` + /// if the lint crate was supplied only from path, this is `None`, 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, } @@ -17,22 +34,20 @@ impl<'a> LintCrateSpec<'a> { } /// Currently only checks for semicolons, can be extended in the future - pub fn validate(&self) -> bool { - self.dir.to_string_lossy().contains(';') + pub fn is_valid(&self) -> bool { + !self.dir.to_string_lossy().contains(';') } - pub fn build_self(&self, target_dir: &Path, verbose: bool) -> Result { + /// 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, verbose: bool) -> Result { build_local_lint_crate(self, target_dir, verbose) } } /// This creates a debug build for a local crate. The path of the build library /// will be returned, if the operation was successful. -pub fn build_local_lint_crate( - krate: &LintCrateSpec<'_>, - target_dir: &Path, - verbose: bool, -) -> Result { +fn build_local_lint_crate(krate: &LintCrateSpec<'_>, target_dir: &Path, verbose: bool) -> Result { if !krate.dir.exists() { eprintln!("The given lint can't be found, searched at: `{}`", krate.dir.display()); return Err(ExitStatus::LintCrateNotFound); diff --git a/cargo-marker/src/main.rs b/cargo-marker/src/main.rs index 0f7f0734..615fc294 100644 --- a/cargo-marker/src/main.rs +++ b/cargo-marker/src/main.rs @@ -160,7 +160,7 @@ fn run_check( return Err(ExitStatus::NoLints); } - if crate_entries.iter().any(LintCrateSpec::validate) { + 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); } @@ -171,7 +171,7 @@ fn run_check( println!("Compiling Lints:"); let target_dir = Path::new(&*MARKER_LINT_DIR); for krate in crate_entries { - let crate_file = krate.build_self(target_dir, verbose)?; + let crate_file = krate.build(target_dir, verbose)?; lint_crates.push(crate_file.as_os_str().to_os_string()); } From d5f5ae57d3933279758a278d461d40fc18f2a0cf Mon Sep 17 00:00:00 2001 From: Niki4tap Date: Tue, 10 Jan 2023 13:18:19 +0300 Subject: [PATCH 7/7] note that `package_name` is always UTF-8 --- cargo-marker/src/lints.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cargo-marker/src/lints.rs b/cargo-marker/src/lints.rs index 3580aaad..60fc1a4f 100644 --- a/cargo-marker/src/lints.rs +++ b/cargo-marker/src/lints.rs @@ -7,7 +7,9 @@ use std::{ use crate::ExitStatus; pub struct LintCrateSpec<'a> { - /// Optional package name, exists if supplied from config: + /// Optional package name (this is always UTF-8, as opposed to `dir`), exists if supplied from + /// config: + /// /// ```toml /// lint_a = { path = "" } /// # `lint_a` is the package_name