diff options
author | Bastien Orivel <eijebong@bananium.fr> | 2018-03-05 15:32:44 +0100 |
---|---|---|
committer | Bastien Orivel <eijebong@bananium.fr> | 2018-03-13 10:24:11 +0100 |
commit | 2bd99317fbe77e7475255d58f6b6f24ec80f7e41 (patch) | |
tree | bb1ee1d6161d5919bd64b9586fa988eb1de94912 /components/style/build_gecko.rs | |
parent | ac71266987ff39483faebd58d4359eef956ae5cf (diff) | |
download | servo-2bd99317fbe77e7475255d58f6b6f24ec80f7e41.tar.gz servo-2bd99317fbe77e7475255d58f6b6f24ec80f7e41.zip |
Update toml to 0.4
Diffstat (limited to 'components/style/build_gecko.rs')
-rw-r--r-- | components/style/build_gecko.rs | 40 |
1 files changed, 16 insertions, 24 deletions
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::<toml::value::Table>(&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<F>(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<Fixup>) -> 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()); } |