mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2025-12-26 17:02:24 +01:00
imp(serde): upgrade to v0.9
This provides proc macros, greatly simplifying the build projects.
This commit is contained in:
14
.travis.yml
14
.travis.yml
@@ -5,20 +5,10 @@ os:
|
||||
rust:
|
||||
- stable
|
||||
- nightly
|
||||
matrix:
|
||||
exclude:
|
||||
- rust: stable
|
||||
env: FEATURE=nightly
|
||||
allow_failures:
|
||||
- os: osx
|
||||
- rust: nightly
|
||||
script:
|
||||
- make gen-all-cli cargo-api ARGS="test --no-default-features --features=$FEATURE"
|
||||
- make cargo-api ARGS="doc --no-default-features --features=$FEATURE"
|
||||
- make gen-all-cli cargo-api ARGS=test
|
||||
- make cargo-api ARGS=doc
|
||||
- "if [[ $TRAVIS_RUST_VERSION = nightly ]]; then cargo test; fi"
|
||||
env:
|
||||
global:
|
||||
secure: Plj5DqAQX/4+KPM+nOAZ2sCbGIsoSrHo1YggfesQnU7paR734XO/4IayWnsNO/3q6bDi4GIcn56RUZAD3xBJJBNLia2CYIickIIYORRqLWbLdbzQaxBbD670ahtzEuUSFJTRKURPwFteAnsWYgNMNzwXOVNwLS5IUBqWTcS+N0g=
|
||||
matrix:
|
||||
- FEATURE=with-serde-codegen
|
||||
- FEATURE=nightly
|
||||
|
||||
@@ -20,7 +20,7 @@ clap = "*"
|
||||
hyper = "*"
|
||||
mime = "*"
|
||||
rustc-serialize = "*"
|
||||
yup-oauth2 = { version = "*", features = ["nightly"], default-features = false }
|
||||
yup-oauth2 = "*"
|
||||
serde = "*"
|
||||
serde_json = "*"
|
||||
serde_macros = "*"
|
||||
|
||||
@@ -76,10 +76,6 @@ make: Nothing to be done for `help'.
|
||||
|
||||
You can easily build the documentation index using `make docs-all` and individual API documentation using `make <api-name>-doc`. Run doctests on all apis with `make cargo-api ARGS=test` or on individual ones using `make <api-name>-cargo ARGS=test`. To see which API targets exist, run `make help-api`.
|
||||
|
||||
If you are using the nightly compiler, you can use compiler plugins, which simplifies and speeds up
|
||||
the compilation process as it doesn't neeed intermediate code generation by `syntex`. To do that,
|
||||
use something like `make cargo-api ARGS="build --no-default-features --features=nightly"`.
|
||||
|
||||
The same goes for commandline programs, just ust `-cli` instead of `-api`, and have a look at `help-cli` for individual targets.
|
||||
|
||||
## Make and parallel job execution
|
||||
|
||||
@@ -18,14 +18,9 @@ make:
|
||||
- source: README.md
|
||||
- source: ../LICENSE.md
|
||||
- source: ../Cargo.toml
|
||||
- source: lib.rs.in
|
||||
output_dir: src
|
||||
- source: lib.rs
|
||||
output_dir: src
|
||||
- source: build.rs
|
||||
output_dir: src
|
||||
cargo:
|
||||
build_script: src/build.rs
|
||||
keywords: [protocol, web, api]
|
||||
doc_base_url: https://docs.rs
|
||||
dependencies:
|
||||
|
||||
@@ -16,9 +16,6 @@ homepage = "${documentationLink}"
|
||||
documentation = "${util.doc_base_url()}"
|
||||
license = "${copyright.license_abbrev}"
|
||||
keywords = ["${name[:20]}", ${", ".join(estr(cargo.keywords))}]
|
||||
% if cargo.get('build_script'):
|
||||
build = "${cargo.build_script}"
|
||||
% endif
|
||||
|
||||
% if cargo.get('is_executable', False):
|
||||
[[bin]]
|
||||
@@ -29,10 +26,10 @@ name = "${util.program_name()}"
|
||||
hyper = "^ 0.10"
|
||||
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
|
||||
mime = "^ 0.2.0"
|
||||
serde = "^ 0.8"
|
||||
serde_json = "^ 0.8"
|
||||
yup-oauth2 = { version = "^ 1.0", optional = true, default-features = false }
|
||||
serde_derive = { version = "^ 0.8", optional = true }
|
||||
serde = "^ 0.9"
|
||||
serde_json = "^ 0.9"
|
||||
serde_derive = "^ 0.9"
|
||||
yup-oauth2 = "^ 1.0"
|
||||
% for dep in cargo.get('dependencies', list()):
|
||||
${dep}
|
||||
% endfor
|
||||
@@ -42,26 +39,14 @@ ${dep}
|
||||
api_name = util.library_name()
|
||||
crate_name_we_depend_on = None
|
||||
|
||||
nightly_features = ["serde_derive", "yup-oauth2/nightly"]
|
||||
default_features = ["serde_codegen", "yup-oauth2/with-serde-codegen"]
|
||||
|
||||
if make.depends_on_suffix is not None:
|
||||
crate_name_we_depend_on = library_to_crate_name(api_name, suffix=make.depends_on_suffix)
|
||||
nightly_features.append(crate_name_we_depend_on + '/nightly')
|
||||
default_features.append(crate_name_we_depend_on + '/with-serde-codegen')
|
||||
%>\
|
||||
default = ["with-serde-codegen"]
|
||||
nightly = [${','.join(enclose_in('"', nightly_features))}]
|
||||
with-serde-codegen = [${','.join(enclose_in('"', default_features))}]
|
||||
|
||||
[build-dependencies]
|
||||
serde_codegen = { version = "^ 0.8", optional = true }
|
||||
|
||||
% if make.depends_on_suffix is not None:
|
||||
|
||||
[dependencies.${crate_name_we_depend_on}]
|
||||
path = "../${api_name}"
|
||||
version = "${util.crate_version()}"
|
||||
optional = true
|
||||
default-features = false
|
||||
% endif
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#[cfg(feature = "with-serde-codegen")]
|
||||
mod inner {
|
||||
extern crate serde_codegen;
|
||||
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn main() {
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
|
||||
let src = Path::new("src/lib.rs.in");
|
||||
let dst = Path::new(&out_dir).join("lib.rs");
|
||||
|
||||
serde_codegen::expand(&src, &dst).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "with-serde-codegen"))]
|
||||
mod inner {
|
||||
pub fn main() {}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
inner::main()
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
<%namespace name="lib" file="lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="lib/schema.mako"/>\
|
||||
<%
|
||||
from util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s, hub_type_bounds,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources, context.get('methods'))
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
<%block filter="rust_comment">\
|
||||
<%util:gen_info source="${self.uri}" />\
|
||||
</%block>
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
extern crate hyper;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate yup_oauth2 as oauth2;
|
||||
extern crate mime;
|
||||
extern crate url;
|
||||
|
||||
mod cmn;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
use std::borrow::BorrowMut;
|
||||
use std::default::Default;
|
||||
use std::collections::BTreeMap;
|
||||
use serde_json as json;
|
||||
use std::io;
|
||||
use std::fs;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part,
|
||||
ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder,
|
||||
Resource, ErrorResponse, remove_json_null_values};
|
||||
|
||||
|
||||
// ##############
|
||||
// UTILITIES ###
|
||||
// ############
|
||||
|
||||
${lib.scope_enum()}
|
||||
|
||||
|
||||
// ########
|
||||
// HUB ###
|
||||
// ######
|
||||
|
||||
/// Central instance to access all ${hub_type} related resource activities
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Instantiate a new hub
|
||||
///
|
||||
<%block filter="rust_doc_comment">\
|
||||
${lib.hub_usage_example(c)}\
|
||||
</%block>
|
||||
pub struct ${hub_type}${ht_params} {
|
||||
client: RefCell<C>,
|
||||
auth: RefCell<A>,
|
||||
_user_agent: String,
|
||||
}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> Hub for ${hub_type}${ht_params} {}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
|
||||
where ${', '.join(hub_type_bounds())} {
|
||||
|
||||
pub fn new(client: C, authenticator: A) -> ${hub_type}${ht_params} {
|
||||
${hub_type} {
|
||||
client: RefCell::new(client),
|
||||
auth: RefCell::new(authenticator),
|
||||
_user_agent: "${default_user_agent}".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
% for resource in sorted(c.rta_map.keys()):
|
||||
pub fn ${mangle_ident(resource)}(&'a self) -> ${rb_type(resource)}${rb_type_params_s(resource, c)} {
|
||||
${rb_type(resource)} { hub: &self }
|
||||
}
|
||||
% endfor
|
||||
|
||||
/// Set the user-agent header field to use in all requests to the server.
|
||||
/// It defaults to `${default_user_agent}`.
|
||||
///
|
||||
/// Returns the previously set user-agent.
|
||||
pub fn user_agent(&mut self, agent_name: String) -> String {
|
||||
let prev = self._user_agent.clone();
|
||||
self._user_agent = agent_name;
|
||||
prev
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
% if c.schemas:
|
||||
// ############
|
||||
// SCHEMAS ###
|
||||
// ##########
|
||||
% for s in c.schemas.values():
|
||||
% if UNUSED_TYPE_MARKER not in schema_markers(s, c, transitive=True):
|
||||
${schema.new(s, c)}
|
||||
% endif
|
||||
% endfor
|
||||
% endif
|
||||
|
||||
// ###################
|
||||
// MethodBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource in c.rta_map:
|
||||
${rbuild.new(resource, c)}
|
||||
|
||||
|
||||
% endfor
|
||||
|
||||
|
||||
// ###################
|
||||
// CallBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource, methods in c.rta_map.iteritems():
|
||||
% for method in methods:
|
||||
${mbuild.new(resource, method, c)}
|
||||
|
||||
% endfor ## method in methods
|
||||
% endfor ## resource, methods
|
||||
@@ -17,11 +17,144 @@ ${lib.docs(c)}
|
||||
// We don't warn about this, as depending on the API, some data structures or facilities are never used.
|
||||
// Instead of pre-determining this, we just disable the lint. It's manually tuned to not have any
|
||||
// unused imports in fully featured APIs. Same with unused_mut ... .
|
||||
#![cfg_attr(feature = "nightly", feature(proc_macro))]
|
||||
#![allow(unused_imports, unused_mut, dead_code)]
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
include!("lib.rs.in");
|
||||
<%namespace name="lib" file="lib/lib.mako"/>\
|
||||
<%namespace name="util" file="../lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="lib/rbuild.mako"/>\
|
||||
<%namespace name="mbuild" file="lib/mbuild.mako"/>\
|
||||
<%namespace name="schema" file="lib/schema.mako"/>\
|
||||
<%
|
||||
from util import (new_context, rust_comment, rust_doc_comment, rust_module_doc_comment,
|
||||
rb_type, hub_type, mangle_ident, hub_type_params_s, hub_type_bounds,
|
||||
rb_type_params_s, find_fattest_resource, HUB_TYPE_PARAMETERS, METHODS_RESOURCE,
|
||||
UNUSED_TYPE_MARKER, schema_markers)
|
||||
|
||||
c = new_context(schemas, resources, context.get('methods'))
|
||||
hub_type = hub_type(c.schemas, util.canonical_name())
|
||||
ht_params = hub_type_params_s()
|
||||
|
||||
default_user_agent = "google-api-rust-client/" + cargo.build_version
|
||||
%>\
|
||||
<%block filter="rust_comment">\
|
||||
<%util:gen_info source="${self.uri}" />\
|
||||
</%block>
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
extern crate hyper;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
extern crate yup_oauth2 as oauth2;
|
||||
extern crate mime;
|
||||
extern crate url;
|
||||
|
||||
mod cmn;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::cell::RefCell;
|
||||
use std::borrow::BorrowMut;
|
||||
use std::default::Default;
|
||||
use std::collections::BTreeMap;
|
||||
use serde_json as json;
|
||||
use std::io;
|
||||
use std::fs;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
pub use cmn::{MultiPartReader, ToParts, MethodInfo, Result, Error, CallBuilder, Hub, ReadSeek, Part,
|
||||
ResponseResult, RequestValue, NestedType, Delegate, DefaultDelegate, MethodsBuilder,
|
||||
Resource, ErrorResponse, remove_json_null_values};
|
||||
|
||||
|
||||
// ##############
|
||||
// UTILITIES ###
|
||||
// ############
|
||||
|
||||
${lib.scope_enum()}
|
||||
|
||||
|
||||
// ########
|
||||
// HUB ###
|
||||
// ######
|
||||
|
||||
/// Central instance to access all ${hub_type} related resource activities
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Instantiate a new hub
|
||||
///
|
||||
<%block filter="rust_doc_comment">\
|
||||
${lib.hub_usage_example(c)}\
|
||||
</%block>
|
||||
pub struct ${hub_type}${ht_params} {
|
||||
client: RefCell<C>,
|
||||
auth: RefCell<A>,
|
||||
_user_agent: String,
|
||||
}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> Hub for ${hub_type}${ht_params} {}
|
||||
|
||||
impl<'a, ${', '.join(HUB_TYPE_PARAMETERS)}> ${hub_type}${ht_params}
|
||||
where ${', '.join(hub_type_bounds())} {
|
||||
|
||||
pub fn new(client: C, authenticator: A) -> ${hub_type}${ht_params} {
|
||||
${hub_type} {
|
||||
client: RefCell::new(client),
|
||||
auth: RefCell::new(authenticator),
|
||||
_user_agent: "${default_user_agent}".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
% for resource in sorted(c.rta_map.keys()):
|
||||
pub fn ${mangle_ident(resource)}(&'a self) -> ${rb_type(resource)}${rb_type_params_s(resource, c)} {
|
||||
${rb_type(resource)} { hub: &self }
|
||||
}
|
||||
% endfor
|
||||
|
||||
/// Set the user-agent header field to use in all requests to the server.
|
||||
/// It defaults to `${default_user_agent}`.
|
||||
///
|
||||
/// Returns the previously set user-agent.
|
||||
pub fn user_agent(&mut self, agent_name: String) -> String {
|
||||
let prev = self._user_agent.clone();
|
||||
self._user_agent = agent_name;
|
||||
prev
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
% if c.schemas:
|
||||
// ############
|
||||
// SCHEMAS ###
|
||||
// ##########
|
||||
% for s in c.schemas.values():
|
||||
% if UNUSED_TYPE_MARKER not in schema_markers(s, c, transitive=True):
|
||||
${schema.new(s, c)}
|
||||
% endif
|
||||
% endfor
|
||||
% endif
|
||||
|
||||
// ###################
|
||||
// MethodBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource in c.rta_map:
|
||||
${rbuild.new(resource, c)}
|
||||
|
||||
|
||||
% endfor
|
||||
|
||||
|
||||
// ###################
|
||||
// CallBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource, methods in c.rta_map.iteritems():
|
||||
% for method in methods:
|
||||
${mbuild.new(resource, method, c)}
|
||||
|
||||
% endfor ## method in methods
|
||||
% endfor ## resource, methods
|
||||
|
||||
#[cfg(feature = "with-serde-codegen")]
|
||||
include!(concat!(env!("OUT_DIR"), "/lib.rs"));
|
||||
@@ -660,7 +660,7 @@ else {
|
||||
let mut json_mime_type = mime::Mime(mime::TopLevel::Application, mime::SubLevel::Json, Default::default());
|
||||
let mut request_value_reader =
|
||||
{
|
||||
let mut value = json::value::to_value(&self.${property(REQUEST_VALUE_PROPERTY_NAME)});
|
||||
let mut value = json::value::to_value(&self.${property(REQUEST_VALUE_PROPERTY_NAME)}).expect("serde to work");
|
||||
remove_json_null_values(&mut value);
|
||||
let mut dst = io::Cursor::new(Vec::with_capacity(128));
|
||||
json::to_writer(&mut dst, &value).unwrap();
|
||||
|
||||
@@ -323,7 +323,7 @@ if dry_run {
|
||||
if !download_mode {
|
||||
% endif
|
||||
% if mc.response_schema:
|
||||
let mut value = json::value::to_value(&output_schema);
|
||||
let mut value = json::value::to_value(&output_schema).expect("serde to work");
|
||||
remove_json_null_values(&mut value);
|
||||
json::to_writer_pretty(&mut ostream, &value).unwrap();
|
||||
ostream.flush().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user