From 9d9b461cd0e52f0c1f2d8d09c36cd326a0c76ce9 Mon Sep 17 00:00:00 2001 From: Joseph Ryan Date: Thu, 19 Oct 2023 12:39:59 -0700 Subject: [PATCH] Use shell parsing for response files --- Cargo.lock | 5 +++-- compiler/rustc_driver_impl/Cargo.toml | 1 + compiler/rustc_driver_impl/src/args.rs | 14 +++++++++++++- src/tools/tidy/src/deps.rs | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa2f9c4147e3b..fd50e013ac71d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3747,6 +3747,7 @@ dependencies = [ "rustc_trait_selection", "rustc_ty_utils", "serde_json", + "shlex", "time", "tracing", "windows", @@ -4950,9 +4951,9 @@ checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" [[package]] name = "shlex" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" [[package]] name = "siphasher" diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index d931a8dab9b8d..3c8cb4abb8244 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -52,6 +52,7 @@ rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_ty_utils = { path = "../rustc_ty_utils" } serde_json = "1.0.59" +shlex = { version = "1.2" } time = { version = "0.3", default-features = false, features = ["alloc", "formatting"] } tracing = { version = "0.1.35" } # tidy-alphabetical-end diff --git a/compiler/rustc_driver_impl/src/args.rs b/compiler/rustc_driver_impl/src/args.rs index 654d7636da200..40e224871a56a 100644 --- a/compiler/rustc_driver_impl/src/args.rs +++ b/compiler/rustc_driver_impl/src/args.rs @@ -14,7 +14,19 @@ fn arg_expand(arg: String) -> Result, Error> { } Err(err) => return Err(Error::IOError(path.to_string(), err)), }; - Ok(file.lines().map(ToString::to_string).collect()) + let mut result = Vec::new(); + for line in file.lines() { + match shlex::split(line) { + Some(v) => result.extend(v), + None => { + return Err(Error::IOError( + path.to_string(), + io::Error::other("invalid shell syntax"), + )); + } + } + } + Ok(result) } else { Ok(vec![arg]) } diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index f89faacc2d17b..d62415c6cf68a 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -248,6 +248,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "sha1", "sha2", "sharded-slab", + "shlex", "smallvec", "snap", "stable_deref_trait",