Skip to content

Commit d4cab49

Browse files
bors[bot]RalfJung
andauthored
Merge #302
302: Update dependencies r=RalfJung a=RalfJung Co-authored-by: Ralf Jung <post@ralfj.de>
2 parents f1b2e41 + 8bf6808 commit d4cab49

File tree

8 files changed

+65
-59
lines changed

8 files changed

+65
-59
lines changed

Cargo.lock

Lines changed: 31 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ default-run = "xargo"
1515
error-chain = "0.12"
1616
fs2 = "0.4.1"
1717
libc = "0.2.18"
18-
rustc_version = "0.1.7"
18+
rustc_version = "0.2.3"
1919
serde_json = "1.0"
2020
tempdir = "0.3.5"
21-
toml = "0.2.1"
21+
toml = "0.5.6"
2222
walkdir = "2.3"
2323
dirs = "3.0"
2424

src/cargo.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::collections::BTreeMap;
21
use std::hash::{Hash, Hasher};
32
use std::path::{Path, PathBuf};
43
use std::process::{Command, ExitStatus};
54
use std::{env, fmt};
65

7-
use toml::Value;
6+
use toml::{Value, map::Map};
87

98
use cli::Args;
109
use errors::*;
@@ -96,15 +95,17 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result<Vec<String
9695
let mut build = false;
9796
if let Some(array) = config
9897
.table
99-
.lookup(&format!("target.{}.{}", target, tool))
98+
.get("target")
99+
.and_then(|t| t.get(target))
100+
.and_then(|t| t.get(tool))
100101
.or_else(|| {
101102
build = true;
102-
config.table.lookup(&format!("build.{}", tool))
103+
config.table.get("build").and_then(|t| t.get(tool))
103104
}) {
104105
let mut flags = vec![];
105106

106107
let mut error = false;
107-
if let Some(array) = array.as_slice() {
108+
if let Some(array) = array.as_array() {
108109
for value in array {
109110
if let Some(flag) = value.as_str() {
110111
flags.push(flag.to_owned());
@@ -161,7 +162,7 @@ pub struct Config {
161162

162163
impl Config {
163164
pub fn target(&self) -> Result<Option<&str>> {
164-
if let Some(v) = self.table.lookup("build.target") {
165+
if let Some(v) = self.table.get("build").and_then(|t| t.get("target")) {
165166
Ok(Some(v.as_str()
166167
.ok_or_else(|| format!(".cargo/config: build.target must be a string"))?))
167168
} else {
@@ -210,9 +211,9 @@ impl<'t> Profile<'t> {
210211

211212
impl<'t> fmt::Display for Profile<'t> {
212213
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
213-
let mut map = BTreeMap::new();
214+
let mut map = Map::new();
214215
map.insert("profile".to_owned(), {
215-
let mut map = BTreeMap::new();
216+
let mut map = Map::new();
216217
map.insert("release".to_owned(), self.table.clone());
217218
Value::Table(map)
218219
});
@@ -229,7 +230,8 @@ impl Toml {
229230
/// `profile.release` part of `Cargo.toml`
230231
pub fn profile(&self) -> Option<Profile> {
231232
self.table
232-
.lookup("profile.release")
233+
.get("profile")
234+
.and_then(|t| t.get("release"))
233235
.map(|t| Profile { table: t })
234236
}
235237
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn run(cargo_mode: XargoMode) -> Result<Option<ExitStatus>> {
111111
let args = cli::args();
112112
let verbose = args.verbose();
113113

114-
let meta = rustc::version();
114+
let meta = rustc::version().map_err(|_| "could not determine rustc version")?;
115115

116116
if let Some(sc) = args.subcommand() {
117117
if !sc.needs_sysroot() {

src/sysroot.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{env, fs};
77

88
use rustc_version::VersionMeta;
99
use tempdir::TempDir;
10-
use toml::{Table, Value};
10+
use toml::{value::Table, Value, map::Map};
1111

1212
use CompilationMode;
1313
use cargo::{Root, Rustflags};
@@ -381,7 +381,7 @@ pub struct Blueprint {
381381
}
382382

383383
trait AsTableMut {
384-
fn as_table_mut<F, R>(&mut self, on_error_path: F) -> Result<&mut Table>
384+
fn as_table_mut_or_err<F, R>(&mut self, on_error_path: F) -> Result<&mut Table>
385385
where
386386
F: FnOnce() -> R,
387387
R: ::std::fmt::Display;
@@ -392,7 +392,7 @@ impl AsTableMut for Value {
392392
/// the contained table. If it's not return `Err` with an error message.
393393
/// The result of `on_error_path` will be inserted in the error message and
394394
/// should indicate the TOML path of `self`.
395-
fn as_table_mut<F, R>(&mut self, on_error_path: F) -> Result<&mut Table>
395+
fn as_table_mut_or_err<F, R>(&mut self, on_error_path: F) -> Result<&mut Table>
396396
where
397397
F: FnOnce() -> R,
398398
R: ::std::fmt::Display,
@@ -422,9 +422,9 @@ impl Blueprint {
422422
// add crate to patch section (if not specified)
423423
fn table_entry<'a>(table: &'a mut Table, key: &str) -> Result<&'a mut Table> {
424424
table
425-
.entry(key.into())
425+
.entry(key)
426426
.or_insert_with(|| Value::Table(Table::new()))
427-
.as_table_mut(|| key)
427+
.as_table_mut_or_err(|| key)
428428
}
429429

430430
let crates_io = table_entry(patch, "crates-io")?;
@@ -438,7 +438,7 @@ impl Blueprint {
438438

439439
fn from(toml: Option<&xargo::Toml>, target: &str, base_path: &Path, src: &Src) -> Result<Self> {
440440
fn make_path_absolute<F, R>(
441-
crate_spec: &mut toml::Table,
441+
crate_spec: &mut Table,
442442
base_path: &Path,
443443
on_error_path: F,
444444
) -> Result<()>
@@ -476,8 +476,8 @@ impl Blueprint {
476476
};
477477

478478
for (k1, v) in patch.iter_mut() {
479-
for (k2, v) in v.as_table_mut(|| format!("patch.{}", k1))?.iter_mut() {
480-
let krate = v.as_table_mut(|| format!("patch.{}.{}", k1, k2))?;
479+
for (k2, v) in v.as_table_mut_or_err(|| format!("patch.{}", k1))?.iter_mut() {
480+
let krate = v.as_table_mut_or_err(|| format!("patch.{}.{}", k1, k2))?;
481481

482482
make_path_absolute(krate, base_path, || format!("patch.{}.{}", k1, k2))?;
483483
}
@@ -530,11 +530,11 @@ impl Blueprint {
530530
(None, None) => {
531531
// If no dependencies were listed, we assume `core` and `compiler_builtins` as the
532532
// dependencies
533-
let mut t = BTreeMap::new();
534-
let mut core = BTreeMap::new();
533+
let mut t = Map::new();
534+
let mut core = Map::new();
535535
core.insert("stage".to_owned(), Value::Integer(0));
536536
t.insert("core".to_owned(), Value::Table(core));
537-
let mut cb = BTreeMap::new();
537+
let mut cb = Map::new();
538538
cb.insert(
539539
"features".to_owned(),
540540
Value::Array(vec![Value::String("mem".to_owned())]),

src/util.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::{Read, Write};
33
use std::path::Path;
44
use std::fs;
55

6-
use toml::{Parser, Value};
6+
use toml::Value;
77
use walkdir::WalkDir;
88

99
use errors::*;
@@ -61,9 +61,8 @@ pub fn mkdir(path: &Path) -> Result<()> {
6161

6262
/// Parses `path` as TOML
6363
pub fn parse(path: &Path) -> Result<Value> {
64-
Ok(Value::Table(Parser::new(&read(path)?)
65-
.parse()
66-
.ok_or_else(|| format!("{} is not valid TOML", path.display()))?))
64+
Ok(toml::from_str(&read(path)?)
65+
.map_err(|_| format!("{} is not valid TOML", path.display()))?)
6766
}
6867

6968
pub fn read(path: &Path) -> Result<String> {

src/xargo.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,20 @@ pub struct Toml {
105105
impl Toml {
106106
/// Returns the `dependencies` part of `Xargo.toml`
107107
pub fn dependencies(&self) -> Option<&Value> {
108-
self.table.lookup("dependencies")
108+
self.table.get("dependencies")
109109
}
110110

111111
/// Returns the `target.{}.dependencies` part of `Xargo.toml`
112112
pub fn target_dependencies(&self, target: &str) -> Option<&Value> {
113113
self.table
114-
.lookup(&format!("target.{}.dependencies", target))
114+
.get("target")
115+
.and_then(|t| t.get(target))
116+
.and_then(|t| t.get("dependencies"))
115117
}
116118

117119
/// Returns the `patch` part of `Xargo.toml`
118120
pub fn patch(&self) -> Option<&Value> {
119-
self.table.lookup("patch")
121+
self.table.get("patch")
120122
}
121123
}
122124

tests/smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn exists(krate: &str, target: &str) -> Result<bool> {
7979
}
8080

8181
fn host() -> String {
82-
rustc_version::version_meta().host
82+
rustc_version::version_meta().unwrap().host
8383
}
8484

8585
fn mkdir(path: &Path) -> Result<()> {

0 commit comments

Comments
 (0)