Move OutFileName writing into rustc_session
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user