Browse Source

Run rustfmt

urgh
Alex Crichton 6 years ago
parent
commit
aa6aac852e
  1. 4
      src/com.rs
  2. 96
      src/lib.rs
  3. 22
      src/setup_config.rs
  4. 4
      src/winapi.rs
  5. 61
      src/windows_registry.rs
  6. 8
      tests/cc_env.rs
  7. 6
      tests/support/mod.rs
  8. 8
      tests/test.rs

4
src/com.rs

@ -13,12 +13,12 @@ use std::ops::Deref;
use std::os::windows::ffi::{OsStrExt, OsStringExt};
use std::ptr::null_mut;
use std::slice::from_raw_parts;
use winapi::CoInitializeEx;
use winapi::IUnknown;
use winapi::Interface;
use winapi::BSTR;
use winapi::CoInitializeEx;
use winapi::COINIT_MULTITHREADED;
use winapi::{SysFreeString, SysStringLen};
use winapi::IUnknown;
use winapi::{HRESULT, S_FALSE, S_OK};
pub fn initialize() -> Result<(), HRESULT> {

96
src/lib.rs

@ -61,15 +61,15 @@
#[cfg(feature = "parallel")]
extern crate rayon;
use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs;
use std::io::{self, BufRead, BufReader, Read, Write};
use std::path::{Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::io::{self, BufRead, BufReader, Read, Write};
use std::thread::{self, JoinHandle};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
// These modules are all glue to support reading the MSVC version from
// the registry and from COM interfaces
@ -891,7 +891,7 @@ impl Build {
return Err(Error::new(
ErrorKind::IOError,
"Getting object file details failed.",
))
));
}
};
@ -1119,12 +1119,18 @@ impl Build {
// CFLAGS/CXXFLAGS, since those variables presumably already contain
// the desired set of warnings flags.
if self.warnings.unwrap_or(if self.has_flags() { false } else { true }) {
if self
.warnings
.unwrap_or(if self.has_flags() { false } else { true })
{
let wflags = cmd.family.warnings_flags().into();
cmd.push_cc_arg(wflags);
}
if self.extra_warnings.unwrap_or(if self.has_flags() { false } else { true }) {
if self
.extra_warnings
.unwrap_or(if self.has_flags() { false } else { true })
{
if let Some(wflags) = cmd.family.extra_warnings_flags() {
cmd.push_cc_arg(wflags.into());
}
@ -1161,7 +1167,12 @@ impl Build {
Ok(cmd)
}
fn add_default_flags(&self, cmd: &mut Tool, target: &str, opt_level: &str) -> Result<(), Error> {
fn add_default_flags(
&self,
cmd: &mut Tool,
target: &str,
opt_level: &str,
) -> Result<(), Error> {
// Non-target flags
// If the flag is not conditioned on target variable, it belongs here :)
match cmd.family {
@ -1175,8 +1186,9 @@ impl Build {
Some(true) => "/MT",
Some(false) => "/MD",
None => {
let features =
self.getenv("CARGO_CFG_TARGET_FEATURE").unwrap_or(String::new());
let features = self
.getenv("CARGO_CFG_TARGET_FEATURE")
.unwrap_or(String::new());
if features.contains("crt-static") {
"/MT"
} else {
@ -1258,7 +1270,8 @@ impl Build {
// the SDK, but for all released versions of the
// Windows SDK it is required.
if target.contains("arm") || target.contains("thumb") {
cmd.args.push("/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1".into());
cmd.args
.push("/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1".into());
}
}
ToolFamily::Gnu => {
@ -1271,14 +1284,18 @@ impl Build {
}
if self.static_flag.is_none() {
let features = self.getenv("CARGO_CFG_TARGET_FEATURE").unwrap_or(String::new());
let features = self
.getenv("CARGO_CFG_TARGET_FEATURE")
.unwrap_or(String::new());
if features.contains("crt-static") {
cmd.args.push("-static".into());
}
}
// armv7 targets get to use armv7 instructions
if (target.starts_with("armv7") || target.starts_with("thumbv7")) && target.contains("-linux-") {
if (target.starts_with("armv7") || target.starts_with("thumbv7"))
&& target.contains("-linux-")
{
cmd.args.push("-march=armv7-a".into());
}
@ -1443,7 +1460,11 @@ impl Build {
fn has_flags(&self) -> bool {
let flags_env_var_name = if self.cpp { "CXXFLAGS" } else { "CFLAGS" };
let flags_env_var_value = self.get_var(flags_env_var_name);
if let Ok(_) = flags_env_var_value { true } else { false }
if let Ok(_) = flags_env_var_value {
true
} else {
false
}
}
fn msvc_macro_assembler(&self) -> Result<(Command, String), Error> {
@ -1548,7 +1569,7 @@ impl Build {
return Err(Error::new(
ErrorKind::IOError,
"Could not copy or create a hard-link to the generated lib file.",
))
));
}
};
} else {
@ -1585,7 +1606,7 @@ impl Build {
return Err(Error::new(
ErrorKind::ArchitectureInvalid,
"Unknown architecture for iOS target.",
))
));
}
};
@ -1604,7 +1625,8 @@ impl Build {
};
self.print(&format!("Detecting iOS SDK path for {}", sdk));
let sdk_path = self.cmd("xcrun")
let sdk_path = self
.cmd("xcrun")
.arg("--show-sdk-path")
.arg("--sdk")
.arg(sdk)
@ -1618,7 +1640,7 @@ impl Build {
return Err(Error::new(
ErrorKind::IOError,
"Unable to determine iOS SDK path.",
))
));
}
};
@ -1669,7 +1691,8 @@ impl Build {
let cl_exe = windows_registry::find_tool(&target, "cl.exe");
let tool_opt: Option<Tool> = self.env_tool(env)
let tool_opt: Option<Tool> = self
.env_tool(env)
.map(|(tool, cc, args)| {
// chop off leading/trailing whitespace to work around
// semi-buggy build scripts which are shared in
@ -1831,9 +1854,9 @@ impl Build {
// configure for invocations like `clang-cl` we still get a "works out
// of the box" experience.
if let Some(cl_exe) = cl_exe {
if tool.family == (ToolFamily::Msvc { clang_cl: true }) &&
tool.env.len() == 0 &&
target.contains("msvc")
if tool.family == (ToolFamily::Msvc { clang_cl: true })
&& tool.env.len() == 0
&& target.contains("msvc")
{
for &(ref k, ref v) in cl_exe.env.iter() {
tool.env.push((k.to_owned(), v.to_owned()));
@ -1849,7 +1872,8 @@ impl Build {
let host = self.get_host()?;
let kind = if host == target { "HOST" } else { "TARGET" };
let target_u = target.replace("-", "_");
let res = self.getenv(&format!("{}_{}", var_base, target))
let res = self
.getenv(&format!("{}_{}", var_base, target))
.or_else(|| self.getenv(&format!("{}_{}", var_base, target_u)))
.or_else(|| self.getenv(&format!("{}_{}", kind, var_base)))
.or_else(|| self.getenv(var_base));
@ -2040,7 +2064,7 @@ impl Build {
fn getenv(&self, v: &str) -> Option<String> {
let mut cache = self.env_cache.lock().unwrap();
if let Some(val) = cache.get(v) {
return val.clone()
return val.clone();
}
let r = env::var(v).ok();
self.print(&format!("{} = {:?}", v, r));
@ -2081,10 +2105,11 @@ impl Tool {
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
if fname.contains("clang-cl") {
ToolFamily::Msvc { clang_cl: true }
} else if fname.contains("cl") &&
!fname.contains("cloudabi") &&
!fname.contains("uclibc") &&
!fname.contains("clang") {
} else if fname.contains("cl")
&& !fname.contains("cloudabi")
&& !fname.contains("uclibc")
&& !fname.contains("clang")
{
ToolFamily::Msvc { clang_cl: false }
} else if fname.contains("clang") {
ToolFamily::Clang
@ -2140,9 +2165,10 @@ impl Tool {
// Check for existing optimization flags (-O, /O)
if chars.next() == Some('O') {
return self.args().iter().any(|ref a|
a.to_str().unwrap_or("").chars().nth(1) == Some('O')
);
return self
.args()
.iter()
.any(|ref a| a.to_str().unwrap_or("").chars().nth(1) == Some('O'));
}
// TODO Check for existing -m..., -m...=..., /arch:... flags
@ -2174,7 +2200,11 @@ impl Tool {
};
cmd.args(&self.cc_wrapper_args);
let value = self.args.iter().filter(|a| !self.removed_args.contains(a)).collect::<Vec<_>>();
let value = self
.args
.iter()
.filter(|a| !self.removed_args.contains(a))
.collect::<Vec<_>>();
cmd.args(&value);
for &(ref k, ref v) in self.env.iter() {
@ -2269,7 +2299,7 @@ fn run(cmd: &mut Command, program: &str) -> Result<(), Error> {
"Failed to wait on spawned child process, command {:?} with args {:?}.",
cmd, program
),
))
));
}
};
print.join().unwrap();
@ -2307,7 +2337,7 @@ fn run_output(cmd: &mut Command, program: &str) -> Result<Vec<u8>, Error> {
"Failed to wait on spawned child process, command {:?} with args {:?}.",
cmd, program
),
))
));
}
};
print.join().unwrap();

22
src/setup_config.rs

@ -11,14 +11,14 @@
use std::ffi::OsString;
use std::ptr::null_mut;
use winapi::Interface;
use winapi::{LPFILETIME, ULONG};
use winapi::S_FALSE;
use winapi::BSTR;
use winapi::LPCOLESTR;
use winapi::{CoCreateInstance, CLSCTX_ALL};
use winapi::LPSAFEARRAY;
use winapi::S_FALSE;
use winapi::{CoCreateInstance, CLSCTX_ALL};
use winapi::{IUnknown, IUnknownVtbl};
use winapi::{HRESULT, LCID, LPCWSTR, PULONGLONG};
use winapi::{LPFILETIME, ULONG};
use com::{BStr, ComPtr};
@ -31,7 +31,7 @@ pub const eRegistered: InstanceState = 2;
pub const eNoRebootRequired: InstanceState = 4;
pub const eComplete: InstanceState = -1i32 as u32;
RIDL!{#[uuid(0xb41463c3, 0x8866, 0x43b5, 0xbc, 0x33, 0x2b, 0x06, 0x76, 0xf7, 0xf4, 0x2e)]
RIDL! {#[uuid(0xb41463c3, 0x8866, 0x43b5, 0xbc, 0x33, 0x2b, 0x06, 0x76, 0xf7, 0xf4, 0x2e)]
interface ISetupInstance(ISetupInstanceVtbl): IUnknown(IUnknownVtbl) {
fn GetInstanceId(
pbstrInstanceId: *mut BSTR,
@ -62,7 +62,7 @@ interface ISetupInstance(ISetupInstanceVtbl): IUnknown(IUnknownVtbl) {
) -> HRESULT,
}}
RIDL!{#[uuid(0x89143c9a, 0x05af, 0x49b0, 0xb7, 0x17, 0x72, 0xe2, 0x18, 0xa2, 0x18, 0x5c)]
RIDL! {#[uuid(0x89143c9a, 0x05af, 0x49b0, 0xb7, 0x17, 0x72, 0xe2, 0x18, 0xa2, 0x18, 0x5c)]
interface ISetupInstance2(ISetupInstance2Vtbl): ISetupInstance(ISetupInstanceVtbl) {
fn GetState(
pState: *mut InstanceState,
@ -78,7 +78,7 @@ interface ISetupInstance2(ISetupInstance2Vtbl): ISetupInstance(ISetupInstanceVtb
) -> HRESULT,
}}
RIDL!{#[uuid(0x6380bcff, 0x41d3, 0x4b2e, 0x8b, 0x2e, 0xbf, 0x8a, 0x68, 0x10, 0xc8, 0x48)]
RIDL! {#[uuid(0x6380bcff, 0x41d3, 0x4b2e, 0x8b, 0x2e, 0xbf, 0x8a, 0x68, 0x10, 0xc8, 0x48)]
interface IEnumSetupInstances(IEnumSetupInstancesVtbl): IUnknown(IUnknownVtbl) {
fn Next(
celt: ULONG,
@ -94,7 +94,7 @@ interface IEnumSetupInstances(IEnumSetupInstancesVtbl): IUnknown(IUnknownVtbl) {
) -> HRESULT,
}}
RIDL!{#[uuid(0x42843719, 0xdb4c, 0x46c2, 0x8e, 0x7c, 0x64, 0xf1, 0x81, 0x6e, 0xfd, 0x5b)]
RIDL! {#[uuid(0x42843719, 0xdb4c, 0x46c2, 0x8e, 0x7c, 0x64, 0xf1, 0x81, 0x6e, 0xfd, 0x5b)]
interface ISetupConfiguration(ISetupConfigurationVtbl): IUnknown(IUnknownVtbl) {
fn EnumInstances(
ppEnumInstances: *mut *mut IEnumSetupInstances,
@ -108,7 +108,7 @@ interface ISetupConfiguration(ISetupConfigurationVtbl): IUnknown(IUnknownVtbl) {
) -> HRESULT,
}}
RIDL!{#[uuid(0x26aab78c, 0x4a60, 0x49d6, 0xaf, 0x3b, 0x3c, 0x35, 0xbc, 0x93, 0x36, 0x5d)]
RIDL! {#[uuid(0x26aab78c, 0x4a60, 0x49d6, 0xaf, 0x3b, 0x3c, 0x35, 0xbc, 0x93, 0x36, 0x5d)]
interface ISetupConfiguration2(ISetupConfiguration2Vtbl):
ISetupConfiguration(ISetupConfigurationVtbl) {
fn EnumAllInstances(
@ -116,7 +116,7 @@ interface ISetupConfiguration2(ISetupConfiguration2Vtbl):
) -> HRESULT,
}}
RIDL!{#[uuid(0xda8d8a16, 0xb2b6, 0x4487, 0xa2, 0xf1, 0x59, 0x4c, 0xcc, 0xcd, 0x6b, 0xf5)]
RIDL! {#[uuid(0xda8d8a16, 0xb2b6, 0x4487, 0xa2, 0xf1, 0x59, 0x4c, 0xcc, 0xcd, 0x6b, 0xf5)]
interface ISetupPackageReference(ISetupPackageReferenceVtbl): IUnknown(IUnknownVtbl) {
fn GetId(
pbstrId: *mut BSTR,
@ -141,7 +141,7 @@ interface ISetupPackageReference(ISetupPackageReferenceVtbl): IUnknown(IUnknownV
) -> HRESULT,
}}
RIDL!{#[uuid(0x42b21b78, 0x6192, 0x463e, 0x87, 0xbf, 0xd5, 0x77, 0x83, 0x8f, 0x1d, 0x5c)]
RIDL! {#[uuid(0x42b21b78, 0x6192, 0x463e, 0x87, 0xbf, 0xd5, 0x77, 0x83, 0x8f, 0x1d, 0x5c)]
interface ISetupHelper(ISetupHelperVtbl): IUnknown(IUnknownVtbl) {
fn ParseVersion(
pwszVersion: LPCOLESTR,
@ -154,7 +154,7 @@ interface ISetupHelper(ISetupHelperVtbl): IUnknown(IUnknownVtbl) {
) -> HRESULT,
}}
DEFINE_GUID!{CLSID_SetupConfiguration,
DEFINE_GUID! {CLSID_SetupConfiguration,
0x177f0c4a, 0x1cd3, 0x4de7, 0xa3, 0x2c, 0x71, 0xdb, 0xbb, 0x9f, 0xa3, 0x6d}
// Safe wrapper around the COM interfaces

4
src/winapi.rs

@ -115,7 +115,7 @@ macro_rules! DEFINE_GUID {
Data3: $w2,
Data4: [$b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8],
};
}
};
}
macro_rules! RIDL {
@ -207,7 +207,7 @@ macro_rules! RIDL {
);
}
RIDL!{#[uuid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)]
RIDL! {#[uuid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)]
interface IUnknown(IUnknownVtbl) {
fn QueryInterface(
riid: REFIID,

61
src/windows_registry.rs

@ -17,10 +17,12 @@ use Tool;
#[cfg(windows)]
macro_rules! otry {
($expr:expr) => (match $expr {
Some(val) => val,
None => return None,
})
($expr:expr) => {
match $expr {
Some(val) => val,
None => return None,
}
};
}
/// Attempts to find a tool within an MSVC installation using the Windows
@ -171,15 +173,15 @@ pub fn find_vs_version() -> Result<VsVers, String> {
#[cfg(windows)]
mod impl_ {
use com;
use registry::{RegistryKey, LOCAL_MACHINE};
use setup_config::{EnumSetupInstances, SetupConfiguration, SetupInstance};
use std::env;
use std::ffi::OsString;
use std::mem;
use std::path::{Path, PathBuf};
use std::fs::File;
use std::io::Read;
use registry::{RegistryKey, LOCAL_MACHINE};
use com;
use setup_config::{EnumSetupInstances, SetupConfiguration, SetupInstance};
use std::mem;
use std::path::{Path, PathBuf};
use Tool;
@ -256,7 +258,8 @@ mod impl_ {
instance
.ok()
.and_then(|instance| instance.installation_path().ok())
}).map(|path| PathBuf::from(path).join(tool))
})
.map(|path| PathBuf::from(path).join(tool))
.find(|ref path| path.is_file()),
None => None,
};
@ -324,13 +327,15 @@ mod impl_ {
let path = instance_path.join(r"VC\Tools\MSVC").join(version);
// This is the path to the toolchain for a particular target, running
// on a given host
let bin_path = path.join("bin")
let bin_path = path
.join("bin")
.join(&format!("Host{}", host))
.join(&target);
// But! we also need PATH to contain the target directory for the host
// architecture, because it contains dlls like mspdb140.dll compiled for
// the host architecture.
let host_dylib_path = path.join("bin")
let host_dylib_path = path
.join("bin")
.join(&format!("Host{}", host))
.join(&host.to_lowercase());
let lib_path = path.join("lib").join(&target);
@ -483,17 +488,16 @@ mod impl_ {
let key = otry!(LOCAL_MACHINE.open(key.as_ref()).ok());
let root = otry!(key.query_str("KitsRoot10").ok());
let readdir = otry!(Path::new(&root).join("lib").read_dir().ok());
let max_libdir = otry!(
readdir
.filter_map(|dir| dir.ok())
.map(|dir| dir.path())
.filter(|dir| dir.components()
.last()
.and_then(|c| c.as_os_str().to_str())
.map(|c| c.starts_with("10.") && dir.join("ucrt").is_dir())
.unwrap_or(false))
.max()
);
let max_libdir = otry!(readdir
.filter_map(|dir| dir.ok())
.map(|dir| dir.path())
.filter(|dir| dir
.components()
.last()
.and_then(|c| c.as_os_str().to_str())
.map(|c| c.starts_with("10.") && dir.join("ucrt").is_dir())
.unwrap_or(false))
.max());
let version = max_libdir.components().last().unwrap();
let version = version.as_os_str().to_str().unwrap().to_string();
Some((root.into(), version))
@ -517,12 +521,11 @@ mod impl_ {
.map(|dir| dir.path())
.collect::<Vec<_>>();
dirs.sort();
let dir = otry!(
dirs.into_iter()
.rev()
.filter(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file())
.next()
);
let dir = otry!(dirs
.into_iter()
.rev()
.filter(|dir| dir.join("um").join("x64").join("kernel32.lib").is_file())
.next());
let version = dir.components().last().unwrap();
let version = version.as_os_str().to_str().unwrap().to_string();
Some((root.into(), version))

8
tests/cc_env.rs

@ -2,8 +2,8 @@ extern crate cc;
extern crate tempdir;
use std::env;
use std::path::Path;
use std::ffi::OsString;
use std::path::Path;
mod support;
use support::Test;
@ -63,14 +63,16 @@ fn ccache_env_flags() {
.cflags_env()
.into_string()
.unwrap()
.contains("ccache") == false
.contains("ccache")
== false
);
assert!(
compiler
.cflags_env()
.into_string()
.unwrap()
.contains(" lol-this-is-not-a-compiler") == false
.contains(" lol-this-is-not-a-compiler")
== false
);
env::set_var("CC", "");

6
tests/support/mod.rs

@ -113,10 +113,12 @@ impl Execution {
}
pub fn must_have_in_order(&self, before: &str, after: &str) -> &Execution {
let before_position = self.args
let before_position = self
.args
.iter()
.rposition(|x| OsStr::new(x) == OsStr::new(before));
let after_position = self.args
let after_position = self
.args
.iter()
.rposition(|x| OsStr::new(x) == OsStr::new(after));
match (before_position, after_position) {

8
tests/test.rs

@ -115,9 +115,7 @@ fn gnu_warnings_overridable() {
fn gnu_no_warnings_if_cflags() {
env::set_var("CFLAGS", "-Wflag-does-not-exist");
let test = Test::gnu();
test.gcc()
.file("foo.c")
.compile("foo");
test.gcc().file("foo.c").compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
env::set_var("CFLAGS", "");
@ -127,9 +125,7 @@ fn gnu_no_warnings_if_cflags() {
fn gnu_no_warnings_if_cxxflags() {
env::set_var("CXXFLAGS", "-Wflag-does-not-exist");
let test = Test::gnu();
test.gcc()
.file("foo.c")
.compile("foo");
test.gcc().file("foo.c").compile("foo");
test.cmd(0).must_not_have("-Wall").must_not_have("-Wextra");
env::set_var("CXXFLAGS", "");

Loading…
Cancel
Save