parent
b0c76ccc21
commit
388e3d744f
102 changed files with 2678 additions and 2910 deletions
@ -1,41 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
# This script updates the CMake file lists (i.e. src/file_lists.cmake), commits |
||||
# the resulting change, and pushes it. This does not do anything useful when |
||||
# run manually, but should be run by our GitHub action instead. |
||||
|
||||
set -ex |
||||
|
||||
# Exit early if the previous commit was made by the bot. This reduces the risk |
||||
# of a bug causing an infinite loop of auto-generated commits. |
||||
if (git log -1 --pretty=format:'%an' | grep -q "Protobuf Team Bot"); then |
||||
echo "Previous commit was authored by bot" |
||||
exit 0 |
||||
fi |
||||
|
||||
$(dirname -- "$0")/update_file_lists.sh |
||||
|
||||
# Try to determine the most recent pull request number. |
||||
title=$(git log -1 --pretty='%s') |
||||
pr_from_merge=$(echo "$title" | sed -n 's/^Merge pull request #\([0-9]\+\).*/\1/p') |
||||
pr_from_squash=$(echo "$title" | sed -n 's/^.*(#\([0-9]\+\))$/\1/p') |
||||
|
||||
pr="" |
||||
if [ ! -z "$pr_from_merge" ]; then |
||||
pr="$pr_from_merge" |
||||
elif [ ! -z "$pr_from_squash" ]; then |
||||
pr="$pr_from_squash" |
||||
fi |
||||
|
||||
if [ ! -z "$pr" ]; then |
||||
commit_message="Auto-generate CMake file lists after PR #$pr" |
||||
else |
||||
# If we are unable to determine the pull request number, we fall back on this |
||||
# default commit message. Typically this should not occur, but could happen |
||||
# if a pull request was merged via a rebase. |
||||
commit_message="Auto-generate CMake file lists" |
||||
fi |
||||
|
||||
git add -A |
||||
git diff --staged --quiet || git commit -am "$commit_message" |
||||
git push |
@ -1,34 +0,0 @@ |
||||
@rem enter repo root |
||||
cd /d %~dp0\..\..\.. |
||||
|
||||
call kokoro\windows\prepare_build_win64.bat || goto :error |
||||
|
||||
@rem TODO(b/241475022) Use docker to guarantee better stability. |
||||
@rem TODO(b/241484899) Run conformance tests in windows. |
||||
|
||||
md build |
||||
md %KOKORO_ARTIFACTS_DIR%\logs |
||||
|
||||
cd build |
||||
|
||||
cmake .. ^ |
||||
-G "NMake Makefiles" ^ |
||||
-DCMAKE_C_COMPILER=cl.exe ^ |
||||
-DCMAKE_CXX_COMPILER=cl.exe ^ |
||||
-Dprotobuf_BUILD_CONFORMANCE=OFF ^ |
||||
-Dprotobuf_WITH_ZLIB=OFF ^ |
||||
-Dprotobuf_TEST_XML_OUTDIR=%KOKORO_ARTIFACTS_DIR%\logs\ || goto :error |
||||
|
||||
cmake --build . || goto :error |
||||
|
||||
ctest --verbose -C Debug || goto :error |
||||
|
||||
goto :success |
||||
|
||||
:error |
||||
cd /d %~dp0\..\..\.. |
||||
echo Failed! |
||||
exit /b 1 |
||||
|
||||
:success |
||||
cd .. |
@ -1,5 +0,0 @@ |
||||
# Config file for running tests in Kokoro |
||||
|
||||
# Location of the build script in repository |
||||
build_file: "protobuf/kokoro/windows/cmake_nmake/build.bat" |
||||
timeout_mins: 1440 |
@ -1 +0,0 @@ |
||||
# Keep this file empty! Use common.cfg instead. |
@ -1 +0,0 @@ |
||||
# Keep this file empty! Use common.cfg instead. |
File diff suppressed because it is too large
Load Diff
@ -1,161 +0,0 @@ |
||||
# Build scripts that publish pre-compiled protoc artifacts |
||||
``protoc`` is the compiler for ``.proto`` files. It generates language bindings |
||||
for the messages and/or RPC services from ``.proto`` files. |
||||
|
||||
Because ``protoc`` is a native executable, the scripts under this directory |
||||
build and publish a ``protoc`` executable (a.k.a. artifact) to Maven |
||||
repositories. The artifact can be used by build automation tools so that users |
||||
would not need to compile and install ``protoc`` for their systems. |
||||
|
||||
If you would like us to publish protoc artifact for a new platform, please send |
||||
us a pull request to add support for the new platform. You would need to change |
||||
the following files: |
||||
|
||||
* [build-protoc.sh](build-protoc.sh): script to cross-build the protoc for your |
||||
platform. |
||||
* [pom.xml](pom.xml): script to upload artifacts to maven. |
||||
* [build-zip.sh](build-zip.sh): script to package published maven artifacts in |
||||
our release page. |
||||
|
||||
## Maven Location |
||||
The published protoc artifacts are available on Maven here: |
||||
|
||||
https://repo.maven.apache.org/maven2/com/google/protobuf/protoc/ |
||||
|
||||
## Versioning |
||||
The version of the ``protoc`` artifact must be the same as the version of the |
||||
Protobuf project. |
||||
|
||||
## Artifact name |
||||
The name of a published ``protoc`` artifact is in the following format: |
||||
``protoc-<version>-<os>-<arch>.exe``, e.g., ``protoc-3.6.1-linux-x86_64.exe``. |
||||
|
||||
Note that artifacts for linux/macos also have the `.exe` suffix but they are |
||||
not windows binaries. |
||||
|
||||
## System requirement |
||||
Install [Apache Maven](http://maven.apache.org/) if you don't have it. |
||||
|
||||
The scripts only work under Unix-like environments, e.g., Linux, MacOSX, and |
||||
Cygwin or MinGW for Windows. Please see ``README.md`` of the Protobuf project |
||||
for how to set up the build environment. |
||||
|
||||
## Building from a freshly checked-out source |
||||
|
||||
If you just checked out the Protobuf source from github, you need to |
||||
pull in any submodules. |
||||
|
||||
Under the protobuf project directory: |
||||
|
||||
|
||||
``` |
||||
git submodule update --init --recursive |
||||
``` |
||||
|
||||
### Build the artifact for each platform |
||||
|
||||
Run the build-protoc.sh script under this protoc-artifacts directory to build the protoc |
||||
artifact for each platform. For example: |
||||
|
||||
``` |
||||
$ cd protoc-artifacts |
||||
$ ./build-protoc.sh linux x86_64 protoc |
||||
``` |
||||
|
||||
The above command will produce a `target/linux/x86_64/protoc` binary under the |
||||
protoc-artifacts directory. |
||||
|
||||
For a list of supported platforms, see the comments in the build-protoc.sh |
||||
script. We only use this script to build artifacts on Ubuntu and MacOS (both |
||||
with x86_64, and do cross-compilation for other platforms. |
||||
|
||||
### Tips for building for Linux |
||||
We build on Centos 6.9 to provide a good compatibility for not very new |
||||
systems. We have provided a ``Dockerfile`` under this directory to build the |
||||
environment. It has been tested with Docker 1.6.1. |
||||
|
||||
To build a image: |
||||
|
||||
``` |
||||
$ docker build -t protoc-artifacts . |
||||
``` |
||||
|
||||
To run the image: |
||||
|
||||
``` |
||||
$ docker run -it --rm=true protoc-artifacts bash |
||||
``` |
||||
|
||||
To checkout protobuf (run within the container): |
||||
|
||||
``` |
||||
$ # Replace v3.5.1 with the version you want |
||||
$ wget -O - https://github.com/protocolbuffers/protobuf/archive/v3.5.1.tar.gz | tar xvzp |
||||
``` |
||||
|
||||
### Windows build |
||||
We no longer use scripts in this directory to build windows artifacts. Instead, |
||||
we use Visual Studio 2015 to build our windows release artifacts. See our |
||||
[kokoro windows build scripts here](../kokoro/release/protoc/windows/build.bat). |
||||
|
||||
To upload windows artifacts, copy the built binaries into this directory and |
||||
put it into the target/windows/(x86_64|x86_32) directory the same way as the |
||||
artifacts for other platforms. That will allow the maven script to find and |
||||
upload the artifacts to maven. |
||||
|
||||
## To push artifacts to Maven Central |
||||
Before you can upload artifacts to Maven Central repository, make sure you have |
||||
read [this page](http://central.sonatype.org/pages/apache-maven.html) on how to |
||||
configure GPG and Sonatype account. |
||||
|
||||
Before you do the deployment, make sure you have built the protoc artifacts for |
||||
every supported platform and put them under the target directory. Example |
||||
target directory layout: |
||||
|
||||
+ pom.xml |
||||
+ target |
||||
+ linux |
||||
+ x86_64 |
||||
protoc.exe |
||||
+ x86_32 |
||||
protoc.exe |
||||
+ aarch_64 |
||||
protoc.exe |
||||
+ ppcle_64 |
||||
protoc.exe |
||||
+ s390_64 |
||||
protoc.exe |
||||
+ osx |
||||
+ x86_64 |
||||
protoc.exe |
||||
+ x86_32 |
||||
protoc.exe |
||||
+ windows |
||||
+ x86_64 |
||||
protoc.exe |
||||
+ x86_32 |
||||
protoc.exe |
||||
|
||||
You will need to build the artifacts on multiple machines and gather them |
||||
together into one place. |
||||
|
||||
Use the following command to deploy artifacts for the host platform to a |
||||
staging repository. |
||||
|
||||
``` |
||||
$ mvn deploy -P release |
||||
``` |
||||
|
||||
It creates a new staging repository. Go to |
||||
https://oss.sonatype.org/#stagingRepositories and find the repository, usually |
||||
in the name like ``comgoogle-123``. Verify that the staging repository has all |
||||
the binaries, close and release this repository. |
||||
|
||||
|
||||
## Tested build environments |
||||
We have successfully built artifacts on the following environments: |
||||
- Linux x86_32 and x86_64: |
||||
- Centos 6.9 (within Docker 1.6.1) |
||||
- Ubuntu 14.04.5 64-bit |
||||
- Linux aarch_64: Cross compiled with `g++-aarch64-linux-gnu` on Ubuntu 14.04.5 64-bit |
||||
- Mac OS X x86_32 and x86_64: Mac OS X 10.9.5 |
@ -1,120 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
if [ $# -ne 2 ]; then |
||||
cat <<EOF |
||||
Usage: $0 <TARGET> <VERSION_NUMBER> |
||||
|
||||
TARGET: protoc | protoc-gen-javalite |
||||
|
||||
Example: |
||||
$ $0 protoc 3.0.0 |
||||
$ $0 protoc-gen-javalite 3.0.0 |
||||
|
||||
This script will download pre-built protoc or protoc plugin binaries from maven |
||||
repository and create .zip packages suitable to be included in the github |
||||
release page. If the target is protoc, well-known type .proto files will also be |
||||
included. Each invocation will create 8 zip packages: |
||||
dist/<TARGET>-<VERSION_NUMBER>-win32.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-win64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-osx-aarch_64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-linux-aarch_64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-linux-ppcle_64.zip |
||||
dist/<TARGET>-<VERSION_NUMBER>-linux-s390_64.zip |
||||
EOF |
||||
exit 1 |
||||
fi |
||||
|
||||
TARGET=$1 |
||||
VERSION_NUMBER=$2 |
||||
|
||||
# <zip file name> <binary file name> pairs. |
||||
declare -a FILE_NAMES=( \ |
||||
win32.zip windows-x86_32.exe \ |
||||
win64.zip windows-x86_64.exe \ |
||||
osx-aarch_64.zip osx-aarch_64.exe \ |
||||
osx-x86_64.zip osx-x86_64.exe \ |
||||
linux-x86_32.zip linux-x86_32.exe \ |
||||
linux-x86_64.zip linux-x86_64.exe \ |
||||
linux-aarch_64.zip linux-aarch_64.exe \ |
||||
linux-ppcle_64.zip linux-ppcle_64.exe \ |
||||
linux-s390_64.zip linux-s390_64.exe \ |
||||
) |
||||
|
||||
# List of all well-known types to be included. |
||||
declare -a WELL_KNOWN_TYPES=( \ |
||||
google/protobuf/descriptor.proto \ |
||||
google/protobuf/any.proto \ |
||||
google/protobuf/api.proto \ |
||||
google/protobuf/duration.proto \ |
||||
google/protobuf/empty.proto \ |
||||
google/protobuf/field_mask.proto \ |
||||
google/protobuf/source_context.proto \ |
||||
google/protobuf/struct.proto \ |
||||
google/protobuf/timestamp.proto \ |
||||
google/protobuf/type.proto \ |
||||
google/protobuf/wrappers.proto \ |
||||
google/protobuf/compiler/plugin.proto \ |
||||
) |
||||
|
||||
set -e |
||||
|
||||
# A temporary working directory to put all files. |
||||
DIR=$(mktemp -d) |
||||
|
||||
# Copy over well-known types. |
||||
mkdir -p ${DIR}/include/google/protobuf/compiler |
||||
for PROTO in ${WELL_KNOWN_TYPES[@]}; do |
||||
cp -f ../src/${PROTO} ${DIR}/include/${PROTO} |
||||
done |
||||
|
||||
# Create a readme file. |
||||
cat <<EOF > ${DIR}/readme.txt |
||||
Protocol Buffers - Google's data interchange format |
||||
Copyright 2008 Google Inc. |
||||
https://developers.google.com/protocol-buffers/ |
||||
|
||||
This package contains a precompiled binary version of the protocol buffer |
||||
compiler (protoc). This binary is intended for users who want to use Protocol |
||||
Buffers in languages other than C++ but do not want to compile protoc |
||||
themselves. To install, simply place this binary somewhere in your PATH. |
||||
|
||||
If you intend to use the included well known types then don't forget to |
||||
copy the contents of the 'include' directory somewhere as well, for example |
||||
into '/usr/local/include/'. |
||||
|
||||
Please refer to our official github site for more installation instructions: |
||||
https://github.com/protocolbuffers/protobuf |
||||
EOF |
||||
|
||||
mkdir -p dist |
||||
mkdir -p ${DIR}/bin |
||||
# Create a zip file for each binary. |
||||
for((i=0;i<${#FILE_NAMES[@]};i+=2));do |
||||
ZIP_NAME=${FILE_NAMES[$i]} |
||||
if [ ${ZIP_NAME:0:3} = "win" ]; then |
||||
BINARY="$TARGET.exe" |
||||
else |
||||
BINARY="$TARGET" |
||||
fi |
||||
BINARY_NAME=${FILE_NAMES[$(($i+1))]} |
||||
BINARY_URL=https://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME} |
||||
if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then |
||||
echo "[ERROR] Failed to download ${BINARY_URL}" >&2 |
||||
echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2 |
||||
continue |
||||
fi |
||||
TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME} |
||||
pushd $DIR &> /dev/null |
||||
chmod +x bin/$BINARY |
||||
if [ "$TARGET" = "protoc" ]; then |
||||
zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null |
||||
else |
||||
zip -r ${TARGET_ZIP_FILE} bin &> /dev/null |
||||
fi |
||||
rm bin/$BINARY |
||||
popd &> /dev/null |
||||
echo "[INFO] Successfully created ${TARGET_ZIP_FILE}" |
||||
done |
@ -1,144 +0,0 @@ |
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
<parent> |
||||
<groupId>com.google</groupId> |
||||
<artifactId>google</artifactId> |
||||
<version>5</version> |
||||
</parent> |
||||
<groupId>com.google.protobuf</groupId> |
||||
<artifactId>protoc</artifactId> |
||||
<version>3.21.6</version> |
||||
<packaging>pom</packaging> |
||||
<name>Protobuf Compiler</name> |
||||
<description> |
||||
Protobuf Compiler (protoc) is a compiler for .proto files. It generates |
||||
language-specific code for Protobuf messages and RPC interfaces. |
||||
</description> |
||||
<inceptionYear>2008</inceptionYear> |
||||
<url>https://developers.google.com/protocol-buffers/</url> |
||||
<licenses> |
||||
<license> |
||||
<name>BSD-3-Clause</name> |
||||
<url>https://opensource.org/licenses/BSD-3-Clause</url> |
||||
<distribution>repo</distribution> |
||||
</license> |
||||
</licenses> |
||||
<scm> |
||||
<url>https://github.com/protocolbuffers/protobuf</url> |
||||
<connection> |
||||
scm:git:https://github.com/protocolbuffers/protobuf.git |
||||
</connection> |
||||
</scm> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>build-helper-maven-plugin</artifactId> |
||||
<version>1.8</version> |
||||
<executions> |
||||
<execution> |
||||
<id>attach-artifacts</id> |
||||
<phase>package</phase> |
||||
<goals> |
||||
<goal>attach-artifact</goal> |
||||
</goals> |
||||
<configuration> |
||||
<artifacts> |
||||
<artifact> |
||||
<file>${basedir}/target/linux/x86_64/protoc.exe</file> |
||||
<classifier>linux-x86_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/linux/x86_32/protoc.exe</file> |
||||
<classifier>linux-x86_32</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/windows/x86_64/protoc.exe</file> |
||||
<classifier>windows-x86_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/windows/x86_32/protoc.exe</file> |
||||
<classifier>windows-x86_32</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/osx/x86_64/protoc.exe</file> |
||||
<classifier>osx-x86_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/osx/aarch_64/protoc.exe</file> |
||||
<classifier>osx-aarch_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/linux/aarch_64/protoc.exe</file> |
||||
<classifier>linux-aarch_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/linux/ppcle_64/protoc.exe</file> |
||||
<classifier>linux-ppcle_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
<artifact> |
||||
<file>${basedir}/target/linux/s390_64/protoc.exe</file> |
||||
<classifier>linux-s390_64</classifier> |
||||
<type>exe</type> |
||||
</artifact> |
||||
</artifacts> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
<profiles> |
||||
<profile> |
||||
<id>release</id> |
||||
<properties> |
||||
<!-- Specify the staging repository to deploy to. This can be left |
||||
empty for the first deployment, and Sonatype will create one. For |
||||
subsequent deployments it should be set to what Sonatype has |
||||
created, so that all deployments will go to the same repository. |
||||
--> |
||||
<staging.repository/> |
||||
</properties> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-gpg-plugin</artifactId> |
||||
<version>1.5</version> |
||||
<executions> |
||||
<execution> |
||||
<id>sign-artifacts</id> |
||||
<phase>verify</phase> |
||||
<goals> |
||||
<goal>sign</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.sonatype.plugins</groupId> |
||||
<artifactId>nexus-staging-maven-plugin</artifactId> |
||||
<version>1.6.3</version> |
||||
<extensions>true</extensions> |
||||
<configuration> |
||||
<serverId>sonatype-nexus-staging</serverId> |
||||
<nexusUrl>https://oss.sonatype.org/</nexusUrl> |
||||
<skipStagingRepositoryClose>true</skipStagingRepositoryClose> |
||||
<autoReleaseAfterClose>false</autoReleaseAfterClose> |
||||
<stagingRepositoryId>${staging.repository}</stagingRepositoryId> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</profile> |
||||
</profiles> |
||||
</project> |
@ -1,13 +0,0 @@ |
||||
#!/bin/bash |
||||
set -eu -o pipefail |
||||
|
||||
quote() { |
||||
local arg |
||||
for arg in "$@"; do |
||||
printf "'" |
||||
printf "%s" "$arg" | sed -e "s/'/'\\\\''/g" |
||||
printf "' " |
||||
done |
||||
} |
||||
|
||||
exec scl enable devtoolset-2 "$(quote "$@")" |
@ -0,0 +1,225 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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 Inc. 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 THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS 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.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
|
||||
#include "google/protobuf/compiler/csharp/names.h" |
||||
|
||||
#include <string> |
||||
|
||||
#include "absl/strings/str_replace.h" |
||||
#include "google/protobuf/compiler/csharp/names.h" |
||||
#include "google/protobuf/descriptor.pb.h" |
||||
|
||||
// Must be last.
|
||||
#include "google/protobuf/port_def.inc" |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace csharp { |
||||
|
||||
namespace { |
||||
|
||||
std::string StripDotProto(const std::string& proto_file) { |
||||
int lastindex = proto_file.find_last_of('.'); |
||||
return proto_file.substr(0, lastindex); |
||||
} |
||||
|
||||
// Returns the Pascal-cased last part of the proto file. For example,
|
||||
// input of "google/protobuf/foo_bar.proto" would result in "FooBar".
|
||||
std::string GetFileNameBase(const FileDescriptor* descriptor) { |
||||
std::string proto_file = descriptor->name(); |
||||
int lastslash = proto_file.find_last_of('/'); |
||||
std::string base = proto_file.substr(lastslash + 1); |
||||
return UnderscoresToPascalCase(StripDotProto(base)); |
||||
} |
||||
|
||||
std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { |
||||
std::string result = GetFileNamespace(file); |
||||
if (!result.empty()) { |
||||
result += '.'; |
||||
} |
||||
std::string classname; |
||||
if (file->package().empty()) { |
||||
classname = name; |
||||
} else { |
||||
// Strip the proto package from full_name since we've replaced it with
|
||||
// the C# namespace.
|
||||
classname = name.substr(file->package().size() + 1); |
||||
} |
||||
result += absl::StrReplaceAll(classname, {{".", ".Types."}}); |
||||
return "global::" + result; |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
std::string GetFileNamespace(const FileDescriptor* descriptor) { |
||||
if (descriptor->options().has_csharp_namespace()) { |
||||
return descriptor->options().csharp_namespace(); |
||||
} |
||||
return UnderscoresToCamelCase(descriptor->package(), true, true); |
||||
} |
||||
|
||||
std::string GetClassName(const Descriptor* descriptor) { |
||||
return ToCSharpName(descriptor->full_name(), descriptor->file()); |
||||
} |
||||
|
||||
std::string GetClassName(const EnumDescriptor* descriptor) { |
||||
return ToCSharpName(descriptor->full_name(), descriptor->file()); |
||||
} |
||||
|
||||
std::string GetReflectionClassUnqualifiedName(const FileDescriptor* descriptor) { |
||||
// TODO: Detect collisions with existing messages,
|
||||
// and append an underscore if necessary.
|
||||
return GetFileNameBase(descriptor) + "Reflection"; |
||||
} |
||||
|
||||
std::string GetReflectionClassName(const FileDescriptor* descriptor) { |
||||
std::string result = GetFileNamespace(descriptor); |
||||
if (!result.empty()) { |
||||
result += '.'; |
||||
} |
||||
result += GetReflectionClassUnqualifiedName(descriptor); |
||||
return "global::" + result; |
||||
} |
||||
|
||||
std::string GetExtensionClassUnqualifiedName(const FileDescriptor* descriptor) { |
||||
// TODO: Detect collisions with existing messages,
|
||||
// and append an underscore if necessary.
|
||||
return GetFileNameBase(descriptor) + "Extensions"; |
||||
} |
||||
|
||||
std::string GetOutputFile(const FileDescriptor* descriptor, |
||||
const std::string file_extension, |
||||
const bool generate_directories, |
||||
const std::string base_namespace, |
||||
std::string* error) { |
||||
std::string relative_filename = GetFileNameBase(descriptor) + file_extension; |
||||
if (!generate_directories) { |
||||
return relative_filename; |
||||
} |
||||
std::string ns = GetFileNamespace(descriptor); |
||||
std::string namespace_suffix = ns; |
||||
if (!base_namespace.empty()) { |
||||
// Check that the base_namespace is either equal to or a leading part of
|
||||
// the file namespace. This isn't just a simple prefix; "Foo.B" shouldn't
|
||||
// be regarded as a prefix of "Foo.Bar". The simplest option is to add "."
|
||||
// to both.
|
||||
std::string extended_ns = ns + "."; |
||||
if (extended_ns.find(base_namespace + ".") != 0) { |
||||
*error = "Namespace " + ns + " is not a prefix namespace of base namespace " + base_namespace; |
||||
return ""; // This will be ignored, because we've set an error.
|
||||
} |
||||
namespace_suffix = ns.substr(base_namespace.length()); |
||||
if (namespace_suffix.find('.') == 0) { |
||||
namespace_suffix = namespace_suffix.substr(1); |
||||
} |
||||
} |
||||
|
||||
std::string namespace_dir = |
||||
absl::StrReplaceAll(namespace_suffix, {{".", "/"}}); |
||||
if (!namespace_dir.empty()) { |
||||
namespace_dir += "/"; |
||||
} |
||||
return namespace_dir + relative_filename; |
||||
} |
||||
|
||||
std::string UnderscoresToPascalCase(const std::string& input) { |
||||
return UnderscoresToCamelCase(input, true); |
||||
} |
||||
|
||||
// TODO(jtattermusch): can we reuse a utility function?
|
||||
std::string UnderscoresToCamelCase(const std::string& input, |
||||
bool cap_next_letter, |
||||
bool preserve_period) { |
||||
std::string result; |
||||
|
||||
// Note: I distrust ctype.h due to locales.
|
||||
for (int i = 0; i < input.size(); i++) { |
||||
if ('a' <= input[i] && input[i] <= 'z') { |
||||
if (cap_next_letter) { |
||||
result += input[i] + ('A' - 'a'); |
||||
} else { |
||||
result += input[i]; |
||||
} |
||||
cap_next_letter = false; |
||||
} else if ('A' <= input[i] && input[i] <= 'Z') { |
||||
if (i == 0 && !cap_next_letter) { |
||||
// Force first letter to lower-case unless explicitly told to
|
||||
// capitalize it.
|
||||
result += input[i] + ('a' - 'A'); |
||||
} else { |
||||
// Capital letters after the first are left as-is.
|
||||
result += input[i]; |
||||
} |
||||
cap_next_letter = false; |
||||
} else if ('0' <= input[i] && input[i] <= '9') { |
||||
result += input[i]; |
||||
cap_next_letter = true; |
||||
} else { |
||||
cap_next_letter = true; |
||||
if (input[i] == '.' && preserve_period) { |
||||
result += '.'; |
||||
} |
||||
} |
||||
} |
||||
// Add a trailing "_" if the name should be altered.
|
||||
if (input.size() > 0 && input[input.size() - 1] == '#') { |
||||
result += '_'; |
||||
} |
||||
|
||||
// https://github.com/protocolbuffers/protobuf/issues/8101
|
||||
// To avoid generating invalid identifiers - if the input string
|
||||
// starts with _<digit> (or multiple underscores then digit) then
|
||||
// we need to preserve the underscore as an identifier cannot start
|
||||
// with a digit.
|
||||
// This check is being done after the loop rather than before
|
||||
// to handle the case where there are multiple underscores before the
|
||||
// first digit. We let them all be consumed so we can see if we would
|
||||
// start with a digit.
|
||||
// Note: not preserving leading underscores for all otherwise valid identifiers
|
||||
// so as to not break anything that relies on the existing behaviour
|
||||
if (result.size() > 0 && ('0' <= result[0] && result[0] <= '9') |
||||
&& input.size() > 0 && input[0] == '_') |
||||
{ |
||||
result.insert(0, 1, '_'); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
} // namespace csharp
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc" |
@ -0,0 +1,193 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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 Inc. 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 THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS 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.
|
||||
|
||||
// Author: kenton@google.com (Kenton Varda)
|
||||
// Based on original Protocol Buffers design by
|
||||
// Sanjay Ghemawat, Jeff Dean, and others.
|
||||
|
||||
#include "google/protobuf/compiler/java/names.h" |
||||
|
||||
#include <string> |
||||
|
||||
#include "absl/container/flat_hash_set.h" |
||||
#include "google/protobuf/compiler/java/helpers.h" |
||||
#include "google/protobuf/compiler/java/name_resolver.h" |
||||
#include "google/protobuf/compiler/java/names.h" |
||||
#include "google/protobuf/compiler/java/options.h" |
||||
#include "google/protobuf/descriptor.pb.h" |
||||
|
||||
// Must be last.
|
||||
#include "google/protobuf/port_def.inc" |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace java { |
||||
|
||||
namespace { |
||||
|
||||
const char* DefaultPackage(Options options) { |
||||
return options.opensource_runtime ? "" : "com.google.protos"; |
||||
} |
||||
|
||||
bool IsReservedName(absl::string_view name) { |
||||
static const auto& kReservedNames = |
||||
*new absl::flat_hash_set<absl::string_view>({ |
||||
"abstract", "assert", "boolean", "break", "byte", |
||||
"case", "catch", "char", "class", "const", |
||||
"continue", "default", "do", "double", "else", |
||||
"enum", "extends", "final", "finally", "float", |
||||
"for", "goto", "if", "implements", "import", |
||||
"instanceof", "int", "interface", "long", "native", |
||||
"new", "package", "private", "protected", "public", |
||||
"return", "short", "static", "strictfp", "super", |
||||
"switch", "synchronized", "this", "throw", "throws", |
||||
"transient", "try", "void", "volatile", "while", |
||||
}); |
||||
return kReservedNames.contains(name); |
||||
} |
||||
|
||||
bool IsForbidden(const std::string& field_name) { |
||||
// 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
|
||||
static const auto& kForbiddenNames = |
||||
*new absl::flat_hash_set<absl::string_view>({ |
||||
// 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", |
||||
}); |
||||
return kForbiddenNames.contains(UnderscoresToCamelCase(field_name, true)); |
||||
} |
||||
|
||||
std::string FieldName(const FieldDescriptor* field) { |
||||
std::string field_name; |
||||
// Groups are hacky: The name of the field is just the lower-cased name
|
||||
// of the group type. In Java, though, we would like to retain the original
|
||||
// capitalization of the type name.
|
||||
if (GetType(field) == FieldDescriptor::TYPE_GROUP) { |
||||
field_name = field->message_type()->name(); |
||||
} else { |
||||
field_name = field->name(); |
||||
} |
||||
if (IsForbidden(field_name)) { |
||||
// Append a trailing "#" to indicate that the name should be decorated to
|
||||
// avoid collision with other names.
|
||||
field_name += "#"; |
||||
} |
||||
return field_name; |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
std::string ClassName(const Descriptor* descriptor) { |
||||
ClassNameResolver name_resolver; |
||||
return name_resolver.GetClassName(descriptor, true); |
||||
} |
||||
|
||||
std::string ClassName(const EnumDescriptor* descriptor) { |
||||
ClassNameResolver name_resolver; |
||||
return name_resolver.GetClassName(descriptor, true); |
||||
} |
||||
|
||||
std::string ClassName(const ServiceDescriptor* descriptor) { |
||||
ClassNameResolver name_resolver; |
||||
return name_resolver.GetClassName(descriptor, true); |
||||
} |
||||
|
||||
std::string ClassName(const FileDescriptor* descriptor) { |
||||
ClassNameResolver name_resolver; |
||||
return name_resolver.GetClassName(descriptor, true); |
||||
} |
||||
|
||||
std::string FileJavaPackage(const FileDescriptor* file, bool immutable, |
||||
Options options) { |
||||
std::string result; |
||||
|
||||
if (file->options().has_java_package()) { |
||||
result = file->options().java_package(); |
||||
} else { |
||||
result = DefaultPackage(options); |
||||
if (!file->package().empty()) { |
||||
if (!result.empty()) result += '.'; |
||||
result += file->package(); |
||||
} |
||||
} |
||||
|
||||
return result; |
||||
} |
||||
|
||||
std::string FileJavaPackage(const FileDescriptor* file, Options options) { |
||||
return FileJavaPackage(file, true /* immutable */, options); |
||||
} |
||||
|
||||
std::string CapitalizedFieldName(const FieldDescriptor* field) { |
||||
return UnderscoresToCamelCase(FieldName(field), true); |
||||
} |
||||
|
||||
std::string UnderscoresToCamelCase(const FieldDescriptor* field) { |
||||
return UnderscoresToCamelCase(FieldName(field), false); |
||||
} |
||||
|
||||
std::string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field) { |
||||
return UnderscoresToCamelCase(FieldName(field), true); |
||||
} |
||||
|
||||
std::string UnderscoresToCamelCase(const MethodDescriptor* method) { |
||||
return UnderscoresToCamelCase(method->name(), false); |
||||
} |
||||
|
||||
std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor* field) { |
||||
std::string name = UnderscoresToCamelCase(field); |
||||
if (IsReservedName(name)) { |
||||
return name + "_"; |
||||
} |
||||
return name; |
||||
} |
||||
|
||||
} // namespace java
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc" |
@ -0,0 +1,363 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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 Inc. 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 THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS 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.
|
||||
|
||||
// Helper functions for generating ObjectiveC code.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__ |
||||
#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__ |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
#include "google/protobuf/descriptor.h" |
||||
#include "google/protobuf/descriptor.pb.h" |
||||
#include "google/protobuf/io/zero_copy_stream.h" |
||||
|
||||
// clang-format off
|
||||
#include "google/protobuf/port_def.inc" |
||||
// clang-format on
|
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace objectivec { |
||||
|
||||
// Get/Set the path to a file to load for objc class prefix lookups.
|
||||
std::string PROTOC_EXPORT GetPackageToPrefixMappingsPath(); |
||||
void PROTOC_EXPORT SetPackageToPrefixMappingsPath( |
||||
const std::string& file_path); |
||||
// 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
|
||||
// are exported.
|
||||
bool PROTOC_EXPORT UseProtoPackageAsDefaultPrefix(); |
||||
void PROTOC_EXPORT SetUseProtoPackageAsDefaultPrefix(bool on_or_off); |
||||
// Get/Set the path to a file to load as exceptions when
|
||||
// `UseProtoPackageAsDefaultPrefix()` is `true`. An empty string means there
|
||||
// should be no exceptions.
|
||||
std::string PROTOC_EXPORT GetProtoPackagePrefixExceptionList(); |
||||
void PROTOC_EXPORT SetProtoPackagePrefixExceptionList( |
||||
const std::string& file_path); |
||||
// Get/Set a prefix to add before the prefix generated from the package name.
|
||||
// This is only used when UseProtoPackageAsDefaultPrefix() is True.
|
||||
std::string PROTOC_EXPORT GetForcedPackagePrefix(); |
||||
void PROTOC_EXPORT SetForcedPackagePrefix(const std::string& prefix); |
||||
|
||||
// Generator Prefix Validation Options (see objectivec_generator.cc for a
|
||||
// description of each):
|
||||
struct Options { |
||||
Options(); |
||||
std::string expected_prefixes_path; |
||||
std::vector<std::string> expected_prefixes_suppressions; |
||||
bool prefixes_must_be_registered; |
||||
bool require_prefixes; |
||||
}; |
||||
|
||||
// Escape C++ trigraphs by escaping question marks to "\?".
|
||||
std::string PROTOC_EXPORT EscapeTrigraphs(absl::string_view to_escape); |
||||
|
||||
// Remove white space from either end of a absl::string_view.
|
||||
void PROTOC_EXPORT TrimWhitespace(absl::string_view* input); |
||||
|
||||
// Returns true if the name requires a ns_returns_not_retained attribute applied
|
||||
// to it.
|
||||
bool PROTOC_EXPORT IsRetainedName(const std::string& name); |
||||
|
||||
// Returns true if the name starts with "init" and will need to have special
|
||||
// handling under ARC.
|
||||
bool PROTOC_EXPORT IsInitName(const std::string& name); |
||||
|
||||
// Returns true if the name requires a cf_returns_not_retained attribute applied
|
||||
// to it.
|
||||
bool PROTOC_EXPORT IsCreateName(const std::string& name); |
||||
|
||||
// Gets the objc_class_prefix or the prefix made from the proto package.
|
||||
std::string PROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); |
||||
|
||||
// Gets the path of the file we're going to generate (sans the .pb.h
|
||||
// extension). The path will be dependent on the objectivec package
|
||||
// declared in the proto package.
|
||||
std::string PROTOC_EXPORT FilePath(const FileDescriptor* file); |
||||
|
||||
// Just like FilePath(), but without the directory part.
|
||||
std::string PROTOC_EXPORT FilePathBasename(const FileDescriptor* file); |
||||
|
||||
// Gets the name of the root class we'll generate in the file. This class
|
||||
// is not meant for external consumption, but instead contains helpers that
|
||||
// the rest of the classes need
|
||||
std::string PROTOC_EXPORT FileClassName(const FileDescriptor* file); |
||||
|
||||
// These return the fully-qualified class name corresponding to the given
|
||||
// descriptor.
|
||||
std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor); |
||||
std::string PROTOC_EXPORT ClassName(const Descriptor* descriptor, |
||||
std::string* out_suffix_added); |
||||
std::string PROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); |
||||
|
||||
// Returns the fully-qualified name of the enum value corresponding to the
|
||||
// the descriptor.
|
||||
std::string PROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); |
||||
|
||||
// Returns the name of the enum value corresponding to the descriptor.
|
||||
std::string PROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor); |
||||
|
||||
// Reverse what an enum does.
|
||||
std::string PROTOC_EXPORT UnCamelCaseEnumShortName(const std::string& name); |
||||
|
||||
// Returns the name to use for the extension (used as the method off the file's
|
||||
// Root class).
|
||||
std::string PROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor); |
||||
|
||||
// Returns the transformed field name.
|
||||
std::string PROTOC_EXPORT FieldName(const FieldDescriptor* field); |
||||
std::string PROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); |
||||
|
||||
// Returns the transformed oneof name.
|
||||
std::string PROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); |
||||
std::string PROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); |
||||
std::string PROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor); |
||||
|
||||
// Returns a symbol that can be used in C code to refer to an Objective C
|
||||
// class without initializing the class.
|
||||
std::string PROTOC_EXPORT ObjCClass(const std::string& class_name); |
||||
|
||||
// Declares an Objective C class without initializing the class so that it can
|
||||
// be refrerred to by ObjCClass.
|
||||
std::string PROTOC_EXPORT ObjCClassDeclaration(const std::string& class_name); |
||||
|
||||
inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) { |
||||
return file->syntax() == FileDescriptor::SYNTAX_PROTO3; |
||||
} |
||||
|
||||
inline bool IsMapEntryMessage(const Descriptor* descriptor) { |
||||
return descriptor->options().map_entry(); |
||||
} |
||||
|
||||
// Reverse of the above.
|
||||
std::string PROTOC_EXPORT UnCamelCaseFieldName(const std::string& name, |
||||
const FieldDescriptor* field); |
||||
|
||||
enum ObjectiveCType { |
||||
OBJECTIVECTYPE_INT32, |
||||
OBJECTIVECTYPE_UINT32, |
||||
OBJECTIVECTYPE_INT64, |
||||
OBJECTIVECTYPE_UINT64, |
||||
OBJECTIVECTYPE_FLOAT, |
||||
OBJECTIVECTYPE_DOUBLE, |
||||
OBJECTIVECTYPE_BOOLEAN, |
||||
OBJECTIVECTYPE_STRING, |
||||
OBJECTIVECTYPE_DATA, |
||||
OBJECTIVECTYPE_ENUM, |
||||
OBJECTIVECTYPE_MESSAGE |
||||
}; |
||||
|
||||
enum FlagType { |
||||
FLAGTYPE_DESCRIPTOR_INITIALIZATION, |
||||
FLAGTYPE_EXTENSION, |
||||
FLAGTYPE_FIELD |
||||
}; |
||||
|
||||
template <class TDescriptor> |
||||
std::string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, |
||||
const FileDescriptor* file = NULL, |
||||
bool preSpace = true, |
||||
bool postNewline = false) { |
||||
bool isDeprecated = descriptor->options().deprecated(); |
||||
// The file is only passed when checking Messages & Enums, so those types
|
||||
// get tagged. At the moment, it doesn't seem to make sense to tag every
|
||||
// field or enum value with when the file is deprecated.
|
||||
bool isFileLevelDeprecation = false; |
||||
if (!isDeprecated && file) { |
||||
isFileLevelDeprecation = file->options().deprecated(); |
||||
isDeprecated = isFileLevelDeprecation; |
||||
} |
||||
if (isDeprecated) { |
||||
std::string message; |
||||
const FileDescriptor* sourceFile = descriptor->file(); |
||||
if (isFileLevelDeprecation) { |
||||
message = sourceFile->name() + " is deprecated."; |
||||
} else { |
||||
message = descriptor->full_name() + " is deprecated (see " + |
||||
sourceFile->name() + ")."; |
||||
} |
||||
|
||||
std::string result = std::string("GPB_DEPRECATED_MSG(\"") + message + "\")"; |
||||
if (preSpace) { |
||||
result.insert(0, " "); |
||||
} |
||||
if (postNewline) { |
||||
result.append("\n"); |
||||
} |
||||
return result; |
||||
} else { |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
std::string PROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field); |
||||
|
||||
ObjectiveCType PROTOC_EXPORT |
||||
GetObjectiveCType(FieldDescriptor::Type field_type); |
||||
|
||||
inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { |
||||
return GetObjectiveCType(field->type()); |
||||
} |
||||
|
||||
bool PROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field); |
||||
bool PROTOC_EXPORT IsReferenceType(const FieldDescriptor* field); |
||||
|
||||
std::string PROTOC_EXPORT |
||||
GPBGenericValueFieldName(const FieldDescriptor* field); |
||||
std::string PROTOC_EXPORT DefaultValue(const FieldDescriptor* field); |
||||
bool PROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field); |
||||
|
||||
std::string PROTOC_EXPORT |
||||
BuildFlagsString(const FlagType type, const std::vector<std::string>& strings); |
||||
|
||||
// Builds HeaderDoc/appledoc style comments out of the comments in the .proto
|
||||
// file.
|
||||
std::string PROTOC_EXPORT BuildCommentsString(const SourceLocation& location, |
||||
bool prefer_single_line); |
||||
|
||||
// The name the commonly used by the library when built as a framework.
|
||||
// This lines up to the name used in the CocoaPod.
|
||||
extern PROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; |
||||
// Returns the CPP symbol name to use as the gate for framework style imports
|
||||
// for the given framework name to use.
|
||||
std::string PROTOC_EXPORT |
||||
ProtobufFrameworkImportSymbol(const std::string& framework_name); |
||||
|
||||
// Checks if the file is one of the proto's bundled with the library.
|
||||
bool PROTOC_EXPORT |
||||
IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); |
||||
|
||||
// Checks the prefix for the given files and outputs any warnings as needed. If
|
||||
// there are flat out errors, then out_error is filled in with the first error
|
||||
// and the result is false.
|
||||
bool PROTOC_EXPORT ValidateObjCClassPrefixes( |
||||
const std::vector<const FileDescriptor*>& files, |
||||
const Options& validation_options, std::string* out_error); |
||||
// Same was the other ValidateObjCClassPrefixes() calls, but the options all
|
||||
// come from the environment variables.
|
||||
bool PROTOC_EXPORT ValidateObjCClassPrefixes( |
||||
const std::vector<const FileDescriptor*>& files, std::string* out_error); |
||||
|
||||
// Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform
|
||||
// the input into the expected output.
|
||||
class PROTOC_EXPORT TextFormatDecodeData { |
||||
public: |
||||
TextFormatDecodeData(); |
||||
~TextFormatDecodeData(); |
||||
|
||||
TextFormatDecodeData(const TextFormatDecodeData&) = delete; |
||||
TextFormatDecodeData& operator=(const TextFormatDecodeData&) = delete; |
||||
|
||||
void AddString(int32_t key, const std::string& input_for_decode, |
||||
const std::string& desired_output); |
||||
size_t num_entries() const { return entries_.size(); } |
||||
std::string Data() const; |
||||
|
||||
static std::string DecodeDataForString(const std::string& input_for_decode, |
||||
const std::string& desired_output); |
||||
|
||||
private: |
||||
typedef std::pair<int32_t, std::string> DataEntry; |
||||
std::vector<DataEntry> entries_; |
||||
}; |
||||
|
||||
// Helper for parsing simple files.
|
||||
class PROTOC_EXPORT LineConsumer { |
||||
public: |
||||
LineConsumer(); |
||||
virtual ~LineConsumer(); |
||||
virtual bool ConsumeLine(const absl::string_view& line, std::string* out_error) = 0; |
||||
}; |
||||
|
||||
bool PROTOC_EXPORT ParseSimpleFile(const std::string& path, |
||||
LineConsumer* line_consumer, |
||||
std::string* out_error); |
||||
|
||||
bool PROTOC_EXPORT ParseSimpleStream(io::ZeroCopyInputStream& input_stream, |
||||
const std::string& stream_name, |
||||
LineConsumer* line_consumer, |
||||
std::string* out_error); |
||||
|
||||
// Helper class for parsing framework import mappings and generating
|
||||
// import statements.
|
||||
class PROTOC_EXPORT ImportWriter { |
||||
public: |
||||
ImportWriter(const std::string& generate_for_named_framework, |
||||
const std::string& named_framework_to_proto_path_mappings_path, |
||||
const std::string& runtime_import_prefix, |
||||
bool include_wkt_imports); |
||||
~ImportWriter(); |
||||
|
||||
void AddFile(const FileDescriptor* file, const std::string& header_extension); |
||||
void Print(io::Printer* printer) const; |
||||
|
||||
static void PrintRuntimeImports(io::Printer* printer, |
||||
const std::vector<std::string>& header_to_import, |
||||
const std::string& runtime_import_prefix, |
||||
bool default_cpp_symbol = false); |
||||
|
||||
private: |
||||
class ProtoFrameworkCollector : public LineConsumer { |
||||
public: |
||||
ProtoFrameworkCollector(std::map<std::string, std::string>* inout_proto_file_to_framework_name) |
||||
: map_(inout_proto_file_to_framework_name) {} |
||||
|
||||
virtual bool ConsumeLine(const absl::string_view& line, std::string* out_error) override; |
||||
|
||||
private: |
||||
std::map<std::string, std::string>* map_; |
||||
}; |
||||
|
||||
void ParseFrameworkMappings(); |
||||
|
||||
const std::string generate_for_named_framework_; |
||||
const std::string named_framework_to_proto_path_mappings_path_; |
||||
const std::string runtime_import_prefix_; |
||||
const bool include_wkt_imports_; |
||||
std::map<std::string, std::string> proto_file_to_framework_name_; |
||||
bool need_to_parse_mapping_file_; |
||||
|
||||
std::vector<std::string> protobuf_imports_; |
||||
std::vector<std::string> other_framework_imports_; |
||||
std::vector<std::string> other_imports_; |
||||
}; |
||||
|
||||
} // namespace objectivec
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc" |
||||
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_NAMES_H__
|
@ -0,0 +1,144 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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 Inc. 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 THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS 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 "google/protobuf/compiler/php/names.h" |
||||
|
||||
#include <string> |
||||
|
||||
#include "google/protobuf/compiler/code_generator.h" |
||||
#include "google/protobuf/compiler/plugin.h" |
||||
#include "google/protobuf/descriptor.h" |
||||
#include "google/protobuf/descriptor.pb.h" |
||||
|
||||
const char* const kReservedNames[] = { |
||||
"abstract", "and", "array", "as", "break", |
||||
"callable", "case", "catch", "class", "clone", |
||||
"const", "continue", "declare", "default", "die", |
||||
"do", "echo", "else", "elseif", "empty", |
||||
"enddeclare", "endfor", "endforeach", "endif", "endswitch", |
||||
"endwhile", "eval", "exit", "extends", "final", |
||||
"finally", "fn", "for", "foreach", "function", |
||||
"global", "goto", "if", "implements", "include", |
||||
"include_once", "instanceof", "insteadof", "interface", "isset", |
||||
"list", "match", "namespace", "new", "or", |
||||
"parent", "print", "private", "protected", "public", |
||||
"readonly", "require", "require_once", "return", "self", |
||||
"static", "switch", "throw", "trait", "try", |
||||
"unset", "use", "var", "while", "xor", |
||||
"yield", "int", "float", "bool", "string", |
||||
"true", "false", "null", "void", "iterable"}; |
||||
const int kReservedNamesSize = 80; |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace php { |
||||
|
||||
bool IsReservedName(absl::string_view name) { |
||||
std::string lower(name); |
||||
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); |
||||
for (int i = 0; i < kReservedNamesSize; i++) { |
||||
if (lower == kReservedNames[i]) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
std::string ReservedNamePrefix(const std::string& classname, |
||||
const FileDescriptor* file) { |
||||
if (IsReservedName(classname)) { |
||||
if (file->package() == "google.protobuf") { |
||||
return "GPB"; |
||||
} else { |
||||
return "PB"; |
||||
} |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
namespace { |
||||
|
||||
template <typename DescriptorType> |
||||
std::string ClassNamePrefixImpl(const std::string& classname, |
||||
const DescriptorType* desc) { |
||||
const std::string& prefix = (desc->file()->options()).php_class_prefix(); |
||||
if (!prefix.empty()) { |
||||
return prefix; |
||||
} |
||||
|
||||
return ReservedNamePrefix(classname, desc->file()); |
||||
} |
||||
|
||||
template <typename DescriptorType> |
||||
std::string GeneratedClassNameImpl(const DescriptorType* desc) { |
||||
std::string classname = ClassNamePrefixImpl(desc->name(), desc) + desc->name(); |
||||
const Descriptor* containing = desc->containing_type(); |
||||
while (containing != NULL) { |
||||
classname = ClassNamePrefixImpl(containing->name(), desc) + containing->name() |
||||
+ '\\' + classname; |
||||
containing = containing->containing_type(); |
||||
} |
||||
return classname; |
||||
} |
||||
|
||||
std::string GeneratedClassNameImpl(const ServiceDescriptor* desc) { |
||||
std::string classname = desc->name(); |
||||
return ClassNamePrefixImpl(classname, desc) + classname; |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
std::string ClassNamePrefix(const std::string& classname, |
||||
const Descriptor* desc) { |
||||
return ClassNamePrefixImpl(classname, desc); |
||||
} |
||||
std::string ClassNamePrefix(const std::string& classname, |
||||
const EnumDescriptor* desc) { |
||||
return ClassNamePrefixImpl(classname, desc); |
||||
} |
||||
|
||||
std::string GeneratedClassName(const Descriptor* desc) { |
||||
return GeneratedClassNameImpl(desc); |
||||
} |
||||
|
||||
std::string GeneratedClassName(const EnumDescriptor* desc) { |
||||
return GeneratedClassNameImpl(desc); |
||||
} |
||||
|
||||
std::string GeneratedClassName(const ServiceDescriptor* desc) { |
||||
return GeneratedClassNameImpl(desc); |
||||
} |
||||
|
||||
} // namespace php
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
@ -0,0 +1,73 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2008 Google Inc. All rights reserved.
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
// 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 Inc. 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 THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS 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.
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__ |
||||
#define GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__ |
||||
|
||||
#include "google/protobuf/descriptor.h" |
||||
|
||||
#include <string> |
||||
|
||||
#include "absl/strings/string_view.h" |
||||
#include "google/protobuf/port_def.inc" |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace php { |
||||
|
||||
// Whether or not a name is reserved.
|
||||
PROTOC_EXPORT bool IsReservedName(absl::string_view name); |
||||
|
||||
// A prefix to stick in front of reserved names to avoid clashes.
|
||||
PROTOC_EXPORT std::string ReservedNamePrefix(const std::string& classname, |
||||
const FileDescriptor* file); |
||||
|
||||
// A prefix to stick in front of all class names.
|
||||
PROTOC_EXPORT std::string ClassNamePrefix(const std::string& classname, |
||||
const Descriptor* desc); |
||||
PROTOC_EXPORT std::string ClassNamePrefix(const std::string& classname, |
||||
const EnumDescriptor* desc); |
||||
|
||||
// To skip reserved keywords in php, some generated classname are prefixed.
|
||||
// Other code generators may need following API to figure out the actual
|
||||
// classname.
|
||||
PROTOC_EXPORT std::string GeneratedClassName(const Descriptor* desc); |
||||
PROTOC_EXPORT std::string GeneratedClassName(const EnumDescriptor* desc); |
||||
PROTOC_EXPORT std::string GeneratedClassName(const ServiceDescriptor* desc); |
||||
|
||||
} // namespace php
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#include "google/protobuf/port_undef.inc" |
||||
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_PHP_NAMES_H__
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue