Add preprocessed_builds to abseil-cpp
This commit is contained in:
parent
9b1f8e4274
commit
1b54364aca
|
|
@ -0,0 +1,29 @@
|
||||||
|
#!/usr/bin/env python2.7
|
||||||
|
|
||||||
|
# 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 os
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
BUILDS_YAML_PATH = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)), 'preprocessed_builds.yaml')
|
||||||
|
with open(BUILDS_YAML_PATH) as f:
|
||||||
|
builds = yaml.load(f)
|
||||||
|
|
||||||
|
for build in builds:
|
||||||
|
build['build'] = 'private'
|
||||||
|
build['build_system'] = []
|
||||||
|
build['language'] = 'c'
|
||||||
|
print(yaml.dump({'libs': builds}))
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,130 @@
|
||||||
|
#!/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 subprocess
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
ABSEIL_PATH = "third_party/abseil-cpp"
|
||||||
|
OUTPUT_PATH = "src/abseil-cpp/preprocessed_builds.yaml"
|
||||||
|
|
||||||
|
# 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_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_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_rule(elem, package)
|
||||||
|
for elem in root
|
||||||
|
if elem.tag == "rule" and elem.attrib["class"].startswith("cc_")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def collect_rules(root_path):
|
||||||
|
"""Collects and returns all 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_build("//" + cur))
|
||||||
|
return rules
|
||||||
|
|
||||||
|
|
||||||
|
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."""
|
||||||
|
rules = filter(lambda r: r.type == "cc_library" and not r.testonly,
|
||||||
|
collect_rules(root_path))
|
||||||
|
builds = []
|
||||||
|
for rule in sorted(rules, key=lambda r: r.package[2:] + ":" + r.name):
|
||||||
|
p = {
|
||||||
|
"name": rule.package[2:] + ":" + rule.name,
|
||||||
|
"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()
|
||||||
|
|
@ -33,6 +33,9 @@
|
||||||
return filename
|
return filename
|
||||||
return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext
|
return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext
|
||||||
|
|
||||||
|
def is_absl_lib(target_name):
|
||||||
|
return target_name.startswith("absl/");
|
||||||
|
|
||||||
def get_deps(target_dict):
|
def get_deps(target_dict):
|
||||||
deps = []
|
deps = []
|
||||||
if target_dict.get('baselib', False) or target_dict['name'] == 'address_sorting':
|
if target_dict.get('baselib', False) or target_dict['name'] == 'address_sorting':
|
||||||
|
|
@ -387,11 +390,16 @@
|
||||||
add_custom_target(buildtests
|
add_custom_target(buildtests
|
||||||
DEPENDS buildtests_c buildtests_cxx)
|
DEPENDS buildtests_c buildtests_cxx)
|
||||||
endif()
|
endif()
|
||||||
|
<%
|
||||||
% for lib in libs:
|
cmake_libs = []
|
||||||
% if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl:
|
for lib in libs:
|
||||||
% if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []):
|
if lib.build not in ["all", "protoc", "tool", "test", "private"] or lib.boringssl: continue
|
||||||
% if not lib.name in ['ares', 'benchmark', 'z']: # we build these using CMake instead
|
if lib.get('build_system', []) and 'cmake' not in lib.get('build_system', []): continue
|
||||||
|
if lib.name in ['ares', 'benchmark', 'z']: continue # we build these using CMake instead
|
||||||
|
if is_absl_lib(lib.name): continue # we build these using CMake instead
|
||||||
|
cmake_libs.append(lib)
|
||||||
|
%>
|
||||||
|
% for lib in cmake_libs:
|
||||||
% if lib.build in ["test", "private"]:
|
% if lib.build in ["test", "private"]:
|
||||||
if(gRPC_BUILD_TESTS)
|
if(gRPC_BUILD_TESTS)
|
||||||
${cc_library(lib)}
|
${cc_library(lib)}
|
||||||
|
|
@ -419,9 +427,6 @@
|
||||||
% endif
|
% endif
|
||||||
% endif
|
% endif
|
||||||
% endif
|
% endif
|
||||||
% endif
|
|
||||||
% endif
|
|
||||||
% endif
|
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
% for tgt in targets:
|
% for tgt in targets:
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,10 @@
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
<%
|
||||||
|
def is_absl_lib(target_name):
|
||||||
|
return target_name.startswith("absl/");
|
||||||
|
%>
|
||||||
{
|
{
|
||||||
'variables': {
|
'variables': {
|
||||||
# The openssl and zlib dependencies must be passed in as variables
|
# The openssl and zlib dependencies must be passed in as variables
|
||||||
|
|
@ -136,7 +139,7 @@
|
||||||
},
|
},
|
||||||
'targets': [
|
'targets': [
|
||||||
% for lib in libs:
|
% for lib in libs:
|
||||||
% if getattr(lib, 'platforms', None) is None and lib.name != 'ares':
|
% if getattr(lib, 'platforms', None) is None and lib.name != 'ares' and not is_absl_lib(lib.name):
|
||||||
{
|
{
|
||||||
'target_name': '${lib.name}',
|
'target_name': '${lib.name}',
|
||||||
'type': 'static_library',
|
'type': 'static_library',
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
gen_build_yaml_dirs=" \
|
gen_build_yaml_dirs=" \
|
||||||
|
src/abseil-cpp \
|
||||||
src/boringssl \
|
src/boringssl \
|
||||||
src/benchmark \
|
src/benchmark \
|
||||||
src/proto \
|
src/proto \
|
||||||
src/upb \
|
src/upb \
|
||||||
src/zlib \
|
src/zlib \
|
||||||
|
|
@ -25,8 +26,8 @@ gen_build_yaml_dirs=" \
|
||||||
test/core/bad_client \
|
test/core/bad_client \
|
||||||
test/core/bad_ssl \
|
test/core/bad_ssl \
|
||||||
test/core/end2end \
|
test/core/end2end \
|
||||||
test/cpp/naming \
|
test/cpp/naming \
|
||||||
test/cpp/qps \
|
test/cpp/qps \
|
||||||
tools/run_tests/lb_interop_tests"
|
tools/run_tests/lb_interop_tests"
|
||||||
gen_build_files=""
|
gen_build_files=""
|
||||||
for gen_build_yaml in $gen_build_yaml_dirs
|
for gen_build_yaml in $gen_build_yaml_dirs
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue