UPDATE - migrate write.rs to new diagnostics infra
This commit is contained in:
parent
086e70f13e
commit
d9197dbbcd
3 changed files with 75 additions and 22 deletions
|
@ -2,11 +2,11 @@ use super::link::{self, ensure_removed};
|
||||||
use super::lto::{self, SerializedModule};
|
use super::lto::{self, SerializedModule};
|
||||||
use super::symbol_export::symbol_name_for_instance_in_crate;
|
use super::symbol_export::symbol_name_for_instance_in_crate;
|
||||||
|
|
||||||
|
use crate::errors;
|
||||||
|
use crate::traits::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind,
|
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::traits::*;
|
|
||||||
use jobserver::{Acquired, Client};
|
use jobserver::{Acquired, Client};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::memmap::Mmap;
|
use rustc_data_structures::memmap::Mmap;
|
||||||
|
@ -530,7 +530,7 @@ fn produce_final_output_artifacts(
|
||||||
// Produce final compile outputs.
|
// Produce final compile outputs.
|
||||||
let copy_gracefully = |from: &Path, to: &Path| {
|
let copy_gracefully = |from: &Path, to: &Path| {
|
||||||
if let Err(e) = fs::copy(from, to) {
|
if let Err(e) = fs::copy(from, to) {
|
||||||
sess.err(&format!("could not copy {:?} to {:?}: {}", from, to, e));
|
sess.emit_err(errors::CopyPath::new(from, to, e));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -546,7 +546,7 @@ fn produce_final_output_artifacts(
|
||||||
ensure_removed(sess.diagnostic(), &path);
|
ensure_removed(sess.diagnostic(), &path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let ext = crate_output
|
let extension = crate_output
|
||||||
.temp_path(output_type, None)
|
.temp_path(output_type, None)
|
||||||
.extension()
|
.extension()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -557,19 +557,11 @@ fn produce_final_output_artifacts(
|
||||||
if crate_output.outputs.contains_key(&output_type) {
|
if crate_output.outputs.contains_key(&output_type) {
|
||||||
// 2) Multiple codegen units, with `--emit foo=some_name`. We have
|
// 2) Multiple codegen units, with `--emit foo=some_name`. We have
|
||||||
// no good solution for this case, so warn the user.
|
// no good solution for this case, so warn the user.
|
||||||
sess.warn(&format!(
|
sess.emit_warning(errors::IgnoringEmitPath { extension });
|
||||||
"ignoring emit path because multiple .{} files \
|
|
||||||
were produced",
|
|
||||||
ext
|
|
||||||
));
|
|
||||||
} else if crate_output.single_output_file.is_some() {
|
} else if crate_output.single_output_file.is_some() {
|
||||||
// 3) Multiple codegen units, with `-o some_name`. We have
|
// 3) Multiple codegen units, with `-o some_name`. We have
|
||||||
// no good solution for this case, so warn the user.
|
// no good solution for this case, so warn the user.
|
||||||
sess.warn(&format!(
|
sess.emit_warning(errors::IgnoringOutput { extension });
|
||||||
"ignoring -o because multiple .{} files \
|
|
||||||
were produced",
|
|
||||||
ext
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
// 4) Multiple codegen units, but no explicit name. We
|
// 4) Multiple codegen units, but no explicit name. We
|
||||||
// just leave the `foo.0.x` files in place.
|
// just leave the `foo.0.x` files in place.
|
||||||
|
@ -880,14 +872,19 @@ fn execute_copy_from_cache_work_item<B: ExtraBackendMethods>(
|
||||||
);
|
);
|
||||||
match link_or_copy(&source_file, &output_path) {
|
match link_or_copy(&source_file, &output_path) {
|
||||||
Ok(_) => Some(output_path),
|
Ok(_) => Some(output_path),
|
||||||
Err(err) => {
|
Err(_) => {
|
||||||
let diag_handler = cgcx.create_diag_handler();
|
// FIXME:
|
||||||
diag_handler.err(&format!(
|
// Should we add Translations support in Handler, or should we pass a session here ?
|
||||||
"unable to copy {} to {}: {}",
|
//
|
||||||
source_file.display(),
|
// As Luis Cardoso mentioned here https://github.com/rust-lang/rust/pull/100753#discussion_r952975345,
|
||||||
output_path.display(),
|
// Translations support in Handler is tricky because SessionDiagnostic is not a trait,
|
||||||
err
|
// and we can't implement it in Handler because rustc_errors cannot depend on rustc_session.
|
||||||
));
|
//
|
||||||
|
// As for passing a session here, my understanding is that all these errors should be reported via
|
||||||
|
// the Shared Handler, which leads us to probably having to support Translations in another way.
|
||||||
|
|
||||||
|
// let diag_handler = cgcx.create_diag_handler();
|
||||||
|
// diag_handler.emit_err(errors::CopyPathBuf { source_file, output_path, error });
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
//! Errors emitted by codegen_ssa
|
//! Errors emitted by codegen_ssa
|
||||||
|
|
||||||
|
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
|
||||||
use rustc_macros::SessionDiagnostic;
|
use rustc_macros::SessionDiagnostic;
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::io::Error;
|
use std::io::Error;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
#[diag(codegen_ssa::missing_native_static_library)]
|
#[diag(codegen_ssa::missing_native_static_library)]
|
||||||
|
@ -56,3 +59,48 @@ pub struct L4BenderExportingSymbolsUnimplemented;
|
||||||
pub struct NoNatvisDirectory {
|
pub struct NoNatvisDirectory {
|
||||||
pub error: Error,
|
pub error: Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(codegen_ssa::copy_path_buf)]
|
||||||
|
pub struct CopyPathBuf {
|
||||||
|
pub source_file: PathBuf,
|
||||||
|
pub output_path: PathBuf,
|
||||||
|
pub error: Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reports Paths using `Debug` implementation rather than Path's `Display` implementation.
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(codegen_ssa::copy_path)]
|
||||||
|
pub struct CopyPath<'a> {
|
||||||
|
from: DebugArgPath<'a>,
|
||||||
|
to: DebugArgPath<'a>,
|
||||||
|
error: Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> CopyPath<'a> {
|
||||||
|
pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
|
||||||
|
CopyPath { from: DebugArgPath { path: from }, to: DebugArgPath { path: to }, error }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DebugArgPath<'a> {
|
||||||
|
pub path: &'a Path,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for DebugArgPath<'_> {
|
||||||
|
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.path)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(codegen_ssa::ignoring_emit_path)]
|
||||||
|
pub struct IgnoringEmitPath {
|
||||||
|
pub extension: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(codegen_ssa::ignoring_output)]
|
||||||
|
pub struct IgnoringOutput {
|
||||||
|
pub extension: String,
|
||||||
|
}
|
||||||
|
|
|
@ -19,3 +19,11 @@ codegen_ssa_linker_unsupported_modifier = `as-needed` modifier not supported for
|
||||||
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
|
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
|
||||||
|
|
||||||
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
|
codegen_ssa_no_natvis_directory = error enumerating natvis directory: {$error}
|
||||||
|
|
||||||
|
codegen_ssa_copy_path = could not copy {$from} to {$to}: {$error}
|
||||||
|
|
||||||
|
codegen_ssa_copy_path_buf = unable to copy {$source_file} to {$output_path}: {$error}
|
||||||
|
|
||||||
|
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced
|
||||||
|
|
||||||
|
codegen_ssa_ignoring_output = ignoring -o because multiple .{$extension} files were produced
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue