Change prefix to include, and add docs

pull/883/head
Jisi Liu 9 years ago
parent d8701b5741
commit 3101e7337c
  1. 4
      BUILD
  2. 37
      protobuf.bzl

@ -146,7 +146,7 @@ cc_proto_library(
name = "cc_wkt_protos", name = "cc_wkt_protos",
srcs = ["src/" + s for s in WELL_KNOWN_PROTOS], srcs = ["src/" + s for s in WELL_KNOWN_PROTOS],
internal_bootstrap_hack = 1, internal_bootstrap_hack = 1,
prefix = "src", include = "src",
cc_libs = [":protobuf"], cc_libs = [":protobuf"],
) )
@ -340,7 +340,7 @@ TEST_PROTOS = [
cc_proto_library( cc_proto_library(
name = "cc_test_protos", name = "cc_test_protos",
srcs = ["src/" + s for s in (LITE_TEST_PROTOS + TEST_PROTOS)], srcs = ["src/" + s for s in (LITE_TEST_PROTOS + TEST_PROTOS)],
prefix = "src", include = "src",
deps = [":cc_wkt_protos"], deps = [":cc_wkt_protos"],
) )

@ -1,11 +1,11 @@
# -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED # -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
def _gen_dir(ctx): def _gen_dir(ctx):
if not ctx.attr.prefix: if not ctx.attr.include:
return ctx.label.package return ctx.label.package
if not ctx.label.package: if not ctx.label.package:
return ctx.attr.prefix return ctx.attr.include
return ctx.label.package + '/' + ctx.attr.prefix return ctx.label.package + '/' + ctx.attr.include
def _cc_outs(srcs): def _cc_outs(srcs):
return [s[:-len(".proto")] + ".pb.h" for s in srcs] + \ return [s[:-len(".proto")] + ".pb.h" for s in srcs] + \
@ -51,7 +51,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"]),
"prefix": attr.string(), "include": attr.string(),
"protoc": attr.label( "protoc": attr.label(
executable = True, executable = True,
single_file = True, single_file = True,
@ -68,12 +68,29 @@ _proto_gen = rule(
def cc_proto_library( def cc_proto_library(
name, name,
srcs=[], srcs=[],
protoc=":protoc",
internal_bootstrap_hack=False,
prefix="",
deps=[], deps=[],
cc_libs=[], cc_libs=[],
include="",
protoc=":protoc",
internal_bootstrap_hack=False,
**kargs): **kargs):
"""Bazel rule to create a C++ protobuf library from proto source files
Args:
name: the name of the cc_proto_library.
srcs: the .proto files of the cc_proto_library.
deps: a list of dependency labels; must be cc_proto_library.
cc_libs: a list of other cc_library targets depended by the generated
cc_library.
include: a string indicating the include path of the .proto files.
protoc: the label of the protocol compiler to generate the sources.
internal_bootstrap_hack: a flag indicate the cc_proto_library is used only
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
cc_proto_library can depend on it.
**kargs: other keyword arguments that are passed to cc_library.
"""
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
@ -82,7 +99,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],
prefix=prefix, include=include,
protoc=protoc, protoc=protoc,
) )
# An empty cc_library to make rule dependency consistent. # An empty cc_library to make rule dependency consistent.
@ -96,7 +113,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],
prefix=prefix, include=include,
protoc=protoc, protoc=protoc,
gen_cc=1, gen_cc=1,
outs=outs, outs=outs,
@ -106,5 +123,5 @@ def cc_proto_library(
name=name, name=name,
srcs=outs, srcs=outs,
deps=cc_libs + deps, deps=cc_libs + deps,
includes=[prefix], includes=[include],
**kargs) **kargs)

Loading…
Cancel
Save