зеркало из https://github.com/mozilla/sccache.git
use local-encoding crate for stdout conversion
This commit is contained in:
Родитель
35cd472997
Коммит
d115dc2c63
|
@ -10,6 +10,7 @@ dependencies = [
|
|||
"hyper 0.9.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"local-encoding 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"number_prefix 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -136,6 +137,11 @@ name = "gcc"
|
|||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "getopts"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hpack"
|
||||
version = "0.2.0"
|
||||
|
@ -203,6 +209,16 @@ name = "libc"
|
|||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "local-encoding"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"skeptic 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.3.6"
|
||||
|
@ -388,6 +404,14 @@ name = "protobuf"
|
|||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "pulldown-cmark"
|
||||
version = "0.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.14"
|
||||
|
@ -472,6 +496,15 @@ name = "sha1"
|
|||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "skeptic"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.1.3"
|
||||
|
|
|
@ -11,6 +11,7 @@ fern = "0.3.5"
|
|||
filetime = "0.1"
|
||||
hyper = { version = "0.9.10", default-features = false }
|
||||
libc = "0.2.10"
|
||||
local-encoding = "0.2.0"
|
||||
log = "0.3.6"
|
||||
mio = "0.5"
|
||||
number_prefix = "0.2.5"
|
||||
|
|
|
@ -19,6 +19,7 @@ use ::compiler::{
|
|||
ParsedArguments,
|
||||
run_input_output,
|
||||
};
|
||||
use local_encoding::{Encoding, Encoder};
|
||||
use log::LogLevel::Trace;
|
||||
use mock_command::{
|
||||
CommandCreatorSync,
|
||||
|
@ -37,41 +38,8 @@ use std::path::Path;
|
|||
use std::process::{self,Stdio};
|
||||
use tempdir::TempDir;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn from_local_codepage(bytes: &Vec<u8>) -> io::Result<String> {
|
||||
use kernel32;
|
||||
use std::ffi::OsString;
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
use std::ptr;
|
||||
use winapi::winnls::CP_ACP;
|
||||
|
||||
if bytes.len() == 0 {
|
||||
return Ok(String::new());
|
||||
}
|
||||
|
||||
let size = unsafe { kernel32::MultiByteToWideChar(CP_ACP, 0, bytes.as_ptr() as *const i8, -1, ptr::null_mut(), 0) };
|
||||
if size <= 0 {
|
||||
Err(Error::last_os_error())
|
||||
} else {
|
||||
let mut wchars = Vec::with_capacity(size as usize);
|
||||
wchars.resize(size as usize, 0);
|
||||
if unsafe { kernel32::MultiByteToWideChar(CP_ACP, 0, bytes.as_ptr() as *const i8, -1, wchars.as_mut_ptr(), wchars.len() as i32) } <= 0 {
|
||||
debug!("MultiByteToWideChar failed: bytes.len(): {}, wchars.len(): {}", bytes.len(), wchars.len());
|
||||
Err(Error::last_os_error())
|
||||
} else {
|
||||
let o = OsString::from_wide(&wchars);
|
||||
o.into_string()
|
||||
.or(Err(Error::new(ErrorKind::Other, "Error converting string")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn from_local_codepage(bytes: &Vec<u8>) -> io::Result<String> {
|
||||
use std::str;
|
||||
str::from_utf8(bytes)
|
||||
.or(Err(Error::new(ErrorKind::Other, "Error parsing UTF-8")))
|
||||
.map(|s| s.to_owned())
|
||||
Encoding::OEM.to_string(bytes)
|
||||
}
|
||||
|
||||
/// Detect the prefix included in the output of MSVC's -showIncludes output.
|
||||
|
|
|
@ -19,6 +19,7 @@ extern crate env_logger;
|
|||
extern crate filetime;
|
||||
extern crate hyper;
|
||||
extern crate kernel32;
|
||||
extern crate local_encoding;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate fern;
|
||||
|
|
Загрузка…
Ссылка в новой задаче