diff options
author | Ivan Lozano <ivanlozano@google.com> | 2021-02-17 17:03:10 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-17 17:03:10 +0000 |
commit | 255e5522aaabba4d57f566d24b87bf6f57a7edf2 (patch) | |
tree | 73ae6097756f20f810c08ea2dd034427514f2c82 | |
parent | 55f1d34131dbc085e5e7013680f408fba3fd92dc (diff) | |
parent | 5f95ff39dfe80f673031098f1eaa08d527992b94 (diff) | |
download | tokio-macros-255e5522aaabba4d57f566d24b87bf6f57a7edf2.tar.gz |
Merge "Upgrade rust/crates/tokio-macros to 1.1.0"android-s-preview-1
-rw-r--r-- | .cargo_vcs_info.json | 5 | ||||
-rw-r--r-- | Android.bp | 25 | ||||
-rw-r--r-- | CHANGELOG.md | 5 | ||||
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | src/entry.rs | 81 | ||||
-rw-r--r-- | src/lib.rs | 35 |
8 files changed, 144 insertions, 32 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json new file mode 100644 index 0000000..482e2e5 --- /dev/null +++ b/.cargo_vcs_info.json @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "d41882e2a18ea4459d8f3a3c7ba61c4c20b806b4" + } +} @@ -35,16 +35,39 @@ rust_test_host { srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, + test_options: { + unit_test: true, + }, edition: "2018", rustlibs: [ "libproc_macro2", "libquote", "libsyn", + "libtokio", ], } // dependent_library ["feature_list"] +// autocfg-1.0.1 +// bytes-1.0.1 "default,std" +// cfg-if-1.0.0 +// instant-0.1.9 +// libc-0.2.86 "align,default,std" +// lock_api-0.4.2 +// log-0.4.14 +// memchr-2.3.4 "default,std" +// mio-0.7.7 "default,net,os-ext,os-poll,os-util,tcp,udp,uds" +// num_cpus-1.13.0 +// once_cell-1.5.2 "alloc,default,std" +// parking_lot-0.11.1 "default" +// parking_lot_core-0.8.2 +// pin-project-lite-0.2.4 // proc-macro2-1.0.24 "default,proc-macro" // quote-1.0.8 "default,proc-macro" -// syn-1.0.55 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote" +// scopeguard-1.1.0 +// signal-hook-registry-1.3.0 +// smallvec-1.6.1 +// syn-1.0.60 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote" +// tokio-1.2.0 "bytes,default,fs,full,io-std,io-util,libc,macros,memchr,mio,net,num_cpus,once_cell,parking_lot,process,rt,rt-multi-thread,signal,signal-hook-registry,sync,time,tokio-macros,winapi" +// tokio-macros-1.1.0 // unicode-xid-0.2.1 "default" diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ee5ea..6760b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.0 (February 5, 2021) + +- add `start_paused` option to macros ([#3492]) + # 1.0.0 (December 23, 2020) - track `tokio` 1.0 release. @@ -55,3 +59,4 @@ [#2177]: https://github.com/tokio-rs/tokio/pull/2177 [#2225]: https://github.com/tokio-rs/tokio/pull/2225 [#3038]: https://github.com/tokio-rs/tokio/pull/3038 +[#3492]: https://github.com/tokio-rs/tokio/pull/3492 @@ -13,11 +13,11 @@ [package] edition = "2018" name = "tokio-macros" -version = "1.0.0" +version = "1.1.0" authors = ["Tokio Contributors <team@tokio.rs>"] description = "Tokio's proc macros.\n" homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-macros/1.0.0/tokio_macros" +documentation = "https://docs.rs/tokio-macros/1.1.0/tokio_macros" categories = ["asynchronous"] license = "MIT" repository = "https://github.com/tokio-rs/tokio" @@ -35,7 +35,8 @@ version = "1" [dependencies.syn] version = "1.0.3" features = ["full"] - -[dev-dependencies] +[dev-dependencies.tokio] +version = "1.0.0" +features = ["full"] [features] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index a1392a3..ea7b2de 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -7,13 +7,13 @@ name = "tokio-macros" # - Cargo.toml # - Update CHANGELOG.md. # - Create "tokio-macros-1.0.x" git tag. -version = "1.0.0" +version = "1.1.0" edition = "2018" authors = ["Tokio Contributors <team@tokio.rs>"] license = "MIT" repository = "https://github.com/tokio-rs/tokio" homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-macros/1.0.0/tokio_macros" +documentation = "https://docs.rs/tokio-macros/1.1.0/tokio_macros" description = """ Tokio's proc macros. """ @@ -30,7 +30,7 @@ quote = "1" syn = { version = "1.0.3", features = ["full"] } [dev-dependencies] -# tokio = { version = "1.0.0", path = "../tokio", features = ["full"] } +tokio = { version = "1.0.0", path = "../tokio", features = ["full"] } [package.metadata.docs.rs] all-features = true @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/tokio-macros/tokio-macros-1.0.0.crate" + value: "https://static.crates.io/crates/tokio-macros/tokio-macros-1.1.0.crate" } - version: "1.0.0" + version: "1.1.0" license_type: NOTICE last_upgrade_date { - year: 2020 - month: 12 - day: 23 + year: 2021 + month: 2 + day: 9 } } diff --git a/src/entry.rs b/src/entry.rs index 8f80499..f82a329 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -25,6 +25,7 @@ impl RuntimeFlavor { struct FinalConfig { flavor: RuntimeFlavor, worker_threads: Option<usize>, + start_paused: Option<bool>, } struct Configuration { @@ -32,6 +33,7 @@ struct Configuration { default_flavor: RuntimeFlavor, flavor: Option<RuntimeFlavor>, worker_threads: Option<(usize, Span)>, + start_paused: Option<(bool, Span)>, } impl Configuration { @@ -44,6 +46,7 @@ impl Configuration { }, flavor: None, worker_threads: None, + start_paused: None, } } @@ -79,31 +82,57 @@ impl Configuration { Ok(()) } + fn set_start_paused(&mut self, start_paused: syn::Lit, span: Span) -> Result<(), syn::Error> { + if self.start_paused.is_some() { + return Err(syn::Error::new(span, "`start_paused` set multiple times.")); + } + + let start_paused = parse_bool(start_paused, span, "start_paused")?; + self.start_paused = Some((start_paused, span)); + Ok(()) + } + fn build(&self) -> Result<FinalConfig, syn::Error> { let flavor = self.flavor.unwrap_or(self.default_flavor); use RuntimeFlavor::*; - match (flavor, self.worker_threads) { - (CurrentThread, Some((_, worker_threads_span))) => Err(syn::Error::new( - worker_threads_span, - "The `worker_threads` option requires the `multi_thread` runtime flavor.", - )), - (CurrentThread, None) => Ok(FinalConfig { - flavor, - worker_threads: None, - }), - (Threaded, worker_threads) if self.rt_multi_thread_available => Ok(FinalConfig { - flavor, - worker_threads: worker_threads.map(|(val, _span)| val), - }), + + let worker_threads = match (flavor, self.worker_threads) { + (CurrentThread, Some((_, worker_threads_span))) => { + return Err(syn::Error::new( + worker_threads_span, + "The `worker_threads` option requires the `multi_thread` runtime flavor.", + )) + } + (CurrentThread, None) => None, + (Threaded, worker_threads) if self.rt_multi_thread_available => { + worker_threads.map(|(val, _span)| val) + } (Threaded, _) => { let msg = if self.flavor.is_none() { "The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled." } else { "The runtime flavor `multi_thread` requires the `rt-multi-thread` feature." }; - Err(syn::Error::new(Span::call_site(), msg)) + return Err(syn::Error::new(Span::call_site(), msg)); } - } + }; + + let start_paused = match (flavor, self.start_paused) { + (Threaded, Some((_, start_paused_span))) => { + return Err(syn::Error::new( + start_paused_span, + "The `start_paused` option requires the `current_thread` runtime flavor.", + )); + } + (CurrentThread, Some((start_paused, _))) => Some(start_paused), + (_, None) => None, + }; + + Ok(FinalConfig { + flavor, + worker_threads, + start_paused, + }) } } @@ -134,6 +163,16 @@ fn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::E } } +fn parse_bool(bool: syn::Lit, span: Span, field: &str) -> Result<bool, syn::Error> { + match bool { + syn::Lit::Bool(b) => Ok(b.value), + _ => Err(syn::Error::new( + span, + format!("Failed to parse {} as bool.", field), + )), + } +} + fn parse_knobs( mut input: syn::ItemFn, args: syn::AttributeArgs, @@ -174,6 +213,9 @@ fn parse_knobs( "flavor" => { config.set_flavor(namevalue.lit.clone(), namevalue.span())?; } + "start_paused" => { + config.set_start_paused(namevalue.lit.clone(), namevalue.span())?; + } "core_threads" => { let msg = "Attribute `core_threads` is renamed to `worker_threads`"; return Err(syn::Error::new_spanned(namevalue, msg)); @@ -204,11 +246,11 @@ fn parse_knobs( macro_name ) } - "flavor" | "worker_threads" => { + "flavor" | "worker_threads" | "start_paused" => { format!("The `{}` attribute requires an argument.", name) } name => { - format!("Unknown attribute {} is specified; expected one of: `flavor`, `worker_threads`", name) + format!("Unknown attribute {} is specified; expected one of: `flavor`, `worker_threads`, `start_paused`", name) } }; return Err(syn::Error::new_spanned(path, msg)); @@ -235,6 +277,9 @@ fn parse_knobs( if let Some(v) = config.worker_threads { rt = quote! { #rt.worker_threads(#v) }; } + if let Some(v) = config.start_paused { + rt = quote! { #rt.start_paused(#v) }; + } let header = { if is_test { @@ -254,7 +299,7 @@ fn parse_knobs( .enable_all() .build() .unwrap() - .block_on(async { #body }) + .block_on(async #body) } }; @@ -1,4 +1,4 @@ -#![doc(html_root_url = "https://docs.rs/tokio-macros/1.0.0")] +#![doc(html_root_url = "https://docs.rs/tokio-macros/1.1.0")] #![allow(clippy::needless_doctest_main)] #![warn( missing_debug_implementations, @@ -144,6 +144,30 @@ use proc_macro::TokenStream; /// } /// ``` /// +/// ### Configure the runtime to start with time paused +/// +/// ```rust +/// #[tokio::main(flavor = "current_thread", start_paused = true)] +/// async fn main() { +/// println!("Hello world"); +/// } +/// ``` +/// +/// Equivalent code not using `#[tokio::main]` +/// +/// ```rust +/// fn main() { +/// tokio::runtime::Builder::new_current_thread() +/// .enable_all() +/// .start_paused(true) +/// .build() +/// .unwrap() +/// .block_on(async { +/// println!("Hello world"); +/// }) +/// } +/// ``` +/// /// ### NOTE: /// /// If you rename the Tokio crate in your dependencies this macro will not work. @@ -225,6 +249,15 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream { /// } /// ``` /// +/// ### Configure the runtime to start with time paused +/// +/// ```no_run +/// #[tokio::test(start_paused = true)] +/// async fn my_test() { +/// assert!(true); +/// } +/// ``` +/// /// ### NOTE: /// /// If you rename the Tokio crate in your dependencies this macro will not work. |