Skip to content

Commit fca490c

Browse files
committed
Add missing dependency fields and follow cargo's dependency renaming rules
1 parent 66c556f commit fca490c

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ members = [
99
]
1010

1111
[workspace.metadata.marker.lints]
12-
dogfood = { path = "marker_lints" }
12+
marker_lints = { path = "marker_lints" }

cargo-marker/src/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub enum LintDependency {
3333
#[serde(deny_unknown_fields)]
3434
pub struct LintDependencyEntry {
3535
path: Option<String>,
36+
package: Option<String>,
3637
// TODO: Everything below is not yet supported
3738
// Registry fetching:
3839
version: Option<String>,
@@ -42,6 +43,8 @@ pub struct LintDependencyEntry {
4243
rev: Option<String>,
4344
branch: Option<String>,
4445
// Features:
46+
#[serde(rename = "default-features")]
47+
default_features: Option<bool>,
4548
features: Option<Vec<String>>,
4649
optional: Option<bool>,
4750
// TODO: do we want lint configuration here too?
@@ -115,7 +118,7 @@ impl Config {
115118
Ok(marker_config)
116119
}
117120

118-
pub fn collect_paths(&self) -> Result<Vec<String>, ExitStatus> {
121+
pub fn collect_crates(&self) -> Result<Vec<(String, String)>, ExitStatus> {
119122
self.lints
120123
.iter()
121124
.map(|(name, dep)| match dep {
@@ -131,12 +134,16 @@ impl Config {
131134
git,
132135
rev,
133136
branch,
137+
default_features,
134138
features,
135139
optional
136140
]
137141
);
138142
if let Some(ref path) = dep.path {
139-
return Ok(path.clone());
143+
if let Some(ref package) = dep.package {
144+
return Ok((package.clone(), path.clone()));
145+
}
146+
return Ok((name.clone(), path.clone()));
140147
}
141148
eprintln!("No `path` field found for lint crate {name}");
142149
Err(ExitStatus::BadConfiguration)

cargo-marker/src/lints.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@ use crate::ExitStatus;
88

99
/// This creates a debug build for a local crate. The path of the build library
1010
/// will be returned, if the operation was successful.
11-
pub fn build_local_lint_crate(crate_dir: &Path, target_dir: &Path, verbose: bool) -> Result<PathBuf, ExitStatus> {
11+
pub fn build_local_lint_crate(
12+
package_name: Option<&str>,
13+
crate_dir: &Path,
14+
target_dir: &Path,
15+
verbose: bool,
16+
) -> Result<PathBuf, ExitStatus> {
1217
if !crate_dir.exists() {
1318
eprintln!("The given lint can't be found, searched at: `{}`", crate_dir.display());
1419
return Err(ExitStatus::LintCrateNotFound);
1520
}
1621

1722
// Compile the lint crate
1823
let mut cmd = Command::new("cargo");
24+
cmd.arg("build");
1925
if verbose {
2026
cmd.arg("--verbose");
2127
}
28+
if let Some(name) = package_name {
29+
cmd.arg("--package");
30+
cmd.arg(name);
31+
}
2232
let exit_status = cmd
2333
.current_dir(std::fs::canonicalize(crate_dir).unwrap())
24-
.args(["build", "--lib", "--target-dir"])
34+
.args(["--lib", "--target-dir"])
2535
.arg(target_dir.as_os_str())
2636
.env("RUSTFLAGS", "--cap-lints=allow")
2737
.spawn()

cargo-marker/src/main.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,19 @@ fn prepare_lint_build_dir(dir_name: &str, info_name: &str) -> String {
7979
.to_string()
8080
}
8181

82-
fn choose_lint_crates(args: &clap::ArgMatches, config: Option<Config>) -> Result<Vec<OsString>, ExitStatus> {
83-
let lint_crates: Vec<OsString> = match args.get_many::<OsString>("lints") {
84-
Some(v) => v.cloned().collect(),
82+
fn choose_lint_crates(
83+
args: &clap::ArgMatches,
84+
config: Option<Config>,
85+
) -> Result<Vec<(Option<String>, OsString)>, ExitStatus> {
86+
let lint_crates: Vec<(Option<String>, OsString)> = match args.get_many::<OsString>("lints") {
87+
Some(v) => v.cloned().map(|v| (None, v)).collect(),
8588
None => {
8689
if let Some(config) = config {
87-
config.collect_paths()?.iter().map(Into::into).collect()
90+
config
91+
.collect_crates()?
92+
.into_iter()
93+
.map(|(name, path)| (Some(name), path.into()))
94+
.collect()
8895
} else {
8996
eprintln!(
9097
"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> {
130137
}
131138

132139
fn run_check(
133-
lint_crate_paths: &[OsString],
140+
crate_entries: &[(Option<String>, OsString)],
134141
verbose: bool,
135142
dev_build: bool,
136143
test_build: bool,
@@ -140,26 +147,34 @@ fn run_check(
140147
driver::install_driver(verbose, dev_build)?;
141148
}
142149

143-
if lint_crate_paths.is_empty() {
150+
if crate_entries.is_empty() {
144151
eprintln!(
145152
"Please provide at least one valid lint crate, with the `--lints` argument, or `[workspace.metadata.marker.lints]` in `Cargo.toml`"
146153
);
147154
return Err(ExitStatus::NoLints);
148155
}
149156

150-
if lint_crate_paths.iter().any(|path| path.to_string_lossy().contains(';')) {
157+
if crate_entries
158+
.iter()
159+
.any(|(_name, path)| path.to_string_lossy().contains(';'))
160+
{
151161
eprintln!("The absolute paths of lint crates are not allowed to contain a `;`");
152162
return Err(ExitStatus::InvalidValue);
153163
}
154164

155-
let mut lint_crates = Vec::with_capacity(lint_crate_paths.len());
165+
let mut lint_crates = Vec::with_capacity(crate_entries.len());
156166

157167
println!();
158168
println!("Compiling Lints:");
159169
let target_dir = Path::new(&*MARKER_LINT_DIR);
160-
for krate in lint_crate_paths {
161-
let src_dir = PathBuf::from(krate);
162-
let crate_file = build_local_lint_crate(src_dir.as_path(), target_dir, verbose)?;
170+
for (name, path) in crate_entries {
171+
let src_dir = PathBuf::from(path);
172+
let crate_file = build_local_lint_crate(
173+
name.as_ref().map(String::as_str),
174+
src_dir.as_path(),
175+
target_dir,
176+
verbose,
177+
)?;
163178
lint_crates.push(crate_file.as_os_str().to_os_string());
164179
}
165180

0 commit comments

Comments
 (0)