diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-12-07 09:24:00 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-01-16 14:46:44 +0000 |
| commit | 9f5cd0315386e761beae8afd07df94e42a4db154 (patch) | |
| tree | 6e64a92962daa43d7eb93fc072225d8e9ee79e6b /compiler/rustc_session/src | |
| parent | 42f75f1e462f90bfe20f458690113c3cb2a26271 (diff) | |
| download | rust-9f5cd0315386e761beae8afd07df94e42a4db154.tar.gz rust-9f5cd0315386e761beae8afd07df94e42a4db154.zip | |
Move compiler input and ouput paths into session
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/output.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 27 |
2 files changed, 19 insertions, 12 deletions
diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index 8ee3057de62..2badccbf603 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -45,7 +45,7 @@ fn is_writeable(p: &Path) -> bool { } } -pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input) -> Symbol { +pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute]) -> Symbol { let validate = |s: Symbol, span: Option<Span>| { validate_crate_name(sess, s, span); s @@ -71,7 +71,7 @@ pub fn find_crate_name(sess: &Session, attrs: &[ast::Attribute], input: &Input) if let Some((attr, s)) = attr_crate_name { return validate(s, Some(attr.span)); } - if let Input::File(ref path) = *input { + if let Input::File(ref path) = sess.io.input { if let Some(s) = path.file_stem().and_then(|s| s.to_str()) { if s.starts_with('-') { sess.emit_err(CrateNameInvalid { s }); diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 1b2e8d9dc70..fe992b91561 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1,6 +1,7 @@ use crate::cgu_reuse_tracker::CguReuseTracker; use crate::code_stats::CodeStats; pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo}; +use crate::config::Input; use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, SwitchWithOptPath}; use crate::errors::{ BranchProtectionRequiresAArch64, CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers, @@ -137,6 +138,13 @@ pub struct Limits { pub const_eval_limit: Limit, } +pub struct CompilerIO { + pub input: Input, + pub output_dir: Option<PathBuf>, + pub output_file: Option<PathBuf>, + pub temps_dir: Option<PathBuf>, +} + /// Represents the data associated with a compilation /// session for a single crate. pub struct Session { @@ -147,9 +155,8 @@ pub struct Session { pub target_tlib_path: Lrc<SearchPath>, pub parse_sess: ParseSess, pub sysroot: PathBuf, - /// The name of the root source file of the crate, in the local file system. - /// `None` means that there is no source file. - pub local_crate_source_file: Option<PathBuf>, + /// Input, input file path and output file path to this compilation process. + pub io: CompilerIO, crate_types: OnceCell<Vec<CrateType>>, /// The `stable_crate_id` is constructed out of the crate name and all the @@ -228,6 +235,11 @@ impl Session { self.miri_unleashed_features.lock().push((span, feature_gate)); } + pub fn local_crate_source_file(&self) -> Option<PathBuf> { + let path = self.io.input.opt_path()?; + Some(self.opts.file_path_mapping().map_prefix(path).0) + } + fn check_miri_unleashed_features(&self) { let unleashed_features = self.miri_unleashed_features.lock(); if !unleashed_features.is_empty() { @@ -1298,7 +1310,7 @@ fn default_emitter( #[allow(rustc::bad_opt_access)] pub fn build_session( sopts: config::Options, - local_crate_source_file: Option<PathBuf>, + io: CompilerIO, bundle: Option<Lrc<rustc_errors::FluentBundle>>, registry: rustc_errors::registry::Registry, driver_lint_caps: FxHashMap<lint::LintId, lint::Level>, @@ -1391,11 +1403,6 @@ pub fn build_session( Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple)) }; - let file_path_mapping = sopts.file_path_mapping(); - - let local_crate_source_file = - local_crate_source_file.map(|path| file_path_mapping.map_prefix(path).0); - let optimization_fuel = Lock::new(OptimizationFuel { remaining: sopts.unstable_opts.fuel.as_ref().map_or(0, |&(_, i)| i), out_of_fuel: false, @@ -1427,7 +1434,7 @@ pub fn build_session( target_tlib_path, parse_sess, sysroot, - local_crate_source_file, + io, crate_types: OnceCell::new(), stable_crate_id: OnceCell::new(), features: OnceCell::new(), |
