Skip to content

Commit

Permalink
fix(build): fixes to help more projects to build
Browse files Browse the repository at this point in the history
Involving
* complete list of reserved words (keywords in Rust)
* use namespace for otherwise clashing types in cmn::, io::
  • Loading branch information
Byron committed Mar 11, 2015
1 parent d99ba9c commit cf258bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/mako/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ use std::io;
use std::fs;
use std::collections::BTreeMap;

pub use cmn::{Hub, ReadSeek, ResourceMethodsBuilder, MethodBuilder, Resource, Part, ResponseResult, RequestValue,
NestedType, Delegate, DefaultDelegate, Result};
pub use cmn::{Hub, ReadSeek, Part, ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate};


// ##############
Expand Down
10 changes: 5 additions & 5 deletions src/mako/lib/mbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub struct ${ThisType}
% endif
}
impl${mb_tparams} MethodBuilder for ${ThisType} {}
impl${mb_tparams} cmn::MethodBuilder for ${ThisType} {}
impl${mb_tparams} ${ThisType} where ${', '.join(mb_type_bounds())} {
Expand Down Expand Up @@ -322,11 +322,11 @@ ${'.' + action_name | indent_by(13)}(${action_args});
where = ''
qualifier = 'pub '
add_args = ''
rtype = 'Result<()>'
rtype = 'cmn::Result<()>'
response_schema = method_response(schemas, c, m)
if response_schema:
rtype = 'Result<%s>' % (response_schema.id)
rtype = 'cmn::Result<%s>' % (response_schema.id)
if media_params:
stripped = lambda s: s.strip().strip(',')
Expand Down Expand Up @@ -377,7 +377,7 @@ ${'.' + action_name | indent_by(13)}(${action_args});
## Additional params - may not overlap with optional params
for &field in [${', '.join(enclose_in('"', (p.name for p in field_params)))}].iter() {
if ${paddfields}.contains_key(field) {
return Result::FieldClash(field);
return cmn::Result::FieldClash(field);
}
}
for (name, value) in ${paddfields}.iter() {
Expand Down Expand Up @@ -432,7 +432,7 @@ else {
## return RequestResult::Error(err);
## }
Result::Success(response)
cmn::Result::Success(response)
}
% for p in media_params:
Expand Down
2 changes: 1 addition & 1 deletion src/mako/lib/rbuild.mako
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct ${ThisType}
hub: &'a ${hub_type_name}${hub_type_params_s()},
}
impl${rb_params} ResourceMethodsBuilder for ${ThisType} {}
impl${rb_params} cmn::ResourceMethodsBuilder for ${ThisType} {}
## Builder Creators Methods ####################
impl${rb_params} ${ThisType} {
Expand Down
13 changes: 10 additions & 3 deletions src/mako/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
'string' : 'String',
'object' : 'HashMap'}

RESERVED_WORDS = set(('abstract', 'alignof', 'as', 'become', 'box', 'break', 'const', 'continue', 'crate', 'do',
'else', 'enum', 'extern', 'false', 'final', 'fn', 'for', 'if', 'impl', 'in', 'let', 'loop',
'macro', 'match', 'mod', 'move', 'mut', 'offsetof', 'override', 'priv', 'pub', 'pure', 'ref',
'return', 'sizeof', 'static', 'self', 'struct', 'super', 'true', 'trait', 'type', 'typeof',
'unsafe', 'unsized', 'use', 'virtual', 'where', 'while', 'yield'))


_words = [w.strip(',') for w in "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.".split(' ')]
RUST_TYPE_RND_MAP = {'bool': lambda: str(bool(randint(0, 1))).lower(),
'u32' : lambda: randint(0, 100),
Expand Down Expand Up @@ -246,8 +253,8 @@ def nested_type_name(sn, pn):

# Make properties which are reserved keywords usable
def mangle_ident(n):
n = '_'.join(singular(w) for w in camel_to_under(n).split('.'))
if n in ('type', 'where', 'override', 'move'):
n = camel_to_under(n).replace('-', '.').replace('.', '')
if n in RESERVED_WORDS:
return n + '_'
return n

Expand Down Expand Up @@ -352,7 +359,7 @@ def schema_markers(s, c):
# it should have at least one activity that matches it's type to qualify for the Resource trait
for fqan, iot in activities.iteritems():
if activity_name_to_type_name(activity_split(fqan)[1]).lower() == s.id.lower():
res.add('Resource')
res.add('cmn::Resource')
if IO_RESPONSE in iot:
res.add('ResponseResult')
if IO_REQUEST in iot:
Expand Down

0 comments on commit cf258bf

Please sign in to comment.