Classes | Functions | Variables
extract_metadata_from_bazel_xml Namespace Reference

Classes

class  ExternalProtoLibrary
 

Functions

ET.Element _bazel_query_xml_tree (str query)
 
None _compute_transitive_metadata (str rule_name, Any bazel_rules, Dict[str, str] bazel_label_to_dep_name)
 
BuildYaml _convert_to_build_yaml_like (BuildMetadata lib_dict)
 
BuildMetadata _create_target_from_bazel_rule (str target_name, BuildDict bazel_rules)
 
None _detect_and_print_issues (BuildYaml build_yaml_like)
 
List[str] _exclude_unwanted_cc_tests (List[str] tests)
 
def _expand_upb_proto_library_rules (bazel_rules)
 
Optional[str] _external_dep_name_from_bazel_dependency (str bazel_dep)
 
List[str] _extract_cc_tests (BuildDict bazel_rules)
 
List[str] _extract_deps (BuildMetadata bazel_rule, BuildDict bazel_rules)
 
List[str] _extract_nonpublic_headers (BuildMetadata bazel_rule)
 
List[str] _extract_public_headers (BuildMetadata bazel_rule)
 
def _extract_rules_from_bazel_xml (xml_tree)
 
str _extract_source_file_path (str label)
 
List[str] _extract_sources (BuildMetadata bazel_rule)
 
BuildDict _generate_build_extra_metadata_for_tests (List[str] tests, BuildDict bazel_rules)
 
BuildDict _generate_build_metadata (BuildDict build_extra_metadata, BuildDict bazel_rules)
 
List[Dict[str, Any]] _generate_external_proto_libraries ()
 
str _get_bazel_label (str target_name)
 
def _get_transitive_protos (bazel_rules, t)
 
Optional[str] _maybe_get_internal_path (str name)
 
'List[ExternalProtoLibrary]' _parse_http_archives (ET.Element xml_tree)
 
None _populate_transitive_metadata (Any bazel_rules, Iterable[str] public_dep_names)
 
def _rule_dict_from_xml_node (rule_xml_node)
 
None update_test_metadata_with_transitive_metadata (BuildDict all_extra_metadata, BuildDict bazel_rules)
 

Variables

list _BAZEL_DEPS_QUERIES
 
dictionary _BUILD_EXTRA_METADATA
 
dictionary all_extra_metadata = {}
 
BuildDict all_targets_dict = _generate_build_metadata(all_extra_metadata, bazel_rules)
 
dictionary bazel_rules = {}
 
BuildYaml build_yaml_like = _convert_to_build_yaml_like(all_targets_dict)
 
 build_yaml_string
 
 BuildDict = Dict[str, BuildMetadata]
 
 BuildMetadata = Dict[str, Any]
 
 BuildYaml = Dict[str, Any]
 
dictionary EXTERNAL_PROTO_LIBRARIES
 
List[str] tests = _exclude_unwanted_cc_tests(_extract_cc_tests(bazel_rules))
 

Function Documentation

◆ _bazel_query_xml_tree()

ET.Element extract_metadata_from_bazel_xml._bazel_query_xml_tree ( str  query)
private
Get xml output of bazel query invocation, parsed as XML tree

Definition at line 105 of file extract_metadata_from_bazel_xml.py.

◆ _compute_transitive_metadata()

None extract_metadata_from_bazel_xml._compute_transitive_metadata ( str  rule_name,
Any  bazel_rules,
Dict[str, str]  bazel_label_to_dep_name 
)
private
Computes the final build metadata for Bazel target with rule_name.

The dependencies that will appear on the deps list are:

* Public build targets including binaries and tests;
* External targets, like absl, re2.

All other intermediate dependencies will be merged, which means their
source file, headers, etc. will be collected into one build target. This
step of processing will greatly reduce the complexity of the generated
build specifications for other build systems, like CMake, Make, setuptools.

The final build metadata are:
* _TRANSITIVE_DEPS: all the transitive dependencies including intermediate
                    targets;
* _COLLAPSED_DEPS:  dependencies that fits our requirement above, and it
                    will remove duplicated items and produce the shortest
                    possible dependency list in alphabetical order;
* _COLLAPSED_SRCS:  the merged source files;
* _COLLAPSED_PUBLIC_HEADERS: the merged public headers;
* _COLLAPSED_HEADERS: the merged non-public headers;
* _EXCLUDE_DEPS: intermediate targets to exclude when performing collapsing
  of sources and dependencies.

For the collapsed_deps, the algorithm improved cases like:

The result in the past:
    end2end_tests -> [grpc_test_util, grpc, gpr, address_sorting, upb]
    grpc_test_util -> [grpc, gpr, address_sorting, upb, ...]
    grpc -> [gpr, address_sorting, upb, ...]

The result of the algorithm:
    end2end_tests -> [grpc_test_util]
    grpc_test_util -> [grpc]
    grpc -> [gpr, address_sorting, upb, ...]

Definition at line 289 of file extract_metadata_from_bazel_xml.py.

◆ _convert_to_build_yaml_like()

BuildYaml extract_metadata_from_bazel_xml._convert_to_build_yaml_like ( BuildMetadata  lib_dict)
private

Definition at line 578 of file extract_metadata_from_bazel_xml.py.

◆ _create_target_from_bazel_rule()

BuildMetadata extract_metadata_from_bazel_xml._create_target_from_bazel_rule ( str  target_name,
BuildDict  bazel_rules 
)
private
Create build.yaml-like target definition from bazel metadata

Definition at line 247 of file extract_metadata_from_bazel_xml.py.

◆ _detect_and_print_issues()

None extract_metadata_from_bazel_xml._detect_and_print_issues ( BuildYaml  build_yaml_like)
private
Try detecting some unusual situations and warn about them.

Definition at line 849 of file extract_metadata_from_bazel_xml.py.

◆ _exclude_unwanted_cc_tests()

List[str] extract_metadata_from_bazel_xml._exclude_unwanted_cc_tests ( List[str]  tests)
private
Filters out bazel tests that we don't want to run with other build systems or we cannot build them reasonably

Definition at line 639 of file extract_metadata_from_bazel_xml.py.

◆ _expand_upb_proto_library_rules()

def extract_metadata_from_bazel_xml._expand_upb_proto_library_rules (   bazel_rules)
private

Definition at line 485 of file extract_metadata_from_bazel_xml.py.

◆ _external_dep_name_from_bazel_dependency()

Optional[str] extract_metadata_from_bazel_xml._external_dep_name_from_bazel_dependency ( str  bazel_dep)
private
Returns name of dependency if external bazel dependency is provided or None

Definition at line 270 of file extract_metadata_from_bazel_xml.py.

◆ _extract_cc_tests()

List[str] extract_metadata_from_bazel_xml._extract_cc_tests ( BuildDict  bazel_rules)
private
Gets list of cc_test tests from bazel rules

Definition at line 627 of file extract_metadata_from_bazel_xml.py.

◆ _extract_deps()

List[str] extract_metadata_from_bazel_xml._extract_deps ( BuildMetadata  bazel_rule,
BuildDict  bazel_rules 
)
private
Gets list of deps from from a bazel rule

Definition at line 232 of file extract_metadata_from_bazel_xml.py.

◆ _extract_nonpublic_headers()

List[str] extract_metadata_from_bazel_xml._extract_nonpublic_headers ( BuildMetadata  bazel_rule)
private
Gets list of non-public headers from a bazel rule

Definition at line 198 of file extract_metadata_from_bazel_xml.py.

◆ _extract_public_headers()

List[str] extract_metadata_from_bazel_xml._extract_public_headers ( BuildMetadata  bazel_rule)
private
Gets list of public headers from a bazel rule

Definition at line 189 of file extract_metadata_from_bazel_xml.py.

◆ _extract_rules_from_bazel_xml()

def extract_metadata_from_bazel_xml._extract_rules_from_bazel_xml (   xml_tree)
private
Extract bazel rules from an XML tree node obtained from "bazel query --output xml" command.

Definition at line 144 of file extract_metadata_from_bazel_xml.py.

◆ _extract_source_file_path()

str extract_metadata_from_bazel_xml._extract_source_file_path ( str  label)
private
Gets relative path to source file from bazel deps listing

Definition at line 177 of file extract_metadata_from_bazel_xml.py.

◆ _extract_sources()

List[str] extract_metadata_from_bazel_xml._extract_sources ( BuildMetadata  bazel_rule)
private
Gets list of source files from a bazel rule

Definition at line 208 of file extract_metadata_from_bazel_xml.py.

◆ _generate_build_extra_metadata_for_tests()

BuildDict extract_metadata_from_bazel_xml._generate_build_extra_metadata_for_tests ( List[str]  tests,
BuildDict  bazel_rules 
)
private
For given tests, generate the "extra metadata" that we need for our "build.yaml"-like output. The extra metadata is generated from the bazel rule metadata by using a bunch of heuristics.

Definition at line 714 of file extract_metadata_from_bazel_xml.py.

◆ _generate_build_metadata()

BuildDict extract_metadata_from_bazel_xml._generate_build_metadata ( BuildDict  build_extra_metadata,
BuildDict  bazel_rules 
)
private
Generate build metadata in build.yaml-like format bazel build metadata and build.yaml-specific "extra metadata".

Definition at line 537 of file extract_metadata_from_bazel_xml.py.

◆ _generate_external_proto_libraries()

List[Dict[str, Any]] extract_metadata_from_bazel_xml._generate_external_proto_libraries ( )
private
Generates the build metadata for external proto libraries

Definition at line 841 of file extract_metadata_from_bazel_xml.py.

◆ _get_bazel_label()

str extract_metadata_from_bazel_xml._get_bazel_label ( str  target_name)
private

Definition at line 168 of file extract_metadata_from_bazel_xml.py.

◆ _get_transitive_protos()

def extract_metadata_from_bazel_xml._get_transitive_protos (   bazel_rules,
  t 
)
private

Definition at line 465 of file extract_metadata_from_bazel_xml.py.

◆ _maybe_get_internal_path()

Optional[str] extract_metadata_from_bazel_xml._maybe_get_internal_path ( str  name)
private

Definition at line 98 of file extract_metadata_from_bazel_xml.py.

◆ _parse_http_archives()

'List[ExternalProtoLibrary]' extract_metadata_from_bazel_xml._parse_http_archives ( ET.Element  xml_tree)
private
Parse Bazel http_archive rule into ExternalProtoLibrary objects.

Definition at line 807 of file extract_metadata_from_bazel_xml.py.

◆ _populate_transitive_metadata()

None extract_metadata_from_bazel_xml._populate_transitive_metadata ( Any  bazel_rules,
Iterable[str]  public_dep_names 
)
private
Add 'transitive_deps' field for each of the rules

Definition at line 430 of file extract_metadata_from_bazel_xml.py.

◆ _rule_dict_from_xml_node()

def extract_metadata_from_bazel_xml._rule_dict_from_xml_node (   rule_xml_node)
private
Converts XML node representing a rule (obtained from "bazel query --output xml") to a dictionary that contains all the metadata we will need.

Definition at line 112 of file extract_metadata_from_bazel_xml.py.

◆ update_test_metadata_with_transitive_metadata()

None extract_metadata_from_bazel_xml.update_test_metadata_with_transitive_metadata ( BuildDict  all_extra_metadata,
BuildDict  bazel_rules 
)
Patches test build metadata with transitive metadata.

Definition at line 446 of file extract_metadata_from_bazel_xml.py.

Variable Documentation

◆ _BAZEL_DEPS_QUERIES

list extract_metadata_from_bazel_xml._BAZEL_DEPS_QUERIES
private
Initial value:
1 = [
2  'deps("//test/...")',
3  'deps("//:all")',
4  'deps("//src/compiler/...")',
5  'deps("//src/proto/...")',
6  # The ^ is needed to differentiate proto_library from go_proto_library
7  'deps(kind("^proto_library", @envoy_api//envoy/...))',
8 ]

Definition at line 1078 of file extract_metadata_from_bazel_xml.py.

◆ _BUILD_EXTRA_METADATA

dictionary extract_metadata_from_bazel_xml._BUILD_EXTRA_METADATA
private

Definition at line 863 of file extract_metadata_from_bazel_xml.py.

◆ all_extra_metadata

dictionary extract_metadata_from_bazel_xml.all_extra_metadata = {}

Definition at line 1158 of file extract_metadata_from_bazel_xml.py.

◆ all_targets_dict

BuildDict extract_metadata_from_bazel_xml.all_targets_dict = _generate_build_metadata(all_extra_metadata, bazel_rules)

Definition at line 1209 of file extract_metadata_from_bazel_xml.py.

◆ bazel_rules

dictionary extract_metadata_from_bazel_xml.bazel_rules = {}

Definition at line 1099 of file extract_metadata_from_bazel_xml.py.

◆ build_yaml_like

BuildYaml extract_metadata_from_bazel_xml.build_yaml_like = _convert_to_build_yaml_like(all_targets_dict)

Definition at line 1223 of file extract_metadata_from_bazel_xml.py.

◆ build_yaml_string

extract_metadata_from_bazel_xml.build_yaml_string
Initial value:

Definition at line 1243 of file extract_metadata_from_bazel_xml.py.

◆ BuildDict

extract_metadata_from_bazel_xml.BuildDict = Dict[str, BuildMetadata]

Definition at line 42 of file extract_metadata_from_bazel_xml.py.

◆ BuildMetadata

extract_metadata_from_bazel_xml.BuildMetadata = Dict[str, Any]

Definition at line 41 of file extract_metadata_from_bazel_xml.py.

◆ BuildYaml

extract_metadata_from_bazel_xml.BuildYaml = Dict[str, Any]

Definition at line 43 of file extract_metadata_from_bazel_xml.py.

◆ EXTERNAL_PROTO_LIBRARIES

dictionary extract_metadata_from_bazel_xml.EXTERNAL_PROTO_LIBRARIES
Initial value:
1 = {
2  'envoy_api':
3  ExternalProtoLibrary(destination='third_party/envoy-api',
4  proto_prefix='third_party/envoy-api/'),
5  'com_google_googleapis':
6  ExternalProtoLibrary(destination='third_party/googleapis',
7  proto_prefix='third_party/googleapis/'),
8  'com_github_cncf_udpa':
9  ExternalProtoLibrary(destination='third_party/xds',
10  proto_prefix='third_party/xds/'),
11  'opencensus_proto':
12  ExternalProtoLibrary(destination='third_party/opencensus-proto/src',
13  proto_prefix='third_party/opencensus-proto/src/'),
14 }

Definition at line 82 of file extract_metadata_from_bazel_xml.py.

◆ tests

List[str] extract_metadata_from_bazel_xml.tests = _exclude_unwanted_cc_tests(_extract_cc_tests(bazel_rules))

Definition at line 1129 of file extract_metadata_from_bazel_xml.py.

build_cleaner.cleaned_build_yaml_dict_as_string
def cleaned_build_yaml_dict_as_string(indict)
Definition: build_cleaner.py:71


grpc
Author(s):
autogenerated on Fri May 16 2025 03:03:10