Jelajahi Sumber

Merge pull request #915 from pherl/master

add default_runtime attribute to cc|py rules.
Jisi Liu 10 tahun lalu
induk
melakukan
12fb61b292
2 mengubah file dengan 16 tambahan dan 1 penghapusan
  1. 5 1
      BUILD
  2. 11 0
      protobuf.bzl

+ 5 - 1
BUILD

@@ -154,9 +154,9 @@ cc_proto_library(
     name = "cc_wkt_protos",
     name = "cc_wkt_protos",
     srcs = WELL_KNOWN_PROTOS,
     srcs = WELL_KNOWN_PROTOS,
     include = "src",
     include = "src",
-    cc_libs = [":protobuf"],
     internal_bootstrap_hack = 1,
     internal_bootstrap_hack = 1,
     protoc = ":protoc",
     protoc = ":protoc",
+    default_runtime = ":protobuf",
 )
 )
 
 
 ################################################################################
 ################################################################################
@@ -334,6 +334,7 @@ cc_proto_library(
     srcs = LITE_TEST_PROTOS + TEST_PROTOS,
     srcs = LITE_TEST_PROTOS + TEST_PROTOS,
     include = "src",
     include = "src",
     protoc = ":protoc",
     protoc = ":protoc",
+    default_runtime = ":protobuf",
     deps = [":cc_wkt_protos"],
     deps = [":cc_wkt_protos"],
 )
 )
 
 
@@ -512,6 +513,7 @@ py_proto_library(
     protoc = ":protoc",
     protoc = ":protoc",
     py_extra_srcs = [":python_srcs"],
     py_extra_srcs = [":python_srcs"],
     py_libs = ["//external:six"],
     py_libs = ["//external:six"],
+    default_runtime = "",
     visibility = ["//visibility:public"],
     visibility = ["//visibility:public"],
 )
 )
 
 
@@ -532,6 +534,7 @@ py_proto_library(
     include = "src",
     include = "src",
     protoc = ":protoc",
     protoc = ":protoc",
     deps = [":protobuf_python"],
     deps = [":protobuf_python"],
+    default_runtime = "",
 )
 )
 
 
 py_proto_library(
 py_proto_library(
@@ -543,6 +546,7 @@ py_proto_library(
     include = "python",
     include = "python",
     protoc = ":protoc",
     protoc = ":protoc",
     deps = [":python_common_test_protos"],
     deps = [":python_common_test_protos"],
+    default_runtime = ":protobuf_python",
 )
 )
 
 
 py_library(
 py_library(

+ 11 - 0
protobuf.bzl

@@ -101,6 +101,7 @@ def cc_proto_library(
         include=None,
         include=None,
         protoc="//google/protobuf:protoc",
         protoc="//google/protobuf:protoc",
         internal_bootstrap_hack=False,
         internal_bootstrap_hack=False,
+        default_runtime="//google/protobuf:protobuf",
         **kargs):
         **kargs):
   """Bazel rule to create a C++ protobuf library from proto source files
   """Bazel rule to create a C++ protobuf library from proto source files
 
 
@@ -116,6 +117,8 @@ def cc_proto_library(
         for bootstraping. When it is set to True, no files will be generated.
         for bootstraping. When it is set to True, no files will be generated.
         The rule will simply be a provider for .proto files, so that other
         The rule will simply be a provider for .proto files, so that other
         cc_proto_library can depend on it.
         cc_proto_library can depend on it.
+    default_runtime: the implicitly default runtime which will be depended on by
+        the generated cc_library target.
     **kargs: other keyword arguments that are passed to cc_library.
     **kargs: other keyword arguments that are passed to cc_library.
 
 
   """
   """
@@ -151,6 +154,8 @@ def cc_proto_library(
       outs=outs,
       outs=outs,
   )
   )
 
 
+  if default_runtime and not default_runtime in cc_libs:
+    cc_libs += [default_runtime]
 
 
   native.cc_library(
   native.cc_library(
       name=name,
       name=name,
@@ -197,6 +202,7 @@ def py_proto_library(
         py_libs=[],
         py_libs=[],
         py_extra_srcs=[],
         py_extra_srcs=[],
         include=None,
         include=None,
+        default_runtime="//google/protobuf:protobuf_python",
         protoc="//google/protobuf:protoc",
         protoc="//google/protobuf:protoc",
         **kargs):
         **kargs):
   """Bazel rule to create a Python protobuf library from proto source files
   """Bazel rule to create a Python protobuf library from proto source files
@@ -210,6 +216,8 @@ def py_proto_library(
     py_extra_srcs: extra source files that will be added to the output
     py_extra_srcs: extra source files that will be added to the output
         py_library. This attribute is used for internal bootstrapping.
         py_library. This attribute is used for internal bootstrapping.
     include: a string indicating the include path of the .proto files.
     include: a string indicating the include path of the .proto files.
+    default_runtime: the implicitly default runtime which will be depended on by
+        the generated py_library target.
     protoc: the label of the protocol compiler to generate the sources.
     protoc: the label of the protocol compiler to generate the sources.
     **kargs: other keyword arguments that are passed to cc_library.
     **kargs: other keyword arguments that are passed to cc_library.
 
 
@@ -239,6 +247,9 @@ def py_proto_library(
         include=include)
         include=include)
     outs=[internal_copied_filegroup_name]
     outs=[internal_copied_filegroup_name]
 
 
+  if default_runtime and not default_runtime in py_libs + deps:
+    py_libs += [default_runtime]
+
   native.py_library(
   native.py_library(
       name=name,
       name=name,
       srcs=outs+py_extra_srcs,
       srcs=outs+py_extra_srcs,