1// Copyright 2014 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// This file contains the protocol buffer representation of a build
16// file or 'blaze query --output=proto' call.
17syntax = "proto2";
18package blaze_query;
19// option cc_api_version = 2;
20// option java_api_version = 1;
21option java_package = "com.google.devtools.build.lib.query2.proto.proto2api";
22option go_package = "prebuilts/bazel/common/proto/build";
23message License {
24  repeated string license_type = 1;
25  repeated string exception = 2;
26}
27message StringDictEntry {
28  required string key = 1;
29  required string value = 2;
30}
31message LabelDictUnaryEntry {
32  required string key = 1;
33  required string value = 2;
34}
35message LabelListDictEntry {
36  required string key = 1;
37  repeated string value = 2;
38}
39message LabelKeyedStringDictEntry {
40  required string key = 1;
41  required string value = 2;
42}
43message StringListDictEntry {
44  required string key = 1;
45  repeated string value = 2;
46}
47// Represents an entry attribute of a Fileset rule in a build file.
48message FilesetEntry {
49  // Indicates what to do when a source file is actually a symlink.
50  enum SymlinkBehavior {
51    COPY = 1;
52    DEREFERENCE = 2;
53  }
54  // The label pointing to the source target where files are copied from.
55  required string source = 1;
56  // The relative path within the fileset rule where files will be mapped.
57  required string destination_directory = 2;
58  // Whether the files= attribute was specified. This is necessary because
59  // no files= attribute and files=[] mean different things.
60  optional bool files_present = 7;
61  // A list of file labels to include from the source directory.
62  repeated string file = 3;
63  // If this is a fileset entry representing files within the rule
64  // package, this lists relative paths to files that should be excluded from
65  // the set.  This cannot contain values if 'file' also has values.
66  repeated string exclude = 4;
67  // This field is optional because there will be some time when the new
68  // PB is used by tools depending on blaze query, but the new blaze version
69  // is not yet released.
70  // TODO(bazel-team): Make this field required once a version of Blaze is
71  // released that outputs this field.
72  optional SymlinkBehavior symlink_behavior = 5 [default = COPY];
73  // The prefix to strip from the path of the files in this FilesetEntry. Note
74  // that no value and the empty string as the value mean different things here.
75  optional string strip_prefix = 6;
76}
77// A rule attribute. Each attribute must have a type and one of the various
78// value fields populated - for the most part.
79//
80// Attributes of BOOLEAN and TRISTATE type may set all of the int, bool, and
81// string values for backwards compatibility with clients that expect them to
82// be set.
83//
84// Attributes of INTEGER, STRING, LABEL, LICENSE, BOOLEAN, and TRISTATE type
85// may set *none* of the values. This can happen if the Attribute message is
86// prepared for a client that doesn't support SELECTOR_LIST, but the rule has
87// a selector list value for the attribute. (Selector lists for attributes of
88// other types--the collection types--are handled differently when prepared
89// for such a client. The possible collection values are gathered together
90// and flattened.)
91//
92// By checking the type, the appropriate value can be extracted - see the
93// comments on each type for the associated value.  The order of lists comes
94// from the blaze parsing. If an attribute is of a list type, the associated
95// list should never be empty.
96message Attribute {
97  reserved 12, 16;
98  // Indicates the type of attribute.
99  enum Discriminator {
100    INTEGER = 1;              // int_value
101    STRING = 2;               // string_value
102    LABEL = 3;                // string_value
103    OUTPUT = 4;               // string_value
104    STRING_LIST = 5;          // string_list_value
105    LABEL_LIST = 6;           // string_list_value
106    OUTPUT_LIST = 7;          // string_list_value
107    DISTRIBUTION_SET = 8;     // string_list_value - order is unimportant
108    LICENSE = 9;              // license
109    STRING_DICT = 10;         // string_dict_value
110    FILESET_ENTRY_LIST = 11;  // fileset_list_value
111    LABEL_LIST_DICT = 12;     // label_list_dict_value
112    STRING_LIST_DICT = 13;    // string_list_dict_value
113    BOOLEAN = 14;             // int, bool and string value
114    TRISTATE = 15;            // tristate, int and string value
115    INTEGER_LIST = 16;        // int_list_value
116    UNKNOWN = 18;             // unknown type, use only for build extensions
117    LABEL_DICT_UNARY = 19;    // label_dict_unary_value
118    SELECTOR_LIST = 20;       // selector_list
119    LABEL_KEYED_STRING_DICT = 21;  // label_keyed_string_dict
120    DEPRECATED_STRING_DICT_UNARY = 17;
121  }
122  // Values for the TriState field type.
123  enum Tristate {
124    NO = 0;
125    YES = 1;
126    AUTO = 2;
127  }
128  message SelectorEntry {
129    reserved 12;
130    // The key of the selector entry. At this time, this is the label of a
131    // config_setting rule, or the pseudo-label "//conditions:default".
132    optional string label = 1;
133    // True if the entry's value is the default value for the type as a
134    // result of the condition value being specified as None (ie:
135    // {"//condition": None}).
136    optional bool is_default_value = 16;
137    // Exactly one of the following fields (except for glob_criteria) must be
138    // populated - note that the BOOLEAN and TRISTATE caveat in Attribute's
139    // comment does not apply here. The type field in the SelectorList
140    // containing this entry indicates which of these fields is populated,
141    // in accordance with the comments on Discriminator enum values above.
142    // (To be explicit: BOOLEAN populates the boolean_value field and TRISTATE
143    // populates the tristate_value field.)
144    optional int32 int_value = 2;
145    optional string string_value = 3;
146    optional bool boolean_value = 4;
147    optional Tristate tristate_value = 5;
148    repeated string string_list_value = 6;
149    optional License license = 7;
150    repeated StringDictEntry string_dict_value = 8;
151    repeated FilesetEntry fileset_list_value = 9;
152    repeated LabelListDictEntry label_list_dict_value = 10;
153    repeated StringListDictEntry string_list_dict_value = 11;
154    repeated int32 int_list_value = 13;
155    repeated LabelDictUnaryEntry label_dict_unary_value = 15;
156    repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 17;
157    repeated bytes DEPRECATED_string_dict_unary_value = 14;
158  }
159  message Selector {
160    // The list of (label, value) pairs in the map that defines the selector.
161    // At this time, this cannot be empty, i.e. a selector has at least one
162    // entry.
163    repeated SelectorEntry entries = 1;
164    // Whether or not this has any default values.
165    optional bool has_default_value = 2;
166    // The error message when no condition matches.
167    optional string no_match_error = 3;
168  }
169  message SelectorList {
170    // The type that this selector list evaluates to, and the type that each
171    // selector in the list evaluates to. At this time, this cannot be
172    // SELECTOR_LIST, i.e. selector lists do not nest.
173    optional Discriminator type = 1;
174    // The list of selector elements in this selector list. At this time, this
175    // cannot be empty, i.e. a selector list is never empty.
176    repeated Selector elements = 2;
177  }
178  // The name of the attribute
179  required string name = 1;
180  // Whether the attribute was explicitly specified
181  optional bool explicitly_specified = 13;
182  // If this attribute has a string value or a string list value, then this
183  // may be set to indicate that the value may be treated as a label that
184  // isn't a dependency of this attribute's rule.
185  optional bool nodep = 20;
186  // The type of attribute.  This message is used for all of the different
187  // attribute types so the discriminator helps for figuring out what is
188  // stored in the message.
189  required Discriminator type = 2;
190  // If this attribute has an integer value this will be populated.
191  // Boolean and TriState also use this field as [0,1] and [-1,0,1]
192  // for [false, true] and [auto, no, yes] respectively.
193  optional int32 int_value = 3;
194  // If the attribute has a string value this will be populated.  Label and
195  // path attributes use this field as the value even though the type may
196  // be LABEL or something else other than STRING.
197  optional string string_value = 5;
198  // If the attribute has a boolean value this will be populated.
199  optional bool boolean_value = 14;
200  // If the attribute is a Tristate value, this will be populated.
201  optional Tristate tristate_value = 15;
202  // The value of the attribute has a list of string values (label and path
203  // note from STRING applies here as well).
204  repeated string string_list_value = 6;
205  // If this is a license attribute, the license information is stored here.
206  optional License license = 7;
207  // If this is a string dict, each entry will be stored here.
208  repeated StringDictEntry string_dict_value = 8;
209  // If the attribute is part of a Fileset, the fileset entries are stored in
210  // this field.
211  repeated FilesetEntry fileset_list_value = 9;
212  // If this is a label list dict, each entry will be stored here.
213  repeated LabelListDictEntry label_list_dict_value = 10;
214  // If this is a string list dict, each entry will be stored here.
215  repeated StringListDictEntry string_list_dict_value = 11;
216  // The value of the attribute has a list of int32 values
217  repeated int32 int_list_value = 17;
218  // If this is a label dict unary, each entry will be stored here.
219  repeated LabelDictUnaryEntry label_dict_unary_value = 19;
220  // If this is a label-keyed string dict, each entry will be stored here.
221  repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 22;
222  // If this attribute's value is an expression containing one or more select
223  // expressions, then its type is SELECTOR_LIST and a SelectorList will be
224  // stored here.
225  optional SelectorList selector_list = 21;
226  repeated bytes DEPRECATED_string_dict_unary_value = 18;
227}
228// A rule instance (e.g., cc_library foo, java_binary bar).
229message Rule {
230  reserved 8, 11;
231  // The name of the rule (formatted as an absolute label, e.g. //foo/bar:baz).
232  required string name = 1;
233  // The rule class (e.g., java_library)
234  required string rule_class = 2;
235  // The BUILD file and line number of the location (formatted as
236  // <absolute_path>:<line_number>:<column_number>) in the rule's package's
237  // BUILD file where the rule instance was instantiated. The line number will
238  // be that of a rule invocation or macro call (that in turn invoked a
239  // rule). See
240  // https://bazel.build/rules/macros#macro-creation
241  optional string location = 3;
242  // All of the attributes that describe the rule.
243  repeated Attribute attribute = 4;
244  // All of the inputs to the rule (formatted as absolute labels). These are
245  // predecessors in the dependency graph.
246  repeated string rule_input = 5;
247  repeated ConfiguredRuleInput configured_rule_input = 15;
248  // All of the outputs of the rule (formatted as absolute labels). These are
249  // successors in the dependency graph.
250  repeated string rule_output = 6;
251  // The set of all "features" inherited from the rule's package declaration.
252  repeated string default_setting = 7;
253  // The rule's class's public by default value.
254  optional bool DEPRECATED_public_by_default = 9;
255  optional bool DEPRECATED_is_skylark = 10;
256  // Hash encapsulating the behavior of this Starlark rule. Any change to this
257  // rule's definition that could change its behavior will be reflected here.
258  optional string skylark_environment_hash_code = 12;
259  // The Starlark call stack at the moment the rule was instantiated.
260  // Each entry has the form "file:line:col: function".
261  // The outermost stack frame ("<toplevel>", the BUILD file) appears first;
262  // the frame for the rule function itself is omitted.
263  // The file name may be relative to package's source root directory.
264  //
265  // Requires --proto:instantiation_stack=true.
266  repeated string instantiation_stack = 13;
267  // The Starlark call stack for the definition of the rule class of this
268  // particular rule instance. If empty, either populating the field was not
269  // enabled on the command line with the --proto:definition_stack flag or the
270  // rule is a native one.
271  repeated string definition_stack = 14;
272}
273message ConfiguredRuleInput {
274  optional string label = 1;
275  optional string configuration_checksum = 2;
276  optional uint32 configuration_id = 3;
277}
278// Summary of all transitive dependencies of 'rule,' where each dependent
279// rule is included only once in the 'dependency' field.  Gives complete
280// information to analyze the single build target labeled rule.name,
281// including optional location of target in BUILD file.
282message RuleSummary {
283  required Rule rule = 1;
284  repeated Rule dependency = 2;
285  optional string location = 3;
286}
287// A package group. Aside from the name, it contains the list of packages
288// present in the group (as specified in the BUILD file).
289message PackageGroup {
290  reserved 4;
291  // The name of the package group
292  required string name = 1;
293  // The list of packages as specified in the BUILD file. Currently this is
294  // only a list of packages, but some time in the future, there might be
295  // some type of wildcard mechanism.
296  repeated string contained_package = 2;
297  // The list of sub package groups included in this one.
298  repeated string included_package_group = 3;
299}
300// An environment group.
301message EnvironmentGroup {
302  // The name of the environment group.
303  required string name = 1;
304  // The environments that belong to this group (as labels).
305  repeated string environment = 2;
306  // The member environments that rules implicitly support if not otherwise
307  // specified.
308  repeated string default = 3;
309}
310// A file that is an input into the build system.
311// Next-Id: 10
312message SourceFile {
313  reserved 7;
314  // The name of the source file (a label).
315  required string name = 1;
316  // The location of the source file.  This is a path with a line number and a
317  // column number not a label in the build system.
318  optional string location = 2;
319  // Labels of .bzl (Starlark) files that are transitively loaded in this BUILD
320  // file. This is present only when the SourceFile represents a BUILD file that
321  // loaded .bzl files.
322  // TODO(bazel-team): Rename this field.
323  repeated string subinclude = 3;
324  // Labels of package groups that are mentioned in the visibility declaration
325  // for this source file.
326  repeated string package_group = 4;
327  // Labels mentioned in the visibility declaration (including :__pkg__ and
328  // //visibility: ones)
329  repeated string visibility_label = 5;
330  // The package-level features enabled for this package. Only present if the
331  // SourceFile represents a BUILD file.
332  repeated string feature = 6;
333  // License attribute for the file.
334  optional License license = 8;
335  // True if the package contains an error. Only present if the SourceFile
336  // represents a BUILD file.
337  optional bool package_contains_errors = 9;
338}
339// A file that is the output of a build rule.
340message GeneratedFile {
341  // The name of the generated file (a label).
342  required string name = 1;
343  // The label of the target that generates the file.
344  required string generating_rule = 2;
345  // The path, line number, and column number of the output file (not a label).
346  optional string location = 3;
347}
348// A target from a blaze query execution.  Similar to the Attribute message,
349// the Discriminator is used to determine which field contains information.
350// For any given type, only one of these can be populated in a single Target.
351message Target {
352  enum Discriminator {
353    RULE = 1;
354    SOURCE_FILE = 2;
355    GENERATED_FILE = 3;
356    PACKAGE_GROUP = 4;
357    ENVIRONMENT_GROUP = 5;
358  }
359  // The type of target contained in the message.
360  required Discriminator type = 1;
361  // If this target represents a rule, the rule is stored here.
362  optional Rule rule = 2;
363  // A file that is not generated by the build system (version controlled
364  // or created by the test harness).
365  optional SourceFile source_file = 3;
366  // A generated file that is the output of a rule.
367  optional GeneratedFile generated_file = 4;
368  // A package group.
369  optional PackageGroup package_group = 5;
370  // An environment group.
371  optional EnvironmentGroup environment_group = 6;
372}
373// Container for all of the blaze query results.
374message QueryResult {
375  // All of the targets returned by the blaze query.
376  repeated Target target = 1;
377}
378////////////////////////////////////////////////////////////////////////////
379// Messages dealing with querying the BUILD language itself. For now, this is
380// quite simplistic: Blaze can only tell the names of the rule classes, their
381// attributes with their type.
382// Information about allowed rule classes for a specific attribute of a rule.
383message AllowedRuleClassInfo {
384  enum AllowedRuleClasses {
385    ANY = 1;        // Any rule is allowed to be in this attribute
386    SPECIFIED = 2;  // Only the explicitly listed rules are allowed
387  }
388  required AllowedRuleClasses policy = 1;
389  // Rule class names of rules allowed in this attribute, e.g "cc_library",
390  // "py_binary". Only present if the allowed_rule_classes field is set to
391  // SPECIFIED.
392  repeated string allowed_rule_class = 2;
393}
394// This message represents a single attribute of a single rule.
395// See https://bazel.build/rules/lib/attr.
396message AttributeDefinition {
397  required string name = 1;  // e.g. "name", "srcs"
398  required Attribute.Discriminator type = 2;
399  optional bool mandatory = 3;
400  optional AllowedRuleClassInfo allowed_rule_classes = 4;  // type=label*
401  optional string documentation = 5;
402  optional bool allow_empty = 6;        // type=*_list|*_dict
403  optional bool allow_single_file = 7;  // type=label
404  optional AttributeValue default =
405      9;  // simple (not computed/late-bound) values only
406  optional bool executable = 10;  // type=label
407  optional bool configurable = 11;
408  optional bool nodep =
409      12;  // label-valued edge does not establish a dependency
410  optional bool cfg_is_host =
411      13;  // edge entails a transition to "host" configuration
412}
413// An AttributeValue represents the value of an attribute.
414// A single field, determined by the attribute type, is populated.
415//
416// It is used only for AttributeDefinition.default. Attribute and
417// SelectorEntry do their own thing for unfortunate historical reasons.
418message AttributeValue {
419  optional int32 int = 1;            // type=int|tristate
420  optional string string = 2;        // type=string|label|output
421  optional bool bool = 3;            // type=bool
422  repeated AttributeValue list = 4;  // type=*_list|distrib
423  repeated DictEntry dict = 5;       // type=*_dict
424  message DictEntry {
425    required string key = 1;
426    required AttributeValue value = 2;
427  }
428}
429message RuleDefinition {
430  required string name = 1;
431  // Only contains documented attributes
432  repeated AttributeDefinition attribute = 2;
433  optional string documentation = 3;
434  // Only for build extensions: label to file that defines the extension
435  optional string label = 4;
436}
437message BuildLanguage {
438  // Only contains documented rule definitions
439  repeated RuleDefinition rule = 1;
440}
441
442