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 /compiler/rustc_interface/src | |
| parent | 18bc4bee9710b181b440a472635150f0d6257713 (diff) | |
| download | rust-5d1e09f44ab0bd3ca29acf44d92e884ec140d00a.tar.gz rust-5d1e09f44ab0bd3ca29acf44d92e884ec140d00a.zip | |
Added the --temps-dir option.
Diffstat (limited to 'compiler/rustc_interface/src')
| -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 |
3 files changed, 24 insertions, 1 deletions
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(), ) |
