Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify no-library-target error into no-target warn #14163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Author

@ryoqun ryoqun Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the earliest ancestor of this error is this: https://github.com/rust-lang/cargo/pull/839/files#r1658124748 (around Nov 15, 2014)

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);
}
};

Comment on lines -524 to -530
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed to move closer to the actually used place to avoid borrow check error.

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`,");
Copy link
Author

@ryoqun ryoqun Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems the earliest ancestor of the following out-of-diff warn is this: https://github.com/rust-lang/cargo/pull/9549/files#diff-98da1b66b532e50e9bca971b453ee7de96b17436de1d7ef3824c9888d55be9bbR1189-R1193 (for some reason, i can't comment on the referenced pr....) (around Jun 10, 2021)

                return shell.warn(format!(
                    "target {}{} specified, but no targets matched; this is a no-op",
                    if miss_count > 1 { "filters" } else { "filter" },
                    filters,
                ));

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