aboutsummaryrefslogtreecommitdiffhomepage
path: root/BUILD
diff options
context:
space:
mode:
authorGravatar David Z. Chen <dzc@google.com>2016-02-11 18:11:10 -0800
committerGravatar David Z. Chen <dzc@google.com>2016-02-25 12:52:21 -0800
commit985c968443e5124327fb600a91856192df4476ac (patch)
tree5e10472534937e070a19be7ab2b5cd94ed976b46 /BUILD
parentfb714b3606bd663b823f6960a73d052f97283b74 (diff)
Remove hack for building Python support with Bazel.
This change makes use of new imports attribute for Bazel's Python rules, which enable adding directories to the PYTHONPATH. This allows us to remove the hack for building protobuf's Python support with Bazel and now allows projects to include protobuf using a Bazel external repository rather than requiring it to be imported directly into the source tree as //google/protobuf. This change also updates the protobuf BUILD file to use a named repository, @python//, for including Python headers rather than //util/python. This allows projects to specify their own package for Python headers when including protobuf with an external repository. Fixes #1230
Diffstat (limited to 'BUILD')
-rw-r--r--BUILD52
1 files changed, 15 insertions, 37 deletions
diff --git a/BUILD b/BUILD
index c4de1c4c..9cbddd5b 100644
--- a/BUILD
+++ b/BUILD
@@ -22,7 +22,6 @@ load(
"protobuf",
"cc_proto_library",
"py_proto_library",
- "internal_copied_filegroup",
"internal_protobuf_py_tests",
)
@@ -484,25 +483,7 @@ java_library(
# Python support
################################################################################
-# Hack:
-# protoc generated files contain imports like:
-# "from google.protobuf.xxx import yyy"
-# However, the sources files of the python runtime are not directly under
-# "google/protobuf" (they are under python/google/protobuf). We workaround
-# this by copying runtime source files into the desired location to workaround
-# the import issue. Ideally py_library should support something similiar to the
-# "include" attribute in cc_library to inject the PYTHON_PATH for all libraries
-# that depend on the target.
-#
-# If you use python protobuf as a third_party library in your bazel managed
-# project:
-# 1) Please import the whole package to //google/protobuf in your
-# project. Otherwise, bazel disallows generated files out of the current
-# package, thus we won't be able to copy protobuf runtime files into
-# //google/protobuf/.
-# 2) The runtime also requires "six" for Python2/3 compatibility, please see the
-# WORKSPACE file and bind "six" to your workspace as well.
-internal_copied_filegroup(
+py_library(
name = "python_srcs",
srcs = glob(
[
@@ -514,7 +495,7 @@ internal_copied_filegroup(
"python/google/protobuf/internal/test_util.py",
],
),
- include = "python",
+ imports = ["python"],
)
cc_binary(
@@ -527,7 +508,7 @@ cc_binary(
linkstatic = 1,
deps = select({
"//conditions:default": [],
- ":use_fast_cpp_protos": ["//util/python:python_headers"],
+ ":use_fast_cpp_protos": ["//external:python_headers"],
}),
)
@@ -553,7 +534,7 @@ cc_binary(
":protobuf",
] + select({
"//conditions:default": [],
- ":use_fast_cpp_protos": ["//util/python:python_headers"],
+ ":use_fast_cpp_protos": ["//external:python_headers"],
}),
)
@@ -584,23 +565,14 @@ py_proto_library(
}),
default_runtime = "",
protoc = ":protoc",
- py_extra_srcs = [":python_srcs"],
- py_libs = ["//external:six"],
+ py_libs = [
+ ":python_srcs",
+ "//external:six"
+ ],
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
)
-internal_copied_filegroup(
- 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,
@@ -624,7 +596,13 @@ py_proto_library(
py_library(
name = "python_tests",
- srcs = [":python_test_srcs"],
+ srcs = glob(
+ [
+ "python/google/protobuf/internal/*_test.py",
+ "python/google/protobuf/internal/test_util.py",
+ ],
+ ),
+ imports = ["python"],
srcs_version = "PY2AND3",
deps = [
":protobuf_python",