Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
993fb701
Commit
993fb701
authored
Oct 20, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python bazel support.
parent
6dac0822
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
214 additions
and
34 deletions
+214
-34
BUILD
BUILD
+120
-29
protobuf.bzl
protobuf.bzl
+94
-5
No files found.
BUILD
View file @
993fb701
...
@@ -18,7 +18,8 @@ COPTS = [
...
@@ -18,7 +18,8 @@ COPTS = [
# Bazel should provide portable link_opts for pthread.
# Bazel should provide portable link_opts for pthread.
LINK_OPTS = ["-lpthread"]
LINK_OPTS = ["-lpthread"]
load("protobuf", "cc_proto_library")
load("protobuf", "cc_proto_library", "py_proto_library", "copied_srcs",
"internal_protobuf_py_tests")
cc_library(
cc_library(
name = "protobuf_lite",
name = "protobuf_lite",
...
@@ -126,7 +127,7 @@ objc_library(
...
@@ -126,7 +127,7 @@ objc_library(
visibility = ["//visibility:public"],
visibility = ["//visibility:public"],
)
)
WELL_KNOWN_PROTOS = [
RELATIVE_
WELL_KNOWN_PROTOS = [
# AUTOGEN(well_known_protos)
# AUTOGEN(well_known_protos)
"google/protobuf/any.proto",
"google/protobuf/any.proto",
"google/protobuf/api.proto",
"google/protobuf/api.proto",
...
@@ -142,12 +143,14 @@ WELL_KNOWN_PROTOS = [
...
@@ -142,12 +143,14 @@ WELL_KNOWN_PROTOS = [
"google/protobuf/wrappers.proto",
"google/protobuf/wrappers.proto",
]
]
WELL_KNOWN_PROTOS = ["src/" + s for s in RELATIVE_WELL_KNOWN_PROTOS]
cc_proto_library(
cc_proto_library(
name = "cc_wkt_protos",
name = "cc_wkt_protos",
srcs = ["src/" + s for s in WELL_KNOWN_PROTOS],
srcs = WELL_KNOWN_PROTOS,
internal_bootstrap_hack = 1,
include = "src",
include = "src",
cc_libs = [":protobuf"],
cc_libs = [":protobuf"],
internal_bootstrap_hack = 1,
)
)
################################################################################
################################################################################
...
@@ -263,32 +266,11 @@ cc_binary(
...
@@ -263,32 +266,11 @@ cc_binary(
deps = [":protoc_lib"],
deps = [":protoc_lib"],
)
)
################################################################################
# Java support
################################################################################
genrule(
name = "generate_java_descriptor_proto",
srcs = ["src/google/protobuf/descriptor.proto"],
outs = ["com/google/protobuf/DescriptorProtos.java"],
cmd = "$(location :protoc) --java_out=$(@D)/../../.. $<",
tools = [":protoc"],
)
java_library(
name = "java_proto",
srcs = glob([
"java/src/main/java/com/google/protobuf/*.java",
]) + [
":generate_java_descriptor_proto",
],
visibility = ["//visibility:public"],
)
################################################################################
################################################################################
# Tests
# Tests
################################################################################
################################################################################
LITE_TEST_PROTOS = [
RELATIVE_
LITE_TEST_PROTOS = [
# AUTOGEN(lite_test_protos)
# AUTOGEN(lite_test_protos)
"google/protobuf/map_lite_unittest.proto",
"google/protobuf/map_lite_unittest.proto",
"google/protobuf/unittest_import_lite.proto",
"google/protobuf/unittest_import_lite.proto",
...
@@ -297,7 +279,9 @@ LITE_TEST_PROTOS = [
...
@@ -297,7 +279,9 @@ LITE_TEST_PROTOS = [
"google/protobuf/unittest_no_arena_lite.proto",
"google/protobuf/unittest_no_arena_lite.proto",
]
]
TEST_PROTOS = [
LITE_TEST_PROTOS = ["src/" + s for s in RELATIVE_LITE_TEST_PROTOS]
RELATIVE_TEST_PROTOS = [
# AUTOGEN(test_protos)
# AUTOGEN(test_protos)
"google/protobuf/any_test.proto",
"google/protobuf/any_test.proto",
"google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
"google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto",
...
@@ -337,9 +321,11 @@ TEST_PROTOS = [
...
@@ -337,9 +321,11 @@ TEST_PROTOS = [
"google/protobuf/util/json_format_proto3.proto",
"google/protobuf/util/json_format_proto3.proto",
]
]
TEST_PROTOS = ["src/" + s for s in RELATIVE_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 =
LITE_TEST_PROTOS + TEST_PROTOS
,
include = "src",
include = "src",
deps = [":cc_wkt_protos"],
deps = [":cc_wkt_protos"],
)
)
...
@@ -445,9 +431,114 @@ cc_test(
...
@@ -445,9 +431,114 @@ cc_test(
],
],
linkopts = LINK_OPTS,
linkopts = LINK_OPTS,
deps = [
deps = [
":cc_test_protos",
":protobuf",
":protobuf",
":protoc_lib",
":protoc_lib",
":cc_test_protos",
"//external:gtest_main",
"//external:gtest_main",
],
],
)
)
################################################################################
# Java support
################################################################################
genrule(
name = "generate_java_descriptor_proto",
srcs = ["src/google/protobuf/descriptor.proto"],
outs = ["com/google/protobuf/DescriptorProtos.java"],
cmd = "$(location :protoc) --java_out=$(@D)/../../.. $<",
tools = [":protoc"],
)
java_library(
name = "java_proto",
srcs = glob([
"java/src/main/java/com/google/protobuf/*.java",
]) + [
":generate_java_descriptor_proto",
],
visibility = ["//visibility:public"],
)
################################################################################
# Python support
################################################################################
copied_srcs(
name = "python_srcs",
srcs = glob(
[
"python/google/protobuf/*.py",
"python/google/protobuf/**/*.py",
],
exclude = [
"python/google/protobuf/internal/*_test.py",
"python/google/protobuf/internal/test_util.py",
],
),
include = "python",
)
py_proto_library(
name = "python_proto",
srcs = WELL_KNOWN_PROTOS,
include = "src",
py_extra_srcs = [":python_srcs"],
visibility = ["//visibility:public"],
)
copied_srcs(
name = "python_test_srcs",
srcs = glob(
[
"python/google/protobuf/internal/*_test.py",
"python/google/protobuf/internal/test_util.py",
],
),
include = "python",
)
py_proto_library(
name = "python_common_test_protos",
srcs = LITE_TEST_PROTOS + TEST_PROTOS,
include = "src",
deps = [":python_proto"],
)
py_proto_library(
name = "python_specific_test_protos",
srcs = glob(["python/google/protobuf/internal/*.proto"]),
include = "python",
deps = [":python_common_test_protos"],
)
py_library(
name = "python_tests",
srcs = [":python_test_srcs"],
deps = [
":python_common_test_protos",
":python_proto",
":python_specific_test_protos",
],
)
internal_protobuf_py_tests(
name = "python_tests",
modules = [
"descriptor_database_test",
"descriptor_pool_test",
"descriptor_test",
"generator_test",
"json_format_test",
"message_factory_test",
# "message_test", # failed due to testdata path
"proto_builder_test",
# "reflection_test", # failed due to testdata path
"service_reflection_test",
"symbol_database_test",
"text_encoding_test",
# "text_format_test", # failed due to testdata path
"unknown_fields_test",
"wire_format_test",
],
deps = [":python_tests"],
)
protobuf.bzl
View file @
993fb701
# -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
# -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
def
_
gen_d
ir
(
ctx
):
def
_
GenD
ir
(
ctx
):
if
ctx
.
attr
.
include
==
None
:
if
ctx
.
attr
.
include
==
None
:
return
""
return
""
if
not
ctx
.
attr
.
include
:
if
not
ctx
.
attr
.
include
:
...
@@ -9,19 +9,41 @@ def _gen_dir(ctx):
...
@@ -9,19 +9,41 @@ def _gen_dir(ctx):
return
ctx
.
attr
.
include
return
ctx
.
attr
.
include
return
ctx
.
label
.
package
+
'/'
+
ctx
.
attr
.
include
return
ctx
.
label
.
package
+
'/'
+
ctx
.
attr
.
include
def
_
cc_o
uts
(
srcs
):
def
_
CcO
uts
(
srcs
):
return
[
s
[:
-
len
(
".proto"
)]
+
".pb.h"
for
s
in
srcs
]
+
\
return
[
s
[:
-
len
(
".proto"
)]
+
".pb.h"
for
s
in
srcs
]
+
\
[
s
[:
-
len
(
".proto"
)]
+
".pb.cc"
for
s
in
srcs
]
[
s
[:
-
len
(
".proto"
)]
+
".pb.cc"
for
s
in
srcs
]
def
_
py_o
uts
(
srcs
):
def
_
PyO
uts
(
srcs
):
return
[
s
[:
-
len
(
".proto"
)]
+
"_pb2.py"
for
s
in
srcs
]
return
[
s
[:
-
len
(
".proto"
)]
+
"_pb2.py"
for
s
in
srcs
]
def
_RelativeOutputPath
(
path
,
include
):
if
include
==
None
:
return
path
if
not
path
.
startswith
(
include
):
fail
(
"Include path
%
s isn't part of the path
%
s."
%
(
include
,
path
))
if
include
and
include
[
-
1
]
!=
'/'
:
include
=
include
+
'/'
path
=
path
[
len
(
include
):]
if
not
path
.
startswith
(
PACKAGE_NAME
):
fail
(
"The package
%
s is not within the path
%
s"
%
(
PACKAGE_NAME
,
path
))
if
not
PACKAGE_NAME
:
return
path
return
path
[
len
(
PACKAGE_NAME
)
+
1
:]
def
_proto_gen_impl
(
ctx
):
def
_proto_gen_impl
(
ctx
):
"""General implementation for generating protos"""
"""General implementation for generating protos"""
srcs
=
ctx
.
files
.
srcs
srcs
=
ctx
.
files
.
srcs
deps
=
[]
deps
=
[]
deps
+=
ctx
.
files
.
srcs
deps
+=
ctx
.
files
.
srcs
gen_dir
=
_
gen_d
ir
(
ctx
)
gen_dir
=
_
GenD
ir
(
ctx
)
import_flags
=
[
"-I"
+
gen_dir
]
import_flags
=
[
"-I"
+
gen_dir
]
for
dep
in
ctx
.
attr
.
deps
:
for
dep
in
ctx
.
attr
.
deps
:
import_flags
+=
dep
.
proto
.
import_flags
import_flags
+=
dep
.
proto
.
import_flags
...
@@ -110,7 +132,7 @@ def cc_proto_library(
...
@@ -110,7 +132,7 @@ def cc_proto_library(
**
kargs
)
**
kargs
)
return
return
outs
=
_
cc_o
uts
(
srcs
)
outs
=
_
CcO
uts
(
srcs
)
_proto_gen
(
_proto_gen
(
name
=
name
+
"_genproto"
,
name
=
name
+
"_genproto"
,
srcs
=
srcs
,
srcs
=
srcs
,
...
@@ -131,3 +153,70 @@ def cc_proto_library(
...
@@ -131,3 +153,70 @@ def cc_proto_library(
deps
=
cc_libs
+
deps
,
deps
=
cc_libs
+
deps
,
includes
=
includes
,
includes
=
includes
,
**
kargs
)
**
kargs
)
def
copied_srcs
(
name
,
srcs
,
include
,
**
kargs
):
outs
=
[
_RelativeOutputPath
(
s
,
include
)
for
s
in
srcs
]
native
.
genrule
(
name
=
name
+
"_genrule"
,
srcs
=
srcs
,
outs
=
outs
,
cmd
=
";"
.
join
([
"cp $(location
%
s) $(location
%
s)"
%
\
(
s
,
_RelativeOutputPath
(
s
,
include
))
\
for
s
in
srcs
]))
native
.
filegroup
(
name
=
name
,
srcs
=
outs
,
**
kargs
)
def
py_proto_library
(
name
,
srcs
=
[],
deps
=
[],
py_libs
=
[],
py_extra_srcs
=
[],
include
=
None
,
protoc
=
":protoc"
,
**
kargs
):
outs
=
_PyOuts
(
srcs
)
_proto_gen
(
name
=
name
+
"_genproto"
,
srcs
=
srcs
,
deps
=
[
s
+
"_genproto"
for
s
in
deps
],
include
=
include
,
protoc
=
protoc
,
gen_py
=
1
,
outs
=
outs
,
)
copied_srcs_name
=
name
+
"_copied_srcs"
if
include
!=
None
:
copied_srcs
(
name
=
copied_srcs_name
,
srcs
=
outs
,
include
=
include
)
srcs
=
[
copied_srcs_name
]
native
.
py_library
(
name
=
name
,
srcs
=
srcs
+
py_extra_srcs
,
deps
=
py_libs
,
**
kargs
)
def
internal_protobuf_py_tests
(
name
,
modules
=
[],
**
kargs
):
for
m
in
modules
:
native
.
py_test
(
name
=
"py_
%
s"
%
m
,
srcs
=
[
"google/protobuf/internal/
%
s.py"
%
m
],
main
=
"google/protobuf/internal/
%
s.py"
%
m
,
**
kargs
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment