diff options
author | Chih-hung Hsieh <chh@google.com> | 2020-10-15 06:08:06 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-10-15 06:08:06 +0000 |
commit | 1d6226ac6f1bd8f370f0a7f22ba4b2a322de2691 (patch) | |
tree | b60283283f54382dee4b452242ff7d7c223c378a | |
parent | b078d52cf7fcf151c423ef0a31e87b248a09c72d (diff) | |
parent | b3bcffa192d5301bc2d65a6bd35094d878627e49 (diff) | |
download | protobuf-codegen-1d6226ac6f1bd8f370f0a7f22ba4b2a322de2691.tar.gz |
Merge "Upgrade rust/crates/protobuf-codegen to 2.18.0" am: b3bcffa192
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/protobuf-codegen/+/1451283
Change-Id: I11e768e22df8ef031e04ad95dbcbe5a751c93734
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.lock | 6 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | patches/0001-Allow-generated-source-to-be-root-module-src.diff | 33 | ||||
-rwxr-xr-x | post_update.sh | 1 | ||||
-rw-r--r-- | src/code_writer.rs | 3 | ||||
-rw-r--r-- | src/customize.rs | 17 | ||||
-rw-r--r-- | src/lib.rs | 48 |
11 files changed, 73 insertions, 55 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 528d884..e7b2111 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "5e7854f82d19505a98ca22e0b83b79a0e6e90c2b" + "sha1": "dddcb17948d6ad78fe610af5a7f016d871d2a380" } } @@ -37,4 +37,4 @@ rust_binary_host { } // dependent_library ["feature_list"] -// protobuf-2.17.0 +// protobuf-2.18.0 @@ -2,13 +2,13 @@ # It is not intended for manual editing. [[package]] name = "protobuf" -version = "2.17.0" +version = "2.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb14183cc7f213ee2410067e1ceeadba2a7478a59432ff0747a335202798b1e2" +checksum = "6d147edb77bcccbfc81fabffdc7bd50c13e103b15ca1e27515fe40de69a5776b" [[package]] name = "protobuf-codegen" -version = "2.17.0" +version = "2.18.0" dependencies = [ "protobuf", ] @@ -12,7 +12,7 @@ [package] name = "protobuf-codegen" -version = "2.17.0" +version = "2.18.0" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] description = "Code generator for rust-protobuf.\n\nIncludes a library and `protoc-gen-rust` binary.\n\nSee `protoc-rust` and `protobuf-codegen-pure` crates.\n" homepage = "https://github.com/stepancheg/rust-protobuf/" @@ -34,4 +34,4 @@ name = "protobuf-bin-gen-rust-do-not-use" path = "src/bin/protobuf-bin-gen-rust-do-not-use.rs" test = false [dependencies.protobuf] -version = "=2.17.0" +version = "=2.18.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 3c3fe29..01d1087 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "protobuf-codegen" -version = "2.17.0" +version = "2.18.0" authors = ["Stepan Koltsov <stepan.koltsov@gmail.com>"] license = "MIT" homepage = "https://github.com/stepancheg/rust-protobuf/" @@ -17,7 +17,7 @@ See `protoc-rust` and `protobuf-codegen-pure` crates. bench = false [dependencies] -protobuf = { path = "../protobuf", version = "=2.17.0" } +protobuf = { path = "../protobuf", version = "=2.18.0" } [[bin]] @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/protobuf-codegen/protobuf-codegen-2.17.0.crate" + value: "https://static.crates.io/crates/protobuf-codegen/protobuf-codegen-2.18.0.crate" } - version: "2.17.0" + version: "2.18.0" license_type: NOTICE last_upgrade_date { year: 2020 - month: 8 - day: 12 + month: 10 + day: 6 } } diff --git a/patches/0001-Allow-generated-source-to-be-root-module-src.diff b/patches/0001-Allow-generated-source-to-be-root-module-src.diff deleted file mode 100644 index a3b6be6..0000000 --- a/patches/0001-Allow-generated-source-to-be-root-module-src.diff +++ /dev/null @@ -1,33 +0,0 @@ -From 38f7b959fdedb839ce412b7e3faa067d315fc13a Mon Sep 17 00:00:00 2001 -From: Ivan Lozano <ivanlozano@google.com> -Date: Wed, 26 Aug 2020 15:19:37 -0400 -Subject: [PATCH] Allow generated source to be root module src. - -rustfmt::skip breaks compilation when used as a root module source. We -don't run rustfmt on generated source anyhow. -See https://github.com/stepancheg/rust-protobuf/issues/493#issuecomment-652874447 - -Bug: 143953733 -Test: rust_protobuf can generate library variants. -Change-Id: I0ea47de25c0ddd65781d6509b09ea648d11c4277 ---- - src/code_writer.rs | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/code_writer.rs b/src/code_writer.rs -index 8b53bc6..855b785 100644 ---- a/src/code_writer.rs -+++ b/src/code_writer.rs -@@ -58,7 +58,8 @@ impl<'a> CodeWriter<'a> { - self.write_line("#![allow(clippy::all)]"); - self.write_line(""); - self.write_line("#![allow(unused_attributes)]"); -- self.write_line("#![rustfmt::skip]"); -+ // ANDROID CHANGE: comment out rustfmt::skip to fix compilation error. -+ //self.write_line("#![rustfmt::skip]"); - self.write_line(""); - self.write_line("#![allow(box_pointers)]"); - self.write_line("#![allow(dead_code)]"); --- -2.28.0.297.g1956fa8f8d-goog - diff --git a/post_update.sh b/post_update.sh index 39f2fdd..98c02de 100755 --- a/post_update.sh +++ b/post_update.sh @@ -9,6 +9,7 @@ set -e # replace CARGO_PKG_VERSION with version string from METADATA SRCFILE=src/lib.rs VERSION=`grep version: METADATA | sed -e 's/^.*version: *//'` +echo "VERSION=$VERSION" OLDSTR='env!("CARGO_PKG_VERSION"));' NEWSTR="$VERSION); // ANDROID ported version" sed -i -e "s:$OLDSTR:$NEWSTR:" $SRCFILE diff --git a/src/code_writer.rs b/src/code_writer.rs index 855b785..8b53bc6 100644 --- a/src/code_writer.rs +++ b/src/code_writer.rs @@ -58,8 +58,7 @@ impl<'a> CodeWriter<'a> { self.write_line("#![allow(clippy::all)]"); self.write_line(""); self.write_line("#![allow(unused_attributes)]"); - // ANDROID CHANGE: comment out rustfmt::skip to fix compilation error. - //self.write_line("#![rustfmt::skip]"); + self.write_line("#![rustfmt::skip]"); self.write_line(""); self.write_line("#![allow(box_pointers)]"); self.write_line("#![allow(dead_code)]"); diff --git a/src/customize.rs b/src/customize.rs index c55fb07..f8e73aa 100644 --- a/src/customize.rs +++ b/src/customize.rs @@ -22,6 +22,12 @@ pub struct Customize { pub serde_derive_cfg: Option<String>, /// Enable lite runtime pub lite_runtime: Option<bool>, + /// Generate `mod.rs` in the output directory. + /// + /// This option allows inclusion of generated files from cargo output directory. + /// + /// This option will likely be on by default in rust-protobuf version 3. + pub gen_mod_rs: Option<bool>, /// Used internally to generate protos bundled in protobuf crate /// like `descriptor.proto` pub inside_protobuf: Option<bool>, @@ -68,6 +74,9 @@ impl Customize { if let Some(v) = that.lite_runtime { self.lite_runtime = Some(v); } + if let Some(v) = that.gen_mod_rs { + self.gen_mod_rs = Some(v); + } if let Some(v) = that.inside_protobuf { self.inside_protobuf = Some(v); } @@ -113,6 +122,8 @@ impl Customize { r.serde_derive_cfg = Some(v.to_owned()); } else if n == "lite_runtime" { r.lite_runtime = Some(parse_bool(v)?); + } else if n == "gen_mod_rs" { + r.gen_mod_rs = Some(parse_bool(v)?); } else if n == "inside_protobuf" { r.inside_protobuf = Some(parse_bool(v)?); } else { @@ -134,6 +145,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz let serde_derive = rustproto::exts::serde_derive.get(source); let serde_derive_cfg = rustproto::exts::serde_derive_cfg.get(source); let lite_runtime = None; + let gen_mod_rs = None; let inside_protobuf = None; Customize { expose_oneof, @@ -144,6 +156,7 @@ pub fn customize_from_rustproto_for_message(source: &MessageOptions) -> Customiz serde_derive, serde_derive_cfg, lite_runtime, + gen_mod_rs, inside_protobuf, _future_options: (), } @@ -159,6 +172,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { let serde_derive = None; let serde_derive_cfg = None; let lite_runtime = None; + let gen_mod_rs = None; let inside_protobuf = None; Customize { expose_oneof, @@ -169,6 +183,7 @@ pub fn customize_from_rustproto_for_field(source: &FieldOptions) -> Customize { serde_derive, serde_derive_cfg, lite_runtime, + gen_mod_rs, inside_protobuf, _future_options: (), } @@ -183,6 +198,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { let serde_derive = rustproto::exts::serde_derive_all.get(source); let serde_derive_cfg = rustproto::exts::serde_derive_cfg_all.get(source); let lite_runtime = rustproto::exts::lite_runtime_all.get(source); + let gen_mod_rs = None; let inside_protobuf = None; Customize { expose_oneof, @@ -194,6 +210,7 @@ pub fn customize_from_rustproto_for_file(source: &FileOptions) -> Customize { serde_derive_cfg, lite_runtime, inside_protobuf, + gen_mod_rs, _future_options: (), } } @@ -61,11 +61,12 @@ use self::code_writer::CodeWriter; use self::enums::*; use self::extensions::*; use self::message::*; -use file::proto_path_to_rust_mod; use inside::protobuf_crate_path; use scope::FileScope; use scope::RootScope; +use crate::file::proto_path_to_rust_mod; + #[doc(hidden)] pub use protobuf_name::ProtobufAbsolutePath; #[doc(hidden)] @@ -162,12 +163,17 @@ fn write_file_descriptor_data( ); } +struct GenFileResult { + compiler_plugin_result: compiler_plugin::GenResult, + mod_name: String, +} + fn gen_file( file: &FileDescriptorProto, _files_map: &HashMap<&str, &FileDescriptorProto>, root_scope: &RootScope, customize: &Customize, -) -> Option<compiler_plugin::GenResult> { +) -> GenFileResult { // TODO: use it let mut customize = customize.clone(); // options specified in invocation have precedence over options specified in file @@ -186,7 +192,7 @@ fn gen_file( { let mut w = CodeWriter::new(&mut v); - w.write_generated_by("rust-protobuf", "2.17.0"); // ANDROID ported version + w.write_generated_by("rust-protobuf", "2.18.0"); // ANDROID ported version w.write_line(&format!("//! Generated file from `{}`", file.get_name())); if customize.inside_protobuf != Some(true) { w.write_line(""); @@ -221,10 +227,28 @@ fn gen_file( } } - Some(compiler_plugin::GenResult { - name: format!("{}.rs", proto_path_to_rust_mod(file.get_name())), + GenFileResult { + compiler_plugin_result: compiler_plugin::GenResult { + name: format!("{}.rs", proto_path_to_rust_mod(file.get_name())), + content: v, + }, + mod_name: proto_path_to_rust_mod(file.get_name()).into_string(), + } +} + +fn gen_mod_rs(mods: &[String]) -> compiler_plugin::GenResult { + let mut v = Vec::new(); + let mut w = CodeWriter::new(&mut v); + w.comment("@generated"); + w.write_line(""); + for m in mods { + w.write_line(&format!("pub mod {};", m)); + } + drop(w); + compiler_plugin::GenResult { + name: "mod.rs".to_owned(), content: v, - }) + } } // This function is also used externally by cargo plugin @@ -246,13 +270,23 @@ pub fn gen( let all_file_names: Vec<&str> = file_descriptors.iter().map(|f| f.get_name()).collect(); + let mut mods = Vec::new(); + for file_name in files_to_generate { let file = files_map.get(&file_name[..]).expect(&format!( "file not found in file descriptors: {:?}, files: {:?}", file_name, all_file_names )); - results.extend(gen_file(file, &files_map, &root_scope, customize)); + + let gen_file_result = gen_file(file, &files_map, &root_scope, customize); + results.push(gen_file_result.compiler_plugin_result); + mods.push(gen_file_result.mod_name); + } + + if customize.gen_mod_rs.unwrap_or(false) { + results.push(gen_mod_rs(&mods)); } + results } |