mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Update toml to 0.4
This commit is contained in:
parent
ac71266987
commit
2bd99317fb
3 changed files with 23 additions and 28 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -2986,7 +2986,7 @@ dependencies = [
|
||||||
"style_derive 0.0.1",
|
"style_derive 0.0.1",
|
||||||
"style_traits 0.0.1",
|
"style_traits 0.0.1",
|
||||||
"time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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-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)",
|
"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]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.2.1"
|
version = "0.4.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "traitobject"
|
name = "traitobject"
|
||||||
|
@ -3944,7 +3947,7 @@ dependencies = [
|
||||||
"checksum time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "ffd7ccbf969a892bf83f1e441126968a07a3941c24ff522a26af9f9f4585d1a3"
|
"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 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 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 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 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"
|
"checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887"
|
||||||
|
|
|
@ -81,4 +81,4 @@ log = "0.3"
|
||||||
bindgen = { version = "0.33.1", optional = true, default-features = false }
|
bindgen = { version = "0.33.1", optional = true, default-features = false }
|
||||||
regex = {version = "0.2", optional = true}
|
regex = {version = "0.2", optional = true}
|
||||||
walkdir = "1.0"
|
walkdir = "1.0"
|
||||||
toml = {version = "0.2.1", optional = true, default-features = false}
|
toml = {version = "0.4.5", optional = true, default-features = false}
|
||||||
|
|
|
@ -43,42 +43,32 @@ mod bindings {
|
||||||
use super::common::*;
|
use super::common::*;
|
||||||
use super::super::PYTHON;
|
use super::super::PYTHON;
|
||||||
use toml;
|
use toml;
|
||||||
|
use toml::value::Table;
|
||||||
|
|
||||||
const STRUCTS_FILE: &'static str = "structs.rs";
|
const STRUCTS_FILE: &'static str = "structs.rs";
|
||||||
const BINDINGS_FILE: &'static str = "bindings.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());
|
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
|
||||||
update_last_modified(&path);
|
update_last_modified(&path);
|
||||||
|
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
File::open(path).expect("Failed to open config file")
|
File::open(path).expect("Failed to open config file")
|
||||||
.read_to_string(&mut contents).expect("Failed to read config file");
|
.read_to_string(&mut contents).expect("Failed to read config file");
|
||||||
let mut parser = toml::Parser::new(&contents);
|
match toml::from_str::<toml::value::Table>(&contents) {
|
||||||
if let Some(result) = parser.parse() {
|
Ok(result) => result,
|
||||||
result
|
Err(e) => panic!("Failed to parse config file: {}", e)
|
||||||
} 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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CONFIG: toml::Table = {
|
static ref CONFIG: Table = {
|
||||||
// Load Gecko's binding generator config from the source tree.
|
// Load Gecko's binding generator config from the source tree.
|
||||||
let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap())
|
let path = PathBuf::from(env::var_os("MOZ_SRC").unwrap())
|
||||||
.join("layout/style/ServoBindings.toml");
|
.join("layout/style/ServoBindings.toml");
|
||||||
read_config(&path)
|
read_config(&path)
|
||||||
};
|
};
|
||||||
static ref BUILD_CONFIG: toml::Table = {
|
static ref BUILD_CONFIG: Table = {
|
||||||
// Load build-specific config overrides.
|
// Load build-specific config overrides.
|
||||||
// FIXME: We should merge with CONFIG above instead of
|
// FIXME: We should merge with CONFIG above instead of
|
||||||
// forcing callers to do it.
|
// forcing callers to do it.
|
||||||
|
@ -169,7 +159,7 @@ mod bindings {
|
||||||
fn mutable_borrowed_type(self, ty: &str) -> Builder;
|
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 {
|
fn add_args(mut builder: Builder, values: &[toml::Value]) -> Builder {
|
||||||
for item in values.iter() {
|
for item in values.iter() {
|
||||||
builder = builder.clang_arg(item.as_str().expect("Expect string in list"));
|
builder = builder.clang_arg(item.as_str().expect("Expect string in list"));
|
||||||
|
@ -178,7 +168,7 @@ mod bindings {
|
||||||
}
|
}
|
||||||
for (k, v) in config.iter() {
|
for (k, v) in config.iter() {
|
||||||
if k == "args" {
|
if k == "args" {
|
||||||
builder = add_args(builder, v.as_slice().unwrap());
|
builder = add_args(builder, v.as_array().unwrap().as_slice());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let equal_idx = k.find('=').expect(&format!("Invalid key: {}", k));
|
let equal_idx = k.find('=').expect(&format!("Invalid key: {}", k));
|
||||||
|
@ -324,11 +314,11 @@ mod bindings {
|
||||||
|
|
||||||
struct BuilderWithConfig<'a> {
|
struct BuilderWithConfig<'a> {
|
||||||
builder: Builder,
|
builder: Builder,
|
||||||
config: &'a toml::Table,
|
config: &'a Table,
|
||||||
used_keys: HashSet<&'static str>,
|
used_keys: HashSet<&'static str>,
|
||||||
}
|
}
|
||||||
impl<'a> BuilderWithConfig<'a> {
|
impl<'a> BuilderWithConfig<'a> {
|
||||||
fn new(builder: Builder, config: &'a toml::Table) -> Self {
|
fn new(builder: Builder, config: &'a Table) -> Self {
|
||||||
BuilderWithConfig {
|
BuilderWithConfig {
|
||||||
builder, config,
|
builder, config,
|
||||||
used_keys: HashSet::new(),
|
used_keys: HashSet::new(),
|
||||||
|
@ -342,7 +332,7 @@ mod bindings {
|
||||||
let mut used_keys = self.used_keys;
|
let mut used_keys = self.used_keys;
|
||||||
if let Some(list) = config.get(key) {
|
if let Some(list) = config.get(key) {
|
||||||
used_keys.insert(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 }
|
BuilderWithConfig { builder, config, used_keys }
|
||||||
}
|
}
|
||||||
|
@ -355,7 +345,9 @@ mod bindings {
|
||||||
self.handle_items(key, |b, item| func(b, item.as_str().unwrap()))
|
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>
|
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()))
|
self.handle_items(key, |b, item| func(b, item.as_table().unwrap()))
|
||||||
}
|
}
|
||||||
fn handle_common(self, fixups: &mut Vec<Fixup>) -> BuilderWithConfig<'a> {
|
fn handle_common(self, fixups: &mut Vec<Fixup>) -> BuilderWithConfig<'a> {
|
||||||
|
@ -419,7 +411,7 @@ mod bindings {
|
||||||
for item in iter {
|
for item in iter {
|
||||||
let item = item.as_table().unwrap();
|
let item = item.as_table().unwrap();
|
||||||
let name = item["enum"].as_str().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(|item| item.as_str().unwrap());
|
||||||
map.insert(name.into(), RegexSet::new(variants).unwrap());
|
map.insert(name.into(), RegexSet::new(variants).unwrap());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue