mirror of https://github.com/grpc/grpc.git
commit
c613162e1d
630 changed files with 19399 additions and 17245 deletions
@ -0,0 +1,35 @@ |
||||
# this file is auto-generated |
||||
*protoc_lib_deps.py |
||||
|
||||
# no need to format protoc generated files |
||||
*_pb2*.py |
||||
|
||||
# no need to format build-yaml generated files |
||||
*.gen.py |
||||
|
||||
# generated files from a template |
||||
*test/cpp/naming/resolver_component_tests_runner.py |
||||
|
||||
# No BUILD, .bzl files |
||||
*BUILD |
||||
*.bzl |
||||
*.bazelrc |
||||
|
||||
# No other languages |
||||
*.bat |
||||
*.c |
||||
*.c++ |
||||
*.cc |
||||
*.css |
||||
*.go |
||||
*.h |
||||
*.html |
||||
*.json |
||||
*.md |
||||
*.objc |
||||
*.php |
||||
*.proto |
||||
*.rb |
||||
*.sh |
||||
*.xml |
||||
*.yaml |
@ -1,8 +1,12 @@ |
||||
# Module path |
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules) |
||||
|
||||
# Depend packages |
||||
@_gRPC_FIND_ZLIB@ |
||||
@_gRPC_FIND_PROTOBUF@ |
||||
@_gRPC_FIND_SSL@ |
||||
@_gRPC_FIND_CARES@ |
||||
@_gRPC_FIND_ABSL@ |
||||
|
||||
# Targets |
||||
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake) |
||||
|
@ -0,0 +1,48 @@ |
||||
include(FindPackageHandleStandardArgs) |
||||
|
||||
function(__cares_get_version) |
||||
if(c-ares_INCLUDE_DIR AND EXISTS "${c-ares_INCLUDE_DIR}/ares_version.h") |
||||
file(STRINGS "${c-ares_INCLUDE_DIR}/ares_version.h" _cares_version_str REGEX "^#define ARES_VERSION_STR \"([^\n]*)\"$") |
||||
if(_cares_version_str MATCHES "#define ARES_VERSION_STR \"([^\n]*)\"") |
||||
set(c-ares_VERSION "${CMAKE_MATCH_1}" PARENT_SCOPE) |
||||
endif() |
||||
endif() |
||||
endfunction() |
||||
|
||||
# We need to disable version checking, since c-ares does not provide it. |
||||
set(_cares_version_var_suffixes "" _MAJOR _MINOR _PATCH _TWEAK _COUNT) |
||||
foreach(_suffix IN LISTS _cares_version_var_suffixes) |
||||
set(_cares_save_FIND_VERSION${_suffix} ${c-ares_FIND_VERSION${_suffix}}) |
||||
unset(c-ares_FIND_VERSION${_suffix}) |
||||
endforeach() |
||||
find_package(c-ares CONFIG) |
||||
foreach(_suffix IN LISTS _cares_version_var_suffixes) |
||||
set(c-ares_FIND_VERSION${_suffix} ${_cares_save_FIND_VERSION${_suffix}}) |
||||
endforeach() |
||||
|
||||
if(c-ares_FOUND) |
||||
if(NOT DEFINED c-ares_VERSION) |
||||
__cares_get_version() |
||||
endif() |
||||
|
||||
find_package_handle_standard_args(c-ares CONFIG_MODE) |
||||
return() |
||||
endif() |
||||
|
||||
find_path(c-ares_INCLUDE_DIR NAMES ares.h) |
||||
__cares_get_version() |
||||
|
||||
find_library(c-ares_LIBRARY cares) |
||||
|
||||
find_package_handle_standard_args(c-ares |
||||
REQUIRED_VARS c-ares_INCLUDE_DIR c-ares_LIBRARY |
||||
VERSION_VAR c-ares_VERSION |
||||
) |
||||
|
||||
if(c-ares_FOUND) |
||||
add_library(c-ares::cares UNKNOWN IMPORTED) |
||||
set_target_properties(c-ares::cares PROPERTIES |
||||
IMPORTED_LOCATION "${c-ares_LIBRARY}" |
||||
INTERFACE_INCLUDE_DIRECTORIES "${c-ares_INCLUDE_DIR}" |
||||
) |
||||
endif() |
@ -1,116 +1,129 @@ |
||||
# Copyright 2018 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
# |
||||
# cmake "superbuild" file for C++ helloworld example. |
||||
# This build file demonstrates how to build the helloworld project |
||||
# and all its dependencies in a single cmake build (hence "superbuild") |
||||
# that is easy to build and maintain. |
||||
# cmake's ExternalProject_Add() is used to import all the sub-projects, |
||||
# including the "helloworld" project itself. |
||||
# See https://blog.kitware.com/cmake-superbuilds-git-submodules/ |
||||
|
||||
cmake_minimum_required(VERSION 3.5.1) |
||||
|
||||
# Project |
||||
project(HelloWorld-SuperBuild C CXX) |
||||
|
||||
include(ExternalProject) |
||||
|
||||
# Builds c-ares project from the git submodule. |
||||
# Note: For all external projects, instead of using checked-out code, one could |
||||
# specify GIT_REPOSITORY and GIT_TAG to have cmake download the dependency directly, |
||||
# without needing to add a submodule to your project. |
||||
ExternalProject_Add(c-ares |
||||
PREFIX c-ares |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/cares/cares" |
||||
CMAKE_CACHE_ARGS |
||||
-DCARES_SHARED:BOOL=OFF |
||||
-DCARES_STATIC:BOOL=ON |
||||
-DCARES_STATIC_PIC:BOOL=ON |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares |
||||
) |
||||
|
||||
# Builds protobuf project from the git submodule. |
||||
ExternalProject_Add(protobuf |
||||
PREFIX protobuf |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/protobuf/cmake" |
||||
CMAKE_CACHE_ARGS |
||||
-Dprotobuf_BUILD_TESTS:BOOL=OFF |
||||
-Dprotobuf_WITH_ZLIB:BOOL=OFF |
||||
-Dprotobuf_MSVC_STATIC_RUNTIME:BOOL=OFF |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/protobuf |
||||
) |
||||
|
||||
# Builds zlib project from the git submodule. |
||||
ExternalProject_Add(zlib |
||||
PREFIX zlib |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/zlib" |
||||
CMAKE_CACHE_ARGS |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
) |
||||
|
||||
# the location where protobuf-config.cmake will be installed varies by platform |
||||
if (WIN32) |
||||
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/cmake") |
||||
else() |
||||
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/lib/cmake/protobuf") |
||||
endif() |
||||
|
||||
# if OPENSSL_ROOT_DIR is set, propagate that hint path to the external projects with OpenSSL dependency. |
||||
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "") |
||||
if (OPENSSL_ROOT_DIR) |
||||
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}") |
||||
endif() |
||||
|
||||
# Builds gRPC based on locally checked-out sources and set arguments so that all the dependencies |
||||
# are correctly located. |
||||
ExternalProject_Add(grpc |
||||
PREFIX grpc |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." |
||||
CMAKE_CACHE_ARGS |
||||
-DgRPC_INSTALL:BOOL=ON |
||||
-DgRPC_BUILD_TESTS:BOOL=OFF |
||||
-DgRPC_PROTOBUF_PROVIDER:STRING=package |
||||
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG |
||||
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
||||
-DgRPC_ZLIB_PROVIDER:STRING=package |
||||
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
-DgRPC_CARES_PROVIDER:STRING=package |
||||
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
||||
-DgRPC_SSL_PROVIDER:STRING=package |
||||
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc |
||||
DEPENDS c-ares protobuf zlib |
||||
) |
||||
|
||||
# Build the helloworld projects itself using a CMakeLists.txt that assumes all the dependencies |
||||
# have already been installed. |
||||
# Even though helloworld is not really an "external project" from perspective of this build, |
||||
# we are still importing it using ExternalProject_Add because that allows us to use find_package() |
||||
# to locate all the dependencies (if we were building helloworld directly in this build we, |
||||
# we would have needed to manually import the libraries as opposed to reusing targets exported by |
||||
# gRPC and protobuf). |
||||
ExternalProject_Add(helloworld |
||||
PREFIX helloworld |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." |
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/helloworld" |
||||
INSTALL_COMMAND "" |
||||
CMAKE_CACHE_ARGS |
||||
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
||||
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
||||
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
||||
-DgRPC_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/cmake/grpc |
||||
DEPENDS protobuf grpc |
||||
) |
||||
# Copyright 2018 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
# |
||||
# cmake "superbuild" file for C++ helloworld example. |
||||
# This build file demonstrates how to build the helloworld project |
||||
# and all its dependencies in a single cmake build (hence "superbuild") |
||||
# that is easy to build and maintain. |
||||
# cmake's ExternalProject_Add() is used to import all the sub-projects, |
||||
# including the "helloworld" project itself. |
||||
# See https://blog.kitware.com/cmake-superbuilds-git-submodules/ |
||||
|
||||
cmake_minimum_required(VERSION 3.5.1) |
||||
|
||||
# Project |
||||
project(HelloWorld-SuperBuild C CXX) |
||||
|
||||
include(ExternalProject) |
||||
|
||||
# Note: For all external projects, instead of using checked-out code, one could |
||||
# specify GIT_REPOSITORY and GIT_TAG to have cmake download the dependency directly, |
||||
# without needing to add a submodule to your project. |
||||
|
||||
# Builds absl project from the git submodule. |
||||
ExternalProject_Add(absl |
||||
PREFIX absl |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/abseil-cpp" |
||||
CMAKE_CACHE_ARGS |
||||
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/absl |
||||
) |
||||
|
||||
# Builds c-ares project from the git submodule. |
||||
ExternalProject_Add(c-ares |
||||
PREFIX c-ares |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/cares/cares" |
||||
CMAKE_CACHE_ARGS |
||||
-DCARES_SHARED:BOOL=OFF |
||||
-DCARES_STATIC:BOOL=ON |
||||
-DCARES_STATIC_PIC:BOOL=ON |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares |
||||
) |
||||
|
||||
# Builds protobuf project from the git submodule. |
||||
ExternalProject_Add(protobuf |
||||
PREFIX protobuf |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/protobuf/cmake" |
||||
CMAKE_CACHE_ARGS |
||||
-Dprotobuf_BUILD_TESTS:BOOL=OFF |
||||
-Dprotobuf_WITH_ZLIB:BOOL=OFF |
||||
-Dprotobuf_MSVC_STATIC_RUNTIME:BOOL=OFF |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/protobuf |
||||
) |
||||
|
||||
# Builds zlib project from the git submodule. |
||||
ExternalProject_Add(zlib |
||||
PREFIX zlib |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/zlib" |
||||
CMAKE_CACHE_ARGS |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
) |
||||
|
||||
# the location where protobuf-config.cmake will be installed varies by platform |
||||
if (WIN32) |
||||
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/cmake") |
||||
else() |
||||
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/lib/cmake/protobuf") |
||||
endif() |
||||
|
||||
# if OPENSSL_ROOT_DIR is set, propagate that hint path to the external projects with OpenSSL dependency. |
||||
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "") |
||||
if (OPENSSL_ROOT_DIR) |
||||
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}") |
||||
endif() |
||||
|
||||
# Builds gRPC based on locally checked-out sources and set arguments so that all the dependencies |
||||
# are correctly located. |
||||
ExternalProject_Add(grpc |
||||
PREFIX grpc |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." |
||||
CMAKE_CACHE_ARGS |
||||
-DgRPC_INSTALL:BOOL=ON |
||||
-DgRPC_BUILD_TESTS:BOOL=OFF |
||||
-DgRPC_PROTOBUF_PROVIDER:STRING=package |
||||
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG |
||||
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
||||
-DgRPC_ZLIB_PROVIDER:STRING=package |
||||
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
-DgRPC_ABSL_PROVIDER:STRING=package |
||||
-Dabsl_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/absl/lib/cmake/absl |
||||
-DgRPC_CARES_PROVIDER:STRING=package |
||||
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
||||
-DgRPC_SSL_PROVIDER:STRING=package |
||||
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
||||
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc |
||||
DEPENDS c-ares protobuf zlib absl |
||||
) |
||||
|
||||
# Build the helloworld projects itself using a CMakeLists.txt that assumes all the dependencies |
||||
# have already been installed. |
||||
# Even though helloworld is not really an "external project" from perspective of this build, |
||||
# we are still importing it using ExternalProject_Add because that allows us to use find_package() |
||||
# to locate all the dependencies (if we were building helloworld directly in this build we, |
||||
# we would have needed to manually import the libraries as opposed to reusing targets exported by |
||||
# gRPC and protobuf). |
||||
ExternalProject_Add(helloworld |
||||
PREFIX helloworld |
||||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." |
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/helloworld" |
||||
INSTALL_COMMAND "" |
||||
CMAKE_CACHE_ARGS |
||||
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
||||
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
||||
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
||||
-Dabsl_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/absl/lib/cmake/absl |
||||
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
||||
-DgRPC_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/cmake/grpc |
||||
DEPENDS protobuf grpc |
||||
) |
||||
|
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCPP_SECURITY_ALTS_CONTEXT_H |
||||
#define GRPCPP_SECURITY_ALTS_CONTEXT_H |
||||
|
||||
#include <grpc/grpc_security_constants.h> |
||||
#include <grpcpp/security/auth_context.h> |
||||
|
||||
#include <memory> |
||||
|
||||
struct grpc_gcp_AltsContext; |
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
// AltsContext is a wrapper class for grpc_gcp_AltsContext.
|
||||
class AltsContext { |
||||
public: |
||||
struct RpcProtocolVersions { |
||||
struct Version { |
||||
int major_version; |
||||
int minor_version; |
||||
}; |
||||
Version max_rpc_version; |
||||
Version min_rpc_version; |
||||
}; |
||||
explicit AltsContext(const grpc_gcp_AltsContext* ctx); |
||||
AltsContext& operator=(const AltsContext&) = default; |
||||
AltsContext(const AltsContext&) = default; |
||||
|
||||
grpc::string application_protocol() const; |
||||
grpc::string record_protocol() const; |
||||
grpc::string peer_service_account() const; |
||||
grpc::string local_service_account() const; |
||||
grpc_security_level security_level() const; |
||||
RpcProtocolVersions peer_rpc_versions() const; |
||||
|
||||
private: |
||||
// TODO(ZhenLian): Also plumb field peer_attributes when it is in use
|
||||
grpc::string application_protocol_; |
||||
grpc::string record_protocol_; |
||||
grpc::string peer_service_account_; |
||||
grpc::string local_service_account_; |
||||
grpc_security_level security_level_ = GRPC_SECURITY_NONE; |
||||
RpcProtocolVersions peer_rpc_versions_ = {{0, 0}, {0, 0}}; |
||||
}; |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCPP_SECURITY_ALTS_CONTEXT_H
|
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2019 gRPC authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCPP_SECURITY_ALTS_UTIL_H |
||||
#define GRPCPP_SECURITY_ALTS_UTIL_H |
||||
|
||||
#include <grpc/grpc_security_constants.h> |
||||
#include <grpcpp/impl/codegen/status.h> |
||||
#include <grpcpp/security/alts_context.h> |
||||
#include <grpcpp/security/auth_context.h> |
||||
|
||||
#include <memory> |
||||
|
||||
struct grpc_gcp_AltsContext; |
||||
|
||||
namespace grpc { |
||||
namespace experimental { |
||||
|
||||
// GetAltsContextFromAuthContext helps to get the AltsContext from AuthContext.
|
||||
// If ALTS is not the transport security protocol used to establish the
|
||||
// connection, this function will return nullptr.
|
||||
std::unique_ptr<AltsContext> GetAltsContextFromAuthContext( |
||||
const std::shared_ptr<const AuthContext>& auth_context); |
||||
|
||||
// This utility function performs ALTS client authorization check on server
|
||||
// side, i.e., checks if the client identity matches one of the expected service
|
||||
// accounts. It returns OK if client is authorized and an error otherwise.
|
||||
grpc::Status AltsClientAuthzCheck( |
||||
const std::shared_ptr<const AuthContext>& auth_context, |
||||
const std::vector<std::string>& expected_service_accounts); |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCPP_SECURITY_ALTS_UTIL_H
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,210 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# Copyright 2019 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import collections |
||||
import os |
||||
import re |
||||
import subprocess |
||||
import xml.etree.ElementTree as ET |
||||
import yaml |
||||
|
||||
ABSEIL_PATH = "third_party/abseil-cpp" |
||||
OUTPUT_PATH = "src/abseil-cpp/preprocessed_builds.yaml" |
||||
CAPITAL_WORD = re.compile("[A-Z]+") |
||||
ABSEIL_CMAKE_RULE_BEGIN = re.compile("^absl_cc_.*\(", re.MULTILINE) |
||||
ABSEIL_CMAKE_RULE_END = re.compile("^\)", re.MULTILINE) |
||||
|
||||
# Rule object representing the rule of Bazel BUILD. |
||||
Rule = collections.namedtuple( |
||||
"Rule", "type name package srcs hdrs textual_hdrs deps visibility testonly") |
||||
|
||||
|
||||
def get_elem_value(elem, name): |
||||
"""Returns the value of XML element with the given name.""" |
||||
for child in elem: |
||||
if child.attrib.get("name") == name: |
||||
if child.tag == "string": |
||||
return child.attrib.get("value") |
||||
elif child.tag == "boolean": |
||||
return child.attrib.get("value") == "true" |
||||
elif child.tag == "list": |
||||
return [nested_child.attrib.get("value") for nested_child in child] |
||||
else: |
||||
raise "Cannot recognize tag: " + child.tag |
||||
return None |
||||
|
||||
|
||||
def normalize_paths(paths): |
||||
"""Returns the list of normalized path.""" |
||||
# e.g. ["//absl/strings:dir/header.h"] -> ["absl/strings/dir/header.h"] |
||||
return [path.lstrip("/").replace(":", "/") for path in paths] |
||||
|
||||
|
||||
def parse_bazel_rule(elem, package): |
||||
"""Returns a rule from bazel XML rule.""" |
||||
return Rule( |
||||
type=elem.attrib["class"], |
||||
name=get_elem_value(elem, "name"), |
||||
package=package, |
||||
srcs=normalize_paths(get_elem_value(elem, "srcs") or []), |
||||
hdrs=normalize_paths(get_elem_value(elem, "hdrs") or []), |
||||
textual_hdrs=normalize_paths(get_elem_value(elem, "textual_hdrs") or []), |
||||
deps=get_elem_value(elem, "deps") or [], |
||||
visibility=get_elem_value(elem, "visibility") or [], |
||||
testonly=get_elem_value(elem, "testonly") or False) |
||||
|
||||
|
||||
def read_bazel_build(package): |
||||
"""Runs bazel query on given package file and returns all cc rules.""" |
||||
result = subprocess.check_output( |
||||
["bazel", "query", package + ":all", "--output", "xml"]) |
||||
root = ET.fromstring(result) |
||||
return [ |
||||
parse_bazel_rule(elem, package) |
||||
for elem in root |
||||
if elem.tag == "rule" and elem.attrib["class"].startswith("cc_") |
||||
] |
||||
|
||||
|
||||
def collect_bazel_rules(root_path): |
||||
"""Collects and returns all bazel rules from root path recursively.""" |
||||
rules = [] |
||||
for cur, _, _ in os.walk(root_path): |
||||
build_path = os.path.join(cur, "BUILD.bazel") |
||||
if os.path.exists(build_path): |
||||
rules.extend(read_bazel_build("//" + cur)) |
||||
return rules |
||||
|
||||
|
||||
def parse_cmake_rule(rule, package): |
||||
"""Returns a rule from absl cmake rule. |
||||
Reference: https://github.com/abseil/abseil-cpp/blob/master/CMake/AbseilHelpers.cmake |
||||
""" |
||||
kv = {} |
||||
bucket = None |
||||
lines = rule.splitlines() |
||||
for line in lines[1:-1]: |
||||
if CAPITAL_WORD.match(line.strip()): |
||||
bucket = kv.setdefault(line.strip(), []) |
||||
else: |
||||
if bucket is not None: |
||||
bucket.append(line.strip()) |
||||
else: |
||||
raise ValueError("Illegal syntax: {}".format(rule)) |
||||
return Rule( |
||||
type=lines[0].rstrip("("), |
||||
name="absl::" + kv["NAME"][0], |
||||
package=package, |
||||
srcs=[package + "/" + f.strip('"') for f in kv.get("SRCS", [])], |
||||
hdrs=[package + "/" + f.strip('"') for f in kv.get("HDRS", [])], |
||||
textual_hdrs=[], |
||||
deps=kv.get("DEPS", []), |
||||
visibility="PUBLIC" in kv, |
||||
testonly="TESTONLY" in kv, |
||||
) |
||||
|
||||
|
||||
def read_cmake_build(build_path, package): |
||||
"""Parses given CMakeLists.txt file and returns all cc rules.""" |
||||
rules = [] |
||||
with open(build_path, "r") as f: |
||||
src = f.read() |
||||
for begin_mo in ABSEIL_CMAKE_RULE_BEGIN.finditer(src): |
||||
end_mo = ABSEIL_CMAKE_RULE_END.search(src[begin_mo.start(0):]) |
||||
expr = src[begin_mo.start(0):begin_mo.start(0) + end_mo.start(0) + 1] |
||||
rules.append(parse_cmake_rule(expr, package)) |
||||
return rules |
||||
|
||||
|
||||
def collect_cmake_rules(root_path): |
||||
"""Collects and returns all cmake rules from root path recursively.""" |
||||
rules = [] |
||||
for cur, _, _ in os.walk(root_path): |
||||
build_path = os.path.join(cur, "CMakeLists.txt") |
||||
if os.path.exists(build_path): |
||||
rules.extend(read_cmake_build(build_path, cur)) |
||||
return rules |
||||
|
||||
|
||||
def pairing_bazel_and_cmake_rules(bazel_rules, cmake_rules): |
||||
"""Returns a pair map between bazel rules and cmake rules based on |
||||
the similarity of the file list in the rule. This is because |
||||
cmake build and bazel build of abseil are not identical. |
||||
""" |
||||
pair_map = {} |
||||
for rule in bazel_rules: |
||||
best_crule, best_similarity = None, 0 |
||||
for crule in cmake_rules: |
||||
similarity = len( |
||||
set(rule.srcs + rule.hdrs + rule.textual_hdrs).intersection( |
||||
set(crule.srcs + crule.hdrs + crule.textual_hdrs))) |
||||
if similarity > best_similarity: |
||||
best_crule, best_similarity = crule, similarity |
||||
if best_crule: |
||||
pair_map[(rule.package, rule.name)] = best_crule.name |
||||
return pair_map |
||||
|
||||
|
||||
def resolve_hdrs(files): |
||||
return [ABSEIL_PATH + "/" + f for f in files if f.endswith((".h", ".inc"))] |
||||
|
||||
|
||||
def resolve_srcs(files): |
||||
return [ABSEIL_PATH + "/" + f for f in files if f.endswith(".cc")] |
||||
|
||||
|
||||
def resolve_deps(targets): |
||||
return [(t[2:] if t.startswith("//") else t) for t in targets] |
||||
|
||||
|
||||
def generate_builds(root_path): |
||||
"""Generates builds from all BUILD files under absl directory.""" |
||||
bazel_rules = list( |
||||
filter(lambda r: r.type == "cc_library" and not r.testonly, |
||||
collect_bazel_rules(root_path))) |
||||
cmake_rules = list( |
||||
filter(lambda r: r.type == "absl_cc_library" and not r.testonly, |
||||
collect_cmake_rules(root_path))) |
||||
pair_map = pairing_bazel_and_cmake_rules(bazel_rules, cmake_rules) |
||||
builds = [] |
||||
for rule in sorted(bazel_rules, key=lambda r: r.package[2:] + ":" + r.name): |
||||
p = { |
||||
"name": |
||||
rule.package[2:] + ":" + rule.name, |
||||
"cmake_target": |
||||
pair_map.get((rule.package, rule.name)) or "", |
||||
"headers": |
||||
sorted(resolve_hdrs(rule.srcs + rule.hdrs + rule.textual_hdrs)), |
||||
"src": |
||||
sorted(resolve_srcs(rule.srcs + rule.hdrs + rule.textual_hdrs)), |
||||
"deps": |
||||
sorted(resolve_deps(rule.deps)), |
||||
} |
||||
builds.append(p) |
||||
return builds |
||||
|
||||
|
||||
def main(): |
||||
previous_dir = os.getcwd() |
||||
os.chdir(ABSEIL_PATH) |
||||
builds = generate_builds("absl") |
||||
os.chdir(previous_dir) |
||||
with open(OUTPUT_PATH, 'w') as outfile: |
||||
outfile.write(yaml.dump(builds, indent=2, sort_keys=True)) |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
main() |
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue