1
Fork 0

Move compiler input and ouput paths into session

This commit is contained in:
Oli Scherer 2022-12-07 09:24:00 +00:00
parent 42f75f1e46
commit 9f5cd03153
15 changed files with 113 additions and 154 deletions

View file

@ -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 });

View file

@ -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(),