Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::path::{Path, PathBuf};
use std::process::{Command, ExitStatus};
use std::{env, fmt};

use toml::{Value, map::Map};
use toml::{map::Map, Value};

use cli::Args;
use errors::*;
use extensions::CommandExt;
use util;
use sysroot::XargoMode;
use util;
use xargo::Home;

#[derive(Clone)]
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Rustflags {
pub fn encode(mut self, home: &Home) -> String {
self.flags.push("--sysroot".to_owned());
self.flags.push(home.display().to_string()); // FIXME: we shouldn't use display, we should keep the OsString
// As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`.
// As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`.
self.flags.join("\x1f")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting change looks semantically wrong. I think the first comment is about home.display()..., but the second one isn't a continuation of it, it's about self.flags.join("\x1f"). The way rustfmt will probably respect the old semantics is by having an empty line between them

}
}
Expand All @@ -75,7 +75,7 @@ impl Rustdocflags {
pub fn encode(mut self, home: &Home) -> String {
self.flags.push("--sysroot".to_owned());
self.flags.push(home.display().to_string()); // FIXME: we shouldn't use display, we should keep the OsString
// As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`.
// As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`.
self.flags.join("\x1f")
}
}
Expand All @@ -84,19 +84,17 @@ pub fn rustdocflags(config: Option<&Config>, target: &str) -> Result<Rustdocflag
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>> {
// TODO: would be nice to also support the CARGO_ENCODED_ env vars
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() {
Expand All @@ -109,7 +107,8 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String
.or_else(|| {
build = true;
config.table.get("build").and_then(|t| t.get(tool))
}) {
})
{
let mut flags = vec![];

let mut error = false;
Expand Down Expand Up @@ -137,8 +136,7 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String
Err(format!(
".cargo/config: target.{}.{} must be an \
array of strings",
target,
tool
target, tool
))?
}
} else {
Expand All @@ -159,9 +157,7 @@ pub fn command() -> Command {
}

pub fn run(args: &Args, verbose: bool) -> Result<ExitStatus> {
command()
.args(args.all())
.run_and_get_status(verbose)
command().args(args.all()).run_and_get_status(verbose)
}

pub struct Config {
Expand All @@ -171,8 +167,9 @@ pub struct Config {
impl Config {
pub fn target(&self) -> Result<Option<&str>> {
if let Some(v) = self.table.get("build").and_then(|t| t.get("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)
}
Expand Down Expand Up @@ -236,7 +233,7 @@ pub struct Toml {

impl Toml {
/// `profile.release` part of `Cargo.toml`
pub fn profile(&self) -> Option<Profile> {
pub fn profile(&self) -> Option<Profile<'_>> {
self.table
.get("profile")
.and_then(|t| t.get("release"))
Expand All @@ -262,7 +259,7 @@ pub fn root(mode: XargoMode, manifest_path: Option<&str>) -> Result<Option<Root>
// Don't require a 'Cargo.toml' to exist when 'xargo-check' is used
let name = match mode {
XargoMode::Build => "Cargo.toml",
XargoMode::Check => "Xargo.toml"
XargoMode::Check => "Xargo.toml",
};

let cd = match manifest_path {
Expand Down
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Args {
subcommand: Option<Subcommand>,
target: Option<String>,
message_format: Option<String>,
manifest_path: Option<String>, // path to the Cargo toml file given in --manifest-path
manifest_path: Option<String>, // path to the Cargo toml file given in --manifest-path
}

impl Args {
Expand Down
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unknown_lints)]
#![allow(unused_doc_comments)]
#![allow(unexpected_cfgs)]
error_chain!();
5 changes: 3 additions & 2 deletions src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::io::Write;
use std::io;
use std::io::Write;
use std::process::{Command, ExitStatus};

use errors::*;
Expand Down Expand Up @@ -42,7 +42,8 @@ impl CommandExt for Command {
writeln!(io::stderr(), "+ {:?}", self).ok();
}

let out = self.output()
let out = self
.output()
.chain_err(|| format!("couldn't execute `{:?}`", self))?;

if out.status.success() {
Expand Down
31 changes: 15 additions & 16 deletions src/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::io::Write;
use std::path::{Display, Path, PathBuf};
use std::{fs, io};

use fs2::FileExt;
use fs2;
use fs2::FileExt;

#[derive(PartialEq)]
enum State {
Expand Down Expand Up @@ -107,15 +107,14 @@ impl Filesystem {

match state {
State::Exclusive => {
acquire(
msg,
&path,
&|| f.try_lock_exclusive(),
&|| f.lock_exclusive(),
)?;
acquire(msg, &path, &|| f.try_lock_exclusive(), &|| {
f.lock_exclusive()
})?;
}
State::Shared => {
acquire(msg, &path, &|| f.try_lock_shared(), &|| f.lock_shared())?;
acquire(msg, &path, &|| Ok(f.try_lock_shared()?), &|| {
f.lock_shared()
})?;
}
}

Expand All @@ -125,7 +124,7 @@ impl Filesystem {
})
}

pub fn display(&self) -> Display {
pub fn display(&self) -> Display<'_> {
self.path.display()
}
}
Expand Down Expand Up @@ -173,21 +172,21 @@ fn acquire(
match try() {
Ok(_) => return Ok(()),
#[cfg(target_os = "macos")]
Err(ref e) if e.raw_os_error() == Some(::libc::ENOTSUP) =>
{
return Ok(())
Err(ref e) if e.raw_os_error() == Some(::libc::ENOTSUP) => return Ok(()),
Err(e) => {
if e.raw_os_error() != fs2::lock_contended_error().raw_os_error() {
return Err(e);
}
}
Err(e) => if e.raw_os_error() != fs2::lock_contended_error().raw_os_error() {
return Err(e);
},
}

writeln!(
io::stderr(),
"{:>12} waiting for file lock on {}",
"Blocking",
msg
).ok();
)
.ok();

block()
}
Expand Down
38 changes: 23 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

#[macro_use]
extern crate error_chain;
extern crate dirs;
extern crate fs2;
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "macos"))]
#[cfg(any(
all(target_os = "linux", not(target_env = "musl")),
target_os = "macos"
))]
extern crate libc;
extern crate rustc_version;
extern crate serde_json;
extern crate tempdir;
extern crate toml;
extern crate walkdir;
extern crate dirs;

use std::hash::{Hash, Hasher};
use std::io::Write;
use std::path::{Path};
use std::path::Path;
use std::process::ExitStatus;
use std::{env, io, process};

Expand Down Expand Up @@ -100,9 +103,11 @@ pub fn main_inner(xargo_mode: XargoMode) {

process::exit(1)
}
Ok(Some(status)) => if !status.success() {
process::exit(status.code().unwrap_or(1))
},
Ok(Some(status)) => {
if !status.success() {
process::exit(status.code().unwrap_or(1))
}
}
Ok(None) => {}
}
}
Expand All @@ -122,7 +127,8 @@ fn run(cargo_mode: XargoMode) -> Result<Option<ExitStatus>> {
io::stderr(),
concat!("xargo ", env!("CARGO_PKG_VERSION"), "{}"),
include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"))
).ok();
)
.ok();

return cargo::run(&args, verbose).map(Some);
}
Expand All @@ -136,11 +142,13 @@ fn run(cargo_mode: XargoMode) -> Result<Option<ExitStatus>> {
"The XARGO_RUST_SRC env variable must be set and point to the \
Rust source directory when working with the 'dev' channel",
)?,
Channel::Nightly => if let Some(src) = rustc::Src::from_env() {
src
} else {
sysroot.src()?
},
Channel::Nightly => {
if let Some(src) = rustc::Src::from_env() {
src
} else {
sysroot.src()?
}
}
Channel::Stable | Channel::Beta => {
eprintln!(
"ERROR: the sysroot can't be built for the {:?} channel. \
Expand Down Expand Up @@ -199,13 +207,13 @@ fn run(cargo_mode: XargoMode) -> Result<Option<ExitStatus>> {
&meta,
config.as_ref(),
verbose,
).map(Some);
)
.map(Some);
} else {
return Ok(None)
return Ok(None);
}
}
}

cargo::run(&args, verbose).map(Some)
}

32 changes: 20 additions & 12 deletions src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use std::process::Command;

pub use rustc_version::version_meta as version;

use serde_json::Value;
use serde_json;
use serde_json::Value;

use cargo::Root;
use errors::*;
use extensions::CommandExt;
use {rustc, util};
use cargo::Root;

fn command() -> Command {
env::var_os("RUSTC")
Expand All @@ -32,10 +32,8 @@ pub fn sysroot(verbose: bool) -> Result<Sysroot> {
command()
.args(&["--print", "sysroot"])
.run_and_get_stdout(verbose)
.map(|l| {
Sysroot {
path: PathBuf::from(l.trim()),
}
.map(|l| Sysroot {
path: PathBuf::from(l.trim()),
})
}
/// Path to Rust source
Expand Down Expand Up @@ -74,22 +72,32 @@ impl Sysroot {
pub fn src(&self) -> Result<Src> {
let src = self.path().join("lib").join("rustlib").join("src");

if src.join("rust").join("src").join("libstd").join("Cargo.toml").is_file() {
if src
.join("rust")
.join("src")
.join("libstd")
.join("Cargo.toml")
.is_file()
{
return Ok(Src {
path: src.join("rust").join("src"),
});
}

if src.join("rust").join("library").join("std").join("Cargo.toml").is_file() {
if src
.join("rust")
.join("library")
.join("std")
.join("Cargo.toml")
.is_file()
{
return Ok(Src {
path: src.join("rust").join("library"),
});
}

Err(
"`rust-src` component not found. Run `rustup component add \
rust-src`.",
)?
Err("`rust-src` component not found. Run `rustup component add \
rust-src`.")?
}
}

Expand Down
Loading