Merge branch 'master' into sync-stage-2

pull/9479/head
Joshua Haberman 3 years ago
commit 42e806fbf2
  1. 5
      CONTRIBUTORS.txt
  2. 1
      cmake/CMakeLists.txt
  3. 178
      cmake/README.md
  4. 2
      cmake/libprotobuf-lite.cmake
  5. 2
      cmake/libprotobuf.cmake
  6. 36
      cmake/protobuf-module.cmake.in
  7. 68
      cmake/tests.cmake
  8. 23
      csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs
  9. 123
      java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
  10. 71
      java/core/src/test/proto/com/google/protobuf/test_bad_identifiers.proto
  11. 11
      kokoro/linux/dockerfile/test/java_stretch/Dockerfile
  12. 18
      kokoro/linux/python36/build.sh
  13. 11
      kokoro/linux/python36/continuous.cfg
  14. 11
      kokoro/linux/python36/presubmit.cfg
  15. 18
      kokoro/linux/python36_cpp/build.sh
  16. 11
      kokoro/linux/python36_cpp/continuous.cfg
  17. 11
      kokoro/linux/python36_cpp/presubmit.cfg
  18. 10
      kokoro/release/python/windows/build_artifacts.bat
  19. 6
      kokoro/release/python/windows/build_single_artifact.bat
  20. 10
      objectivec/README.md
  21. 2
      python/README.md
  22. 29
      python/google/protobuf/service_reflection.py
  23. 9
      python/setup.py
  24. 4
      python/tox.ini
  25. 27
      src/google/protobuf/compiler/java/java_helpers.cc
  26. 14
      src/google/protobuf/compiler/objectivec/objectivec_generator.cc
  27. 17
      src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
  28. 4
      src/google/protobuf/compiler/objectivec/objectivec_helpers.h
  29. 58
      tests.sh

@ -100,3 +100,8 @@ Patch contributors:
Andrew Paprocki <andrew@ishiboo.com>
* Fixed minor IBM xlC compiler build issues
* Added atomicops for AIX (POWER)
Nipunn Koorapati <nipunn1313@gmail.com>
* Provide a type alias field ValueType on EnumTypeWrapper
* Match service argument names to abstract interface

@ -297,6 +297,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE
endif ()
if (protobuf_BUILD_TESTS)
enable_testing()
include(tests.cmake)
endif (protobuf_BUILD_TESTS)

@ -36,6 +36,10 @@ If *git* command is not available from *Command Prompt*, add it to system *PATH*
C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd
Optionally, you will want to download [ninja](https://ninja-build.org/) and add it to your *PATH* variable.
C:\Path\to>set PATH=%PATH%;C:\tools\ninja
Good. Now you are ready to continue.
Getting Sources
@ -52,29 +56,25 @@ download `protobuf-all-[VERSION].tar.gz`.
Or you can use git to clone from protobuf git repository.
C:\Path\to> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
C:\Path\to> mkdir src & cd src
C:\Path\to\src> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *master*
if you want to get the latest code.
Go to the project folder:
C:\Path\to>cd protobuf
C:\Path\to\protobuf>
C:\Path\to\src> cd protobuf
C:\Path\to\src\protobuf>
Remember to update any submodules if you are using git clone (you can skip this
step if you are using a release .tar.gz or .zip package):
```console
C:\Path\to> git submodule update --init --recursive
C:\Path\to\src\protobuf> git submodule update --init --recursive
```
Now go to *cmake* folder in protobuf sources:
C:\Path\to\protobuf>cd cmake
C:\Path\to\protobuf\cmake>
Good. Now you are ready to *CMake* configuration.
Good. Now you are ready for *CMake* configuration.
CMake Configuration
===================
@ -82,71 +82,119 @@ CMake Configuration
*CMake* supports a lot of different
[generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html)
for various native build systems.
We are only interested in
[Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators)
and
[Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
generators.
We will use shadow building to separate the temporary files from the protobuf source code.
Of most interest to Windows programmers are the following:
* [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators).
This generates NMake Makefiles for Visual Studio. These work, but they are rather slow.
* [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators)
This generates a Visual Studio solution for the project.
* [Ninja](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#ninja-generator)
This uses the external tool [Ninja](https://ninja-build.org/) to build. It is the fastest solution available.
Note that as of Visual Studio 2015, Visual Studio includes
[support for opening directly CMake-based projects](https://docs.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio).
It is considered good practice not to build CMake projects in the source tree but in a separate folder.
Create a temporary *build* folder and change your working directory to it:
C:\Path\to\protobuf\cmake>mkdir build & cd build
C:\Path\to\protobuf\cmake\build>
mkdir C:\Path\to\build\protobuf
cd C:\Path\to\build\protobuf
C:\Path\to\build\protobuf>
The *Makefile* generator can build the project in only one configuration, so you need to build
The *Makefile* and *Ninja* generators can build the project in only one configuration, so you need to build
a separate folder for each configuration.
To start using a *Release* configuration:
To start using a *Release* configuration via the *NMmake* generator:
C:\Path\to\protobuf\cmake\build>mkdir release & cd release
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
C:\Path\to\build\protobuf>mkdir release & cd release
C:\Path\to\build\protobuf\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *nmake* *Makefile* in current directory.
It will generate a *NMake* *Makefile* in the current directory.
To use *Debug* configuration:
To use *Debug* configuration using *Ninja*:
C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^
C:\Path\to\build\protobuf>mkdir debug & cd debug
C:\Path\to\build\protobuf\debug>cmake -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *nmake* *Makefile* in current directory.
It will generate *Ninja* build scripts in current directory.
To create *Visual Studio* solution file:
The *Visual Studio* generator is multi-configuration: it will generate a single *.sln* file that can be used for both *Debug* and *Release*:
C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
C:\Path\to\src\protobuf
It will generate *Visual Studio* solution file *protobuf.sln* in current directory.
If the *gmock* directory does not exist, and you do not want to build protobuf unit tests,
you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing.
Unit Tests
----------
Unit tests are being built along with the rest of protobuf. The unit tests require Google Mock (now a part of Google Test).
A copy of [Google Test](https://github.com/google/googletest) is included as a Git submodule in the `third-party/googletest` folder.
(You do need to initialize the Git submodules as explained above.)
Alternately, you may want to use protobuf in a larger set-up, you may want to use that standard CMake approach where
you build and install a shared copy of Google Test.
After you've built and installed your Google Test copy, you need add the following definition to your *cmake* command line
during the configuration step: `-Dprotobuf_USE_EXTERNAL_GTEST=ON`.
This will cause the standard CMake `find_package(GTest REQUIRED)` to be used.
To make a *Visual Studio* file for Visual Studio 16 2019, create the *Visual Studio*
solution file above and edit the CMakeCache file.
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) will search in a default location,
which on Windows is *C:\Program Files*. This is most likely not what you want. You will want instead to search for
Google Test in your project's root directory (i.e. the same directory you've passed to `CMAKE_INSTALL_PREFIX` when
building Google Test). For this, you need to set the `CMAKE_PREFIX_PATH` CMake variable. (There are other ways in CMake,
see the [manual](https://cmake.org/cmake/help/latest/command/find_package.html) for details.)
C:Path\to\protobuf\cmake\build\solution\CMakeCache
For example:
Then create the *Visual Studio* solution file again
C:\Path\to\build\protobuf>mkdir solution & cd solution
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-DCMAKE_PREFIX_PATH=C:\Path\to\my_big_project ^
-Dprotobuf_USE_EXTERNAL_GTEST=ON ^
C:\Path\to\src\protobuf
In most cases, `CMAKE_PREFIX_PATH` and `CMAKE_INSTALL_PREFIX` will point to the same directory.
To disable testing completely, you need to add the following argument to you *cmake* command line: `-Dprotobuf_BUILD_TESTS=OFF`.
For example:
C:\Path\to\build\protobuf\solution>cmake -G "Visual Studio 16 2019" ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^
-Dprotobuf_BUILD_TESTS=OFF ^
C:\Path\to\src\protobuf
Compiling
=========
To compile protobuf:
The standard way to compile a *CMake* project is `cmake --build <directory>`.
Note that if your generator supports multiple configurations, you will probably want to specify which one to build:
C:\Path\to\protobuf\cmake\build\release>nmake
cmake --build C:\Path\to\build\protobuf\solution --config Release
You can also run directly the build tool you've configured:
C:\Path\to\build\protobuf\release>nmake
or
C:\Path\to\protobuf\cmake\build\debug>nmake
C:\Path\to\build\protobuf\debug>ninja
And wait for the compilation to finish.
@ -164,11 +212,15 @@ Testing
To run unit-tests, first you must compile protobuf as described above.
Then run:
C:\Path\to\protobuf\cmake\build\release>nmake check
C:\Path\to\protobuf\cmake\build\release>ctest --progress --output-on-failure
You can also build the `check` target (not idiomatic CMake usage, though):
C:\Path\to\protobuf\cmake\build\release>cmake --build . --target check
or
C:\Path\to\protobuf\cmake\build\debug>nmake check
C:\Path\to\build\protobuf\release>ninja check
You can also build project *check* from Visual Studio solution.
Yes, it may sound strange, but it works.
@ -183,9 +235,9 @@ You should see output similar to:
[==========] 1546 tests from 165 test cases ran. (2529 ms total)
[ PASSED ] 1546 tests.
To run specific tests:
To run specific tests, you need to pass some command line arguments to the test program itself:
C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest*
C:\Path\to\build\protobuf\release>tests.exe --gtest_filter=AnyTest*
Running main() from gmock_main.cc
Note: Google Test filter = AnyTest*
[==========] Running 3 tests from 1 test case.
@ -210,13 +262,17 @@ If all tests are passed, safely continue.
Installing
==========
To install protobuf to the specified *install* folder:
To install protobuf to the *install* folder you've specified in the configuration step, you need to build the `install` target:
cmake --build C:\Path\to\build\protobuf\solution --config Release --target install
Or if you prefer:
C:\Path\to\protobuf\cmake\build\release>nmake install
C:\Path\to\build\protobuf\release>nmake install
or
C:\Path\to\protobuf\cmake\build\debug>nmake install
C:\Path\to\build\protobuf\debug>ninja install
You can also build project *INSTALL* from Visual Studio solution.
It sounds not so strange and it works.
@ -280,16 +336,16 @@ You can also compile it from source by yourself.
Getting sources:
C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git
C:\Path\to>cd zlib
C:\Path\to\src>git clone -b v1.2.8 https://github.com/madler/zlib.git
C:\Path\to\src>cd zlib
Compiling and Installing:
C:\Path\to\zlib>mkdir build & cd build
C:\Path\to\zlib\build>mkdir release & cd release
C:\Path\to\zlib\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../install ../..
C:\Path\to\zlib\build\release>nmake & nmake install
C:\Path\to\src\zlib>mkdir C:\Path\to\build\zlib & cd C:\Path\to\build\zlib
C:\Path\to\build\zlib>mkdir release & cd release
C:\Path\to\build\zlib\release>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=C:\Path\to\install C:\Path\to\src\zlib
C:\Path\to\src\zlib\build\release>cmake --build . --target install
You can make *debug* version or use *Visual Studio* generator also as before for the
protobuf project.
@ -308,8 +364,8 @@ the headers or the .lib file in the right directory.
If you already have ZLIB library and headers at some other location on your system then alternatively you can define following configuration flags to locate them:
-DZLIB_INCLUDE_DIR=<path to dir containing zlib headers>
-DZLIB_LIB=<path to dir containing zlib>
-DZLIB_INCLUDE_DIR=<path to dir containing zlib headers>
-DZLIB_LIB=<path to dir containing zlib>
Build and testing protobuf as usual.

@ -101,7 +101,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf-lite log)
endif()
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf-lite
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS)

@ -118,7 +118,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Android")
target_link_libraries(libprotobuf log)
endif()
target_include_directories(libprotobuf PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
if(protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotobuf
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS)

@ -94,7 +94,7 @@ function(_protobuf_find_libraries name filename)
elseif(${name}_LIBRARY)
# Honor cache entry used by CMake 3.5 and lower.
set(${name}_LIBRARIES "${${name}_LIBRARY}" PARENT_SCOPE)
else()
elseif(TARGET protobuf::lib${filename})
get_target_property(${name}_LIBRARY_RELEASE protobuf::lib${filename}
LOCATION_RELEASE)
get_target_property(${name}_LIBRARY_RELWITHDEBINFO protobuf::lib${filename}
@ -134,23 +134,25 @@ get_target_property(Protobuf_INCLUDE_DIRS protobuf::libprotobuf
INTERFACE_INCLUDE_DIRECTORIES)
# Set the protoc Executable
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELEASE)
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_MINSIZEREL)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_DEBUG)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_NOCONFIG)
IMPORTED_LOCATION_RELEASE)
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_RELWITHDEBINFO)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_MINSIZEREL)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_DEBUG)
endif()
if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
IMPORTED_LOCATION_NOCONFIG)
endif()
endif()
# Version info variable

@ -1,32 +1,42 @@
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()
option(protobuf_USE_EXTERNAL_GTEST "Use external Google Test (i.e. not the one in third_party/googletest)" OFF)
option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
"Using absolute test_plugin path in tests" ON)
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)
if (protobuf_USE_EXTERNAL_GTEST)
find_package(GTest REQUIRED)
else()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/../third_party/googletest/CMakeLists.txt")
message(FATAL_ERROR
"Cannot find third_party/googletest directory that's needed to "
"build tests. If you use git, make sure you have cloned submodules:\n"
" git submodule update --init --recursive\n"
"If instead you want to skip tests, run cmake with:\n"
" cmake -Dprotobuf_BUILD_TESTS=OFF\n")
endif()
set(googlemock_source_dir "${protobuf_source_dir}/third_party/googletest/googlemock")
set(googletest_source_dir "${protobuf_source_dir}/third_party/googletest/googletest")
include_directories(
${googlemock_source_dir}
${googletest_source_dir}
${googletest_source_dir}/include
${googlemock_source_dir}/include
)
add_library(gmock STATIC
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gmock_main ALIAS gmock_main)
endif()
add_library(gmock STATIC
"${googlemock_source_dir}/src/gmock-all.cc"
"${googletest_source_dir}/src/gtest-all.cc"
)
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
add_library(gmock_main STATIC "${googlemock_source_dir}/src/gmock_main.cc")
target_link_libraries(gmock_main gmock)
set(lite_test_protos
google/protobuf/map_lite_unittest.proto
@ -229,7 +239,7 @@ if (MSVC)
/wd4146 # unary minus operator applied to unsigned type, result still unsigned
)
endif()
target_link_libraries(tests libprotoc libprotobuf gmock_main)
target_link_libraries(tests libprotoc libprotobuf GTest::gmock_main)
set(test_plugin_files
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
@ -239,21 +249,25 @@ set(test_plugin_files
)
add_executable(test_plugin ${test_plugin_files})
target_link_libraries(test_plugin libprotoc libprotobuf gmock)
target_link_libraries(test_plugin libprotoc libprotobuf GTest::gmock)
set(lite_test_files
${protobuf_source_dir}/src/google/protobuf/lite_unittest.cc
)
add_executable(lite-test ${lite_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-test libprotobuf-lite gmock_main)
target_link_libraries(lite-test libprotobuf-lite GTest::gmock_main)
set(lite_arena_test_files
${protobuf_source_dir}/src/google/protobuf/lite_arena_unittest.cc
)
add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
target_link_libraries(lite-arena-test libprotobuf-lite GTest::gmock_main)
add_custom_target(check
COMMAND tests
DEPENDS tests test_plugin
WORKING_DIRECTORY ${protobuf_source_dir})
add_test(NAME check
COMMAND tests
WORKING_DIRECTORY "${protobuf_source_dir}")

@ -138,6 +138,29 @@ namespace Google.Protobuf
Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray());
}
[Test]
public void TestClone_LengthDelimited()
{
var unknownVarintField = new UnknownField();
unknownVarintField.AddVarint(99);
var unknownLengthDelimitedField1 = new UnknownField();
unknownLengthDelimitedField1.AddLengthDelimited(ByteString.CopyFromUtf8("some data"));
var unknownLengthDelimitedField2 = new UnknownField();
unknownLengthDelimitedField2.AddLengthDelimited(ByteString.CopyFromUtf8("some more data"));
var destUnknownFieldSet = new UnknownFieldSet();
destUnknownFieldSet.AddOrReplaceField(997, unknownVarintField);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField1);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField2);
var clone = UnknownFieldSet.Clone(destUnknownFieldSet);
Assert.IsTrue(clone.HasField(997));
Assert.IsTrue(clone.HasField(999));
}
[Test]
[TestCaseSource(typeof(Data), "Messages")]
public void TestDiscardUnknownFields(IMessage message)

@ -61,8 +61,31 @@ import java.util.concurrent.ConcurrentHashMap;
final class DescriptorMessageInfoFactory implements MessageInfoFactory {
private static final String GET_DEFAULT_INSTANCE_METHOD_NAME = "getDefaultInstance";
private static final DescriptorMessageInfoFactory instance = new DescriptorMessageInfoFactory();
/**
* Names that should be avoided (in UpperCamelCase format).
* Using them causes the compiler to generate accessors whose names
* collide with methods defined in base classes.
*
* Keep this list in sync with kForbiddenWordList in
* src/google/protobuf/compiler/java/java_helpers.cc
*/
private static final Set<String> specialFieldNames =
new HashSet<>(Arrays.asList("cached_size", "serialized_size", "class"));
new HashSet<>(Arrays.asList(
// java.lang.Object:
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize"));
// Disallow construction - it's a singleton.
private DescriptorMessageInfoFactory() {}
@ -593,21 +616,101 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
String name = (fd.getType() == FieldDescriptor.Type.GROUP)
? fd.getMessageType().getName()
: fd.getName();
String suffix = specialFieldNames.contains(name) ? "__" : "_";
return snakeCaseToCamelCase(name) + suffix;
// convert to UpperCamelCase for comparison to the specialFieldNames
// (which are in UpperCamelCase)
String upperCamelCaseName = snakeCaseToUpperCamelCase(name);
// Append underscores to match the behavior of the protoc java compiler
final String suffix;
if (specialFieldNames.contains(upperCamelCaseName)) {
// For proto field names that match the specialFieldNames,
// the protoc java compiler appends "__" to the java field name
// to prevent the field's accessor method names from clashing with other methods.
// For example:
// proto field name = "class"
// java field name = "class__"
// accessor method name = "getClass_()" (so that it does not clash with Object.getClass())
suffix = "__";
} else {
// For other proto field names,
// the protoc java compiler appends "_" to the java field name
// to prevent field names from clashing with java keywords.
// For example:
// proto field name = "int"
// java field name = "int_" (so that it does not clash with int keyword)
// accessor method name = "getInt()"
suffix = "_";
}
return snakeCaseToLowerCamelCase(name) + suffix;
}
private static String getCachedSizeFieldName(FieldDescriptor fd) {
return snakeCaseToCamelCase(fd.getName()) + "MemoizedSerializedSize";
return snakeCaseToLowerCamelCase(fd.getName()) + "MemoizedSerializedSize";
}
/**
* Converts a snake case string into lower camel case.
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToLowerCamelCase("foo_bar") => "fooBar"
* snakeCaseToLowerCamelCase("foo") => "foo"
* </pre>
*
* @param snakeCase the string in snake case to convert
* @return the string converted to camel case, with a lowercase first character
*/
private static String snakeCaseToLowerCamelCase(String snakeCase) {
return snakeCaseToCamelCase(snakeCase, false);
}
/**
* This method must match exactly with the corresponding function in protocol compiler. See:
* https://github.com/google/protobuf/blob/v3.0.0/src/google/protobuf/compiler/java/java_helpers.cc#L153
* Converts a snake case string into upper camel case.
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToUpperCamelCase("foo_bar") => "FooBar"
* snakeCaseToUpperCamelCase("foo") => "Foo"
* </pre>
*
* @param snakeCase the string in snake case to convert
* @return the string converted to camel case, with an uppercase first character
*/
private static String snakeCaseToUpperCamelCase(String snakeCase) {
return snakeCaseToCamelCase(snakeCase, true);
}
/**
* Converts a snake case string into camel case.
*
* <p>For better readability, prefer calling either
* {@link #snakeCaseToLowerCamelCase(String)} or {@link #snakeCaseToUpperCamelCase(String)}.</p>
*
* <p>Some examples:</p>
* <pre>
* snakeCaseToCamelCase("foo_bar", false) => "fooBar"
* snakeCaseToCamelCase("foo_bar", true) => "FooBar"
* snakeCaseToCamelCase("foo", false) => "foo"
* snakeCaseToCamelCase("foo", true) => "Foo"
* snakeCaseToCamelCase("Foo", false) => "foo"
* snakeCaseToCamelCase("fooBar", false) => "fooBar"
* </pre>
*
* <p>This implementation of this method must exactly match the corresponding
* function in the protocol compiler. Specifically, the
* {@code UnderscoresToCamelCase} function in
* {@code src/google/protobuf/compiler/java/java_helpers.cc}.</p>
*
* @param snakeCase the string in snake case to convert
* @param capFirst true if the first letter of the returned string should be uppercase.
* false if the first letter of the returned string should be lowercase.
* @return the string converted to camel case, with an uppercase or lowercase first
* character depending on if {@code capFirst} is true or false, respectively
*/
private static String snakeCaseToCamelCase(String snakeCase) {
private static String snakeCaseToCamelCase(String snakeCase, boolean capFirst) {
StringBuilder sb = new StringBuilder(snakeCase.length() + 1);
boolean capNext = false;
boolean capNext = capFirst;
for (int ctr = 0; ctr < snakeCase.length(); ctr++) {
char next = snakeCase.charAt(ctr);
if (next == '_') {
@ -653,7 +756,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
/** Constructs the name of the get method for the given field in the proto. */
private static String getterForField(String snakeCase) {
String camelCase = snakeCaseToCamelCase(snakeCase);
String camelCase = snakeCaseToLowerCamelCase(snakeCase);
StringBuilder builder = new StringBuilder("get");
// Capitalize the first character in the field name.
builder.append(Character.toUpperCase(camelCase.charAt(0)));
@ -679,7 +782,7 @@ final class DescriptorMessageInfoFactory implements MessageInfoFactory {
}
private static OneofInfo newInfo(Class<?> messageType, OneofDescriptor desc) {
String camelCase = snakeCaseToCamelCase(desc.getName());
String camelCase = snakeCaseToLowerCamelCase(desc.getName());
String valueFieldName = camelCase + "_";
String caseFieldName = camelCase + "Case_";

@ -41,10 +41,61 @@ option java_generic_services = true; // auto-added
option java_package = "com.google.protobuf";
option java_outer_classname = "TestBadIdentifiersProto";
message TestMessage {
optional string cached_size = 1;
optional string serialized_size = 2;
optional string class = 3;
// Message with field names using underscores that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsUnderscoreMessage {
// java.lang.Object
optional bool class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool default_instance_for_type = 2;
// com.google.protobuf.MessageLite
optional bool parser_for_type = 3;
optional bool serialized_size = 4;
// com.google.protobuf.MessageOrBuilder
optional bool all_fields = 5;
optional bool descriptor_for_type = 6;
optional bool initialization_error_string = 7;
optional bool unknown_fields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool cached_size = 9;
}
// Message with field names using leading underscores that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsLeadingUnderscoreMessage {
// java.lang.Object
optional bool _class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool _default_instance_for_type = 2;
// com.google.protobuf.MessageLite
optional bool _parser_for_type = 3;
optional bool _serialized_size = 4;
// com.google.protobuf.MessageOrBuilder
optional bool _all_fields = 5;
optional bool _descriptor_for_type = 6;
optional bool _initialization_error_string = 7;
optional bool _unknown_fields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool _cached_size = 9;
}
// Message with field names in camel case that conflict with accessors in the base message class in java.
// See kForbiddenWordList in src/google/protobuf/compiler/java/java_helpers.cc
message ForbiddenWordsCamelMessage {
// java.lang.Object
optional bool class = 1;
// com.google.protobuf.MessageLiteOrBuilder
optional bool defaultInstanceForType = 2;
// com.google.protobuf.MessageLite
optional bool serializedSize = 3;
optional bool parserForType = 4;
// com.google.protobuf.MessageOrBuilder:
optional bool initializationErrorString = 5;
optional bool descriptorForType = 6;
optional bool allFields = 7;
optional bool unknownFields = 8;
// obsolete. kept for backwards compatibility of generated code
optional bool cachedSize = 9;
}
message Descriptor {
@ -82,7 +133,7 @@ message Deprecated {
optional int32 field1 = 1 [deprecated = true];
optional TestEnum field2 = 2 [deprecated = true];
optional TestMessage field3 = 3 [deprecated = true];
optional ForbiddenWordsUnderscoreMessage field3 = 3 [deprecated = true];
}
message Override {
@ -115,7 +166,7 @@ message Double {
}
service TestConflictingMethodNames {
rpc Override(TestMessage) returns (TestMessage);
rpc Override(ForbiddenWordsUnderscoreMessage) returns (ForbiddenWordsUnderscoreMessage);
}
message TestConflictingFieldNames {
@ -123,24 +174,24 @@ message TestConflictingFieldNames {
UNKNOWN = 0;
FOO = 1;
}
message TestMessage {}
message ForbiddenWordsUnderscoreMessage {}
repeated int32 int32_field = 1;
repeated TestEnum enum_field = 2;
repeated string string_field = 3;
repeated bytes bytes_field = 4;
repeated TestMessage message_field = 5;
repeated ForbiddenWordsUnderscoreMessage message_field = 5;
optional int32 int32_field_count = 11;
optional TestEnum enum_field_count = 12;
optional string string_field_count = 13;
optional bytes bytes_field_count = 14;
optional TestMessage message_field_count = 15;
optional ForbiddenWordsUnderscoreMessage message_field_count = 15;
repeated int32 Int32Field = 21; // NO_PROTO3
repeated TestEnum EnumField = 22; // NO_PROTO3
repeated string StringField = 23; // NO_PROTO3
repeated bytes BytesField = 24; // NO_PROTO3
repeated TestMessage MessageField = 25; // NO_PROTO3
repeated ForbiddenWordsUnderscoreMessage MessageField = 25; // NO_PROTO3
// This field conflicts with "int32_field" as they both generate
// the method getInt32FieldList().

@ -1,4 +1,7 @@
FROM debian:stretch
# Despite the name of this image, we are no longer on stretch.
# We should consider renaming this image, and/or evaluating what
# software versions we actually need.
FROM debian:bullseye
# Install dependencies. We start with the basic ones required to build protoc
# and the C++ build
@ -22,9 +25,11 @@ RUN apt-get update && apt-get install -y \
wget \
# Java dependencies
maven \
openjdk-8-jdk \
openjdk-11-jdk \
# Required for the gtest build.
python2 \
# Python dependencies
python3-setuptools \
python3-pip \
virtualenv \
python3-venv \
&& apt-get clean

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,18 +0,0 @@
#!/bin/bash
#
# This is the top-level script we give to Kokoro as the entry point for
# running the "pull request" project:
#
# This script selects a specific Dockerfile (for building a Docker image) and
# a script to run inside that image. Then we delegate to the general
# build_and_run_docker.sh script.
# Change to repo root
cd $(dirname $0)/../../..
export DOCKERHUB_ORGANIZATION=protobuftesting
export DOCKERFILE_DIR=kokoro/linux/dockerfile/test/python36
export DOCKER_RUN_SCRIPT=kokoro/linux/pull_request_in_docker.sh
export OUTPUT_DIR=testoutput
export TEST_SET="python36_cpp"
./kokoro/linux/build_and_run_docker.sh

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -1,11 +0,0 @@
# Config file for running tests in Kokoro
# Location of the build script in repository
build_file: "protobuf/kokoro/linux/python36_cpp/build.sh"
timeout_mins: 120
action {
define_artifacts {
regex: "**/sponge_log.xml"
}
}

@ -40,16 +40,6 @@ mkdir %ARTIFACT_DIR%
REM Build wheel
SET PYTHON=C:\python36_32bit
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=32
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python36
SET PYTHON_VERSION=3.6
SET PYTHON_ARCH=64
CALL build_single_artifact.bat || goto :error
SET PYTHON=C:\python37_32bit
SET PYTHON_VERSION=3.7
SET PYTHON_ARCH=32

@ -1,11 +1,5 @@
setlocal
if %PYTHON%==C:\python36_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python36_32bit set vcplatform=Win32
if %PYTHON%==C:\python36 set generator=Visual Studio 14 Win64
if %PYTHON%==C:\python36 set vcplatform=x64
if %PYTHON%==C:\python37_32bit set generator=Visual Studio 14
if %PYTHON%==C:\python37_32bit set vcplatform=Win32

@ -133,8 +133,8 @@ This options allow you to provide a custom prefix for all the symbols generated
from a proto file (classes (from message), enums, the Root for extension
support).
If not set, the generation option `use_package_as_prefix` (documented below)
controls what is used instead. Since Objective C uses a global namespace for all
If not set, the generation options `default_objc_class_prefix` and `use_package_as_prefix`
(documented below) control what is used instead. Since Objective C uses a global namespace for all
of its classes, there can be collisions. `use_package_as_prefix=yes` should
avoid collisions since proto package are used to scope/name things in other
languages, but this option can be used to get shorter names instead. Convention
@ -182,6 +182,12 @@ supported keys are:
having to add the runtime directory to the header search path since the
generate `#import` will be more complete.
* `default_objc_class_prefix`: The default ObjC prefix value to use when
generating sources. The generator will use this if the `objc_class_prefix`
file option is not set. This option can be useful if multiple iOS apps
consume the same proto file but wish to use a different prefix for their
generated sources.
* `use_package_as_prefix` and `proto_package_prefix_exceptions_path`: The
`value` for `use_package_as_prefix` can be `yes` or `no`, and indicates
if a prefix should be derived from the proto package for all the symbols

@ -26,7 +26,7 @@ use python c++ implementation.
Installation
============
1) Make sure you have Python 3.5 or newer. If in doubt, run:
1) Make sure you have Python 3.7 or newer. If in doubt, run:
$ python -V

@ -133,7 +133,7 @@ class _ServiceBuilder(object):
"""
self.descriptor = service_descriptor
def BuildService(self, cls):
def BuildService(builder, cls):
"""Constructs the service class.
Args:
@ -143,18 +143,25 @@ class _ServiceBuilder(object):
# CallMethod needs to operate with an instance of the Service class. This
# internal wrapper function exists only to be able to pass the service
# instance to the method that does the real CallMethod work.
def _WrapCallMethod(srvc, method_descriptor,
rpc_controller, request, callback):
return self._CallMethod(srvc, method_descriptor,
rpc_controller, request, callback)
self.cls = cls
# Making sure to use exact argument names from the abstract interface in
# service.py to match the type signature
def _WrapCallMethod(self, method_descriptor,
rpc_controller, request, done):
return builder._CallMethod(self, method_descriptor,
rpc_controller, request, done)
def _WrapGetRequestClass(self, method_descriptor):
return builder._GetRequestClass(method_descriptor)
def _WrapGetResponseClass(self, method_descriptor):
return builder._GetResponseClass(method_descriptor)
builder.cls = cls
cls.CallMethod = _WrapCallMethod
cls.GetDescriptor = staticmethod(lambda: self.descriptor)
cls.GetDescriptor = staticmethod(lambda: builder.descriptor)
cls.GetDescriptor.__doc__ = "Returns the service descriptor."
cls.GetRequestClass = self._GetRequestClass
cls.GetResponseClass = self._GetResponseClass
for method in self.descriptor.methods:
setattr(cls, method.name, self._GenerateNonImplementedMethod(method))
cls.GetRequestClass = _WrapGetRequestClass
cls.GetResponseClass = _WrapGetResponseClass
for method in builder.descriptor.methods:
setattr(cls, method.name, builder._GenerateNonImplementedMethod(method))
def _CallMethod(self, srvc, method_descriptor,
rpc_controller, request, callback):

@ -301,11 +301,10 @@ if __name__ == '__main__':
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
],
namespace_packages=['google'],
packages=find_packages(
@ -322,5 +321,5 @@ if __name__ == '__main__':
},
install_requires=install_requires,
ext_modules=ext_module_list,
python_requires=">=3.5",
python_requires=">=3.7",
)

@ -1,6 +1,6 @@
[tox]
envlist =
py{35,36,37,38,39,310}-{cpp,python}
py{37,38,39,310}-{cpp,python}
[testenv]
usedevelop=true
@ -14,7 +14,7 @@ setenv =
commands =
python setup.py -q build_py
python: python setup.py -q build
py{35,36,37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
py{37,38,39,310}-cpp: python setup.py -q build --cpp_implementation --warnings_as_errors --compile_static_extension
python: python setup.py -q test -q
cpp: python setup.py -q test -q --cpp_implementation
python: python setup.py -q test_conformance

@ -66,15 +66,26 @@ namespace {
const char* kDefaultPackage = "";
// Names that should be avoided as field names.
// Using them will cause the compiler to generate accessors whose names are
// colliding with methods defined in base classes.
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
// collide with methods defined in base classes.
// Keep this list in sync with specialFieldNames in
// java/core/src/main/java/com/google/protobuf/DescriptorMessageInfoFactory.java
const char* kForbiddenWordList[] = {
// message base class:
"cached_size",
"serialized_size",
// java.lang.Object:
"class",
"Class",
// com.google.protobuf.MessageLiteOrBuilder:
"DefaultInstanceForType",
// com.google.protobuf.MessageLite:
"ParserForType",
"SerializedSize",
// com.google.protobuf.MessageOrBuilder:
"AllFields",
"DescriptorForType",
"InitializationErrorString",
"UnknownFields",
// obsolete. kept for backwards compatibility of generated code
"CachedSize",
};
const std::unordered_set<std::string>* kReservedNames =
@ -93,7 +104,7 @@ const std::unordered_set<std::string>* kReservedNames =
bool IsForbidden(const std::string& field_name) {
for (int i = 0; i < GOOGLE_ARRAYSIZE(kForbiddenWordList); ++i) {
if (field_name == kForbiddenWordList[i]) {
if (UnderscoresToCamelCase(field_name, true) == kForbiddenWordList[i]) {
return true;
}
}

@ -190,10 +190,20 @@ bool ObjectiveCGenerator::GenerateAll(
// header search path since the generate #import will be more complete.
generation_options.runtime_import_prefix =
StripSuffixString(options[i].second, "/");
} else if (options[i].first == "default_objc_class_prefix") {
// The default objc class prefix to use if specified by the command line
// invocation. The file option is always honored first if one is present.
std::string value = options[i].second;
if (value.empty()) {
*error = "error: default_objc_class_prefix cannot be empty.";
return false;
}
SetDefaultObjcClassPrefix(value);
} else if (options[i].first == "use_package_as_prefix") {
// Controls how the symbols should be prefixed to avoid symbols
// collisions. The objc_class_prefix file option is always honored, this
// is just what to do if that isn't set. The available options are:
// collisions. The objc_class_prefix file option is always honored first
// followed by the default_objc_class_prefix generator option. This is is just
// what to do if either of these options are not set. The available options are:
// "no": Not prefixed (the existing mode).
// "yes": Make a prefix out of the proto package.
bool value = false;

@ -99,6 +99,9 @@ class PrefixModeStorage {
public:
PrefixModeStorage();
const std::string default_objc_class_prefix() const { return default_objc_class_prefix_; }
void set_default_objc_class_prefix(const std::string& default_objc_class_prefix) { default_objc_class_prefix_ = default_objc_class_prefix; }
bool use_package_name() const { return use_package_name_; }
void set_use_package_name(bool on_or_off) { use_package_name_ = on_or_off; }
@ -116,13 +119,14 @@ class PrefixModeStorage {
private:
bool use_package_name_;
std::string default_objc_class_prefix_;
std::string exception_path_;
std::string forced_prefix_;
std::unordered_set<std::string> exceptions_;
};
PrefixModeStorage::PrefixModeStorage() {
// Even thought there are generation options, have an env back door since some
// Even though there are generation options, have an env back door since some
// of these helpers could be used in other plugins.
use_package_name_ = BoolFromEnvVar("GPB_OBJC_USE_PACKAGE_AS_PREFIX", false);
@ -169,6 +173,10 @@ PrefixModeStorage g_prefix_mode;
} // namespace
void SetDefaultObjcClassPrefix(const std::string& default_objc_class_prefix) {
g_prefix_mode.set_default_objc_class_prefix(default_objc_class_prefix);
}
bool UseProtoPackageAsDefaultPrefix() {
return g_prefix_mode.use_package_name();
}
@ -526,11 +534,16 @@ std::string BaseFileName(const FileDescriptor* file) {
}
std::string FileClassPrefix(const FileDescriptor* file) {
// Always honor the file option.
// Always honor the file option first.
if (file->options().has_objc_class_prefix()) {
return file->options().objc_class_prefix();
}
// If a default prefix is passed through objc_opt then accept it.
if (!g_prefix_mode.default_objc_class_prefix().empty()) {
return g_prefix_mode.default_objc_class_prefix();
}
// If package prefix isn't enabled, done.
if (!g_prefix_mode.use_package_name()) {
return "";

@ -47,6 +47,9 @@ namespace protobuf {
namespace compiler {
namespace objectivec {
// Set the default objc class prefix that should be used. This method is used only
// when default_objc_class_prefix is passed through objc_opt.
void PROTOC_EXPORT SetDefaultObjcClassPrefix(const std::string& objc_class_prefix);
// Get/Set if the proto package should be used to make the default prefix for
// symbols. This will then impact most of the type naming apis below. It is done
// as a global to not break any other generator reusing the methods since they
@ -68,6 +71,7 @@ struct Options {
std::string generate_for_named_framework;
std::string named_framework_to_proto_path_mappings_path;
std::string runtime_import_prefix;
std::string default_objc_class_prefix;
bool prefixes_must_be_registered;
bool require_prefixes;
};

@ -116,12 +116,12 @@ build_dist_install() {
# Try to install Java
pushd java
use_java jdk8
use_java jdk11
$MVN install
popd
# Try to install Python
virtualenv --no-site-packages venv
python3 -m venv venv
source venv/bin/activate
pushd python
python3 setup.py clean build sdist
@ -189,6 +189,10 @@ build_golang() {
use_java() {
version=$1
case "$version" in
jdk11)
export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
;;
jdk8)
export PATH=/usr/lib/jvm/java-8-openjdk-amd64/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
@ -268,7 +272,7 @@ build_java_linkage_monitor() {
# Linkage Monitor checks compatibility with other Google libraries
# https://github.com/GoogleCloudPlatform/cloud-opensource-java/tree/master/linkage-monitor
use_java jdk8
use_java jdk11
internal_build_cpp
# Linkage Monitor uses $HOME/.m2 local repository
@ -330,12 +334,7 @@ build_objectivec_cocoapods_integration() {
build_python() {
internal_build_cpp
cd python
if [ $(uname -s) == "Linux" ]; then
envlist=py\{35,36\}-python
else
envlist=py\{36\}-python
fi
python -m tox -e $envlist
tox --skip-missing-interpreters
cd ..
}
@ -343,26 +342,10 @@ build_python_version() {
internal_build_cpp
cd python
envlist=$1
python -m tox -e $envlist
tox -e $envlist
cd ..
}
build_python33() {
build_python_version py33-python
}
build_python34() {
build_python_version py34-python
}
build_python35() {
build_python_version py35-python
}
build_python36() {
build_python_version py36-python
}
build_python37() {
build_python_version py37-python
}
@ -384,12 +367,7 @@ build_python_cpp() {
export LD_LIBRARY_PATH=../src/.libs # for Linux
export DYLD_LIBRARY_PATH=../src/.libs # for OS X
cd python
if [ $(uname -s) == "Linux" ]; then
envlist=py\{35,36\}-cpp
else
envlist=py\{36\}-cpp
fi
tox -e $envlist
tox --skip-missing-interpreters
cd ..
}
@ -403,22 +381,6 @@ build_python_cpp_version() {
cd ..
}
build_python33_cpp() {
build_python_cpp_version py33-cpp
}
build_python34_cpp() {
build_python_cpp_version py34-cpp
}
build_python35_cpp() {
build_python_cpp_version py35-cpp
}
build_python36_cpp() {
build_python_cpp_version py36-cpp
}
build_python37_cpp() {
build_python_cpp_version py37-cpp
}

Loading…
Cancel
Save