From 2bd99317fbe77e7475255d58f6b6f24ec80f7e41 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Mon, 5 Mar 2018 15:32:44 +0100 Subject: [PATCH] Update toml to 0.4 --- Cargo.lock | 9 +++++--- components/style/Cargo.toml | 2 +- components/style/build_gecko.rs | 40 +++++++++++++-------------------- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0973bb94a3a..0506eb301eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2986,7 +2986,7 @@ dependencies = [ "style_derive 0.0.1", "style_traits 0.0.1", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "uluru 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3210,8 +3210,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "toml" -version = "0.2.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "traitobject" @@ -3944,7 +3947,7 @@ dependencies = [ "checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3" "checksum tinyfiledialogs 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d92a5f7395a9e2895a2361c3121d4a0be0f8dac3be7d91841a5c1c5291b1c6dc" "checksum token_store 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a686838375fc11103b9c1529c6508320b7bd5e2401cd62831ca51b3e82e61849" -"checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" +"checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum truetype 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "acec30350633d6dac9dc1a625786b6cbe9150664be941aac2c35ad7199eab877" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 88b64ca8144..2a81d1e0fea 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -81,4 +81,4 @@ log = "0.3" bindgen = { version = "0.33.1", optional = true, default-features = false } regex = {version = "0.2", optional = true} walkdir = "1.0" -toml = {version = "0.2.1", optional = true, default-features = false} +toml = {version = "0.4.5", optional = true, default-features = false} diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index eeb15c8e718..0ff05604966 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -43,42 +43,32 @@ mod bindings { use super::common::*; use super::super::PYTHON; use toml; + use toml::value::Table; const STRUCTS_FILE: &'static str = "structs.rs"; const BINDINGS_FILE: &'static str = "bindings.rs"; - fn read_config(path: &PathBuf) -> toml::Table { + fn read_config(path: &PathBuf) -> Table { println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); update_last_modified(&path); let mut contents = String::new(); File::open(path).expect("Failed to open config file") .read_to_string(&mut contents).expect("Failed to read config file"); - let mut parser = toml::Parser::new(&contents); - if let Some(result) = parser.parse() { - result - } else { - use std::fmt::Write; - let mut reason = String::from("Failed to parse config file:"); - for err in parser.errors.iter() { - let parsed = &contents[..err.lo]; - write!(&mut reason, "\n* line {} column {}: {}", - parsed.lines().count(), - parsed.lines().last().map_or(0, |l| l.len()), - err).unwrap(); - } - panic!(reason) + match toml::from_str::(&contents) { + Ok(result) => result, + Err(e) => panic!("Failed to parse config file: {}", e) } } lazy_static! { - static ref CONFIG: toml::Table = { + static ref CONFIG: Table = { // Load Gecko's binding generator config from the source tree. let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap()) .join("layout/style/ServoBindings.toml"); read_config(&path) }; - static ref BUILD_CONFIG: toml::Table = { + static ref BUILD_CONFIG: Table = { // Load build-specific config overrides. // FIXME: We should merge with CONFIG above instead of // forcing callers to do it. @@ -169,7 +159,7 @@ mod bindings { fn mutable_borrowed_type(self, ty: &str) -> Builder; } - fn add_clang_args(mut builder: Builder, config: &toml::Table, matched_os: &mut bool) -> Builder { + fn add_clang_args(mut builder: Builder, config: &Table, matched_os: &mut bool) -> Builder { fn add_args(mut builder: Builder, values: &[toml::Value]) -> Builder { for item in values.iter() { builder = builder.clang_arg(item.as_str().expect("Expect string in list")); @@ -178,7 +168,7 @@ mod bindings { } for (k, v) in config.iter() { if k == "args" { - builder = add_args(builder, v.as_slice().unwrap()); + builder = add_args(builder, v.as_array().unwrap().as_slice()); continue; } let equal_idx = k.find('=').expect(&format!("Invalid key: {}", k)); @@ -324,11 +314,11 @@ mod bindings { struct BuilderWithConfig<'a> { builder: Builder, - config: &'a toml::Table, + config: &'a Table, used_keys: HashSet<&'static str>, } impl<'a> BuilderWithConfig<'a> { - fn new(builder: Builder, config: &'a toml::Table) -> Self { + fn new(builder: Builder, config: &'a Table) -> Self { BuilderWithConfig { builder, config, used_keys: HashSet::new(), @@ -342,7 +332,7 @@ mod bindings { let mut used_keys = self.used_keys; if let Some(list) = config.get(key) { used_keys.insert(key); - builder = func(builder, list.as_slice().unwrap().iter()); + builder = func(builder, list.as_array().unwrap().as_slice().iter()); } BuilderWithConfig { builder, config, used_keys } } @@ -355,7 +345,9 @@ mod bindings { self.handle_items(key, |b, item| func(b, item.as_str().unwrap())) } fn handle_table_items(self, key: &'static str, mut func: F) -> BuilderWithConfig<'a> - where F: FnMut(Builder, &'a toml::Table) -> Builder { + where + F: FnMut(Builder, &'a Table) -> Builder + { self.handle_items(key, |b, item| func(b, item.as_table().unwrap())) } fn handle_common(self, fixups: &mut Vec) -> BuilderWithConfig<'a> { @@ -419,7 +411,7 @@ mod bindings { for item in iter { let item = item.as_table().unwrap(); let name = item["enum"].as_str().unwrap(); - let variants = item["variants"].as_slice().unwrap().iter() + let variants = item["variants"].as_array().unwrap().as_slice().iter() .map(|item| item.as_str().unwrap()); map.insert(name.into(), RegexSet::new(variants).unwrap()); }