Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Backport syntax libs update #5316

Merged
merged 1 commit into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 65 additions & 46 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dapps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ serde = "0.9"
serde_json = "0.9"
serde_derive = "0.9"
linked-hash-map = "0.3"
parity-dapps-glue = "1.4"
parity-dapps-glue = "1.7"
base32 = "0.3"
mime = "0.2"
mime_guess = "1.6.1"
Expand Down
14 changes: 7 additions & 7 deletions dapps/js-glue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ authors = ["Parity Technologies <admin@parity.io>"]
build = "build.rs"

[build-dependencies]
quasi_codegen = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }
quasi_codegen = { version = "0.32", optional = true }
syntex = { version = "0.58", optional = true }

[dependencies]
glob = { version = "0.2.11" }
mime_guess = { version = "1.6.1" }
aster = { version = "0.17", default-features = false }
quasi = { version = "0.11", default-features = false }
quasi_macros = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }
syntex_syntax = { version = "0.33", optional = true }
aster = { version = "0.41", default-features = false }
quasi = { version = "0.32", default-features = false }
quasi_macros = { version = "0.32", optional = true }
syntex = { version = "0.58", optional = true }
syntex_syntax = { version = "0.58", optional = true }
clippy = { version = "0.0.90", optional = true }

[features]
Expand Down
4 changes: 1 addition & 3 deletions dapps/js-glue/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ mod inner {

pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut registry = syntex::Registry::new();
quasi_codegen::register(&mut registry);

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");

registry.expand("", &src, &dst).unwrap();
quasi_codegen::expand(&src, &dst).unwrap();
}
}

Expand Down
5 changes: 2 additions & 3 deletions dapps/js-glue/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ pub mod inner {

impl fold::Folder for StripAttributeFolder {
fn fold_attribute(&mut self, attr: ast::Attribute) -> Option<ast::Attribute> {
match attr.node.value.node {
ast::MetaItemKind::List(ref n, _) if n == &"webapp" => { return None; }
_ => {}
if &*attr.value.name.as_str() == "webapp" {
return None;
}

Some(attr)
Expand Down
56 changes: 30 additions & 26 deletions dapps/js-glue/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ use self::mime_guess::guess_mime_type;
use std::path::{self, Path, PathBuf};
use std::ops::Deref;

use syntax::ast::{MetaItem, Item};

use syntax::ast;
use syntax::attr;
use syntax::ast::{self, MetaItem, Item};
use syntax::codemap::Span;
use syntax::ext::base::{Annotatable, ExtCtxt};
use syntax::ptr::P;
use syntax::print::pprust::{lit_to_string};
use syntax::parse::token::{InternedString};

use syntax::print::pprust::lit_to_string;
use syntax::symbol::InternedString;

pub fn expand_webapp_implementation(
cx: &mut ExtCtxt,
Expand All @@ -48,7 +44,7 @@ pub fn expand_webapp_implementation(
},
};
let builder = aster::AstBuilder::new().span(span);
implement_webapp(cx, &builder, &item, push);
implement_webapp(cx, &builder, item, push);
}

fn implement_webapp(cx: &ExtCtxt, builder: &aster::AstBuilder, item: &Item, push: &mut FnMut(Annotatable)) {
Expand Down Expand Up @@ -117,11 +113,12 @@ fn implement_webapp(cx: &ExtCtxt, builder: &aster::AstBuilder, item: &Item, push
}

fn extract_path(cx: &ExtCtxt, item: &Item) -> String {
for meta_items in item.attrs().iter().filter_map(webapp_meta_items) {
for meta_items in item.attrs.iter().filter_map(webapp_meta_items) {
for meta_item in meta_items {
let is_path = &*meta_item.name.as_str() == "path";
match meta_item.node {
ast::MetaItemKind::NameValue(ref name, ref lit) if name == &"path" => {
if let Some(s) = get_str_from_lit(cx, name, lit) {
ast::MetaItemKind::NameValue(ref lit) if is_path => {
if let Some(s) = get_str_from_lit(cx, lit) {
return s.deref().to_owned();
}
},
Expand All @@ -134,14 +131,32 @@ fn extract_path(cx: &ExtCtxt, item: &Item) -> String {
"web".to_owned()
}

fn get_str_from_lit(cx: &ExtCtxt, name: &str, lit: &ast::Lit) -> Option<InternedString> {
fn webapp_meta_items(attr: &ast::Attribute) -> Option<Vec<ast::MetaItem>> {
let is_webapp = &*attr.value.name.as_str() == "webapp";
match attr.value.node {
ast::MetaItemKind::List(ref items) if is_webapp => {
attr::mark_used(&attr);
Some(
items.iter()
.map(|item| item.node.clone())
.filter_map(|item| match item {
ast::NestedMetaItemKind::MetaItem(item) => Some(item),
_ => None,
})
.collect()
)
}
_ => None
}
}

fn get_str_from_lit(cx: &ExtCtxt, lit: &ast::Lit) -> Option<InternedString> {
match lit.node {
ast::LitKind::Str(ref s, _) => Some(s.clone()),
ast::LitKind::Str(ref s, _) => Some(s.clone().as_str()),
_ => {
cx.span_err(
lit.span,
&format!("webapp annotation `{}` must be a string, not `{}`",
name,
&format!("webapp annotation path must be a string, not `{}`",
lit_to_string(lit)
)
);
Expand All @@ -150,16 +165,6 @@ fn get_str_from_lit(cx: &ExtCtxt, name: &str, lit: &ast::Lit) -> Option<Interned
}
}

fn webapp_meta_items(attr: &ast::Attribute) -> Option<&[P<ast::MetaItem>]> {
match attr.node.value.node {
ast::MetaItemKind::List(ref name, ref items) if name == &"webapp" => {
attr::mark_used(&attr);
Some(items)
}
_ => None
}
}

fn as_uri(path: &Path) -> String {
let mut s = String::new();
for component in path.iter() {
Expand All @@ -169,7 +174,6 @@ fn as_uri(path: &Path) -> String {
s[0..s.len()-1].into()
}


#[test]
fn should_convert_path_separators_on_all_platforms() {
// given
Expand Down
1 change: 0 additions & 1 deletion dapps/js-glue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
extern crate syntex;

#[cfg(feature = "with-syntex")]
#[macro_use]
extern crate syntex_syntax as syntax;

#[cfg(feature = "with-syntex")]
Expand Down
14 changes: 7 additions & 7 deletions ipc/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ nightly-testing = ["clippy"]
with-syntex = ["quasi/with-syntex", "quasi_codegen", "quasi_codegen/with-syntex", "syntex", "syntex_syntax"]

[build-dependencies]
quasi_codegen = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }
quasi_codegen = { version = "0.32", optional = true }
syntex = { version = "0.58", optional = true }

[dependencies]
aster = { version = "0.17", default-features = false }
aster = { version = "0.41", default-features = false }
clippy = { version = "^0.*", optional = true }
quasi = { version = "0.11", default-features = false }
quasi_macros = { version = "0.11", optional = true }
syntex = { version = "0.33", optional = true }
syntex_syntax = { version = "0.33", optional = true }
quasi = { version = "0.32", default-features = false }
quasi_macros = { version = "0.32", optional = true }
syntex = { version = "0.58", optional = true }
syntex_syntax = { version = "0.58", optional = true }
4 changes: 1 addition & 3 deletions ipc/codegen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ mod inner {

pub fn main() {
let out_dir = env::var_os("OUT_DIR").unwrap();
let mut registry = syntex::Registry::new();
quasi_codegen::register(&mut registry);

let src = Path::new("src/lib.rs.in");
let dst = Path::new(&out_dir).join("lib.rs");

registry.expand("", &src, &dst).unwrap();
quasi_codegen::expand(&src, &dst).unwrap();
}
}

Expand Down
Loading