Skip to content

Commit ec5e297

Browse files
committed
Change --no-filter-targets to --target=all.
1 parent a9ff02e commit ec5e297

File tree

8 files changed

+37
-41
lines changed

8 files changed

+37
-41
lines changed

src/bin/cargo/commands/tree.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub fn cli() -> App {
1616
.arg_target_triple(
1717
"Filter dependencies matching the given target-triple (default host platform)",
1818
)
19-
.arg(opt(
20-
"no-filter-targets",
21-
"Return dependencies for all targets",
22-
))
2319
.arg(opt("no-dev-dependencies", "Skip dev dependencies"))
2420
.arg(opt("invert", "Invert the tree direction").short("i"))
2521
.arg(Arg::with_name("no-indent").long("no-indent").hidden(true))
@@ -81,13 +77,13 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
8177
.map_err(|e| anyhow::anyhow!("{}", e))?;
8278
let prefix = tree::Prefix::from_str(args.value_of("prefix").unwrap())
8379
.map_err(|e| anyhow::anyhow!("{}", e))?;
80+
let target = tree::Target::from_cli(args.value_of("target"));
8481
let opts = tree::TreeOptions {
8582
features: values(args, "features"),
8683
all_features: args.is_present("all-features"),
8784
no_default_features: args.is_present("no-default-features"),
8885
packages: args.packages_from_flags()?,
89-
target: args.target(),
90-
no_filter_targets: args.is_present("no-filter-targets"),
86+
target,
9187
no_dev_dependencies: args.is_present("no-dev-dependencies"),
9288
invert: args.is_present("invert"),
9389
prefix,

src/cargo/ops/tree/graph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ fn add_pkg(
315315
let mut dep_name_map: HashMap<InternedString, HashSet<(usize, bool)>> = HashMap::new();
316316
let mut deps: Vec<_> = resolve.deps(package_id).collect();
317317
deps.sort_unstable_by_key(|(dep_id, _)| *dep_id);
318+
let show_all_targets = opts.target == super::Target::All;
318319
for (dep_id, deps) in deps {
319320
let mut deps: Vec<_> = deps
320321
.iter()
@@ -328,7 +329,7 @@ fn add_pkg(
328329
(_, DepKind::Development) => node_kind,
329330
};
330331
// Filter out inactivated targets.
331-
if !opts.no_filter_targets && !target_data.dep_platform_activated(dep, kind) {
332+
if !show_all_targets && !target_data.dep_platform_activated(dep, kind) {
332333
return false;
333334
}
334335
// Filter out dev-dependencies if requested.

src/cargo/ops/tree/mod.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ pub struct TreeOptions {
2424
/// The packages to display the tree for.
2525
pub packages: Packages,
2626
/// The platform to filter for.
27-
/// If `None`, use the host platform.
28-
pub target: Option<String>,
29-
/// If `true`, ignores the `target` field and returns all targets.
30-
pub no_filter_targets: bool,
27+
pub target: Target,
3128
pub no_dev_dependencies: bool,
3229
pub invert: bool,
3330
/// The style of prefix for each line.
@@ -48,6 +45,23 @@ pub struct TreeOptions {
4845
pub graph_features: bool,
4946
}
5047

48+
#[derive(PartialEq)]
49+
pub enum Target {
50+
Host,
51+
Specific(String),
52+
All,
53+
}
54+
55+
impl Target {
56+
pub fn from_cli(target: Option<&str>) -> Target {
57+
match target {
58+
None => Target::Host,
59+
Some("all") => Target::All,
60+
Some(target) => Target::Specific(target.to_string()),
61+
}
62+
}
63+
}
64+
5165
pub enum Charset {
5266
Utf8,
5367
Ascii,
@@ -108,13 +122,16 @@ static ASCII_SYMBOLS: Symbols = Symbols {
108122

109123
/// Entry point for the `cargo tree` command.
110124
pub fn build_and_print(ws: &Workspace<'_>, opts: &TreeOptions) -> CargoResult<()> {
111-
if opts.no_filter_targets && opts.target.is_some() {
112-
bail!("cannot specify both `--target` and `--no-filter-targets`");
113-
}
114125
if opts.graph_features && opts.duplicates {
115126
bail!("the `--graph-features` flag does not support `--duplicates`");
116127
}
117-
let requested_kind = CompileKind::from_requested_target(ws.config(), opts.target.as_deref())?;
128+
let requested_target = match &opts.target {
129+
Target::All | Target::Host => None,
130+
Target::Specific(t) => Some(t.as_ref()),
131+
};
132+
// TODO: Target::All is broken with -Zfeatures=itarget. To handle that properly,
133+
// `FeatureResolver` will need to be taught what "all" means.
134+
let requested_kind = CompileKind::from_requested_target(ws.config(), requested_target)?;
118135
let target_data = RustcTargetData::new(ws, requested_kind)?;
119136
let specs = opts.packages.to_package_id_specs(ws)?;
120137
let resolve_opts = ResolveOpts::new(

src/doc/man/cargo-tree.adoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ only one instance is built.
6868

6969
*--target* _TRIPLE_::
7070
Filter dependencies matching the given target-triple.
71-
The default is the host platform.
72-
73-
*--no-filter-targets*::
74-
Show dependencies for all target platforms. Cannot be specified with
75-
`--target`.
71+
The default is the host platform. Use the value `all` to include *all*
72+
targets.
7673

7774
*--graph-features*::
7875
Runs in a special mode where features are included as individual nodes.

src/doc/man/generated/cargo-tree.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ <h3 id="cargo_tree_tree_options">Tree Options</h3>
8181
<dt class="hdlist1"><strong>--target</strong> <em>TRIPLE</em></dt>
8282
<dd>
8383
<p>Filter dependencies matching the given target-triple.
84-
The default is the host platform.</p>
85-
</dd>
86-
<dt class="hdlist1"><strong>--no-filter-targets</strong></dt>
87-
<dd>
88-
<p>Show dependencies for all target platforms. Cannot be specified with
89-
<code>--target</code>.</p>
84+
The default is the host platform. Use the value <code>all</code> to include <strong>all</strong>
85+
targets.</p>
9086
</dd>
9187
<dt class="hdlist1"><strong>--graph-features</strong></dt>
9288
<dd>

src/etc/man/cargo-tree.1

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,8 @@ Do not include dev\-dependencies.
9595
\fB\-\-target\fP \fITRIPLE\fP
9696
.RS 4
9797
Filter dependencies matching the given target\-triple.
98-
The default is the host platform.
99-
.RE
100-
.sp
101-
\fB\-\-no\-filter\-targets\fP
102-
.RS 4
103-
Show dependencies for all target platforms. Cannot be specified with
104-
\fB\-\-target\fP.
98+
The default is the host platform. Use the value \fBall\fP to include \fBall\fP
99+
targets.
105100
.RE
106101
.sp
107102
\fB\-\-graph\-features\fP

tests/testsuite/tree.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,7 @@ foo v0.1.0 ([..]/foo)
414414
)
415415
.run();
416416

417-
p.cargo("tree --no-filter-targets --target")
418-
.arg(alternate())
419-
.with_status(101)
420-
.with_stderr("[ERROR] cannot specify both `--target` and `--no-filter-targets`")
421-
.run();
422-
423-
p.cargo("tree --no-filter-targets")
417+
p.cargo("tree --target=all")
424418
.with_stdout(
425419
"\
426420
foo v0.1.0 ([..]/foo)

tests/testsuite/tree_graph_features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ foo v0.1.0 ([..]/foo)
344344
",
345345
)
346346
.run();
347-
p.cargo("tree --graph-features --all-features --no-filter-targets")
347+
p.cargo("tree --graph-features --all-features --target=all")
348348
.with_stdout(
349349
"\
350350
foo v0.1.0 ([..]/foo)

0 commit comments

Comments
 (0)