diff --git a/Cargo.toml b/Cargo.toml index 7db980c3d9..5799dc9a23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ # This library is just to try out the code that should ultimately go into the code generator ! [package] -name = "youtube3-dev" +name = "cmn" version = "0.0.1" authors = ["Sebastian Thiel "] description = "A library to facilitate interacting with your youtube account" @@ -10,6 +10,11 @@ repository = "https://github.com/Byron/google-apis-rs" license = "MIT" keywords = ["youtube", "google", "protocol", "not-for-use"] +[lib] +# The common code, used by all generated implementations +name = "cmn" +path = "src/rust/lib.rs" + [dependencies] # Just to get hyper to work ! openssl = "= 0.4.3" diff --git a/etc/api/shared.yaml b/etc/api/shared.yaml index 6c45081ad4..8c5f288c22 100644 --- a/etc/api/shared.yaml +++ b/etc/api/shared.yaml @@ -1,9 +1,9 @@ # Contains values shared among all API implementations directories: # directory under which all generated sources should reside - output: lib + output: gen # how to get from `output` back to common library - common: ../ + common: .. # where are all the API meta files api_base: etc/api # all mako source files @@ -18,7 +18,8 @@ api: - source: README.md - source: LICENSE.md - source: cargo.toml - # output_dir: optional - not there if unset + - source: lib.rs + output_dir: src cargo: build_version: "0.0.1" repo_base_url: https://github.com/Byron/google-apis-rs diff --git a/src/mako/cargo.toml.mako b/src/mako/cargo.toml.mako index 0b81485440..92c381e69d 100644 --- a/src/mako/cargo.toml.mako +++ b/src/mako/cargo.toml.mako @@ -24,5 +24,8 @@ hyper = "*" rustc-serialize = "*" yup-oauth2 = "*" +[dependencies.cmn] +path = "${directories.common}/.." + [dev-dependencies] yup-hyper-mock = "*" diff --git a/src/mako/deps.mako b/src/mako/deps.mako index 4dc6e7ceec..f74026c4ce 100644 --- a/src/mako/deps.mako +++ b/src/mako/deps.mako @@ -10,7 +10,7 @@ api_name = util.library_name(a.name, a.version) api_clean = api_name + '-clean' # source, destination of individual output files - sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + i.get('output_dir', '') + '/' + i.source) + sds = [(directories.mako_src + '/' + i.source + '.mako', gen_root + '/' + i.get('output_dir', '') + '/' + i.source) for i in api.templates] api_json = directories.api_base + '/' + a.name + '/' + a.version + '/' + a.name + '-api.json' api_json_inputs = api_json + " $(API_SHARED_INFO)" diff --git a/src/mako/lib.rs.mako b/src/mako/lib.rs.mako new file mode 100644 index 0000000000..cf73e30c59 --- /dev/null +++ b/src/mako/lib.rs.mako @@ -0,0 +1,9 @@ +<% import util %>\ +<%namespace name="lib" file="lib/lib.mako"/>\ +<%namespace name="mutil" file="lib/util.mako"/>\ +<%block filter="util.rust_module_doc_comment">\ +<%lib:docs />\ + +extern crate cmn; +extern crate "rustc-serialize" as rustc_serialize; +extern crate "yup-oauth2" as oauth2; \ No newline at end of file diff --git a/src/mako/lib/lib.mako b/src/mako/lib/lib.mako index b0860afdd2..8eb323e878 100644 --- a/src/mako/lib/lib.mako +++ b/src/mako/lib/lib.mako @@ -1,6 +1,9 @@ <%! import util %>\ +<%namespace name="util" file="lib/util.mako"/>\ + <%def name="docs()">\ TODO: Library level fully fledged documentation, incuding **summary** and **usage**. +And another line, for testing <%def name="license()">\ diff --git a/src/mako/lib/util.py b/src/mako/lib/util.py index 9466840016..94e4f331d0 100644 --- a/src/mako/lib/util.py +++ b/src/mako/lib/util.py @@ -1,11 +1,13 @@ +import re +re_linestart = re.compile('^', flags=re.MULTILINE) # rust module doc comment filter -def rmdc(s): - return '//! ' + s +def rust_module_doc_comment(s): + return re_linestart.sub('//! ', s) # rust doc comment filter -def rdc(s): - return '/// ' + s +def rust_doc_comment(s): + return re_linestart.sub('/// ', s) # Expects v to be 'v\d+', throws otherwise def to_api_version(v): @@ -22,7 +24,7 @@ def put_and(l): # escape each string in l with "s" and return the new list def estr(l): - return ["%s" % i for i in l] + return ['"%s"' % i for i in l] # build a full library name (non-canonical) def library_name(name, version): diff --git a/src/common.rs b/src/rust/dev/common.rs similarity index 100% rename from src/common.rs rename to src/rust/dev/common.rs diff --git a/src/lib.rs b/src/rust/dev/mod.rs similarity index 94% rename from src/lib.rs rename to src/rust/dev/mod.rs index a7482e030b..40cfd55365 100644 --- a/src/lib.rs +++ b/src/rust/dev/mod.rs @@ -11,14 +11,13 @@ //! # // TODO - generate ! //! # } //! ``` -extern crate hyper; -extern crate "rustc-serialize" as rustc_serialize; -extern crate "yup-oauth2" as oauth2; - use std::marker::PhantomData; use std::borrow::BorrowMut; use std::cell::RefCell; +use hyper; +use oauth2; + mod common; pub mod videos; diff --git a/src/videos/mod.rs b/src/rust/dev/videos/mod.rs similarity index 100% rename from src/videos/mod.rs rename to src/rust/dev/videos/mod.rs diff --git a/src/videos/service.rs b/src/rust/dev/videos/service.rs similarity index 100% rename from src/videos/service.rs rename to src/rust/dev/videos/service.rs diff --git a/src/rust/lib.rs b/src/rust/lib.rs new file mode 100644 index 0000000000..f353eded45 --- /dev/null +++ b/src/rust/lib.rs @@ -0,0 +1,8 @@ +//! library with code shared by all generated implementations +extern crate hyper; +extern crate "rustc-serialize" as rustc_serialize; +extern crate "yup-oauth2" as oauth2; + +/// This module is for testing only, its code is used in mako templates +#[cfg(test)] +mod dev; \ No newline at end of file