Update to new upb module name.

PiperOrigin-RevId: 444699974
pull/13171/head
Joshua Haberman 3 years ago committed by Copybara-Service
parent f75d707ae9
commit 22c7daf1e3
  1. 89
      bazel/protobuf.patch
  2. 10
      bazel/workspace_deps.bzl
  3. 13
      python/BUILD
  4. 50
      python/api_implementation.c
  5. 9
      python/dist/BUILD.bazel
  6. 2
      python/pb_unit_tests/BUILD
  7. 1
      python/pb_unit_tests/pyproto_test_wrapper.bzl
  8. 5
      python/pb_unit_tests/unknown_fields_test_wrapper.py
  9. 3
      python/protobuf.h
  10. 8
      python/py_extension.bzl

@ -1,89 +0,0 @@
--- BUILD
+++ BUILD
@@ -525,7 +525,7 @@ cc_binary(
filegroup(
name = "testdata",
srcs = glob(["src/google/protobuf/testdata/**/*"]),
- visibility = ["//:__subpackages__"],
+ visibility = ["//visibility:public"],
)
RELATIVE_LITE_TEST_PROTOS = [
@@ -931,13 +931,10 @@ py_library(
[
"python/google/protobuf/**/*.py",
],
- exclude = [
- "python/google/protobuf/internal/*_test.py",
- "python/google/protobuf/internal/test_util.py",
- ],
),
imports = ["python"],
srcs_version = "PY2AND3",
+ visibility = ["//visibility:public"],
)
cc_binary(
@@ -1038,13 +1035,6 @@ py_proto_library(
name = "protobuf_python",
srcs = COPIED_WELL_KNOWN_PROTOS,
include = "python",
- data = select({
- "//conditions:default": [],
- ":use_fast_cpp_protos": [
- ":python/google/protobuf/internal/_api_implementation.so",
- ":python/google/protobuf/pyext/_message.so",
- ],
- }),
default_runtime = "",
protoc = ":protoc",
py_libs = [
@@ -1080,6 +1070,7 @@ py_proto_library(
protoc = ":protoc",
srcs_version = "PY2AND3",
deps = [":protobuf_python"],
+ visibility = ["//visibility:public"],
)
py_proto_library(
@@ -1093,6 +1084,7 @@ py_proto_library(
protoc = ":protoc",
srcs_version = "PY2AND3",
deps = [":python_common_test_protos"],
+ visibility = ["//visibility:public"],
)
py_library(
--- python/google/protobuf/internal/test_util.py
+++ python/google/protobuf/internal/test_util.py
@@ -634,6 +634,13 @@ def GoldenFile(filename):
# Found it. Load the golden file from the testdata directory.
return open(full_path, 'rb')
+ # Search for cross-repo path.
+ full_path = os.path.join('external/com_google_protobuf/src/google/protobuf/testdata',
+ filename)
+ if os.path.exists(full_path):
+ # Found it. Load the golden file from the testdata directory.
+ return open(full_path, 'rb')
+
raise RuntimeError(
'Could not find golden files. This test must be run from within the '
'protobuf source package so that it can read test data files from the '
--- python/google/protobuf/internal/testing_refleaks.py
+++ python/google/protobuf/internal/testing_refleaks.py
@@ -67,6 +67,12 @@ class ReferenceLeakCheckerMixin(object):
NB_RUNS = 3
def run(self, result=None):
+ testMethod = getattr(self, self._testMethodName)
+ expecting_failure_method = getattr(testMethod, "__unittest_expecting_failure__", False)
+ expecting_failure_class = getattr(self, "__unittest_expecting_failure__", False)
+ if expecting_failure_class or expecting_failure_method:
+ return
+
# python_message.py registers all Message classes to some pickle global
# registry, which makes the classes immortal.
# We save a copy of this registry, and reset it before we could references.

@ -15,16 +15,8 @@ def upb_deps():
maybe( maybe(
git_repository, git_repository,
name = "com_google_protobuf", name = "com_google_protobuf",
commit = "654c25352e831b991f668a2edd97ce6ea4e1f4c3", commit = "ec79d0d328c7e6cea15cc27fbeb9b018ca289590",
remote = "https://github.com/protocolbuffers/protobuf.git", remote = "https://github.com/protocolbuffers/protobuf.git",
patches = [
"//bazel:protobuf.patch",
],
patch_cmds = [
"rm python/google/protobuf/__init__.py",
"rm python/google/protobuf/pyext/__init__.py",
"rm python/google/protobuf/internal/__init__.py",
],
) )
rules_python_version = "740825b7f74930c62f44af95c9a4c1bd428d2c53" # Latest @ 2021-06-23 rules_python_version = "740825b7f74930c62f44af95c9a4c1bd428d2c53" # Latest @ 2021-06-23

@ -213,16 +213,3 @@ py_extension(
"//upb/util:required_fields", "//upb/util:required_fields",
], ],
) )
py_extension(
name = "_api_implementation",
srcs = [
"api_implementation.c",
"python_api.h",
],
copts = UPB_DEFAULT_COPTS + select(LIMITED_API_FLAG_SELECT) + [
# The Python API requires patterns that are ISO C incompatible, like
# casts between function pointers and object pointers.
"-Wno-pedantic",
],
)

@ -1,50 +0,0 @@
/*
* Copyright (c) 2009-2021, Google LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Google LLC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "python/python_api.h"
static struct PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
"google.protobuf.internal._api_implementation",
"Protobuf Module",
-1,
NULL,
NULL,
NULL,
NULL,
NULL};
PyMODINIT_FUNC PyInit__api_implementation(void) {
PyObject* module = PyModule_Create(&module_def);
if (PyModule_AddIntConstant(module, "api_version", 2)) {
Py_DECREF(module);
return NULL;
}
return module;
}

@ -34,13 +34,7 @@ licenses(["notice"])
py_dist_module( py_dist_module(
name = "message_mod", name = "message_mod",
extension = "//python:_message_binary", extension = "//python:_message_binary",
module_name = "google.protobuf.pyext._message", module_name = "google._upb._message",
)
py_dist_module(
name = "api_implementation_mod",
extension = "//python:_api_implementation_binary",
module_name = "google.protobuf.internal.api_implementation",
) )
py_proto_library( py_proto_library(
@ -114,7 +108,6 @@ py_wheel(
version = PROTOBUF_VERSION, version = PROTOBUF_VERSION,
deps = [ deps = [
":message_mod", ":message_mod",
":api_implementation_mod",
":well_known_proto_py_pb2", ":well_known_proto_py_pb2",
#TODO(https://github.com/protocolbuffers/upb/issues/503): currently #TODO(https://github.com/protocolbuffers/upb/issues/503): currently
# this includes the unit tests. We should filter these out so we are # this includes the unit tests. We should filter these out so we are

@ -23,7 +23,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
load("//bazel:pyproto_test_wrapper.bzl", "pyproto_test_wrapper") load(":pyproto_test_wrapper.bzl", "pyproto_test_wrapper")
licenses(["notice"]) licenses(["notice"])

@ -9,7 +9,6 @@ def pyproto_test_wrapper(name):
main = src, main = src,
data = ["@com_google_protobuf//:testdata"], data = ["@com_google_protobuf//:testdata"],
deps = [ deps = [
"//python:_api_implementation",
"//python:_message", "//python:_message",
"@com_google_protobuf//:python_common_test_protos", "@com_google_protobuf//:python_common_test_protos",
"@com_google_protobuf//:python_specific_test_protos", "@com_google_protobuf//:python_specific_test_protos",

@ -26,10 +26,5 @@
from google.protobuf.internal import unknown_fields_test from google.protobuf.internal import unknown_fields_test
import unittest import unittest
# begin:github_only
# Until internal test changes propagate to unknown_fields_test.py
unknown_fields_test.UnknownFieldsAccessorsTest.testUnknownExtensions.__unittest_expecting_failure__ = True
# end:github_only
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(module=unknown_fields_test, verbosity=2) unittest.main(module=unknown_fields_test, verbosity=2)

@ -34,13 +34,12 @@
#include "python/python_api.h" #include "python/python_api.h"
#include "upb/table_internal.h" #include "upb/table_internal.h"
// begin:github_only // begin:github_only
#define PYUPB_PROTOBUF_PUBLIC_PACKAGE "google.protobuf" #define PYUPB_PROTOBUF_PUBLIC_PACKAGE "google.protobuf"
#define PYUPB_PROTOBUF_INTERNAL_PACKAGE "google.protobuf.internal" #define PYUPB_PROTOBUF_INTERNAL_PACKAGE "google.protobuf.internal"
#define PYUPB_DESCRIPTOR_PROTO_PACKAGE "google.protobuf" #define PYUPB_DESCRIPTOR_PROTO_PACKAGE "google.protobuf"
#define PYUPB_DESCRIPTOR_MODULE "google.protobuf.descriptor_pb2" #define PYUPB_DESCRIPTOR_MODULE "google.protobuf.descriptor_pb2"
#define PYUPB_MODULE_NAME "google.protobuf.pyext._message" #define PYUPB_MODULE_NAME "google._upb._message"
// end:github_only // end:github_only
// begin:google_only // begin:google_only

@ -46,13 +46,7 @@ def py_extension(name, srcs, copts, deps = []):
) )
EXT_SUFFIX = ".abi3.so" EXT_SUFFIX = ".abi3.so"
output_file = "google/_upb/" + name + EXT_SUFFIX
module_name_map = {
"_message": "pyext",
"_api_implementation": "internal",
}
output_file = "google/protobuf/" + module_name_map[name] + "/" + name + EXT_SUFFIX
native.genrule( native.genrule(
name = "copy" + name, name = "copy" + name,

Loading…
Cancel
Save