-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move argfile expansion into run_compiler
This will make @path work with miri and other non-standard entrypoints. Also since this simplifies librustc_driver::args, move it into a simple source file. Also remove the tests since they're doing nothing more than checking `str::lines` has the right behaviour.
- Loading branch information
Showing
8 changed files
with
70 additions
and
239 deletions.
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
error: Argument $N is not valid: Utf8 error in $DIR/commandline-argfile-badutf8.args | ||
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
error: Argument $N is not valid: IO Error: $DIR/commandline-argfile-missing.args: $FILE_MISSING (os error $ERR) | ||
error: Failed to load argument file: IO Error: $DIR/commandline-argfile-missing.args: $FILE_MISSING (os error $ERR) | ||
|