Pārlūkot izejas kodu

Change the impl rule include to includes.

We need to use the list to indicate field presense.
The field must only contain 0 or 1 string element.
Jisi Liu 10 gadi atpakaļ
vecāks
revīzija
53a56be4c4
2 mainītis faili ar 29 papildinājumiem un 19 dzēšanām
  1. 7 7
      BUILD
  2. 22 12
      protobuf.bzl

+ 7 - 7
BUILD

@@ -124,13 +124,13 @@ cc_library(
     deps = [":protobuf_lite"],
     deps = [":protobuf_lite"],
 )
 )
 
 
-objc_library(
-    name = "protobuf_objc",
-    hdrs = ["objectivec/GPBProtocolBuffers.h"],
-    includes = ["objectivec"],
-    non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
-    visibility = ["//visibility:public"],
-)
+# objc_library(
+#     name = "protobuf_objc",
+#     hdrs = ["objectivec/GPBProtocolBuffers.h"],
+#     includes = ["objectivec"],
+#     non_arc_srcs = ["objectivec/GPBProtocolBuffers.m"],
+#     visibility = ["//visibility:public"],
+# )
 
 
 RELATIVE_WELL_KNOWN_PROTOS = [
 RELATIVE_WELL_KNOWN_PROTOS = [
     # AUTOGEN(well_known_protos)
     # AUTOGEN(well_known_protos)

+ 22 - 12
protobuf.bzl

@@ -1,13 +1,13 @@
 # -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
 # -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
 
 
 def _GenDir(ctx):
 def _GenDir(ctx):
-  if ctx.attr.include == None:
+  if not ctx.attr.includes:
     return ""
     return ""
-  if not ctx.attr.include:
+  if not ctx.attr.includes[0]:
     return ctx.label.package
     return ctx.label.package
   if not ctx.label.package:
   if not ctx.label.package:
-    return ctx.attr.include
-  return ctx.label.package + '/' + ctx.attr.include
+    return ctx.attr.includes[0]
+  return ctx.label.package + '/' + ctx.attr.includes[0]
 
 
 def _CcOuts(srcs):
 def _CcOuts(srcs):
   return [s[:-len(".proto")] +  ".pb.h" for s in srcs] + \
   return [s[:-len(".proto")] +  ".pb.h" for s in srcs] + \
@@ -44,7 +44,11 @@ def _proto_gen_impl(ctx):
   deps = []
   deps = []
   deps += ctx.files.srcs
   deps += ctx.files.srcs
   gen_dir = _GenDir(ctx)
   gen_dir = _GenDir(ctx)
-  import_flags = ["-I" + gen_dir]
+  if gen_dir:
+    import_flags = ["-I" + gen_dir]
+  else:
+    import_flags = ["-I."]
+
   for dep in ctx.attr.deps:
   for dep in ctx.attr.deps:
     import_flags += dep.proto.import_flags
     import_flags += dep.proto.import_flags
     deps += dep.proto.deps
     deps += dep.proto.deps
@@ -75,7 +79,7 @@ _proto_gen = rule(
     attrs = {
     attrs = {
         "srcs": attr.label_list(allow_files = True),
         "srcs": attr.label_list(allow_files = True),
         "deps": attr.label_list(providers = ["proto"]),
         "deps": attr.label_list(providers = ["proto"]),
-        "include": attr.string(),
+        "includes": attr.string_list(),
         "protoc": attr.label(
         "protoc": attr.label(
             executable = True,
             executable = True,
             single_file = True,
             single_file = True,
@@ -116,6 +120,10 @@ def cc_proto_library(
 
 
   """
   """
 
 
+  includes = []
+  if include != None:
+    includes = [include]
+
   if internal_bootstrap_hack:
   if internal_bootstrap_hack:
     # For pre-checked-in generated files, we add the internal_bootstrap_hack
     # For pre-checked-in generated files, we add the internal_bootstrap_hack
     # which will skip the codegen action.
     # which will skip the codegen action.
@@ -123,7 +131,7 @@ def cc_proto_library(
         name=name + "_genproto",
         name=name + "_genproto",
         srcs=srcs,
         srcs=srcs,
         deps=[s + "_genproto" for s in deps],
         deps=[s + "_genproto" for s in deps],
-        include=include,
+        includes=includes,
         protoc=protoc,
         protoc=protoc,
     )
     )
     # An empty cc_library to make rule dependency consistent.
     # An empty cc_library to make rule dependency consistent.
@@ -137,15 +145,12 @@ def cc_proto_library(
       name=name + "_genproto",
       name=name + "_genproto",
       srcs=srcs,
       srcs=srcs,
       deps=[s + "_genproto" for s in deps],
       deps=[s + "_genproto" for s in deps],
-      include=include,
+      includes=includes,
       protoc=protoc,
       protoc=protoc,
       gen_cc=1,
       gen_cc=1,
       outs=outs,
       outs=outs,
   )
   )
 
 
-  includes = []
-  if include != None:
-    includes = [include]
 
 
   native.cc_library(
   native.cc_library(
       name=name,
       name=name,
@@ -210,11 +215,16 @@ def py_proto_library(
 
 
   """
   """
   outs = _PyOuts(srcs)
   outs = _PyOuts(srcs)
+
+  includes = []
+  if include != None:
+    includes = [include]
+
   _proto_gen(
   _proto_gen(
       name=name + "_genproto",
       name=name + "_genproto",
       srcs=srcs,
       srcs=srcs,
       deps=[s + "_genproto" for s in deps],
       deps=[s + "_genproto" for s in deps],
-      include=include,
+      includes=includes,
       protoc=protoc,
       protoc=protoc,
       gen_py=1,
       gen_py=1,
       outs=outs,
       outs=outs,