diff options
| author | Tor Hovland <tor.hovland@bekk.no> | 2021-11-02 22:41:34 +0100 |
|---|---|---|
| committer | Tor Hovland <tor.hovland@bekk.no> | 2021-11-02 22:41:34 +0100 |
| commit | 5d1e09f44ab0bd3ca29acf44d92e884ec140d00a (patch) | |
| tree | 57ecc54c99e43c3668a72ad77b3d7cb8937cd15c | |
| parent | 18bc4bee9710b181b440a472635150f0d6257713 (diff) | |
| download | rust-5d1e09f44ab0bd3ca29acf44d92e884ec140d00a.tar.gz rust-5d1e09f44ab0bd3ca29acf44d92e884ec140d00a.zip | |
Added the --temps-dir option.
| -rw-r--r-- | compiler/rustc_driver/src/lib.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/interface.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/util.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 14 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 1 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 1 |
7 files changed, 49 insertions, 4 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 9a57ec99144..6b3c65dd527 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -215,6 +215,7 @@ fn run_compiler( let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg")); let (odir, ofile) = make_output(&matches); + let temps_dir = make_temps_dir(&matches); let mut config = interface::Config { opts: sopts, crate_cfg: cfg, @@ -222,6 +223,7 @@ fn run_compiler( input_path: None, output_file: ofile, output_dir: odir, + temps_dir, file_loader, diagnostic_output, stderr: None, @@ -267,6 +269,7 @@ fn run_compiler( None, compiler.output_dir(), compiler.output_file(), + compiler.temps_dir(), ); if should_stop == Compilation::Stop { @@ -295,6 +298,7 @@ fn run_compiler( Some(compiler.input()), compiler.output_dir(), compiler.output_file(), + compiler.temps_dir(), ) .and_then(|| { RustcDefaultCalls::list_metadata( @@ -454,6 +458,11 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>) (odir, ofile) } +// Extract temporary directory from matches. +fn make_temps_dir(matches: &getopts::Matches) -> Option<PathBuf> { + matches.opt_str("temps-dir").map(|o| PathBuf::from(&o)) +} + // Extract input (string or file and optional path) from matches. fn make_input( error_format: ErrorOutputType, @@ -647,6 +656,7 @@ impl RustcDefaultCalls { input: Option<&Input>, odir: &Option<PathBuf>, ofile: &Option<PathBuf>, + temps_dir: &Option<PathBuf>, ) -> Compilation { use rustc_session::config::PrintRequest::*; // PrintRequest::NativeStaticLibs is special - printed during linking @@ -685,7 +695,7 @@ impl RustcDefaultCalls { }); let attrs = attrs.as_ref().unwrap(); let t_outputs = rustc_interface::util::build_output_filenames( - input, odir, ofile, attrs, sess, + input, odir, ofile, temps_dir, attrs, sess, ); let id = rustc_session::output::find_crate_name(sess, attrs, input); if *req == PrintRequest::CrateName { diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 7a6a643e3d0..7b235be48b3 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -36,6 +36,7 @@ pub struct Compiler { pub(crate) input_path: Option<PathBuf>, pub(crate) output_dir: Option<PathBuf>, pub(crate) output_file: Option<PathBuf>, + pub(crate) temps_dir: Option<PathBuf>, pub(crate) register_lints: Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>>, pub(crate) override_queries: Option<fn(&Session, &mut ty::query::Providers, &mut ty::query::ExternProviders)>, @@ -57,6 +58,9 @@ impl Compiler { pub fn output_file(&self) -> &Option<PathBuf> { &self.output_file } + pub fn temps_dir(&self) -> &Option<PathBuf> { + &self.temps_dir + } pub fn register_lints(&self) -> &Option<Box<dyn Fn(&Session, &mut LintStore) + Send + Sync>> { &self.register_lints } @@ -65,7 +69,14 @@ impl Compiler { sess: &Session, attrs: &[ast::Attribute], ) -> OutputFilenames { - util::build_output_filenames(&self.input, &self.output_dir, &self.output_file, attrs, sess) + util::build_output_filenames( + &self.input, + &self.output_dir, + &self.output_file, + &self.temps_dir, + attrs, + sess, + ) } } @@ -132,6 +143,7 @@ pub struct Config { pub input_path: Option<PathBuf>, pub output_dir: Option<PathBuf>, pub output_file: Option<PathBuf>, + pub temps_dir: Option<PathBuf>, pub file_loader: Option<Box<dyn FileLoader + Send + Sync>>, pub diagnostic_output: DiagnosticOutput, @@ -193,6 +205,7 @@ pub fn create_compiler_and_run<R>(config: Config, f: impl FnOnce(&Compiler) -> R input_path: config.input_path, output_dir: config.output_dir, output_file: config.output_file, + temps_dir: config.temps_dir, register_lints: config.register_lints, override_queries: config.override_queries, }; diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 62f5f09aa48..b14b1c4f1e6 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -692,6 +692,7 @@ pub fn prepare_outputs( &compiler.input, &compiler.output_dir, &compiler.output_file, + &compiler.temps_dir, &krate.attrs, sess, ); @@ -734,6 +735,12 @@ pub fn prepare_outputs( return Err(ErrorReported); } } + if let Some(ref dir) = compiler.temps_dir { + if fs::create_dir_all(dir).is_err() { + sess.err("failed to find or create the directory specified by `--temps-dir`"); + return Err(ErrorReported); + } + } } Ok(outputs) diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index cffb087af18..b446422f62f 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -604,6 +604,7 @@ pub fn build_output_filenames( input: &Input, odir: &Option<PathBuf>, ofile: &Option<PathBuf>, + temps_dir: &Option<PathBuf>, attrs: &[ast::Attribute], sess: &Session, ) -> OutputFilenames { @@ -626,6 +627,7 @@ pub fn build_output_filenames( dirpath, stem, None, + temps_dir.clone(), sess.opts.cg.extra_filename.clone(), sess.opts.output_types.clone(), ) @@ -654,6 +656,7 @@ pub fn build_output_filenames( out_file.parent().unwrap_or_else(|| Path::new("")).to_path_buf(), out_file.file_stem().unwrap_or_default().to_str().unwrap().to_string(), ofile, + temps_dir.clone(), sess.opts.cg.extra_filename.clone(), sess.opts.output_types.clone(), ) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 299dfed9d5d..52cd8638b00 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -578,6 +578,7 @@ pub struct OutputFilenames { pub out_directory: PathBuf, filestem: String, pub single_output_file: Option<PathBuf>, + pub temps_directory: Option<PathBuf>, pub outputs: OutputTypes, } @@ -592,12 +593,14 @@ impl OutputFilenames { out_directory: PathBuf, out_filestem: String, single_output_file: Option<PathBuf>, + temps_directory: Option<PathBuf>, extra: String, outputs: OutputTypes, ) -> Self { OutputFilenames { out_directory, single_output_file, + temps_directory, outputs, filestem: format!("{}{}", out_filestem, extra), } @@ -643,11 +646,17 @@ impl OutputFilenames { extension.push_str(ext); } - self.with_extension(&extension) + let temps_directory = self.temps_directory.as_ref().unwrap_or(&self.out_directory); + + self.with_directory_and_extension(&temps_directory, &extension) } pub fn with_extension(&self, extension: &str) -> PathBuf { - let mut path = self.out_directory.join(&self.filestem); + self.with_directory_and_extension(&self.out_directory, extension) + } + + fn with_directory_and_extension(&self, directory: &PathBuf, extension: &str) -> PathBuf { + let mut path = directory.join(&self.filestem); path.set_extension(extension); path } @@ -1094,6 +1103,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { in <dir>", "DIR", ), + opt::opt_s("", "temps-dir", "Write temporary output files to <dir>", "DIR"), opt::opt_s( "", "explain", diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index b7251e8f571..063c0bc20c6 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -259,6 +259,7 @@ crate fn create_config( input_path: cpath, output_file: None, output_dir: None, + temps_dir: None, file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 9b32ad979e3..63eaded0320 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -94,6 +94,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { input_path: None, output_file: None, output_dir: None, + temps_dir: None, file_loader: None, diagnostic_output: DiagnosticOutput::Default, stderr: None, |
