Port DlltoolFailImportLibrary and implement IntoDiagnosticArg for Cow<'a, str>

This commit is contained in:
SLASHLogin 2022-08-26 19:01:22 +02:00
parent 81f7a8d7f1
commit c01546fcd6
4 changed files with 26 additions and 6 deletions

View File

@ -13,7 +13,8 @@
use crate::common;
use crate::errors::{
ArchiveBuildFailure, ErrorCallingDllTool, ErrorCreatingImportLibrary, ErrorWritingDEFFile,
ArchiveBuildFailure, DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary,
ErrorWritingDEFFile,
};
use crate::llvm::archive_ro::{ArchiveRO, Child};
use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport};
@ -244,11 +245,12 @@ fn create_dll_import_lib(
Err(e) => {
sess.emit_fatal(ErrorCallingDllTool { error: e });
}
Ok(output) if !output.status.success() => sess.fatal(&format!(
"Dlltool could not create import library: {}\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
)),
Ok(output) if !output.status.success() => {
sess.emit_fatal(DlltoolFailImportLibrary {
stdout: String::from_utf8_lossy(&output.stdout),
stderr: String::from_utf8_lossy(&output.stderr),
})
}
_ => {}
}
} else {

View File

@ -1,3 +1,5 @@
use std::borrow::Cow;
use rustc_errors::fluent;
use rustc_errors::DiagnosticBuilder;
use rustc_macros::SessionDiagnostic;
@ -102,3 +104,10 @@ pub(crate) struct ErrorWritingDEFFile {
pub(crate) struct ErrorCallingDllTool {
pub error: std::io::Error,
}
#[derive(SessionDiagnostic)]
#[diag(codegen_llvm::dlltool_fail_import_library)]
pub(crate) struct DlltoolFailImportLibrary<'a> {
pub stdout: Cow<'a, str>,
pub stderr: Cow<'a, str>,
}

View File

@ -45,3 +45,6 @@ codegen_llvm_error_writing_def_file =
codegen_llvm_error_calling_dlltool =
Error calling dlltool: {$error}
codegen_llvm_dlltool_fail_import_library =
Dlltool could not create import library: {$stdout}\n{$stderr}

View File

@ -107,6 +107,12 @@ fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
}
}
impl<'a> IntoDiagnosticArg for Cow<'a, str> {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Str(Cow::Owned(self.into_owned()))
}
}
impl<'a> IntoDiagnosticArg for &'a Path {
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
DiagnosticArgValue::Str(Cow::Owned(self.display().to_string()))