Update gRPC's BUILD.gn template to fix the public_configs, and targets dependencies.

BUG=618889
R=gcasto@chromium.org

Review URL: https://codereview.chromium.org/2214453002 .
diff --git a/BUILD.gn b/BUILD.gn
index a33d8a3..d8d6dfe 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -9,22 +9,22 @@
     "include/",
   ]
 
-  defines = [ "GRPC_USE_PROTO_LITE" ]
-}
-
-config("grpc_no_cxx11_threads") {
-  # TODO(xyzzyz): the <condition_variable> header in libstdc++-4.6 we're using
-  # in Chromium has a bug, which causes a compilation error on Clang.
-  # Therefore, we need to make gRPC not use standard library threading support.
-  # https://crbug.com/593874
-  defines = [ "GRPC_CXX0X_NO_THREAD" ]
+  defines = [
+    "GRPC_USE_PROTO_LITE",
+    # TODO(xyzzyz): the <condition_variable> header in libstdc++-4.6 we're using
+    # in Chromium has a bug, which causes a compilation error on Clang.
+    # Therefore, we need to make gRPC not use standard library threading
+    # support.
+    # https://crbug.com/593874
+    "GRPC_CXX0X_NO_THREAD",
+  ]
 }
 
 
 
 
 
-component("gpr") {
+source_set("gpr") {
   sources = [
     "include/grpc/support/alloc.h",
     "include/grpc/support/atm.h",
@@ -131,12 +131,14 @@
   configs += [
     "//build/config/compiler:no_chromium_code",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc") {
+source_set("grpc") {
   sources = [
     "include/grpc/byte_buffer.h",
     "include/grpc/byte_buffer_reader.h",
@@ -508,12 +510,14 @@
   configs += [
     "//build/config/compiler:no_chromium_code",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc_cronet") {
+source_set("grpc_cronet") {
   sources = [
     "include/grpc/byte_buffer.h",
     "include/grpc/byte_buffer_reader.h",
@@ -860,12 +864,14 @@
   configs += [
     "//build/config/compiler:no_chromium_code",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc_unsecure") {
+source_set("grpc_unsecure") {
   sources = [
     "include/grpc/byte_buffer.h",
     "include/grpc/byte_buffer_reader.h",
@@ -1174,18 +1180,21 @@
     "src/core/plugin_registry/grpc_unsecure_plugin_registry.c",
   ]
   deps = [
+    "//third_party/zlib",
     ":gpr",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [
     "//build/config/compiler:no_chromium_code",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc++") {
+source_set("grpc++") {
   sources = [
     "include/grpc++/alarm.h",
     "include/grpc++/channel.h",
@@ -1334,14 +1343,15 @@
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [
     "//build/config/compiler:no_chromium_code",
-    ":grpc_no_cxx11_threads",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc++_unsecure") {
+source_set("grpc++_unsecure") {
   sources = [
     "include/grpc++/alarm.h",
     "include/grpc++/channel.h",
@@ -1477,19 +1487,19 @@
     "//third_party/protobuf:protobuf_lite",
     ":gpr",
     ":grpc_unsecure",
-    ":grpc",
   ]
   configs -= [ "//build/config/compiler:chromium_code" ]
   configs += [
     "//build/config/compiler:no_chromium_code",
-    ":grpc_no_cxx11_threads",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
 
-component("grpc_plugin_support") {
+source_set("grpc_plugin_support") {
   sources = [
     "include/grpc++/impl/codegen/config_protobuf.h",
     "src/compiler/config.h",
@@ -1521,7 +1531,9 @@
   configs += [
     "//build/config/compiler:no_chromium_code",
   ]
-  public_configs = [ ":grpc_config" ]
+  public_configs = [
+    ":grpc_config",
+  ]
 }
 
 
diff --git a/templates/BUILD.gn.template b/templates/BUILD.gn.template
index 46865d2..2e3cc22 100644
--- a/templates/BUILD.gn.template
+++ b/templates/BUILD.gn.template
@@ -11,15 +11,15 @@
       "include/",
     ]
 
-    defines = [ "GRPC_USE_PROTO_LITE" ]
-  }
-
-  config("grpc_no_cxx11_threads") {
-    # TODO(xyzzyz): the <condition_variable> header in libstdc++-4.6 we're using
-    # in Chromium has a bug, which causes a compilation error on Clang.
-    # Therefore, we need to make gRPC not use standard library threading support.
-    # https://crbug.com/593874
-    defines = [ "GRPC_CXX0X_NO_THREAD" ]
+    defines = [
+      "GRPC_USE_PROTO_LITE",
+      # TODO(xyzzyz): the <condition_variable> header in libstdc++-4.6 we're using
+      # in Chromium has a bug, which causes a compilation error on Clang.
+      # Therefore, we need to make gRPC not use standard library threading
+      # support.
+      # https://crbug.com/593874
+      "GRPC_CXX0X_NO_THREAD",
+    ]
   }
 
   <%!
@@ -36,10 +36,17 @@
     name = target_dict.get("name", None)
     if name in ("grpc++_unsecure", "grpc++", "grpc++_codegen_lib"):
       deps.append("//third_party/protobuf:protobuf_lite")
-    elif name == "grpc":
+    elif name in ("grpc", "grpc_unsecure"):
       deps.append("//third_party/zlib")
 
     for d in target_dict.get("deps", []):
+      # TODO(xyzzyz): grpc++_unsecure mistakenly depends on both grpc and
+      # grpc_unsecure. Remove when it's fixed.
+      # See https://github.com/grpc/grpc/issues/7739
+      if name == "grpc++_unsecure" and d == "grpc":
+        # Ignore.
+        continue
+
       if d.startswith(("//", ":")):
         deps.append(d)
       else:
@@ -47,8 +54,6 @@
     return deps
 
   def get_extra_configs(target_dict):
-    if target_dict.get("name", "") in ("grpc++", "grpc++_unsecure"):
-      return [":grpc_no_cxx11_threads"]
     if target_dict.get("name", "") == "grpc_cpp_plugin":
       return ["//third_party/protobuf:protobuf_config"]
     return []
@@ -90,7 +95,7 @@
     hdrs = [h for h in lib_hdrs if not uses_nanopb_or_protofull(h)]
     srcs = [s for s in lib.src if not uses_nanopb_or_protofull(s)]
   %>
-  component("${lib.name}") {
+  source_set("${lib.name}") {
     sources = [
   % for hdr in lib.get("public_headers", []):
       "${hdr}",
@@ -114,7 +119,9 @@
       "${config}",
   % endfor
     ]
-    public_configs = [ ":grpc_config" ]
+    public_configs = [
+      ":grpc_config",
+    ]
   }
   </%def>