about summary refs log tree commit diff
path: root/src/librustc_driver/lib.rs
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jsgf@fb.com>2019-07-30 15:57:10 -0700
committerJeremy Fitzhardinge <jsgf@fb.com>2019-08-19 19:06:46 -0700
commitd2219c2e2e287d50c0f9761203d26d5fe3b0e639 (patch)
treeffa424e0cfa2350cbc589c6ce85f2865e0ce81ec /src/librustc_driver/lib.rs
parent859657f2c5dbe2cf55cf7a7665383a81e676bdf3 (diff)
downloadrust-d2219c2e2e287d50c0f9761203d26d5fe3b0e639.tar.gz
rust-d2219c2e2e287d50c0f9761203d26d5fe3b0e639.zip
rustc: implement argsfiles for command line
This makes `rustc` support `@path` arguments on the command line. The `path` is opened and the file is interpreted
as new command line options which are logically inserted at that point in the command-line. The options in the file
are one per line. The file is UTF-8 encoded, and may have either Unix or Windows line endings.
It does not support recursive use of `@path`.

This is useful for very large command lines, or when command-lines are being generated into files by other tooling.
Diffstat (limited to 'src/librustc_driver/lib.rs')
-rw-r--r--src/librustc_driver/lib.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index cd030f3c918..4843c1a951b 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -66,6 +66,7 @@ use syntax::symbol::sym;
 use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
 
 pub mod pretty;
+mod args;
 
 /// Exit status code used for successful compilation and help output.
 pub const EXIT_SUCCESS: i32 = 0;
@@ -777,11 +778,17 @@ fn usage(verbose: bool, include_unstable_options: bool) {
     } else {
         "\n    --help -v           Print the full set of options rustc accepts"
     };
-    println!("{options}\nAdditional help:
+    let at_path = if verbose && nightly_options::is_nightly_build() {
+        "    @path               Read newline separated options from `path`\n"
+    } else {
+        ""
+    };
+    println!("{options}{at_path}\nAdditional help:
     -C help             Print codegen options
     -W help             \
               Print 'lint' options and default settings{nightly}{verbose}\n",
              options = options.usage(message),
+             at_path = at_path,
              nightly = nightly_help,
              verbose = verbose_help);
 }
@@ -1008,6 +1015,12 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
     //   (unstable option being used on stable)
     nightly_options::check_nightly_options(&matches, &config::rustc_optgroups());
 
+    // Late check to see if @file was used without unstable options enabled
+    if crate::args::used_unstable_argsfile() && !nightly_options::is_unstable_enabled(&matches) {
+        early_error(ErrorOutputType::default(),
+            "@path is unstable - use -Z unstable-options to enable its use");
+    }
+
     if matches.opt_present("h") || matches.opt_present("help") {
         // Only show unstable options in --help if we accept unstable options.
         usage(matches.opt_present("verbose"), nightly_options::is_unstable_enabled(&matches));
@@ -1186,10 +1199,10 @@ pub fn main() {
     init_rustc_env_logger();
     let mut callbacks = TimePassesCallbacks::default();
     let result = report_ices_to_stderr_if_any(|| {
-        let args = env::args_os().enumerate()
-            .map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
+        let args = args::ArgsIter::new().enumerate()
+            .map(|(i, arg)| arg.unwrap_or_else(|err| {
                 early_error(ErrorOutputType::default(),
-                            &format!("Argument {} is not valid Unicode: {:?}", i, arg))
+                            &format!("Argument {} is not valid: {}", i, err))
             }))
             .collect::<Vec<_>>();
         run_compiler(&args, &mut callbacks, None, None)