Use cargo2android.py with a patch file. am: 98a8525e01 am: 6a343cde9e am: 09c8579ed9

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/grpcio-sys/+/1483800

Change-Id: I42691e44c1b2b21dd3f48f9225c8afbfc40fc304
diff --git a/Android.bp b/Android.bp
index 4c2a568..12753bb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,6 +1,7 @@
+// This file is generated by cargo2android.py --run --device --features=default,secure --dependencies --patch=patches/Android.bp.patch --ignore-cargo-errors.
+
 rust_library {
     name: "libgrpcio_sys",
-    // has rustc warnings
     host_supported: true,
     crate_name: "grpcio_sys",
     srcs: [
@@ -68,28 +69,29 @@
         "--blacklist-type=gpr_once",
     ]
 }
+
 // dependent_library ["feature_list"]
-//   aho-corasick-0.7.13 "default,std"
+//   aho-corasick-0.7.14 "default,std"
 //   bindgen-0.51.1
 //   bitflags-1.2.1 "default"
-//   cc-1.0.60
+//   cc-1.0.61
 //   cexpr-0.3.6
 //   cfg-if-0.1.10
 //   clang-sys-0.28.1 "clang_6_0,gte_clang_3_6,gte_clang_3_7,gte_clang_3_8,gte_clang_3_9,gte_clang_4_0,gte_clang_5_0,gte_clang_6_0,libloading,runtime"
 //   cmake-0.1.44
 //   glob-0.3.0
 //   lazy_static-1.4.0
-//   libc-0.2.77 "default,std"
+//   libc-0.2.80 "default,std"
 //   libloading-0.5.2
 //   libz-sys-1.1.2 "default,libc,static,stock-zlib"
-//   memchr-2.3.3 "default,std,use_std"
+//   memchr-2.3.4 "default,std,use_std"
 //   nom-4.2.3 "alloc,default,std,verbose-errors"
 //   peeking_take_while-0.1.2
-//   pkg-config-0.3.18
-//   proc-macro2-1.0.21
+//   pkg-config-0.3.19
+//   proc-macro2-1.0.24
 //   quote-1.0.7
-//   regex-1.3.9 "aho-corasick,default,memchr,perf,perf-cache,perf-dfa,perf-inline,perf-literal,std,thread_local,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
-//   regex-syntax-0.6.18 "default,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
+//   regex-1.4.2 "aho-corasick,default,memchr,perf,perf-cache,perf-dfa,perf-inline,perf-literal,std,thread_local,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
+//   regex-syntax-0.6.21 "default,unicode,unicode-age,unicode-bool,unicode-case,unicode-gencat,unicode-perl,unicode-script,unicode-segment"
 //   rustc-hash-1.1.0 "default,std"
 //   same-file-1.0.6
 //   shlex-0.1.1
diff --git a/patches/Android.bp.patch b/patches/Android.bp.patch
new file mode 100644
index 0000000..16c5f03
--- /dev/null
+++ b/patches/Android.bp.patch
@@ -0,0 +1,97 @@
+--- Android.bp	2020-10-30 19:20:08.709277813 -0700
++++ Android.bp	2020-10-30 19:17:57.837789872 -0700
+@@ -4,7 +4,10 @@
+     name: "libgrpcio_sys",
+     host_supported: true,
+     crate_name: "grpcio_sys",
+-    srcs: ["src/lib.rs"],
++    srcs: [
++        "src/lib.rs",
++        ":libgrpc_bindgen",
++    ],
+     edition: "2018",
+     features: [
+         "default",
+@@ -14,32 +17,57 @@
+         "liblibc",
+         "liblibz_sys",
+     ],
+-    static_libs: [
+-        "libabsl_bad_optional_access",
+-        "libabsl_base",
+-        "libabsl_civil_time",
+-        "libabsl_dynamic_annotations",
+-        "libabsl_int128",
+-        "libabsl_log_severity",
+-        "libabsl_raw_logging_internal",
+-        "libabsl_spinlock_wait",
+-        "libabsl_str_format_internal",
+-        "libabsl_strings",
+-        "libabsl_strings_internal",
+-        "libabsl_throw_delegate",
+-        "libabsl_time",
+-        "libabsl_time_zone",
+-        "libaddress_sorting",
+-        "libcares",
+-        "libcrypto",
+-        "libgpr",
+-        "libgrpc",
+-        "libgrpc_wrap",
+-        "libssl",
+-        "libupb",
+-        "libz",
++    shared_libs: [
++        "libgrpc++",
++        "libgrpc_wrap"
++    ],
++}
++
++cc_defaults {
++    name: "libgrpcio_sys_defaults",
++    cflags: [
++        "-DGRPC_SYS_SECURE",
+     ],
+-    shared_libs: ["libstdc++"],
++    cpp_std: "c++11",
++    shared_libs: ["libgrpc++"],
++}
++
++cc_library {
++    name: "libgrpc_wrap",
++    defaults: ["libgrpcio_sys_defaults"],
++    host_supported: true,
++    srcs: ["grpc_wrap.cc"],
++}
++
++rust_bindgen {
++    name: "libgrpc_bindgen",
++    defaults: ["libgrpcio_sys_defaults"],
++    host_supported: true,
++    wrapper_src: "android/bindgen_wrapper.hpp",
++    source_stem: "grpc-bindings",
++    crate_name: "grpc_bindgen",
++    bindgen_flags: [
++        "--size_t-is-usize",
++        "--constified-enum-module grpc_status_code",
++        "--default-enum-style rust",
++        "--whitelist-function=\\bgrpc_.*",
++        "--whitelist-function=\\bgpr_.*",
++        "--whitelist-function=gpr_inf_future",
++        "--whitelist-function=\\bgrpcwrap_.*",
++        "--whitelist-var=\\bGRPC_.*",
++        "--whitelist-type=\\bgrpc_.*",
++        "--whitelist-type=\\bgpr_.*",
++        "--whitelist-type=\\bgrpcwrap_.*",
++        "--whitelist-type=\\bcensus_context.*",
++        "--whitelist-type=\\bverify_peer_options.*",
++        "--blacklist-type=(__)?pthread.*",
++        "--blacklist-function=\\bgpr_mu_.*",
++        "--blacklist-function=\\bgpr_cv_.*",
++        "--blacklist-function=\\bgpr_once_.*",
++        "--blacklist-type=gpr_mu",
++        "--blacklist-type=gpr_cv",
++        "--blacklist-type=gpr_once",
++    ]
+ }
+ 
+ // dependent_library ["feature_list"]
diff --git a/post_update.sh b/post_update.sh
new file mode 100755
index 0000000..90e3877
--- /dev/null
+++ b/post_update.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# $1 Path to the new version.
+# $2 Path to the old version.
+
+set -x
+set -e
+
+cp -a -n -r $2/android $1/
+
+# upstream OWNERS files are not AOSP Gerrit OWNERS files.
+rm -f `find grpc -name OWNERS`