mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 11:12:25 +00:00
Add examples to the warning about missing features
This commit is contained in:
parent
2e883c22d2
commit
bac6a9a49c
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
|||
use std::{env, fs};
|
||||
|
||||
use crate::core::compiler::{CompileKind, DefaultExecutor, Executor, UnitOutput};
|
||||
use crate::core::{Dependency, Edition, Package, PackageId, Source, SourceId, Workspace};
|
||||
use crate::core::{Dependency, Edition, Package, PackageId, Source, SourceId, Target, Workspace};
|
||||
use crate::ops::{common_for_install_and_uninstall::*, FilterRule};
|
||||
use crate::ops::{CompileFilter, Packages};
|
||||
use crate::sources::{GitSource, PathSource, SourceConfigMap};
|
||||
|
@ -361,32 +361,16 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
|
|||
//
|
||||
// Note that we know at this point that _if_ bins or examples is set to `::Just`,
|
||||
// they're `::Just([])`, which is `FilterRule::none()`.
|
||||
let binaries: Vec<_> = self.pkg.targets().iter().filter(|t| t.is_bin()).collect();
|
||||
let binaries: Vec<_> = self
|
||||
.pkg
|
||||
.targets()
|
||||
.iter()
|
||||
.filter(|t| t.is_executable())
|
||||
.collect();
|
||||
if !binaries.is_empty() {
|
||||
let target_features_message = binaries
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let name = b.name();
|
||||
let features = b
|
||||
.required_features()
|
||||
.unwrap_or(&Vec::new())
|
||||
.iter()
|
||||
.map(|f| format!("`{f}`"))
|
||||
.join(", ");
|
||||
format!(" Target `{name}` requires the features: {features}")
|
||||
})
|
||||
.join("\n");
|
||||
let example_features = binaries[0]
|
||||
.required_features()
|
||||
.map(|f| f.join(" "))
|
||||
.unwrap_or_default();
|
||||
let message = format!(
|
||||
"\
|
||||
none of the package's binaries are available for install using the selected features
|
||||
{target_features_message}
|
||||
Consider enabling some of them by passing, e.g., `--features=\"{example_features}\"`"
|
||||
);
|
||||
self.config.shell().warn(message)?;
|
||||
self.config
|
||||
.shell()
|
||||
.warn(make_warning_about_missing_features(&binaries))?;
|
||||
}
|
||||
|
||||
return Ok(false);
|
||||
|
@ -569,6 +553,45 @@ Consider enabling some of them by passing, e.g., `--features=\"{example_features
|
|||
}
|
||||
}
|
||||
|
||||
fn make_warning_about_missing_features(binaries: &[&Target]) -> String {
|
||||
let max_targets_listed = 7;
|
||||
let target_features_message = binaries
|
||||
.iter()
|
||||
.take(max_targets_listed)
|
||||
.map(|b| {
|
||||
let name = b.description_named();
|
||||
let features = b
|
||||
.required_features()
|
||||
.unwrap_or(&Vec::new())
|
||||
.iter()
|
||||
.map(|f| format!("`{f}`"))
|
||||
.join(", ");
|
||||
format!(" {name} requires the features: {features}")
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
let additional_bins_message = if binaries.len() > max_targets_listed {
|
||||
format!(
|
||||
"\n{} more targets also requires features not enabled, see them in the Cargo.toml file.",
|
||||
binaries.len() - max_targets_listed
|
||||
)
|
||||
} else {
|
||||
"".into()
|
||||
};
|
||||
|
||||
let example_features = binaries[0]
|
||||
.required_features()
|
||||
.map(|f| f.join(" "))
|
||||
.unwrap_or_default();
|
||||
|
||||
format!(
|
||||
"\
|
||||
none of the package's binaries are available for install using the selected features
|
||||
{target_features_message}{additional_bins_message}
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"{example_features}\"`"
|
||||
)
|
||||
}
|
||||
|
||||
pub fn install(
|
||||
config: &Config,
|
||||
root: Option<&str>,
|
||||
|
|
|
@ -640,8 +640,9 @@ fn install_default_features() {
|
|||
[INSTALLING] foo v0.0.1 ([..])
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo` requires the features: `a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"a\"`
|
||||
bin \"foo\" requires the features: `a`
|
||||
example \"foo\" requires the features: `a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"a\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -794,9 +795,11 @@ fn install_multiple_required_features() {
|
|||
[INSTALLING] foo v0.0.1 ([..])
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo_1` requires the features: `b`, `c`
|
||||
Target `foo_2` requires the features: `a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
||||
bin \"foo_1\" requires the features: `b`, `c`
|
||||
bin \"foo_2\" requires the features: `a`
|
||||
example \"foo_3\" requires the features: `b`, `c`
|
||||
example \"foo_4\" requires the features: `a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -807,9 +810,11 @@ Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
|||
[WARNING] Target filter `bins` specified, but no targets matched. This is a no-op
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo_1` requires the features: `b`, `c`
|
||||
Target `foo_2` requires the features: `a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
||||
bin \"foo_1\" requires the features: `b`, `c`
|
||||
bin \"foo_2\" requires the features: `a`
|
||||
example \"foo_3\" requires the features: `b`, `c`
|
||||
example \"foo_4\" requires the features: `a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -820,9 +825,11 @@ Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
|||
[WARNING] Target filter `examples` specified, but no targets matched. This is a no-op
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo_1` requires the features: `b`, `c`
|
||||
Target `foo_2` requires the features: `a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
||||
bin \"foo_1\" requires the features: `b`, `c`
|
||||
bin \"foo_2\" requires the features: `a`
|
||||
example \"foo_3\" requires the features: `b`, `c`
|
||||
example \"foo_4\" requires the features: `a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -833,9 +840,11 @@ Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
|||
[WARNING] Target filters `bins`, `examples` specified, but no targets matched. This is a no-op
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo_1` requires the features: `b`, `c`
|
||||
Target `foo_2` requires the features: `a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"b c\"`
|
||||
bin \"foo_1\" requires the features: `b`, `c`
|
||||
bin \"foo_2\" requires the features: `a`
|
||||
example \"foo_3\" requires the features: `b`, `c`
|
||||
example \"foo_4\" requires the features: `a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"b c\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
@ -1094,8 +1103,9 @@ Consider enabling them by passing, e.g., `--features=\"bar/a\"`
|
|||
[INSTALLING] foo v0.0.1 ([..])
|
||||
[FINISHED] release [optimized] target(s) in [..]
|
||||
[WARNING] none of the package's binaries are available for install using the selected features
|
||||
Target `foo` requires the features: `bar/a`
|
||||
Consider enabling some of them by passing, e.g., `--features=\"bar/a\"`
|
||||
bin \"foo\" requires the features: `bar/a`
|
||||
example \"foo\" requires the features: `bar/a`
|
||||
Consider enabling some of the needed features by passing, e.g., `--features=\"bar/a\"`
|
||||
",
|
||||
)
|
||||
.run();
|
||||
|
|
Loading…
Reference in a new issue