Skip to content

Commit

Permalink
Unify no-library-target error into no-target warn
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Jun 28, 2024
1 parent 6ed64a7 commit 52b43d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
36 changes: 12 additions & 24 deletions src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl<'a> UnitGenerator<'a, '_> {
}
}
CompileFilter::Only {
all_targets,
all_targets: _,
ref lib,
ref bins,
ref examples,
Expand All @@ -372,21 +372,6 @@ impl<'a> UnitGenerator<'a, '_> {
libs.push(proposal)
}
}
if !all_targets && libs.is_empty() && *lib == LibRule::True {
let names = self
.packages
.iter()
.map(|pkg| pkg.name())
.collect::<Vec<_>>();
if names.len() == 1 {
anyhow::bail!("no library targets found in package `{}`", names[0]);
} else {
anyhow::bail!(
"no library targets found in packages: {}",
names.join(", ")
);
}
}
proposals.extend(libs);
}

Expand Down Expand Up @@ -510,7 +495,7 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
let mut shell = self.ws.gctx().shell();
if let CompileFilter::Only {
all_targets,
lib: _,
ref lib,
ref bins,
ref examples,
ref tests,
Expand All @@ -521,16 +506,19 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
let mut filters = String::new();
let mut miss_count = 0;

let mut append = |t: &FilterRule, s| {
if let FilterRule::All = *t {
miss_count += 1;
filters.push_str(s);
}
};

if all_targets {
filters.push_str(" `all-targets`");
} else {
if *lib == LibRule::True {
miss_count += 1;
filters.push_str(" `lib`,");
}
let mut append = |t: &FilterRule, s| {
if let FilterRule::All = *t {
miss_count += 1;
filters.push_str(s);
}
};
append(bins, " `bins`,");
append(tests, " `tests`,");
append(examples, " `examples`,");
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6232,10 +6232,10 @@ fn target_filters_workspace_not_found() {
.build();

ws.cargo("build -v --lib")
.with_status(101)
.with_stderr_data(str![[r#"
[LOCKING] 2 packages to latest compatible versions
[ERROR] no library targets found in packages: a, b
[WARNING] target filter `lib` specified, but no targets matched; this is a no-op
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
Expand Down Expand Up @@ -6522,9 +6522,9 @@ fn build_with_no_lib() {
.build();

p.cargo("build --lib")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] no library targets found in package `foo`
[WARNING] target filter `lib` specified, but no targets matched; this is a no-op
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4204,11 +4204,11 @@ fn doctest_skip_staticlib() {
.build();

p.cargo("test --doc")
.with_status(101)
.with_stderr(
"\
[WARNING] doc tests are not supported for crate type(s) `staticlib` in package `foo`
[ERROR] no library targets found in package `foo`",
[WARNING] target filter `lib` specified, but no targets matched; this is a no-op
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]",
)
.run();

Expand Down

0 comments on commit 52b43d6

Please sign in to comment.