Skip to content

Commit ebd20d2

Browse files
authored
Support --filter-platform=host for cargo metadata #9423 (#16312)
This PR fixes this issue-: #9423
2 parents e90598e + 6fffcee commit ebd20d2

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/doc/man/cargo-metadata.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ possible value.
362362
{{#option "`--filter-platform` _triple_" }}
363363
This filters the `resolve` output to only include dependencies for the
364364
given [target triple](../appendix/glossary.html#target).
365+
A literal `"host-tuple"` can be used, which will internally be substituted by the host's target.
365366
Without this flag, the resolve includes all targets.
366367

367368
Note that the dependencies listed in the "packages" array still includes all

src/doc/man/generated_txt/cargo-metadata.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ OPTIONS
354354
--filter-platform triple
355355
This filters the resolve output to only include dependencies for the
356356
given target triple
357-
<https://doc.rust-lang.org/cargo/appendix/glossary.html#target>.
358-
Without this flag, the resolve includes all targets.
357+
<https://doc.rust-lang.org/cargo/appendix/glossary.html#target>. A
358+
literal "host-tuple" can be used, which will internally be
359+
substituted by the host’s target. Without this flag, the resolve
360+
includes all targets.
359361

360362
Note that the dependencies listed in the “packages” array still
361363
includes all dependencies. Each package definition is intended to be

src/doc/src/commands/cargo-metadata.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ possible value.</p>
364364
<dt class="option-term" id="option-cargo-metadata---filter-platform"><a class="option-anchor" href="#option-cargo-metadata---filter-platform"><code>--filter-platform</code> <em>triple</em></a></dt>
365365
<dd class="option-desc"><p>This filters the <code>resolve</code> output to only include dependencies for the
366366
given <a href="../appendix/glossary.html#target">target triple</a>.
367+
A literal <code>"host-tuple"</code> can be used, which will internally be substituted by the host’s target.
367368
Without this flag, the resolve includes all targets.</p>
368369
<p>Note that the dependencies listed in the “packages” array still includes all
369370
dependencies. Each package definition is intended to be an unaltered

src/etc/man/cargo-metadata.1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ possible value.
367367
.RS 4
368368
This filters the \fBresolve\fR output to only include dependencies for the
369369
given \fItarget triple\fR <https://doc.rust\-lang.org/cargo/appendix/glossary.html#target>\&.
370+
A literal \fB"host\-tuple"\fR can be used, which will internally be substituted by the host\[cq]s target.
370371
Without this flag, the resolve includes all targets.
371372
.sp
372373
Note that the dependencies listed in the \[lq]packages\[rq] array still includes all

tests/testsuite/metadata.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,21 +3842,15 @@ fn filter_platform() {
38423842
.run();
38433843
clear();
38443844

3845-
// Filter on host, removes alt and cfg.
3846-
p.cargo("metadata --filter-platform")
3847-
.arg(&host_target)
3848-
.with_stderr_data(
3849-
str![[r#"
3845+
let host_filtered_stderr = str![[r#"
38503846
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
38513847
[DOWNLOADING] crates ...
38523848
[DOWNLOADED] normal-dep v0.0.1 (registry `dummy-registry`)
38533849
[DOWNLOADED] host-dep v0.0.1 (registry `dummy-registry`)
38543850
3855-
"#]]
3856-
.unordered(),
3857-
)
3858-
.with_stdout_data(
3859-
str![[r#"
3851+
"#]];
3852+
3853+
let host_filtered_stdout = str![[r#"
38603854
{
38613855
"packages": [
38623856
{
@@ -3945,10 +3939,21 @@ fn filter_platform() {
39453939
},
39463940
"...": "{...}"
39473941
}
3948-
"#]]
3949-
.is_json()
3950-
.unordered(),
3951-
)
3942+
"#]];
3943+
3944+
// Filter on host, removes alt and cfg.
3945+
p.cargo("metadata --filter-platform")
3946+
.arg(&host_target)
3947+
.with_stderr_data(host_filtered_stderr.clone().unordered())
3948+
.with_stdout_data(host_filtered_stdout.clone().is_json().unordered())
3949+
.run();
3950+
clear();
3951+
3952+
// Filter on host-tuple, should produce same result as explicit host target.
3953+
p.cargo("metadata --filter-platform")
3954+
.arg("host-tuple")
3955+
.with_stderr_data(host_filtered_stderr.unordered())
3956+
.with_stdout_data(host_filtered_stdout.is_json().unordered())
39523957
.run();
39533958
clear();
39543959

0 commit comments

Comments
 (0)