diff options
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/config.rs | 31 | ||||
| -rw-r--r-- | compiler/rustc_session/src/output.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 27 |
3 files changed, 46 insertions, 16 deletions
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index dcc2d9db614..586454f7657 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -591,6 +591,24 @@ impl Input { Input::Str { ref name, .. } => name.clone(), } } + + pub fn opt_path(&self) -> Option<&Path> { + match self { + Input::File(file) => Some(file), + Input::Str { name, .. } => match name { + FileName::Real(real) => real.local_path(), + FileName::QuoteExpansion(_) => None, + FileName::Anon(_) => None, + FileName::MacroExpansion(_) => None, + FileName::ProcMacroSourceCode(_) => None, + FileName::CfgSpec(_) => None, + FileName::CliCrateAttr(_) => None, + FileName::Custom(_) => None, + FileName::DocTest(path, _) => Some(path), + FileName::InlineAsm(_) => None, + }, + } + } } #[derive(Clone, Hash, Debug, HashStable_Generic)] @@ -2459,6 +2477,11 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { let pretty = parse_pretty(&unstable_opts, error_format); + // query-dep-graph is required if dump-dep-graph is given #106736 + if unstable_opts.dump_dep_graph && !unstable_opts.query_dep_graph { + early_error(error_format, "can't dump dependency graph without `-Z query-dep-graph`"); + } + // Try to find a directory containing the Rust `src`, for more details see // the doc comment on the `real_rust_source_base_dir` field. let tmp_buf; @@ -2491,12 +2514,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { early_error(error_format, &format!("Current directory is invalid: {e}")); }); - let (path, remapped) = - FilePathMapping::new(remap_path_prefix.clone()).map_prefix(working_dir.clone()); + let remap = FilePathMapping::new(remap_path_prefix.clone()); + let (path, remapped) = remap.map_prefix(&working_dir); let working_dir = if remapped { - RealFileName::Remapped { local_path: Some(working_dir), virtual_name: path } + RealFileName::Remapped { virtual_name: path.into_owned(), local_path: Some(working_dir) } } else { - RealFileName::LocalPath(path) + RealFileName::LocalPath(path.into_owned()) }; Options { diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index cf45d6f1aa5..c3f0c4b58f5 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 8d92954ec94..95f199de6ff 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.into_owned()) + } + 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(), |
