fix(solc): use path slash for remapping display on windows (#1454)

This commit is contained in:
Matthias Seitz 2022-07-05 17:54:42 +02:00 committed by GitHub
parent 2d8020eb3c
commit cf1046e1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 6 deletions

View File

@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize};
use std::{ use std::{
collections::{hash_map::Entry, HashMap}, collections::{hash_map::Entry, HashMap},
fmt, fmt,
fmt::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
str::FromStr, str::FromStr,
}; };
@ -110,11 +109,23 @@ impl<'de> Deserialize<'de> for Remapping {
// Remappings are printed as `prefix=target` // Remappings are printed as `prefix=target`
impl fmt::Display for Remapping { impl fmt::Display for Remapping {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}={}", self.name, self.path)?; let mut s = {
if !self.path.ends_with('/') { #[cfg(target_os = "windows")]
f.write_char('/')?; {
// ensure we have `/` slashes on windows
use path_slash::PathExt;
format!("{}={}", self.name, std::path::Path::new(&self.path).to_slash_lossy())
}
#[cfg(not(target_os = "windows"))]
{
format!("{}={}", self.name, self.path)
}
};
if !s.ends_with('/') {
s.push('/');
} }
Ok(()) f.write_str(&s)
} }
} }
@ -251,7 +262,19 @@ impl RelativeRemapping {
// Remappings are printed as `prefix=target` // Remappings are printed as `prefix=target`
impl fmt::Display for RelativeRemapping { impl fmt::Display for RelativeRemapping {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = format!("{}={}", self.name, self.path.original().display()); let mut s = {
#[cfg(target_os = "windows")]
{
// ensure we have `/` slashes on windows
use path_slash::PathExt;
format!("{}={}", self.name, self.path.original().to_slash_lossy())
}
#[cfg(not(target_os = "windows"))]
{
format!("{}={}", self.name, self.path.original().display())
}
};
if !s.ends_with('/') { if !s.ends_with('/') {
s.push('/'); s.push('/');
} }