Move OutFileName writing into rustc_session
This commit is contained in:
parent
32cac2e002
commit
f2e3d3fc63
7 changed files with 24 additions and 22 deletions
|
@ -26,6 +26,8 @@ session_feature_gate_error = {$explain}
|
|||
|
||||
session_file_is_not_writeable = output file {$file} is not writeable -- check its permissions
|
||||
|
||||
session_file_write_fail = failed to write `{$path}` due to error `{$err}`
|
||||
|
||||
session_hexadecimal_float_literal_not_supported = hexadecimal float literal is not supported
|
||||
|
||||
session_incompatible_linker_flavor = linker flavor `{$flavor}` is incompatible with the current target
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
pub use crate::options::*;
|
||||
|
||||
use crate::errors::FileWriteFail;
|
||||
use crate::search_paths::SearchPath;
|
||||
use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
|
||||
use crate::{lint, HashStableContext};
|
||||
|
@ -31,6 +32,7 @@ use std::collections::btree_map::{
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt;
|
||||
use std::fs;
|
||||
use std::hash::Hash;
|
||||
use std::iter;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -861,6 +863,17 @@ impl OutFileName {
|
|||
OutFileName::Stdout => outputs.temp_path(flavor, codegen_unit_name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn overwrite(&self, content: &str, sess: &Session) {
|
||||
match self {
|
||||
OutFileName::Stdout => print!("{content}"),
|
||||
OutFileName::Real(path) => {
|
||||
if let Err(e) = fs::write(path, content) {
|
||||
sess.emit_fatal(FileWriteFail { path, err: e.to_string() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, Debug, HashStable_Generic)]
|
||||
|
|
|
@ -163,6 +163,13 @@ pub struct FileIsNotWriteable<'a> {
|
|||
pub file: &'a std::path::Path,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(session_file_write_fail)]
|
||||
pub(crate) struct FileWriteFail<'a> {
|
||||
pub path: &'a std::path::Path,
|
||||
pub err: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(session_crate_name_does_not_match)]
|
||||
pub struct CrateNameDoesNotMatch {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue