Skip to content

Commit 1073915

Browse files
committed
Auto merge of #10546 - weihanglo:issue-10381-rustc-argfile, r=epage
Retry command invocation with argfile ### What does this PR try to resolve? Fixes #10381 The goal is to invoke `rustc` and `rustdoc` with ``@path`` arg file as a fallback. Since the `-Zcheck-cfg-features`[^1] has already been implemented, in the foreseeable future cargo will probably hit the “**command line too big**” more often on Windows. `rustdoc` and `rustc` both support ``@path`` argfile [^2][^3], so we can leverage the feature for the fallback logic. The idea behind this PR is that we put the **retry logic** in `ProcessBuilder::exec*` functions and reuse them as much as possible. ### How should we test and review this PR? Review it commit by commit is recommended. Argfile fallback is hard to tested with integration tests, so I added some unit tests for `cargo_util::ProcessBuilder` and `cargo::ops::fix::FixArgs`. If you do want to test the support of argfile manually, a new environment variable `__CARGO_TEST_FORCE_ARGFILE` is added for the sake of forcing cargo to use argfile for rustc invocations. For example, `__CARGO_TEST_FORCE_ARGFILE cargo test --test testsuite -- fix::` is usually a good start to test this feature. [^1]: https://doc.rust-lang.org/beta/cargo/reference/unstable.html?highlight=check#check-cfg-features [^2]: https://doc.rust-lang.org/rustc/command-line-arguments.html#path-load-command-line-flags-from-a-path [^3]: https://doc.rust-lang.org/rustdoc/command-line-arguments.html#path-load-command-line-flags-from-a-path
2 parents f51e799 + 275b0c6 commit 1073915

File tree

13 files changed

+466
-119
lines changed

13 files changed

+466
-119
lines changed

Diff for: .github/workflows/main.yml

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ jobs:
6868

6969
# Deny warnings on CI to avoid warnings getting into the codebase.
7070
- run: cargo test --features 'deny-warnings'
71+
- name: Check operability of rustc invocation with argfile
72+
env:
73+
__CARGO_TEST_FORCE_ARGFILE: 1
74+
run: |
75+
# This only tests `cargo fix` because fix-proxy-mode is one of the most
76+
# complicated subprocess management in Cargo.
77+
cargo test --test testsuite --features 'deny-warnings' -- fix::
7178
- run: cargo test --features 'deny-warnings' --manifest-path crates/cargo-test-support/Cargo.toml
7279
env:
7380
CARGO_TARGET_DIR: target

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/cargo/lib.rs"
1919
atty = "0.2"
2020
bytesize = "1.0"
2121
cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
22-
cargo-util = { path = "crates/cargo-util", version = "0.1.2" }
22+
cargo-util = { path = "crates/cargo-util", version = "0.1.3" }
2323
crates-io = { path = "crates/crates-io", version = "0.34.0" }
2424
crossbeam-utils = "0.8"
2525
curl = { version = "0.4.41", features = ["http2"] }

Diff for: crates/cargo-test-support/src/tools.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ pub fn echo_wrapper() -> PathBuf {
2424
.file(
2525
"src/main.rs",
2626
r#"
27+
use std::fs::read_to_string;
28+
use std::path::PathBuf;
2729
fn main() {
28-
let args = std::env::args().collect::<Vec<_>>();
30+
// Handle args from `@path` argfile for rustc
31+
let args = std::env::args()
32+
.flat_map(|p| if let Some(p) = p.strip_prefix("@") {
33+
read_to_string(p).unwrap().lines().map(String::from).collect()
34+
} else {
35+
vec![p]
36+
})
37+
.collect::<Vec<_>>();
2938
eprintln!("WRAPPER CALLED: {}", args[1..].join(" "));
3039
let status = std::process::Command::new(&args[1])
3140
.args(&args[2..]).status().unwrap();

Diff for: crates/cargo-util/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
homepage = "https://github.com/rust-lang/cargo"

0 commit comments

Comments
 (0)