mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-25 14:12:13 +00:00
webidl: Add logging and use env_logger in the tests
This commit is contained in:
parent
346d2fda22
commit
8faebc56f2
@ -18,7 +18,7 @@ matrix:
|
|||||||
- rust: nightly
|
- rust: nightly
|
||||||
before_install: rustup component add rustfmt-preview --toolchain nightly
|
before_install: rustup component add rustfmt-preview --toolchain nightly
|
||||||
script: (cd crates/webidl && cargo test)
|
script: (cd crates/webidl && cargo test)
|
||||||
env: RUST_BACKTRACE=1
|
env: RUST_BACKTRACE=1 RUST_LOG=wasm_bindgen_webidl
|
||||||
|
|
||||||
# Dist linux binary
|
# Dist linux binary
|
||||||
- env: TARGET=x86_64-unknown-linux-musl DEPLOY=1
|
- env: TARGET=x86_64-unknown-linux-musl DEPLOY=1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "wasm-bindgen-webidl"
|
name = "wasm-bindgen-webidl"
|
||||||
version = "0.1.0"
|
version = "0.2.11"
|
||||||
authors = ["Nick Fitzgerald <fitzgen@gmail.com>"]
|
authors = ["Nick Fitzgerald <fitzgen@gmail.com>"]
|
||||||
|
|
||||||
[[test]]
|
[[test]]
|
||||||
@ -12,12 +12,14 @@ name = "webidl-expected"
|
|||||||
path = "tests/expected/lib.rs"
|
path = "tests/expected/lib.rs"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
diff = "0.1.11"
|
||||||
|
env_logger = "0.5.10"
|
||||||
wasm-bindgen = { version = "=0.2.11", path = "../..", default-features = false }
|
wasm-bindgen = { version = "=0.2.11", path = "../..", default-features = false }
|
||||||
wasm-bindgen-backend = { version = "=0.2.11", path = "../backend", features = ["extra-traits"] }
|
wasm-bindgen-backend = { version = "=0.2.11", path = "../backend", features = ["extra-traits"] }
|
||||||
diff = "0.1.11"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
|
log = "0.4.1"
|
||||||
proc-macro2 = "0.4"
|
proc-macro2 = "0.4"
|
||||||
quote = '0.6'
|
quote = '0.6'
|
||||||
syn = { version = '0.14', features = ['full'] }
|
syn = { version = '0.14', features = ['full'] }
|
||||||
|
@ -9,6 +9,8 @@ emitted for the types and methods described in the WebIDL.
|
|||||||
#![deny(missing_debug_implementations)]
|
#![deny(missing_debug_implementations)]
|
||||||
|
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
extern crate quote;
|
extern crate quote;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
@ -99,7 +101,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
|
|||||||
| webidl::ast::Definition::Includes(..)
|
| webidl::ast::Definition::Includes(..)
|
||||||
| webidl::ast::Definition::Mixin(..)
|
| webidl::ast::Definition::Mixin(..)
|
||||||
| webidl::ast::Definition::Namespace(..)
|
| webidl::ast::Definition::Namespace(..)
|
||||||
| webidl::ast::Definition::Typedef(..) => Ok(()),
|
| webidl::ast::Definition::Typedef(..) => {
|
||||||
|
warn!("Unsupported WebIDL definition: {:?}", self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +118,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Interface {
|
|||||||
interface.webidl_parse(program, ())
|
interface.webidl_parse(program, ())
|
||||||
}
|
}
|
||||||
// TODO
|
// TODO
|
||||||
webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => Ok(()),
|
webidl::ast::Interface::Callback(..) | webidl::ast::Interface::Partial(..) => {
|
||||||
|
warn!("Unsupported WebIDL interface: {:?}", self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +161,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::InterfaceMember {
|
|||||||
| webidl::ast::InterfaceMember::Const(_)
|
| webidl::ast::InterfaceMember::Const(_)
|
||||||
| webidl::ast::InterfaceMember::Iterable(_)
|
| webidl::ast::InterfaceMember::Iterable(_)
|
||||||
| webidl::ast::InterfaceMember::Maplike(_)
|
| webidl::ast::InterfaceMember::Maplike(_)
|
||||||
| webidl::ast::InterfaceMember::Setlike(_) => Ok(()),
|
| webidl::ast::InterfaceMember::Setlike(_) => {
|
||||||
|
warn!("Unsupported WebIDL interface member: {:?}", self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +178,10 @@ impl<'a> WebidlParse<'a> for webidl::ast::Operation {
|
|||||||
// TODO
|
// TODO
|
||||||
webidl::ast::Operation::Special(_)
|
webidl::ast::Operation::Special(_)
|
||||||
| webidl::ast::Operation::Static(_)
|
| webidl::ast::Operation::Static(_)
|
||||||
| webidl::ast::Operation::Stringifier(_) => Ok(()),
|
| webidl::ast::Operation::Stringifier(_) => {
|
||||||
|
warn!("Unsupported WebIDL operation: {:?}", self);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,14 +290,26 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation {
|
|||||||
|
|
||||||
fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> {
|
fn webidl_parse(&self, program: &mut backend::ast::Program, self_name: &'a str) -> Result<()> {
|
||||||
let fn_name = match self.name {
|
let fn_name = match self.name {
|
||||||
None => return Ok(()),
|
None => {
|
||||||
|
warn!(
|
||||||
|
"Operations without a name are unsupported. Skipping {:?}",
|
||||||
|
self
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
Some(ref name) => Ident::new(name, proc_macro2::Span::call_site()),
|
Some(ref name) => Ident::new(name, proc_macro2::Span::call_site()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (output, ret) = match self.return_type {
|
let (output, ret) = match self.return_type {
|
||||||
webidl::ast::ReturnType::Void => (syn::ReturnType::Default, None),
|
webidl::ast::ReturnType::Void => (syn::ReturnType::Default, None),
|
||||||
webidl::ast::ReturnType::NonVoid(ref ty) => match webidl_ty_to_syn_ty(ty) {
|
webidl::ast::ReturnType::NonVoid(ref ty) => match webidl_ty_to_syn_ty(ty) {
|
||||||
None => return Ok(()),
|
None => {
|
||||||
|
warn!(
|
||||||
|
"Operation's return type is not yet supported: {:?}. Skipping bindings for {:?}",
|
||||||
|
ty, self
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
Some(ty) => (
|
Some(ty) => (
|
||||||
syn::ReturnType::Type(Default::default(), Box::new(ty.clone())),
|
syn::ReturnType::Type(Default::default(), Box::new(ty.clone())),
|
||||||
Some(ty),
|
Some(ty),
|
||||||
@ -303,14 +329,30 @@ impl<'a> WebidlParse<'a> for webidl::ast::RegularOperation {
|
|||||||
arguments.push(self_ref_ty);
|
arguments.push(self_ref_ty);
|
||||||
|
|
||||||
for arg in &self.arguments {
|
for arg in &self.arguments {
|
||||||
if arg.optional || arg.variadic {
|
if arg.optional {
|
||||||
// We don't support optional or variadic functions yet; skip
|
warn!(
|
||||||
// bindings for this this whole function.
|
"Optional arguments are not supported yet. Skipping bindings for {:?}",
|
||||||
|
self
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if arg.variadic {
|
||||||
|
warn!(
|
||||||
|
"Variadic arguments are not supported yet. Skipping bindings for {:?}",
|
||||||
|
self
|
||||||
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
match webidl_ty_to_syn_ty(&arg.type_) {
|
match webidl_ty_to_syn_ty(&arg.type_) {
|
||||||
None => return Ok(()),
|
None => {
|
||||||
|
warn!(
|
||||||
|
"Argument's type is not yet supported: {:?}. Skipping bindings for {:?}",
|
||||||
|
arg.type_, self
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
Some(ty) => {
|
Some(ty) => {
|
||||||
inputs.push(simple_fn_arg(
|
inputs.push(simple_fn_arg(
|
||||||
proc_macro2::Ident::new(&arg.name, proc_macro2::Span::call_site()),
|
proc_macro2::Ident::new(&arg.name, proc_macro2::Span::call_site()),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
extern crate diff;
|
extern crate diff;
|
||||||
|
extern crate env_logger;
|
||||||
extern crate proc_macro2;
|
extern crate proc_macro2;
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
extern crate wasm_bindgen_backend as backend;
|
extern crate wasm_bindgen_backend as backend;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use diff;
|
use diff;
|
||||||
|
use env_logger;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::{Once, ONCE_INIT};
|
use std::sync::{Once, ONCE_INIT};
|
||||||
@ -90,6 +91,11 @@ fn strip_wasm_bindgen_generated(source: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn assert_compile(webidl: &str, expected: &str) {
|
pub fn assert_compile(webidl: &str, expected: &str) {
|
||||||
|
static INIT_ENV_LOGGER: Once = ONCE_INIT;
|
||||||
|
INIT_ENV_LOGGER.call_once(|| {
|
||||||
|
env_logger::init();
|
||||||
|
});
|
||||||
|
|
||||||
let actual = wb_webidl::compile(webidl).expect("should compile the webidl source OK");
|
let actual = wb_webidl::compile(webidl).expect("should compile the webidl source OK");
|
||||||
|
|
||||||
let (actual, actual_stderr) = rustfmt(actual);
|
let (actual, actual_stderr) = rustfmt(actual);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user