Skip to content

Commit

Permalink
fix(lib): setup nightly crate meta data correctly
Browse files Browse the repository at this point in the history
* Previously the meta-data was applied to the crate, which doesn't seem
  to work.
* attempted to make `examples/auth.rs` work on stable. This isn't
  properly tested now, as tests don't compile.

We are now at a state were stable as well as nightly work similarly,
but fail because `include!` doesn't behave correctly if macros are
involved. Namely it happens before crates are linked, yet it will
try to expand macros right away, which is a problem.

If the macro is defined in an empty fashion, it will actually be used
at include time, and expanded. Which causes issues further down the
compilation.

With the current 'fix' we manage to at least make everything but
`cargo test` work.

Related to #12
  • Loading branch information
Byron committed Jun 11, 2015
1 parent 37231fa commit a260b13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
14 changes: 6 additions & 8 deletions examples/auth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(collections, exit_status)]
#![allow(deprecated)]
extern crate yup_oauth2 as oauth2;
extern crate yup_hyper_mock as mock;
extern crate hyper;
Expand All @@ -17,15 +15,17 @@ use time::Duration;
use std::thread::sleep_ms;


fn usage(program: &str, opts: &Options, err: Option<Fail>) {
fn usage(program: &str, opts: &Options, err: Option<Fail>) -> ! {
if err.is_some() {
println!("{}", err.unwrap());
env::set_exit_status(1);
std::process::exit(1);
}
println!("{}", opts.short_usage(program) + " SCOPE [SCOPE ...]");
println!("{}", opts.usage("A program to authenticate against oauthv2 services.\n\
See https://developers.google.com/youtube/registering_an_application\n\
and https://developers.google.com/youtube/v3/guides/authentication#devices"));

std::process::exit(0);
}

fn main() {
Expand All @@ -36,18 +36,16 @@ fn main() {
opts.opt("c", "id", "oauthv2 ID of your application", "CLIENT_ID", HasArg::Yes, Occur::Req)
.opt("s", "secret", "oauthv2 secret of your application", "CLIENT_SECRET", HasArg::Yes, Occur::Req);

let m = match opts.parse(args.tail()) {
let m = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(e) => {
usage(&prog, &opts, Some(e));
return
}
};

if m.free.len() == 0 {
let msg = Fail::ArgumentMissing("you must provide one or more authorization scopes as free options".to_string());
usage(&prog, &opts, Some(msg));
return
}

let secret = oauth2::ApplicationSecret {
Expand Down Expand Up @@ -93,7 +91,7 @@ fn main() {
},
Err(err) => {
println!("Access token wasn't obtained: {}", err);
env::set_exit_status(10);
std::process::exit(10);
}
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
//! };
//! # }
//! ```
#![cfg_attr(feature = "nightly", feature(custom_derive))]
#![cfg_attr(feature = "nightly", feature(custom_derive, custom_attribute, plugin))]
#![cfg_attr(feature = "nightly", plugin(serde_macros))]

#[cfg(feature = "nightly")]
include!("lib.rs.in");
Expand Down
24 changes: 20 additions & 4 deletions src/lib.rs.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
#[cfg_attr(feature = "nightly", feature(plugin))]
#[cfg_attr(feature = "nightly", plugin(serde_macros))]
/// NOTE: This makes `cargo build` work, but `cargo test` still fails as these
/// override the macros that should come from `yup_hyper_mock`
#[cfg(not(test))]
macro_rules! mock_connector (
($name:ident {
$($url:expr => $res:expr)*
}) => (
)
);

#[cfg(not(test))]
macro_rules! mock_connector_in_order (
($name:ident {
$( $res:expr )*
}) => (
)
);


extern crate serde;

extern crate chrono;

#[macro_use]
extern crate hyper;
#[macro_use]
#[macro_use] #[cfg(test)]
extern crate log;
#[macro_use] #[cfg(test)]
extern crate yup_hyper_mock;
Expand Down

0 comments on commit a260b13

Please sign in to comment.