-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc: implement argsfiles for command line #63175
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::error; | ||
use std::fmt; | ||
use std::fs; | ||
use std::io; | ||
use std::str; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
static USED_ARGSFILE_FEATURE: AtomicBool = AtomicBool::new(false); | ||
|
||
pub fn used_unstable_argsfile() -> bool { | ||
USED_ARGSFILE_FEATURE.load(Ordering::Relaxed) | ||
} | ||
|
||
pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> { | ||
if arg.starts_with("@") { | ||
let path = &arg[1..]; | ||
let file = match fs::read_to_string(path) { | ||
Ok(file) => { | ||
USED_ARGSFILE_FEATURE.store(true, Ordering::Relaxed); | ||
file | ||
} | ||
Err(ref err) if err.kind() == io::ErrorKind::InvalidData => { | ||
return Err(Error::Utf8Error(Some(path.to_string()))); | ||
} | ||
Err(err) => return Err(Error::IOError(path.to_string(), err)), | ||
}; | ||
Ok(file.lines().map(ToString::to_string).collect()) | ||
} else { | ||
Ok(vec![arg]) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
Utf8Error(Option<String>), | ||
IOError(String, io::Error), | ||
} | ||
|
||
impl fmt::Display for Error { | ||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Error::Utf8Error(None) => write!(fmt, "Utf8 error"), | ||
Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {}", path), | ||
Error::IOError(path, err) => write!(fmt, "IO Error: {}: {}", path, err), | ||
} | ||
} | ||
} | ||
|
||
impl error::Error for Error { | ||
fn description(&self) -> &'static str { | ||
"argument error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--cfg | ||
unbroken� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Check to see if we can get parameters from an @argsfile file | ||
// | ||
// build-fail | ||
// compile-flags: --cfg cmdline_set @{{src-base}}/commandline-argfile-badutf8.args | ||
|
||
#[cfg(not(cmdline_set))] | ||
compile_error!("cmdline_set not set"); | ||
|
||
#[cfg(not(unbroken))] | ||
compile_error!("unbroken not set"); | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: Failed to load argument file: Utf8 error in $DIR/commandline-argfile-badutf8.args | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Check to see if we can get parameters from an @argsfile file | ||
// | ||
// ignore-tidy-linelength | ||
// build-fail | ||
// normalize-stderr-test: "os error \d+" -> "os error $$ERR" | ||
// normalize-stderr-test: "commandline-argfile-missing.args:[^(]*" -> "commandline-argfile-missing.args: $$FILE_MISSING " | ||
// compile-flags: --cfg cmdline_set @{{src-base}}/commandline-argfile-missing.args | ||
|
||
#[cfg(not(cmdline_set))] | ||
compile_error!("cmdline_set not set"); | ||
|
||
#[cfg(not(unbroken))] | ||
compile_error!("unbroken not set"); | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: Failed to load argument file: IO Error: $DIR/commandline-argfile-missing.args: $FILE_MISSING (os error $ERR) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--cfg | ||
unbroken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Check to see if we can get parameters from an @argsfile file | ||
// | ||
// build-pass | ||
// compile-flags: --cfg cmdline_set @{{src-base}}/commandline-argfile.args | ||
|
||
#[cfg(not(cmdline_set))] | ||
compile_error!("cmdline_set not set"); | ||
|
||
#[cfg(not(unbroken))] | ||
compile_error!("unbroken not set"); | ||
|
||
fn main() { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only in the verbose case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the rationale for verbose-only
--help
options is ones that are likely to be only used when rustc is invoked by some other tool, vs more "common" ones. But I don't really know what the rationale one way or the other is.Either way
@path
seemed like it was on the obscure end of the spectrum.