Permalink
Browse files

rustfmt

  • Loading branch information...
japaric committed May 31, 2017
1 parent 3353277 commit a3564ef03d7c3ea9b6c680f2ff291d9fe5dc80fa
Showing with 477 additions and 337 deletions.
  1. +4 −2 build.rs
  2. +57 −33 src/cargo.rs
  3. +3 −1 src/cli.rs
  4. +21 −14 src/extensions.rs
  5. +57 −40 src/flock.rs
  6. +36 −25 src/main.rs
  7. +14 −10 src/rustc.rs
  8. +109 −81 src/sysroot.rs
  9. +37 −30 src/util.rs
  10. +17 −14 src/xargo.rs
  11. +122 −87 tests/smoke.rs
View
@@ -8,7 +8,8 @@ use std::process::Command;
struct Some {}
impl<E> From<E> for Some
where E: Error
where
E: Error,
{
fn from(_: E) -> Some {
Some {}
@@ -32,7 +33,8 @@ fn commit_info() -> String {
}
fn commit_hash() -> Result<String, Some> {
let output = Command::new("git").args(&["rev-parse", "--short", "HEAD"])
let output = Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()?;
if output.status.success() {
View
@@ -18,15 +18,17 @@ pub struct Rustflags {
impl Rustflags {
pub fn hash<H>(&self, hasher: &mut H)
where H: Hasher
where
H: Hasher,
{
let mut flags = self.flags.iter();
while let Some(flag) = flags.next() {
if flag == "-C" {
if let Some(next) = flags.next() {
if next.starts_with("link-arg=") ||
next.starts_with("link-args=") {
next.starts_with("link-args=")
{
// don't hash linker arguments
} else {
flag.hash(hasher);
@@ -74,35 +76,41 @@ impl Rustdocflags {
}
}
pub fn rustdocflags(config: Option<&Config>,
target: &str)
-> Result<Rustdocflags> {
pub fn rustdocflags(
config: Option<&Config>,
target: &str,
) -> Result<Rustdocflags> {
flags(config, target, "rustdocflags").map(|fs| Rustdocflags { flags: fs })
}
/// Returns the flags for `tool` (e.g. rustflags)
///
/// This looks into the environment and into `.cargo/config`
fn flags(config: Option<&Config>,
target: &str,
tool: &str)
-> Result<Vec<String>> {
fn flags(
config: Option<&Config>,
target: &str,
tool: &str,
) -> Result<Vec<String>> {
if let Some(t) = env::var_os(tool.to_uppercase()) {
return Ok(t.to_string_lossy()
.split_whitespace()
.map(|w| w.to_owned())
.collect());
return Ok(
t.to_string_lossy()
.split_whitespace()
.map(|w| w.to_owned())
.collect(),
);
}
if let Some(config) = config.as_ref() {
let mut build = false;
if let Some(array) = config.table
if let Some(array) = config
.table
.lookup(&format!("target.{}.{}", target, tool))
.or_else(|| {
build = true;
config.table.lookup(&format!("build.{}", tool))
}) {
})
{
let mut flags = vec![];
let mut error = false;
@@ -121,14 +129,18 @@ fn flags(config: Option<&Config>,
if error {
if build {
Err(format!(".cargo/config: build.{} must be an array \
Err(format!(
".cargo/config: build.{} must be an array \
of strings",
tool))?
tool
))?
} else {
Err(format!(".cargo/config: target.{}.{} must be an \
Err(format!(
".cargo/config: target.{}.{} must be an \
array of strings",
target,
tool))?
target,
tool
))?
}
} else {
Ok(flags)
@@ -142,7 +154,9 @@ fn flags(config: Option<&Config>,
}
pub fn run(args: &Args, verbose: bool) -> Result<ExitStatus> {
Command::new("cargo").args(args.all()).run_and_get_status(verbose)
Command::new("cargo").args(args.all()).run_and_get_status(
verbose,
)
}
pub struct Config {
@@ -152,22 +166,26 @@ pub struct Config {
impl Config {
pub fn target(&self) -> Result<Option<&str>> {
if let Some(v) = self.table.lookup("build.target") {
Ok(Some(v.as_str()
.ok_or_else(|| {
format!(".cargo/config: build.target must be a string")
})?))
Ok(Some(
v.as_str().ok_or_else(
|| format!(".cargo/config: build.target must be a string"),
)?,
))
} else {
Ok(None)
}
}
}
pub fn config() -> Result<Option<Config>> {
let cd =
env::current_dir().chain_err(|| "couldn't get the current directory")?;
let cd = env::current_dir().chain_err(
|| "couldn't get the current directory",
)?;
if let Some(p) = util::search(&cd, ".cargo/config") {
Ok(Some(Config { table: util::parse(&p.join(".cargo/config"))? }))
Ok(Some(
Config { table: util::parse(&p.join(".cargo/config"))? },
))
} else {
Ok(None)
}
@@ -179,7 +197,8 @@ pub struct Profile<'t> {
impl<'t> Profile<'t> {
pub fn hash<H>(&self, hasher: &mut H)
where H: Hasher
where
H: Hasher,
{
let mut v = self.table.clone();
@@ -218,7 +237,9 @@ pub struct Toml {
impl Toml {
/// `profile.release` part of `Cargo.toml`
pub fn profile(&self) -> Option<Profile> {
self.table.lookup("profile.release").map(|t| Profile { table: t })
self.table.lookup("profile.release").map(
|t| Profile { table: t },
)
}
}
@@ -237,10 +258,13 @@ impl Root {
}
pub fn root() -> Result<Option<Root>> {
let cd =
env::current_dir().chain_err(|| "couldn't get the current directory")?;
let cd = env::current_dir().chain_err(
|| "couldn't get the current directory",
)?;
Ok(util::search(&cd, "Cargo.toml").map(|p| Root { path: p.to_owned() }))
Ok(
util::search(&cd, "Cargo.toml").map(|p| Root { path: p.to_owned() }),
)
}
#[derive(Clone, Copy, PartialEq)]
View
@@ -22,7 +22,9 @@ impl Args {
}
pub fn verbose(&self) -> bool {
self.all.iter().any(|a| a == "--verbose" || a == "-v" || a == "-vv")
self.all.iter().any(|a| {
a == "--verbose" || a == "-v" || a == "-vv"
})
}
pub fn version(&self) -> bool {
View
@@ -18,9 +18,11 @@ impl CommandExt for Command {
if status.success() {
Ok(())
} else {
Err(format!("`{:?}` failed with exit code: {:?}",
self,
status.code()))?
Err(format!(
"`{:?}` failed with exit code: {:?}",
self,
status.code()
))?
}
}
@@ -30,8 +32,9 @@ impl CommandExt for Command {
writeln!(io::stderr(), "+ {:?}", self).ok();
}
self.status()
.chain_err(|| format!("couldn't execute `{:?}`", self))
self.status().chain_err(
|| format!("couldn't execute `{:?}`", self),
)
}
/// Runs the command to completion and returns its stdout
@@ -40,18 +43,22 @@ impl CommandExt for Command {
writeln!(io::stderr(), "+ {:?}", self).ok();
}
let out = self.output()
.chain_err(|| format!("couldn't execute `{:?}`", self))?;
let out = self.output().chain_err(
|| format!("couldn't execute `{:?}`", self),
)?;
if out.status.success() {
Ok(String::from_utf8(out.stdout).chain_err(|| {
format!("`{:?}` output was not UTF-8",
self)
})?)
Ok(
String::from_utf8(out.stdout).chain_err(|| {
format!("`{:?}` output was not UTF-8", self)
})?,
)
} else {
Err(format!("`{:?}` failed with exit code: {:?}",
self,
out.status.code()))?
Err(format!(
"`{:?}` failed with exit code: {:?}",
self,
out.status.code()
))?
}
}
}
Oops, something went wrong.

0 comments on commit a3564ef

Please sign in to comment.