Merge changes Idbee5519,I4114923e,I29373877,If03d0518,If3bd3301

* changes:
  gn2bp:
  gn2bp: Add source genrule for proto to the srcs
  gn2bp: Remove srcs from out/test
  gn2bp: Skip generating pb2.py files
  gn2bp: Split genrule for proto to source and header
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 92ae832..d5c1e94 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -1964,11 +1964,17 @@
 cc_library_static {
     name: "cronet_aml_net_cert_root_store_proto_full",
     srcs: [
-        "out/test/clang_x64/gen/net/cert/root_store_proto_full/root_store.pb.cc",
+        ":cronet_aml_net_cert_root_store_proto_full_gen",
     ],
     static_libs: [
         "cronet_aml_third_party_protobuf_protobuf_full",
     ],
+    generated_headers: [
+        "cronet_aml_net_cert_root_store_proto_full_gen_headers",
+    ],
+    export_generated_headers: [
+        "cronet_aml_net_cert_root_store_proto_full_gen_headers",
+    ],
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -2023,13 +2029,37 @@
          "--proto-in-dir " +
          "`dirname $(location net/cert/root_store.proto)` " +
          "--cc-out-dir " +
-         "clang_x64/gen/net/cert/root_store_proto_full/ " +
-         "--py-out-dir " +
-         "$(genDir)/clang_x64/pyproto/net/cert/root_store_proto_full/",
+         "$(genDir) " +
+         " " +
+         "",
     out: [
-        "clang_x64/pyproto/net/cert/root_store_proto_full/root_store_pb2.py",
-        "net/cert/root_store_proto_full/root_store.pb.cc",
-        "net/cert/root_store_proto_full/root_store.pb.h",
+        "root_store.pb.cc",
+    ],
+    tool_files: [
+        "tools/protoc_wrapper/protoc_wrapper.py",
+    ],
+}
+
+// GN: //net/cert:root_store_proto_full_gen
+genrule {
+    name: "cronet_aml_net_cert_root_store_proto_full_gen_headers",
+    srcs: [
+        "net/cert/root_store.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "$(location tools/protoc_wrapper/protoc_wrapper.py) root_store.proto " +
+         "--protoc " +
+         "$(location aprotoc) " +
+         "--proto-in-dir " +
+         "`dirname $(location net/cert/root_store.proto)` " +
+         "--cc-out-dir " +
+         "$(genDir) " +
+         " " +
+         "",
+    out: [
+        "root_store.pb.h",
     ],
     tool_files: [
         "tools/protoc_wrapper/protoc_wrapper.py",
@@ -2175,7 +2205,7 @@
 cc_library_static {
     name: "cronet_aml_net_isolation_info_proto",
     srcs: [
-        "out/test/gen/net/base/isolation_info.pb.cc",
+        ":cronet_aml_net_isolation_info_proto_gen",
     ],
     shared_libs: [
         "liblog",
@@ -2183,6 +2213,12 @@
     static_libs: [
         "cronet_aml_third_party_protobuf_protobuf_lite",
     ],
+    generated_headers: [
+        "cronet_aml_net_isolation_info_proto_gen_headers",
+    ],
+    export_generated_headers: [
+        "cronet_aml_net_isolation_info_proto_gen_headers",
+    ],
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -2233,13 +2269,37 @@
          "--proto-in-dir " +
          "`dirname $(location net/base/isolation_info.proto)` " +
          "--cc-out-dir " +
-         "$(genDir)/net/base " +
-         "--py-out-dir " +
-         "$(genDir)/pyproto/net/base",
+         "$(genDir) " +
+         " " +
+         "",
     out: [
-        "net/base/isolation_info.pb.cc",
-        "net/base/isolation_info.pb.h",
-        "pyproto/net/base/isolation_info_pb2.py",
+        "isolation_info.pb.cc",
+    ],
+    tool_files: [
+        "tools/protoc_wrapper/protoc_wrapper.py",
+    ],
+}
+
+// GN: //net:isolation_info_proto_gen
+genrule {
+    name: "cronet_aml_net_isolation_info_proto_gen_headers",
+    srcs: [
+        "net/base/isolation_info.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "$(location tools/protoc_wrapper/protoc_wrapper.py) isolation_info.proto " +
+         "--protoc " +
+         "$(location aprotoc) " +
+         "--proto-in-dir " +
+         "`dirname $(location net/base/isolation_info.proto)` " +
+         "--cc-out-dir " +
+         "$(genDir) " +
+         " " +
+         "",
+    out: [
+        "isolation_info.pb.h",
     ],
     tool_files: [
         "tools/protoc_wrapper/protoc_wrapper.py",
@@ -2955,7 +3015,7 @@
     name: "cronet_aml_net_net_nqe_proto",
     srcs: [
         ":cronet_aml_net_net_export_header",
-        "out/test/gen/net/nqe/proto/network_id_proto.pb.cc",
+        ":cronet_aml_net_net_nqe_proto_gen",
     ],
     shared_libs: [
         "liblog",
@@ -2963,6 +3023,12 @@
     static_libs: [
         "cronet_aml_third_party_protobuf_protobuf_lite",
     ],
+    generated_headers: [
+        "cronet_aml_net_net_nqe_proto_gen_headers",
+    ],
+    export_generated_headers: [
+        "cronet_aml_net_net_nqe_proto_gen_headers",
+    ],
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -3015,18 +3081,48 @@
          "--proto-in-dir " +
          "`dirname $(location net/nqe/proto/network_id_proto.proto)` " +
          "--cc-out-dir " +
-         "$(genDir)/net/nqe/proto " +
+         "$(genDir) " +
          "--cc-options " +
          "dllexport_decl=NET_EXPORT_PRIVATE: " +
          " " +
          "--include " +
          "$(location net/base/net_export.h) " +
-         "--py-out-dir " +
-         "$(genDir)/pyproto/net/nqe/proto",
+         " " +
+         "",
     out: [
-        "net/nqe/proto/network_id_proto.pb.cc",
-        "net/nqe/proto/network_id_proto.pb.h",
-        "pyproto/net/nqe/proto/network_id_proto_pb2.py",
+        "network_id_proto.pb.cc",
+    ],
+    tool_files: [
+        "tools/protoc_wrapper/protoc_wrapper.py",
+    ],
+}
+
+// GN: //net:net_nqe_proto_gen
+genrule {
+    name: "cronet_aml_net_net_nqe_proto_gen_headers",
+    srcs: [
+        "net/base/net_export.h",
+        "net/nqe/proto/network_id_proto.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "$(location tools/protoc_wrapper/protoc_wrapper.py) network_id_proto.proto " +
+         "--protoc " +
+         "$(location aprotoc) " +
+         "--proto-in-dir " +
+         "`dirname $(location net/nqe/proto/network_id_proto.proto)` " +
+         "--cc-out-dir " +
+         "$(genDir) " +
+         "--cc-options " +
+         "dllexport_decl=NET_EXPORT_PRIVATE: " +
+         " " +
+         "--include " +
+         "$(location net/base/net_export.h) " +
+         " " +
+         "",
+    out: [
+        "network_id_proto.pb.h",
     ],
     tool_files: [
         "tools/protoc_wrapper/protoc_wrapper.py",
@@ -3172,9 +3268,7 @@
 cc_library_static {
     name: "cronet_aml_net_third_party_quiche_net_quic_proto",
     srcs: [
-        "out/test/gen/net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.pb.cc",
-        "out/test/gen/net/third_party/quiche/src/quiche/quic/core/proto/crypto_server_config.pb.cc",
-        "out/test/gen/net/third_party/quiche/src/quiche/quic/core/proto/source_address_token.pb.cc",
+        ":cronet_aml_net_third_party_quiche_net_quic_proto_gen",
     ],
     shared_libs: [
         "libandroid",
@@ -3184,6 +3278,12 @@
         "cronet_aml_base_base",
         "cronet_aml_third_party_protobuf_protobuf_lite",
     ],
+    generated_headers: [
+        "cronet_aml_net_third_party_quiche_net_quic_proto_gen_headers",
+    ],
+    export_generated_headers: [
+        "cronet_aml_net_third_party_quiche_net_quic_proto_gen_headers",
+    ],
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -3242,24 +3342,56 @@
          "--proto-in-dir " +
          "`dirname $(location net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.proto)`/../../../../ " +
          "--cc-out-dir " +
-         "$(genDir)/net/third_party/quiche/src " +
+         "$(genDir) " +
          "--cc-options " +
          "dllexport_decl=COMPONENT_EXPORT(QUICHE): " +
          " " +
          "--include " +
          "$(location base/component_export.h) " +
-         "--py-out-dir " +
-         "$(genDir)/pyproto/net/third_party/quiche/src",
+         " " +
+         "",
     out: [
-        "net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.pb.cc",
-        "net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.pb.h",
-        "net/third_party/quiche/src/quiche/quic/core/proto/crypto_server_config.pb.cc",
-        "net/third_party/quiche/src/quiche/quic/core/proto/crypto_server_config.pb.h",
-        "net/third_party/quiche/src/quiche/quic/core/proto/source_address_token.pb.cc",
-        "net/third_party/quiche/src/quiche/quic/core/proto/source_address_token.pb.h",
-        "pyproto/net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters_pb2.py",
-        "pyproto/net/third_party/quiche/src/quiche/quic/core/proto/crypto_server_config_pb2.py",
-        "pyproto/net/third_party/quiche/src/quiche/quic/core/proto/source_address_token_pb2.py",
+        "cached_network_parameters.pb.cc",
+        "crypto_server_config.pb.cc",
+        "source_address_token.pb.cc",
+    ],
+    tool_files: [
+        "tools/protoc_wrapper/protoc_wrapper.py",
+    ],
+}
+
+// GN: //net/third_party/quiche:net_quic_proto_gen
+genrule {
+    name: "cronet_aml_net_third_party_quiche_net_quic_proto_gen_headers",
+    srcs: [
+        "base/component_export.h",
+        "net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.proto",
+        "net/third_party/quiche/src/quiche/quic/core/proto/crypto_server_config.proto",
+        "net/third_party/quiche/src/quiche/quic/core/proto/source_address_token.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "$(location tools/protoc_wrapper/protoc_wrapper.py) quiche/quic/core/proto/cached_network_parameters.proto " +
+         "quiche/quic/core/proto/crypto_server_config.proto " +
+         "quiche/quic/core/proto/source_address_token.proto " +
+         "--protoc " +
+         "$(location aprotoc) " +
+         "--proto-in-dir " +
+         "`dirname $(location net/third_party/quiche/src/quiche/quic/core/proto/cached_network_parameters.proto)`/../../../../ " +
+         "--cc-out-dir " +
+         "$(genDir) " +
+         "--cc-options " +
+         "dllexport_decl=COMPONENT_EXPORT(QUICHE): " +
+         " " +
+         "--include " +
+         "$(location base/component_export.h) " +
+         " " +
+         "",
+    out: [
+        "cached_network_parameters.pb.h",
+        "crypto_server_config.pb.h",
+        "source_address_token.pb.h",
     ],
     tool_files: [
         "tools/protoc_wrapper/protoc_wrapper.py",
@@ -3271,7 +3403,7 @@
     name: "cronet_aml_net_third_party_quiche_net_quic_test_tools_proto",
     srcs: [
         ":cronet_aml_net_net_export_header",
-        "out/test/gen/net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.pb.cc",
+        ":cronet_aml_net_third_party_quiche_net_quic_test_tools_proto_gen",
     ],
     shared_libs: [
         "liblog",
@@ -3279,6 +3411,12 @@
     static_libs: [
         "cronet_aml_third_party_protobuf_protobuf_lite",
     ],
+    generated_headers: [
+        "cronet_aml_net_third_party_quiche_net_quic_test_tools_proto_gen_headers",
+    ],
+    export_generated_headers: [
+        "cronet_aml_net_third_party_quiche_net_quic_test_tools_proto_gen_headers",
+    ],
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -3331,18 +3469,48 @@
          "--proto-in-dir " +
          "`dirname $(location net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.proto)` " +
          "--cc-out-dir " +
-         "$(genDir)/net/third_party/quiche/src/quiche/quic/test_tools " +
+         "$(genDir) " +
          "--cc-options " +
          "dllexport_decl=NET_EXPORT_PRIVATE: " +
          " " +
          "--include " +
          "$(location net/base/net_export.h) " +
-         "--py-out-dir " +
-         "$(genDir)/pyproto/net/third_party/quiche/src/quiche/quic/test_tools",
+         " " +
+         "",
     out: [
-        "net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.pb.cc",
-        "net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.pb.h",
-        "pyproto/net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result_pb2.py",
+        "send_algorithm_test_result.pb.cc",
+    ],
+    tool_files: [
+        "tools/protoc_wrapper/protoc_wrapper.py",
+    ],
+}
+
+// GN: //net/third_party/quiche:net_quic_test_tools_proto_gen
+genrule {
+    name: "cronet_aml_net_third_party_quiche_net_quic_test_tools_proto_gen_headers",
+    srcs: [
+        "net/base/net_export.h",
+        "net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "$(location tools/protoc_wrapper/protoc_wrapper.py) send_algorithm_test_result.proto " +
+         "--protoc " +
+         "$(location aprotoc) " +
+         "--proto-in-dir " +
+         "`dirname $(location net/third_party/quiche/src/quiche/quic/test_tools/send_algorithm_test_result.proto)` " +
+         "--cc-out-dir " +
+         "$(genDir) " +
+         "--cc-options " +
+         "dllexport_decl=NET_EXPORT_PRIVATE: " +
+         " " +
+         "--include " +
+         "$(location net/base/net_export.h) " +
+         " " +
+         "",
+    out: [
+        "send_algorithm_test_result.pb.h",
     ],
     tool_files: [
         "tools/protoc_wrapper/protoc_wrapper.py",
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index be9c3ba..88a7463 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -32,6 +32,7 @@
 import os
 import re
 import sys
+import copy
 
 import gn_utils
 
@@ -859,7 +860,7 @@
   elif target.script == "//tools/protoc_wrapper/protoc_wrapper.py":
     # Use protoc in the android
     module.tools.add("aprotoc")
-    target.outputs = [re.sub('^//out/test/', '', out) for out in target.outputs]
+    target.outputs = [os.path.basename(out) for out in target.outputs]
     for i, val in enumerate(target.args):
       if val == '--protoc':
         target.args[i + 1] = '$(location aprotoc)'
@@ -873,7 +874,7 @@
         if target.name == "//net/third_party/quiche:net_quic_proto_gen":
           target.args[i + 1] += '/../../../../'
       elif val == '--cc-out-dir':
-        target.args[i + 1] = re.sub('^gen', '$(genDir)', target.args[i + 1])
+        target.args[i + 1] = '$(genDir)'
       elif val == 'dllexport_decl':
         # Needs to be dllexport_decl=value format
         target.args[i] += '=' + target.args[i+1]
@@ -885,7 +886,9 @@
         module.srcs.add(target.args[i+1])
         target.args[i + 1] = '$(location %s)' % target.args[i + 1]
       elif val == "--py-out-dir":
-        target.args[i + 1] = '$(genDir)/' + target.args[i + 1]
+        # pb2.py files are not used by others.
+        target.args[i] = ''
+        target.args[i + 1] = ''
 
   script = gn_utils.label_to_path(target.script)
   module.tool_files.add(script)
@@ -937,6 +940,16 @@
   elif target.script == "//tools/grit/stamp_grit_sources.py":
     # stamp_grit_sources.py is not executable
     module.cmd = "python " + module.cmd
+  elif target.script == "//tools/protoc_wrapper/protoc_wrapper.py":
+    # Split module to source module and header module.
+    # Source module has the .cc files and header module has the .h files in the out.
+    header_module = copy.deepcopy(module)
+    header_module.name += "_headers"
+    header_module.out = [file for file in header_module.out if os.path.splitext(file)[1] == '.h']
+    module.out = [file for file in module.out if os.path.splitext(file)[1] == '.cc']
+    module.genrule_headers.add(header_module.name)
+    module.genrule_srcs.add(':' + module.name)
+    blueprint.add_module(header_module)
 
   blueprint.add_module(module)
   return module
@@ -1017,7 +1030,7 @@
   module.srcs.update(
       gn_utils.label_to_path(src)
       for src in target.sources
-      if is_supported_source_file(src))
+      if is_supported_source_file(src) and not src.startswith("//out/test"))
 
   local_include_dirs_set = set()
   if target.type in gn_utils.LINKER_UNIT_TYPES: