From de70a14db82be9e405ac665ec7dc742e9af6b398 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Tue, 29 Mar 2022 20:35:04 +0100 Subject: [PATCH 1/7] Adds graphdef_from_bazel.py binary --- BUILD | 6 ++++++ graphdef_from_bazel.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 graphdef_from_bazel.py diff --git a/BUILD b/BUILD index 0528ef0..80e7e1c 100644 --- a/BUILD +++ b/BUILD @@ -19,6 +19,12 @@ py_library( ], ) +py_binary( + name = "graphdef_from_bazel", + srcs = ["graphdef_from_bazel.py"], + deps = [":splitbrain"], +) + py_binary( name = "main", srcs = ["main.py"], diff --git a/graphdef_from_bazel.py b/graphdef_from_bazel.py new file mode 100644 index 0000000..c60af75 --- /dev/null +++ b/graphdef_from_bazel.py @@ -0,0 +1,31 @@ +"""Extracts a GraphDef based on a Bazel workspace. + +This tool launches the Bazel binary to extract some data from a workspace, and +processes the protocol buffer output to produce a GraphDef. + +Usage: + ./graphdef_from_bazel.py --input_dir=path/to/WORKSPACE \\ + --output_dir=path/to/out +""" + +from absl import app +from absl import flags +import graphdef_utils + +FLAGS = flags.FLAGS +flags.DEFINE_string('input_path', None, 'Path to Bazel WORKSPACE file.') +flags.DEFINE_string('output_dir', None, 'Directory to write output to.') +flags.DEFINE_multi_string('modified_files', [], + 'List of modified files to `bazel query` for.') +flags.DEFINE_bool('textproto', False, + 'If true, writes output statistics as textproto format.') +flags.mark_flag_as_required('input_path') +flags.mark_flag_as_required('output_dir') + + +def main(argv): + del argv + + +if __name__ == '__main__': + app.run(main) \ No newline at end of file From 4bfdb393941e0377db455422d0c53965b31a81a7 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 14:08:42 +0100 Subject: [PATCH 2/7] Adds submodules for bazel and kythe --- .gitsubmodules | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitsubmodules diff --git a/.gitsubmodules b/.gitsubmodules new file mode 100644 index 0000000..00f3262 --- /dev/null +++ b/.gitsubmodules @@ -0,0 +1,6 @@ +[submodule "kythe"] + path = third_party/kythe + url = https://github.com/kythe/kythe +[submodule "bazel"] + path = third_party/bazel + url = https://github.com/bazelbuild/bazel From 41f100dba6ca9165c3732e97ef99b7e0c94b3ff6 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 14:11:52 +0100 Subject: [PATCH 3/7] Adds third_party/README.md --- third_party/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 third_party/README.md diff --git a/third_party/README.md b/third_party/README.md new file mode 100644 index 0000000..005faa2 --- /dev/null +++ b/third_party/README.md @@ -0,0 +1 @@ +# third_party From 57ca539c2089c6b5f6405a43d7e506df0f064838 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 14:22:40 +0100 Subject: [PATCH 4/7] Temporarily vendor build.proto from bazel --- third_party/bazel/src/main/protobuf/BUILD | 7 + .../bazel/src/main/protobuf/build.proto | 533 ++++++++++++++++++ 2 files changed, 540 insertions(+) create mode 100644 third_party/bazel/src/main/protobuf/BUILD create mode 100644 third_party/bazel/src/main/protobuf/build.proto diff --git a/third_party/bazel/src/main/protobuf/BUILD b/third_party/bazel/src/main/protobuf/BUILD new file mode 100644 index 0000000..79859dd --- /dev/null +++ b/third_party/bazel/src/main/protobuf/BUILD @@ -0,0 +1,7 @@ +load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") + +py_proto_library( + name = "build_py_proto", + srcs = ["build.proto"], + srcs_version = "PY2AND3", +) diff --git a/third_party/bazel/src/main/protobuf/build.proto b/third_party/bazel/src/main/protobuf/build.proto new file mode 100644 index 0000000..b9fa984 --- /dev/null +++ b/third_party/bazel/src/main/protobuf/build.proto @@ -0,0 +1,533 @@ +// Copyright 2014 The Bazel Authors. All rights reserved. +// +// 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. +// +// This file contains the protocol buffer representation of a build +// file or 'blaze query --output=proto' call. + +syntax = "proto2"; + +package blaze_query; + +// option cc_api_version = 2; +// option java_api_version = 1; +option java_package = "com.google.devtools.build.lib.query2.proto.proto2api"; + +message License { + repeated string license_type = 1; + repeated string exception = 2; +} + +message StringDictEntry { + required string key = 1; + required string value = 2; +} + +message LabelDictUnaryEntry { + required string key = 1; + required string value = 2; +} + +message LabelListDictEntry { + required string key = 1; + repeated string value = 2; +} + +message LabelKeyedStringDictEntry { + required string key = 1; + required string value = 2; +} + +message StringListDictEntry { + required string key = 1; + repeated string value = 2; +} + +// Represents an entry attribute of a Fileset rule in a build file. +message FilesetEntry { + // Indicates what to do when a source file is actually a symlink. + enum SymlinkBehavior { + COPY = 1; + DEREFERENCE = 2; + } + + // The label pointing to the source target where files are copied from. + required string source = 1; + + // The relative path within the fileset rule where files will be mapped. + required string destination_directory = 2; + + // Whether the files= attribute was specified. This is necessary because + // no files= attribute and files=[] mean different things. + optional bool files_present = 7; + + // A list of file labels to include from the source directory. + repeated string file = 3; + + // If this is a fileset entry representing files within the rule + // package, this lists relative paths to files that should be excluded from + // the set. This cannot contain values if 'file' also has values. + repeated string exclude = 4; + + // This field is optional because there will be some time when the new + // PB is used by tools depending on blaze query, but the new blaze version + // is not yet released. + // TODO(bazel-team): Make this field required once a version of Blaze is + // released that outputs this field. + optional SymlinkBehavior symlink_behavior = 5 [default = COPY]; + + // The prefix to strip from the path of the files in this FilesetEntry. Note + // that no value and the empty string as the value mean different things here. + optional string strip_prefix = 6; +} + +// A rule attribute. Each attribute must have a type and one of the various +// value fields populated - for the most part. +// +// Attributes of BOOLEAN and TRISTATE type may set all of the int, bool, and +// string values for backwards compatibility with clients that expect them to +// be set. +// +// Attributes of INTEGER, STRING, LABEL, LICENSE, BOOLEAN, and TRISTATE type +// may set *none* of the values. This can happen if the Attribute message is +// prepared for a client that doesn't support SELECTOR_LIST, but the rule has +// a selector list value for the attribute. (Selector lists for attributes of +// other types--the collection types--are handled differently when prepared +// for such a client. The possible collection values are gathered together +// and flattened.) +// +// By checking the type, the appropriate value can be extracted - see the +// comments on each type for the associated value. The order of lists comes +// from the blaze parsing. If an attribute is of a list type, the associated +// list should never be empty. +message Attribute { + reserved 12, 16; + + // Indicates the type of attribute. + enum Discriminator { + INTEGER = 1; // int_value + STRING = 2; // string_value + LABEL = 3; // string_value + OUTPUT = 4; // string_value + STRING_LIST = 5; // string_list_value + LABEL_LIST = 6; // string_list_value + OUTPUT_LIST = 7; // string_list_value + DISTRIBUTION_SET = 8; // string_list_value - order is unimportant + LICENSE = 9; // license + STRING_DICT = 10; // string_dict_value + FILESET_ENTRY_LIST = 11; // fileset_list_value + LABEL_LIST_DICT = 12; // label_list_dict_value + STRING_LIST_DICT = 13; // string_list_dict_value + BOOLEAN = 14; // int, bool and string value + TRISTATE = 15; // tristate, int and string value + INTEGER_LIST = 16; // int_list_value + UNKNOWN = 18; // unknown type, use only for build extensions + LABEL_DICT_UNARY = 19; // label_dict_unary_value + SELECTOR_LIST = 20; // selector_list + LABEL_KEYED_STRING_DICT = 21; // label_keyed_string_dict + + DEPRECATED_STRING_DICT_UNARY = 17; + } + + // Values for the TriState field type. + enum Tristate { + NO = 0; + YES = 1; + AUTO = 2; + } + + message SelectorEntry { + reserved 12; + + // The key of the selector entry. At this time, this is the label of a + // config_setting rule, or the pseudo-label "//conditions:default". + optional string label = 1; + + // True if the entry's value is the default value for the type as a + // result of the condition value being specified as None (ie: + // {"//condition": None}). + optional bool is_default_value = 16; + + // Exactly one of the following fields (except for glob_criteria) must be + // populated - note that the BOOLEAN and TRISTATE caveat in Attribute's + // comment does not apply here. The type field in the SelectorList + // containing this entry indicates which of these fields is populated, + // in accordance with the comments on Discriminator enum values above. + // (To be explicit: BOOLEAN populates the boolean_value field and TRISTATE + // populates the tristate_value field.) + optional int32 int_value = 2; + optional string string_value = 3; + optional bool boolean_value = 4; + optional Tristate tristate_value = 5; + repeated string string_list_value = 6; + optional License license = 7; + repeated StringDictEntry string_dict_value = 8; + repeated FilesetEntry fileset_list_value = 9; + repeated LabelListDictEntry label_list_dict_value = 10; + repeated StringListDictEntry string_list_dict_value = 11; + repeated int32 int_list_value = 13; + repeated LabelDictUnaryEntry label_dict_unary_value = 15; + repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 17; + + repeated bytes DEPRECATED_string_dict_unary_value = 14; + } + + message Selector { + // The list of (label, value) pairs in the map that defines the selector. + // At this time, this cannot be empty, i.e. a selector has at least one + // entry. + repeated SelectorEntry entries = 1; + + // Whether or not this has any default values. + optional bool has_default_value = 2; + + // The error message when no condition matches. + optional string no_match_error = 3; + } + + message SelectorList { + // The type that this selector list evaluates to, and the type that each + // selector in the list evaluates to. At this time, this cannot be + // SELECTOR_LIST, i.e. selector lists do not nest. + optional Discriminator type = 1; + + // The list of selector elements in this selector list. At this time, this + // cannot be empty, i.e. a selector list is never empty. + repeated Selector elements = 2; + } + + // The name of the attribute + required string name = 1; + + // Whether the attribute was explicitly specified + optional bool explicitly_specified = 13; + + // If this attribute has a string value or a string list value, then this + // may be set to indicate that the value may be treated as a label that + // isn't a dependency of this attribute's rule. + optional bool nodep = 20; + + // The type of attribute. This message is used for all of the different + // attribute types so the discriminator helps for figuring out what is + // stored in the message. + required Discriminator type = 2; + + // If this attribute has an integer value this will be populated. + // Boolean and TriState also use this field as [0,1] and [-1,0,1] + // for [false, true] and [auto, no, yes] respectively. + optional int32 int_value = 3; + + // If the attribute has a string value this will be populated. Label and + // path attributes use this field as the value even though the type may + // be LABEL or something else other than STRING. + optional string string_value = 5; + + // If the attribute has a boolean value this will be populated. + optional bool boolean_value = 14; + + // If the attribute is a Tristate value, this will be populated. + optional Tristate tristate_value = 15; + + // The value of the attribute has a list of string values (label and path + // note from STRING applies here as well). + repeated string string_list_value = 6; + + // If this is a license attribute, the license information is stored here. + optional License license = 7; + + // If this is a string dict, each entry will be stored here. + repeated StringDictEntry string_dict_value = 8; + + // If the attribute is part of a Fileset, the fileset entries are stored in + // this field. + repeated FilesetEntry fileset_list_value = 9; + + // If this is a label list dict, each entry will be stored here. + repeated LabelListDictEntry label_list_dict_value = 10; + + // If this is a string list dict, each entry will be stored here. + repeated StringListDictEntry string_list_dict_value = 11; + + // The value of the attribute has a list of int32 values + repeated int32 int_list_value = 17; + + // If this is a label dict unary, each entry will be stored here. + repeated LabelDictUnaryEntry label_dict_unary_value = 19; + + // If this is a label-keyed string dict, each entry will be stored here. + repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 22; + + // If this attribute's value is an expression containing one or more select + // expressions, then its type is SELECTOR_LIST and a SelectorList will be + // stored here. + optional SelectorList selector_list = 21; + + repeated bytes DEPRECATED_string_dict_unary_value = 18; +} + +// A rule instance (e.g., cc_library foo, java_binary bar). +message Rule { + reserved 8, 11; + + // The name of the rule (formatted as an absolute label, e.g. //foo/bar:baz). + required string name = 1; + + // The rule class (e.g., java_library) + required string rule_class = 2; + + // The BUILD file and line number of the location (formatted as + // ::) in the rule's package's + // BUILD file where the rule instance was instantiated. The line number will + // be that of a rule invocation or macro call (that in turn invoked a + // rule). See + // https://bazel.build/rules/macros#macro-creation + optional string location = 3; + + // All of the attributes that describe the rule. + repeated Attribute attribute = 4; + + // All of the inputs to the rule (formatted as absolute labels). These are + // predecessors in the dependency graph. + repeated string rule_input = 5; + + // All of the outputs of the rule (formatted as absolute labels). These are + // successors in the dependency graph. + repeated string rule_output = 6; + + // The set of all "features" inherited from the rule's package declaration. + repeated string default_setting = 7; + + // The rule's class's public by default value. + optional bool DEPRECATED_public_by_default = 9; + + optional bool DEPRECATED_is_skylark = 10; + + // Hash encapsulating the behavior of this Starlark rule. Any change to this + // rule's definition that could change its behavior will be reflected here. + optional string skylark_environment_hash_code = 12; + + // The Starlark call stack at the moment the rule was instantiated. + // Each entry has the form "file:line:col: function". + // The outermost stack frame ("", the BUILD file) appears first; + // the frame for the rule function itself is omitted. + // The file name may be relative to package's source root directory. + // + // Requires --proto:instantiation_stack=true. + repeated string instantiation_stack = 13; + + // The Starlark call stack for the definition of the rule class of this + // particular rule instance. If empty, either populating the field was not + // enabled on the command line with the --proto:definition_stack flag or the + // rule is a native one. + repeated string definition_stack = 14; +} + +// Summary of all transitive dependencies of 'rule,' where each dependent +// rule is included only once in the 'dependency' field. Gives complete +// information to analyze the single build target labeled rule.name, +// including optional location of target in BUILD file. +message RuleSummary { + required Rule rule = 1; + repeated Rule dependency = 2; + optional string location = 3; +} + +// A package group. Aside from the name, it contains the list of packages +// present in the group (as specified in the BUILD file). +message PackageGroup { + reserved 4; + + // The name of the package group + required string name = 1; + + // The list of packages as specified in the BUILD file. Currently this is + // only a list of packages, but some time in the future, there might be + // some type of wildcard mechanism. + repeated string contained_package = 2; + + // The list of sub package groups included in this one. + repeated string included_package_group = 3; +} + +// An environment group. +message EnvironmentGroup { + // The name of the environment group. + required string name = 1; + + // The environments that belong to this group (as labels). + repeated string environment = 2; + + // The member environments that rules implicitly support if not otherwise + // specified. + repeated string default = 3; +} + +// A file that is an input into the build system. +// Next-Id: 10 +message SourceFile { + reserved 7; + + // The name of the source file (a label). + required string name = 1; + + // The location of the source file. This is a path with a line number and a + // column number not a label in the build system. + optional string location = 2; + + // Labels of .bzl (Starlark) files that are transitively loaded in this BUILD + // file. This is present only when the SourceFile represents a BUILD file that + // loaded .bzl files. + // TODO(bazel-team): Rename this field. + repeated string subinclude = 3; + + // Labels of package groups that are mentioned in the visibility declaration + // for this source file. + repeated string package_group = 4; + + // Labels mentioned in the visibility declaration (including :__pkg__ and + // //visibility: ones) + repeated string visibility_label = 5; + + // The package-level features enabled for this package. Only present if the + // SourceFile represents a BUILD file. + repeated string feature = 6; + + // License attribute for the file. + optional License license = 8; + + // True if the package contains an error. Only present if the SourceFile + // represents a BUILD file. + optional bool package_contains_errors = 9; +} + +// A file that is the output of a build rule. +message GeneratedFile { + // The name of the generated file (a label). + required string name = 1; + + // The label of the target that generates the file. + required string generating_rule = 2; + + // The path, line number, and column number of the output file (not a label). + optional string location = 3; +} + +// A target from a blaze query execution. Similar to the Attribute message, +// the Discriminator is used to determine which field contains information. +// For any given type, only one of these can be populated in a single Target. +message Target { + enum Discriminator { + RULE = 1; + SOURCE_FILE = 2; + GENERATED_FILE = 3; + PACKAGE_GROUP = 4; + ENVIRONMENT_GROUP = 5; + } + + // The type of target contained in the message. + required Discriminator type = 1; + + // If this target represents a rule, the rule is stored here. + optional Rule rule = 2; + + // A file that is not generated by the build system (version controlled + // or created by the test harness). + optional SourceFile source_file = 3; + + // A generated file that is the output of a rule. + optional GeneratedFile generated_file = 4; + + // A package group. + optional PackageGroup package_group = 5; + + // An environment group. + optional EnvironmentGroup environment_group = 6; +} + +// Container for all of the blaze query results. +message QueryResult { + // All of the targets returned by the blaze query. + repeated Target target = 1; +} + +//////////////////////////////////////////////////////////////////////////// +// Messages dealing with querying the BUILD language itself. For now, this is +// quite simplistic: Blaze can only tell the names of the rule classes, their +// attributes with their type. + +// Information about allowed rule classes for a specific attribute of a rule. +message AllowedRuleClassInfo { + enum AllowedRuleClasses { + ANY = 1; // Any rule is allowed to be in this attribute + SPECIFIED = 2; // Only the explicitly listed rules are allowed + } + + required AllowedRuleClasses policy = 1; + + // Rule class names of rules allowed in this attribute, e.g "cc_library", + // "py_binary". Only present if the allowed_rule_classes field is set to + // SPECIFIED. + repeated string allowed_rule_class = 2; +} + +// This message represents a single attribute of a single rule. +// See https://bazel.build/rules/lib/attr. +message AttributeDefinition { + required string name = 1; // e.g. "name", "srcs" + required Attribute.Discriminator type = 2; + optional bool mandatory = 3; + optional AllowedRuleClassInfo allowed_rule_classes = 4; // type=label* + optional string documentation = 5; + optional bool allow_empty = 6; // type=*_list|*_dict + optional bool allow_single_file = 7; // type=label + optional AttributeValue default = + 9; // simple (not computed/late-bound) values only + optional bool executable = 10; // type=label + optional bool configurable = 11; + optional bool nodep = + 12; // label-valued edge does not establish a dependency + optional bool cfg_is_host = + 13; // edge entails a transition to "host" configuration +} + +// An AttributeValue represents the value of an attribute. +// A single field, determined by the attribute type, is populated. +// +// It is used only for AttributeDefinition.default. Attribute and +// SelectorEntry do their own thing for unfortunate historical reasons. +message AttributeValue { + optional int32 int = 1; // type=int|tristate + optional string string = 2; // type=string|label|output + optional bool bool = 3; // type=bool + repeated AttributeValue list = 4; // type=*_list|distrib + repeated DictEntry dict = 5; // type=*_dict + + message DictEntry { + required string key = 1; + required AttributeValue value = 2; + } +} + +message RuleDefinition { + required string name = 1; + // Only contains documented attributes + repeated AttributeDefinition attribute = 2; + optional string documentation = 3; + // Only for build extensions: label to file that defines the extension + optional string label = 4; +} + +message BuildLanguage { + // Only contains documented rule definitions + repeated RuleDefinition rule = 1; +} \ No newline at end of file From 33ed0d7ad07c05c651e5dd6ddd28302e1c861657 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 14:22:43 +0100 Subject: [PATCH 5/7] Create bazel_query_on_repo.binarypb --- testdata/bazel_query_on_repo.binarypb | Bin 0 -> 13054 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 testdata/bazel_query_on_repo.binarypb diff --git a/testdata/bazel_query_on_repo.binarypb b/testdata/bazel_query_on_repo.binarypb new file mode 100644 index 0000000000000000000000000000000000000000..fb4e76832ba631f97e4808f83aae663c68f023ac GIT binary patch literal 13054 zcmeHN-E!O35f*Jpq}GFVS1D~H-nSyj5!HjVN#Q+2!4 zU{3kD#=dqNWyjJr*02@LD1Z5C|KM3omTQ%b;#W{8sVZTnsjD4qB<$3p`D@aHC*BfX zgHtZ^cAVU@YVn?(i9cpC#k+93q?$%cYm+9msL`Z`s!=CD&6_8Rzl2+*woNUf8LI9! zvEjP(S=#)(;}=0kF@6olYYw3&RCSrs&}shGaz>hDwo5w`R;IWMGbLSd4YfnIS++p|tt$21ZpunjkG9^Nc7a}zglug?U$i&%aGvZXhgWqJEv zOB#Z$HPJ(iSb=;^QJH2MMAsZf4IJu=c^77Dy{g1r{5)yOm=?vX%P?0%F=z&(wq;ZN zH-BBU+<|$;Leo*X+;K^j8cw9yS(sGpwv(R{ofqJy;#gE=q=Qq1`p4N-vui0#<8!>$ zSSQ#rj&CYV34Y#&8)!c^Rk5pS>s6AhP35h8x$XkZYnKY^~wsb8>FK zezbR3e|jK>&cJnQ9Ot1k!EKZq5J}m|0?c{MmTjUo7`I+N>J!MdsKQ(ufBT2L3xzfp zyTVMHw9x9rUZn}KWUN^?gQEn^D{w0sZQx}^WAjJmA**#Q(?-GhOFe>uPTPulN>m$n zK~X^(%g-(U82pE~KyjJbnK-#tT!dVxo|)P-Ox9o2_wWcP<1Sw8K%qsL^p~Aaa4ABj zcVW(SndP!b;k`3Hf?LAY$uYVdPg7EX1d=B&_v%Oc^*vt&i!h7AL;a|XHu0hby8av{ z9b4sET}k$C>(;5*%^KX~J$n|*e*3-rwEoP$L~AhRFr{my2?hngl*mZ$!6HMWr7X=9 zRv^c4$EKm5qNACRrdo>bQ1mnt#d(0xRfOjKDHNEk7>>rYV~UezJ$5e_FLyx+qKHhpseVEDMOzGpg&f>9B{sk z2ws5m2Tu@MleTHL5#)P9Y`85UU}oZ0iuQPQd$%$u=hj#IgV{!$|}7pM~zQ?}TXp{6Xl{md;;;hCGai^S1Y^0A9-*gnaw` z(bq5Ps;}G<*2>4EmgZ%|P+IuzjCHFfkO)XU6*<|9wfm=jxnDa!Swhe$Q(N3%J;Y$5fi0 zc-4lMqUo5TN2zo|+P(zSC{LoQXLGtm(O~gpFQ_VIu&VSSIuAT|P&&gJf_FXFLoabJ z+3kd8C;FpXz}(--XXUgzA^Oe1w57Z4sIagGbK(Qh6{GDcZLW{Wwr#0mz!FvsyaB|t zc*!KJa;)P_Jm#ucu)5nXi1-twIW+W#eno-TOJj#!_ZATQc(3Jv&(D+t=Hul6w}B-b zzRgULz)Hz>F_dCWNTlMXFM{znR*eA_hswj=>PHUsp*xssCcjN}$-jp}0>ZT%7 zS#9mATU(EJ9`C5za;36E)eU8{TCG&&t;*Kpjb>F!5z+t^q*?|1EsGBB&sm7qDq=wD z?Tgfv&03}MaUiM4Cwh5p-@4|-9A<)7j8!Wyx0sm*V=%e$3zBfQwwrd-pNBU+k2gIU zg_uS5zVN%^Fimy%7c99&?1{@XoqrX+U{GmsguY@_NG0(!(m6SZFTHXY2xZ_e3wVS7 zv;f@kM?xhHWOF)Q#r~m?Mcm9wqZdFWn_IQ&Xvn4mSVpo**E!9gnplCxNJAXe)+~kr zB$2q`d#;@w6O`*OmAd+Hsi`W=mbl!A?HWu&o?=@5SrVJ%$=2^9MEV3dHE*OtnQKL= zxt}^b>MdsYMX>g3Bs~Q=mdF=+YkPzJj$-&XuuwYb>KxekG)-t8kNWQ+HcCvki_9MX z{Myz$T1-kmM$}CV{eNNizJpb?e*dN*y^0i5BpbXla;i{LM~MUO!6(tgj%)Fm2i(En zzKYIb8mvszbXBvUHp@uPV<%!{0xGQAy5dqiL;EA1l105sxhWy2yfIZ2@`8z>z{+-_2jZy56!@SNL z62-2CD0Z#~#d2-FZva~g0qny0z&pmSF_}ooB9eMCN z;HLj@+S3;%%HgZO1p|`!?6V1!?1m8a+SLi)rT4(fxT@K+n KDiULu&HoRnB{}5) literal 0 HcmV?d00001 From d63e13f54710047c4edc354dd0bfe8e4cce40f10 Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 15:10:30 +0100 Subject: [PATCH 6/7] deletes bazel --- third_party/bazel/src/main/protobuf/BUILD | 7 - .../bazel/src/main/protobuf/build.proto | 533 ------------------ 2 files changed, 540 deletions(-) delete mode 100644 third_party/bazel/src/main/protobuf/BUILD delete mode 100644 third_party/bazel/src/main/protobuf/build.proto diff --git a/third_party/bazel/src/main/protobuf/BUILD b/third_party/bazel/src/main/protobuf/BUILD deleted file mode 100644 index 79859dd..0000000 --- a/third_party/bazel/src/main/protobuf/BUILD +++ /dev/null @@ -1,7 +0,0 @@ -load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") - -py_proto_library( - name = "build_py_proto", - srcs = ["build.proto"], - srcs_version = "PY2AND3", -) diff --git a/third_party/bazel/src/main/protobuf/build.proto b/third_party/bazel/src/main/protobuf/build.proto deleted file mode 100644 index b9fa984..0000000 --- a/third_party/bazel/src/main/protobuf/build.proto +++ /dev/null @@ -1,533 +0,0 @@ -// Copyright 2014 The Bazel Authors. All rights reserved. -// -// 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. -// -// This file contains the protocol buffer representation of a build -// file or 'blaze query --output=proto' call. - -syntax = "proto2"; - -package blaze_query; - -// option cc_api_version = 2; -// option java_api_version = 1; -option java_package = "com.google.devtools.build.lib.query2.proto.proto2api"; - -message License { - repeated string license_type = 1; - repeated string exception = 2; -} - -message StringDictEntry { - required string key = 1; - required string value = 2; -} - -message LabelDictUnaryEntry { - required string key = 1; - required string value = 2; -} - -message LabelListDictEntry { - required string key = 1; - repeated string value = 2; -} - -message LabelKeyedStringDictEntry { - required string key = 1; - required string value = 2; -} - -message StringListDictEntry { - required string key = 1; - repeated string value = 2; -} - -// Represents an entry attribute of a Fileset rule in a build file. -message FilesetEntry { - // Indicates what to do when a source file is actually a symlink. - enum SymlinkBehavior { - COPY = 1; - DEREFERENCE = 2; - } - - // The label pointing to the source target where files are copied from. - required string source = 1; - - // The relative path within the fileset rule where files will be mapped. - required string destination_directory = 2; - - // Whether the files= attribute was specified. This is necessary because - // no files= attribute and files=[] mean different things. - optional bool files_present = 7; - - // A list of file labels to include from the source directory. - repeated string file = 3; - - // If this is a fileset entry representing files within the rule - // package, this lists relative paths to files that should be excluded from - // the set. This cannot contain values if 'file' also has values. - repeated string exclude = 4; - - // This field is optional because there will be some time when the new - // PB is used by tools depending on blaze query, but the new blaze version - // is not yet released. - // TODO(bazel-team): Make this field required once a version of Blaze is - // released that outputs this field. - optional SymlinkBehavior symlink_behavior = 5 [default = COPY]; - - // The prefix to strip from the path of the files in this FilesetEntry. Note - // that no value and the empty string as the value mean different things here. - optional string strip_prefix = 6; -} - -// A rule attribute. Each attribute must have a type and one of the various -// value fields populated - for the most part. -// -// Attributes of BOOLEAN and TRISTATE type may set all of the int, bool, and -// string values for backwards compatibility with clients that expect them to -// be set. -// -// Attributes of INTEGER, STRING, LABEL, LICENSE, BOOLEAN, and TRISTATE type -// may set *none* of the values. This can happen if the Attribute message is -// prepared for a client that doesn't support SELECTOR_LIST, but the rule has -// a selector list value for the attribute. (Selector lists for attributes of -// other types--the collection types--are handled differently when prepared -// for such a client. The possible collection values are gathered together -// and flattened.) -// -// By checking the type, the appropriate value can be extracted - see the -// comments on each type for the associated value. The order of lists comes -// from the blaze parsing. If an attribute is of a list type, the associated -// list should never be empty. -message Attribute { - reserved 12, 16; - - // Indicates the type of attribute. - enum Discriminator { - INTEGER = 1; // int_value - STRING = 2; // string_value - LABEL = 3; // string_value - OUTPUT = 4; // string_value - STRING_LIST = 5; // string_list_value - LABEL_LIST = 6; // string_list_value - OUTPUT_LIST = 7; // string_list_value - DISTRIBUTION_SET = 8; // string_list_value - order is unimportant - LICENSE = 9; // license - STRING_DICT = 10; // string_dict_value - FILESET_ENTRY_LIST = 11; // fileset_list_value - LABEL_LIST_DICT = 12; // label_list_dict_value - STRING_LIST_DICT = 13; // string_list_dict_value - BOOLEAN = 14; // int, bool and string value - TRISTATE = 15; // tristate, int and string value - INTEGER_LIST = 16; // int_list_value - UNKNOWN = 18; // unknown type, use only for build extensions - LABEL_DICT_UNARY = 19; // label_dict_unary_value - SELECTOR_LIST = 20; // selector_list - LABEL_KEYED_STRING_DICT = 21; // label_keyed_string_dict - - DEPRECATED_STRING_DICT_UNARY = 17; - } - - // Values for the TriState field type. - enum Tristate { - NO = 0; - YES = 1; - AUTO = 2; - } - - message SelectorEntry { - reserved 12; - - // The key of the selector entry. At this time, this is the label of a - // config_setting rule, or the pseudo-label "//conditions:default". - optional string label = 1; - - // True if the entry's value is the default value for the type as a - // result of the condition value being specified as None (ie: - // {"//condition": None}). - optional bool is_default_value = 16; - - // Exactly one of the following fields (except for glob_criteria) must be - // populated - note that the BOOLEAN and TRISTATE caveat in Attribute's - // comment does not apply here. The type field in the SelectorList - // containing this entry indicates which of these fields is populated, - // in accordance with the comments on Discriminator enum values above. - // (To be explicit: BOOLEAN populates the boolean_value field and TRISTATE - // populates the tristate_value field.) - optional int32 int_value = 2; - optional string string_value = 3; - optional bool boolean_value = 4; - optional Tristate tristate_value = 5; - repeated string string_list_value = 6; - optional License license = 7; - repeated StringDictEntry string_dict_value = 8; - repeated FilesetEntry fileset_list_value = 9; - repeated LabelListDictEntry label_list_dict_value = 10; - repeated StringListDictEntry string_list_dict_value = 11; - repeated int32 int_list_value = 13; - repeated LabelDictUnaryEntry label_dict_unary_value = 15; - repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 17; - - repeated bytes DEPRECATED_string_dict_unary_value = 14; - } - - message Selector { - // The list of (label, value) pairs in the map that defines the selector. - // At this time, this cannot be empty, i.e. a selector has at least one - // entry. - repeated SelectorEntry entries = 1; - - // Whether or not this has any default values. - optional bool has_default_value = 2; - - // The error message when no condition matches. - optional string no_match_error = 3; - } - - message SelectorList { - // The type that this selector list evaluates to, and the type that each - // selector in the list evaluates to. At this time, this cannot be - // SELECTOR_LIST, i.e. selector lists do not nest. - optional Discriminator type = 1; - - // The list of selector elements in this selector list. At this time, this - // cannot be empty, i.e. a selector list is never empty. - repeated Selector elements = 2; - } - - // The name of the attribute - required string name = 1; - - // Whether the attribute was explicitly specified - optional bool explicitly_specified = 13; - - // If this attribute has a string value or a string list value, then this - // may be set to indicate that the value may be treated as a label that - // isn't a dependency of this attribute's rule. - optional bool nodep = 20; - - // The type of attribute. This message is used for all of the different - // attribute types so the discriminator helps for figuring out what is - // stored in the message. - required Discriminator type = 2; - - // If this attribute has an integer value this will be populated. - // Boolean and TriState also use this field as [0,1] and [-1,0,1] - // for [false, true] and [auto, no, yes] respectively. - optional int32 int_value = 3; - - // If the attribute has a string value this will be populated. Label and - // path attributes use this field as the value even though the type may - // be LABEL or something else other than STRING. - optional string string_value = 5; - - // If the attribute has a boolean value this will be populated. - optional bool boolean_value = 14; - - // If the attribute is a Tristate value, this will be populated. - optional Tristate tristate_value = 15; - - // The value of the attribute has a list of string values (label and path - // note from STRING applies here as well). - repeated string string_list_value = 6; - - // If this is a license attribute, the license information is stored here. - optional License license = 7; - - // If this is a string dict, each entry will be stored here. - repeated StringDictEntry string_dict_value = 8; - - // If the attribute is part of a Fileset, the fileset entries are stored in - // this field. - repeated FilesetEntry fileset_list_value = 9; - - // If this is a label list dict, each entry will be stored here. - repeated LabelListDictEntry label_list_dict_value = 10; - - // If this is a string list dict, each entry will be stored here. - repeated StringListDictEntry string_list_dict_value = 11; - - // The value of the attribute has a list of int32 values - repeated int32 int_list_value = 17; - - // If this is a label dict unary, each entry will be stored here. - repeated LabelDictUnaryEntry label_dict_unary_value = 19; - - // If this is a label-keyed string dict, each entry will be stored here. - repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 22; - - // If this attribute's value is an expression containing one or more select - // expressions, then its type is SELECTOR_LIST and a SelectorList will be - // stored here. - optional SelectorList selector_list = 21; - - repeated bytes DEPRECATED_string_dict_unary_value = 18; -} - -// A rule instance (e.g., cc_library foo, java_binary bar). -message Rule { - reserved 8, 11; - - // The name of the rule (formatted as an absolute label, e.g. //foo/bar:baz). - required string name = 1; - - // The rule class (e.g., java_library) - required string rule_class = 2; - - // The BUILD file and line number of the location (formatted as - // ::) in the rule's package's - // BUILD file where the rule instance was instantiated. The line number will - // be that of a rule invocation or macro call (that in turn invoked a - // rule). See - // https://bazel.build/rules/macros#macro-creation - optional string location = 3; - - // All of the attributes that describe the rule. - repeated Attribute attribute = 4; - - // All of the inputs to the rule (formatted as absolute labels). These are - // predecessors in the dependency graph. - repeated string rule_input = 5; - - // All of the outputs of the rule (formatted as absolute labels). These are - // successors in the dependency graph. - repeated string rule_output = 6; - - // The set of all "features" inherited from the rule's package declaration. - repeated string default_setting = 7; - - // The rule's class's public by default value. - optional bool DEPRECATED_public_by_default = 9; - - optional bool DEPRECATED_is_skylark = 10; - - // Hash encapsulating the behavior of this Starlark rule. Any change to this - // rule's definition that could change its behavior will be reflected here. - optional string skylark_environment_hash_code = 12; - - // The Starlark call stack at the moment the rule was instantiated. - // Each entry has the form "file:line:col: function". - // The outermost stack frame ("", the BUILD file) appears first; - // the frame for the rule function itself is omitted. - // The file name may be relative to package's source root directory. - // - // Requires --proto:instantiation_stack=true. - repeated string instantiation_stack = 13; - - // The Starlark call stack for the definition of the rule class of this - // particular rule instance. If empty, either populating the field was not - // enabled on the command line with the --proto:definition_stack flag or the - // rule is a native one. - repeated string definition_stack = 14; -} - -// Summary of all transitive dependencies of 'rule,' where each dependent -// rule is included only once in the 'dependency' field. Gives complete -// information to analyze the single build target labeled rule.name, -// including optional location of target in BUILD file. -message RuleSummary { - required Rule rule = 1; - repeated Rule dependency = 2; - optional string location = 3; -} - -// A package group. Aside from the name, it contains the list of packages -// present in the group (as specified in the BUILD file). -message PackageGroup { - reserved 4; - - // The name of the package group - required string name = 1; - - // The list of packages as specified in the BUILD file. Currently this is - // only a list of packages, but some time in the future, there might be - // some type of wildcard mechanism. - repeated string contained_package = 2; - - // The list of sub package groups included in this one. - repeated string included_package_group = 3; -} - -// An environment group. -message EnvironmentGroup { - // The name of the environment group. - required string name = 1; - - // The environments that belong to this group (as labels). - repeated string environment = 2; - - // The member environments that rules implicitly support if not otherwise - // specified. - repeated string default = 3; -} - -// A file that is an input into the build system. -// Next-Id: 10 -message SourceFile { - reserved 7; - - // The name of the source file (a label). - required string name = 1; - - // The location of the source file. This is a path with a line number and a - // column number not a label in the build system. - optional string location = 2; - - // Labels of .bzl (Starlark) files that are transitively loaded in this BUILD - // file. This is present only when the SourceFile represents a BUILD file that - // loaded .bzl files. - // TODO(bazel-team): Rename this field. - repeated string subinclude = 3; - - // Labels of package groups that are mentioned in the visibility declaration - // for this source file. - repeated string package_group = 4; - - // Labels mentioned in the visibility declaration (including :__pkg__ and - // //visibility: ones) - repeated string visibility_label = 5; - - // The package-level features enabled for this package. Only present if the - // SourceFile represents a BUILD file. - repeated string feature = 6; - - // License attribute for the file. - optional License license = 8; - - // True if the package contains an error. Only present if the SourceFile - // represents a BUILD file. - optional bool package_contains_errors = 9; -} - -// A file that is the output of a build rule. -message GeneratedFile { - // The name of the generated file (a label). - required string name = 1; - - // The label of the target that generates the file. - required string generating_rule = 2; - - // The path, line number, and column number of the output file (not a label). - optional string location = 3; -} - -// A target from a blaze query execution. Similar to the Attribute message, -// the Discriminator is used to determine which field contains information. -// For any given type, only one of these can be populated in a single Target. -message Target { - enum Discriminator { - RULE = 1; - SOURCE_FILE = 2; - GENERATED_FILE = 3; - PACKAGE_GROUP = 4; - ENVIRONMENT_GROUP = 5; - } - - // The type of target contained in the message. - required Discriminator type = 1; - - // If this target represents a rule, the rule is stored here. - optional Rule rule = 2; - - // A file that is not generated by the build system (version controlled - // or created by the test harness). - optional SourceFile source_file = 3; - - // A generated file that is the output of a rule. - optional GeneratedFile generated_file = 4; - - // A package group. - optional PackageGroup package_group = 5; - - // An environment group. - optional EnvironmentGroup environment_group = 6; -} - -// Container for all of the blaze query results. -message QueryResult { - // All of the targets returned by the blaze query. - repeated Target target = 1; -} - -//////////////////////////////////////////////////////////////////////////// -// Messages dealing with querying the BUILD language itself. For now, this is -// quite simplistic: Blaze can only tell the names of the rule classes, their -// attributes with their type. - -// Information about allowed rule classes for a specific attribute of a rule. -message AllowedRuleClassInfo { - enum AllowedRuleClasses { - ANY = 1; // Any rule is allowed to be in this attribute - SPECIFIED = 2; // Only the explicitly listed rules are allowed - } - - required AllowedRuleClasses policy = 1; - - // Rule class names of rules allowed in this attribute, e.g "cc_library", - // "py_binary". Only present if the allowed_rule_classes field is set to - // SPECIFIED. - repeated string allowed_rule_class = 2; -} - -// This message represents a single attribute of a single rule. -// See https://bazel.build/rules/lib/attr. -message AttributeDefinition { - required string name = 1; // e.g. "name", "srcs" - required Attribute.Discriminator type = 2; - optional bool mandatory = 3; - optional AllowedRuleClassInfo allowed_rule_classes = 4; // type=label* - optional string documentation = 5; - optional bool allow_empty = 6; // type=*_list|*_dict - optional bool allow_single_file = 7; // type=label - optional AttributeValue default = - 9; // simple (not computed/late-bound) values only - optional bool executable = 10; // type=label - optional bool configurable = 11; - optional bool nodep = - 12; // label-valued edge does not establish a dependency - optional bool cfg_is_host = - 13; // edge entails a transition to "host" configuration -} - -// An AttributeValue represents the value of an attribute. -// A single field, determined by the attribute type, is populated. -// -// It is used only for AttributeDefinition.default. Attribute and -// SelectorEntry do their own thing for unfortunate historical reasons. -message AttributeValue { - optional int32 int = 1; // type=int|tristate - optional string string = 2; // type=string|label|output - optional bool bool = 3; // type=bool - repeated AttributeValue list = 4; // type=*_list|distrib - repeated DictEntry dict = 5; // type=*_dict - - message DictEntry { - required string key = 1; - required AttributeValue value = 2; - } -} - -message RuleDefinition { - required string name = 1; - // Only contains documented attributes - repeated AttributeDefinition attribute = 2; - optional string documentation = 3; - // Only for build extensions: label to file that defines the extension - optional string label = 4; -} - -message BuildLanguage { - // Only contains documented rule definitions - repeated RuleDefinition rule = 1; -} \ No newline at end of file From 1a2d1629b7e5ea66847c8f594be47b666ffe51fc Mon Sep 17 00:00:00 2001 From: Cameron Brown Date: Fri, 1 Apr 2022 15:29:23 +0100 Subject: [PATCH 7/7] Adds TODOs to graphdef_from_bazel.py --- graphdef_from_bazel.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/graphdef_from_bazel.py b/graphdef_from_bazel.py index c60af75..5e99b4e 100644 --- a/graphdef_from_bazel.py +++ b/graphdef_from_bazel.py @@ -11,6 +11,7 @@ from absl import app from absl import flags import graphdef_utils +from third_party.bazel.src.main.protobuf import build_pb2 FLAGS = flags.FLAGS flags.DEFINE_string('input_path', None, 'Path to Bazel WORKSPACE file.') @@ -26,6 +27,17 @@ def main(argv): del argv + with open(FLAGS.input_path) as f: + pass + + # TODO(cameron): Load bazel proto using vendored dependency. + # TODO(cameron): Filter on predicates: Must be a working change in the CL? Maybe keep transitive. + # TODO(cameron): Find testdata based stuff and make changes bi-directional. Same with proto. + # TODO(cameron): Merge bi-directional dependencies. + # TODO(cameron): Import tests from internal. + # TODO(cameron): Assert the graph is a DAG. Find and merge cycles. + graphdef = program_graph_pb2.GraphDef() + if __name__ == '__main__': app.run(main) \ No newline at end of file