build.proto 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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.
  17. syntax = "proto2";
  18. package blaze_query;
  19. // option cc_api_version = 2;
  20. // option java_api_version = 1;
  21. option java_package = "com.google.devtools.build.lib.query2.proto.proto2api";
  22. message License {
  23. repeated string license_type = 1;
  24. repeated string exception = 2;
  25. }
  26. message StringDictEntry {
  27. required string key = 1;
  28. required string value = 2;
  29. }
  30. message LabelDictUnaryEntry {
  31. required string key = 1;
  32. required string value = 2;
  33. }
  34. message LabelListDictEntry {
  35. required string key = 1;
  36. repeated string value = 2;
  37. }
  38. message LabelKeyedStringDictEntry {
  39. required string key = 1;
  40. required string value = 2;
  41. }
  42. message StringListDictEntry {
  43. required string key = 1;
  44. repeated string value = 2;
  45. }
  46. // Represents an entry attribute of a Fileset rule in a build file.
  47. message FilesetEntry {
  48. // Indicates what to do when a source file is actually a symlink.
  49. enum SymlinkBehavior {
  50. COPY = 1;
  51. DEREFERENCE = 2;
  52. }
  53. // The label pointing to the source target where files are copied from.
  54. required string source = 1;
  55. // The relative path within the fileset rule where files will be mapped.
  56. required string destination_directory = 2;
  57. // Whether the files= attribute was specified. This is necessary because
  58. // no files= attribute and files=[] mean different things.
  59. optional bool files_present = 7;
  60. // A list of file labels to include from the source directory.
  61. repeated string file = 3;
  62. // If this is a fileset entry representing files within the rule
  63. // package, this lists relative paths to files that should be excluded from
  64. // the set. This cannot contain values if 'file' also has values.
  65. repeated string exclude = 4;
  66. // This field is optional because there will be some time when the new
  67. // PB is used by tools depending on blaze query, but the new blaze version
  68. // is not yet released.
  69. // TODO(bazel-team): Make this field required once a version of Blaze is
  70. // released that outputs this field.
  71. optional SymlinkBehavior symlink_behavior = 5 [ default=COPY ];
  72. // The prefix to strip from the path of the files in this FilesetEntry. Note
  73. // that no value and the empty string as the value mean different things here.
  74. optional string strip_prefix = 6;
  75. }
  76. // A rule attribute. Each attribute must have a type and one of the various
  77. // value fields populated - for the most part.
  78. //
  79. // Attributes of BOOLEAN and TRISTATE type may set all of the int, bool, and
  80. // string values for backwards compatibility with clients that expect them to
  81. // be set.
  82. //
  83. // Attributes of INTEGER, STRING, LABEL, LICENSE, BOOLEAN, and TRISTATE type
  84. // may set *none* of the values. This can happen if the Attribute message is
  85. // prepared for a client that doesn't support SELECTOR_LIST, but the rule has
  86. // a selector list value for the attribute. (Selector lists for attributes of
  87. // other types--the collection types--are handled differently when prepared
  88. // for such a client. The possible collection values are gathered together
  89. // and flattened.)
  90. //
  91. // By checking the type, the appropriate value can be extracted - see the
  92. // comments on each type for the associated value. The order of lists comes
  93. // from the blaze parsing. If an attribute is of a list type, the associated
  94. // list should never be empty.
  95. message Attribute {
  96. // Indicates the type of attribute.
  97. enum Discriminator {
  98. INTEGER = 1; // int_value
  99. STRING = 2; // string_value
  100. LABEL = 3; // string_value
  101. OUTPUT = 4; // string_value
  102. STRING_LIST = 5; // string_list_value
  103. LABEL_LIST = 6; // string_list_value
  104. OUTPUT_LIST = 7; // string_list_value
  105. DISTRIBUTION_SET = 8; // string_list_value - order is unimportant
  106. LICENSE = 9; // license
  107. STRING_DICT = 10; // string_dict_value
  108. FILESET_ENTRY_LIST = 11; // fileset_list_value
  109. LABEL_LIST_DICT = 12; // label_list_dict_value
  110. STRING_LIST_DICT = 13; // string_list_dict_value
  111. BOOLEAN = 14; // int, bool and string value
  112. TRISTATE = 15; // tristate, int and string value
  113. INTEGER_LIST = 16; // int_list_value
  114. UNKNOWN = 18; // unknown type, use only for build extensions
  115. LABEL_DICT_UNARY = 19; // label_dict_unary_value
  116. SELECTOR_LIST = 20; // selector_list
  117. LABEL_KEYED_STRING_DICT = 21; // label_keyed_string_dict
  118. DEPRECATED_STRING_DICT_UNARY = 17;
  119. }
  120. // Values for the TriState field type.
  121. enum Tristate {
  122. NO = 0;
  123. YES = 1;
  124. AUTO = 2;
  125. }
  126. message SelectorEntry {
  127. // The key of the selector entry. At this time, this is the label of a
  128. // config_setting rule, or the pseudo-label "//conditions:default".
  129. optional string label = 1;
  130. // True if the entry's value is the default value for the type as a
  131. // result of the condition value being specified as None (ie:
  132. // {"//condition": None}).
  133. optional bool is_default_value = 16;
  134. // Exactly one of the following fields (except for glob_criteria) must be
  135. // populated - note that the BOOLEAN and TRISTATE caveat in Attribute's
  136. // comment does not apply here. The type field in the SelectorList
  137. // containing this entry indicates which of these fields is populated,
  138. // in accordance with the comments on Discriminator enum values above.
  139. // (To be explicit: BOOLEAN populates the boolean_value field and TRISTATE
  140. // populates the tristate_value field.)
  141. optional int32 int_value = 2;
  142. optional string string_value = 3;
  143. optional bool boolean_value = 4;
  144. optional Tristate tristate_value = 5;
  145. repeated string string_list_value = 6;
  146. optional License license = 7;
  147. repeated StringDictEntry string_dict_value = 8;
  148. repeated FilesetEntry fileset_list_value = 9;
  149. repeated LabelListDictEntry label_list_dict_value = 10;
  150. repeated StringListDictEntry string_list_dict_value = 11;
  151. repeated int32 int_list_value = 13;
  152. repeated LabelDictUnaryEntry label_dict_unary_value = 15;
  153. repeated LabelKeyedStringDictEntry label_keyed_string_dict_value = 17;
  154. repeated DEPRECATED_GlobCriteria DEPRECATED_glob_criteria = 12;
  155. repeated bytes DEPRECATED_string_dict_unary_value = 14;
  156. }
  157. message Selector {
  158. // The list of (label, value) pairs in the map that defines the selector.
  159. // At this time, this cannot be empty, i.e. a selector has at least one
  160. // entry.
  161. repeated SelectorEntry entries = 1;
  162. // Whether or not this has any default values.
  163. optional bool has_default_value = 2;
  164. // The error message when no condition matches.
  165. optional string no_match_error = 3;
  166. }
  167. message SelectorList {
  168. // The type that this selector list evaluates to, and the type that each
  169. // selector in the list evaluates to. At this time, this cannot be
  170. // SELECTOR_LIST, i.e. selector lists do not nest.
  171. optional Discriminator type = 1;
  172. // The list of selector elements in this selector list. At this time, this
  173. // cannot be empty, i.e. a selector list is never empty.
  174. repeated Selector elements = 2;
  175. }
  176. // The name of the attribute
  177. required string name = 1;
  178. // The location of the target in the BUILD file in a machine-parseable form.
  179. optional Location DEPRECATED_parseable_location = 12;
  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 DEPRECATED_GlobCriteria DEPRECATED_glob_criteria = 16;
  227. repeated bytes DEPRECATED_string_dict_unary_value = 18;
  228. }
  229. // A rule instance (e.g., cc_library foo, java_binary bar).
  230. message Rule {
  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>) in the rule's package's BUILD file where the
  237. // rule instance was instantiated. The line number will be that of a rule
  238. // invocation or macro call (that in turn invoked a rule). See
  239. // https://docs.bazel.build/versions/master/skylark/macros.html#macro-creation
  240. optional string location = 3;
  241. // All of the attributes that describe the rule.
  242. repeated Attribute attribute = 4;
  243. // All of the inputs to the rule (formatted as absolute labels). These are
  244. // predecessors in the dependency graph.
  245. repeated string rule_input = 5;
  246. // All of the outputs of the rule (formatted as absolute labels). These are
  247. // successors in the dependency graph.
  248. repeated string rule_output = 6;
  249. // The set of all default settings affecting this rule. The name of a default
  250. // setting is "<setting type>_<setting name>". There currently defined setting
  251. // types are:
  252. //
  253. // - 'blaze': settings implemented in Blaze itself
  254. repeated string default_setting = 7;
  255. // The location of the target in the BUILD file in a machine-parseable form.
  256. optional Location DEPRECATED_parseable_location = 8;
  257. // The rule's class's public by default value.
  258. optional bool public_by_default = 9;
  259. // If this rule is of a skylark-defined RuleClass.
  260. optional bool is_skylark = 10;
  261. // List of Skylark aspects that this rule applies.
  262. repeated AttributeAspect skylark_attribute_aspects = 11;
  263. // Hash encapsulating the behavior of this Skylark rule. Any change to this
  264. // rule's definition that could change its behavior will be reflected here.
  265. optional string skylark_environment_hash_code = 12;
  266. }
  267. // A pairing of attribute name and a Skylark aspect that is applied to that
  268. // attribute.
  269. message AttributeAspect {
  270. required string attribute_name = 1;
  271. required SkylarkAspect aspect = 2;
  272. }
  273. // Aspect defined in Skylark.
  274. message SkylarkAspect {
  275. required string extension_file_label = 1;
  276. required string exported_name = 2;
  277. repeated Attribute attribute = 3;
  278. }
  279. // Summary of all transitive dependencies of 'rule,' where each dependent
  280. // rule is included only once in the 'dependency' field. Gives complete
  281. // information to analyze the single build target labeled rule.name,
  282. // including optional location of target in BUILD file.
  283. message RuleSummary {
  284. required Rule rule = 1;
  285. repeated Rule dependency = 2;
  286. optional string location = 3;
  287. }
  288. // A package group. Aside from the name, it contains the list of packages
  289. // present in the group (as specified in the BUILD file).
  290. message PackageGroup {
  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. // The location of the target in the BUILD file in a machine-parseable form.
  300. optional Location DEPRECATED_parseable_location = 4;
  301. }
  302. // An environment group.
  303. message EnvironmentGroup {
  304. // The name of the environment group.
  305. required string name = 1;
  306. // The environments that belong to this group (as labels).
  307. repeated string environment = 2;
  308. // The member environments that rules implicitly support if not otherwise
  309. // specified.
  310. repeated string default = 3;
  311. }
  312. // A file that is an input into the build system.
  313. // Next-Id: 10
  314. message SourceFile {
  315. // The name of the source file (a label).
  316. required string name = 1;
  317. // The location of the source file. This is a path with line numbers, not
  318. // a label in the build system.
  319. optional string location = 2;
  320. // The location of the corresponding label in the BUILD file in a
  321. // machine-parseable form.
  322. optional Location DEPRECATED_parseable_location = 7;
  323. // Labels of .bzl (Skylark) files that are transitively loaded in this BUILD
  324. // file. This is present only when the SourceFile represents a BUILD file that
  325. // loaded .bzl files.
  326. // TODO(bazel-team): Rename this field.
  327. repeated string subinclude = 3;
  328. // Labels of package groups that are mentioned in the visibility declaration
  329. // for this source file.
  330. repeated string package_group = 4;
  331. // Labels mentioned in the visibility declaration (including :__pkg__ and
  332. // //visibility: ones)
  333. repeated string visibility_label = 5;
  334. // The package-level features enabled for this package. Only present if the
  335. // SourceFile represents a BUILD file.
  336. repeated string feature = 6;
  337. // License attribute for the file.
  338. optional License license = 8;
  339. // True if the package contains an error. Only present if the SourceFile
  340. // represents a BUILD file.
  341. optional bool package_contains_errors = 9;
  342. }
  343. // A file that is the output of a build rule.
  344. message GeneratedFile {
  345. // The name of the generated file (a label).
  346. required string name = 1;
  347. // The label of the target that generates the file.
  348. required string generating_rule = 2;
  349. // The path of the output file (not a label).
  350. optional string location = 3;
  351. }
  352. // A target from a blaze query execution. Similar to the Attribute message,
  353. // the Discriminator is used to determine which field contains information.
  354. // For any given type, only one of these can be populated in a single Target.
  355. message Target {
  356. enum Discriminator {
  357. RULE = 1;
  358. SOURCE_FILE = 2;
  359. GENERATED_FILE = 3;
  360. PACKAGE_GROUP = 4;
  361. ENVIRONMENT_GROUP = 5;
  362. }
  363. // The type of target contained in the message.
  364. required Discriminator type = 1;
  365. // If this target represents a rule, the rule is stored here.
  366. optional Rule rule = 2;
  367. // A file that is not generated by the build system (version controlled
  368. // or created by the test harness).
  369. optional SourceFile source_file = 3;
  370. // A generated file that is the output of a rule.
  371. optional GeneratedFile generated_file = 4;
  372. // A package group.
  373. optional PackageGroup package_group = 5;
  374. // An environment group.
  375. optional EnvironmentGroup environment_group = 6;
  376. }
  377. // Container for all of the blaze query results.
  378. message QueryResult {
  379. // All of the targets returned by the blaze query.
  380. repeated Target target = 1;
  381. }
  382. ////////////////////////////////////////////////////////////////////////////
  383. // Messages dealing with querying the BUILD language itself. For now, this is
  384. // quite simplistic: Blaze can only tell the names of the rule classes, their
  385. // attributes with their type.
  386. // Information about allowed rule classes for a specific attribute of a rule.
  387. message AllowedRuleClassInfo {
  388. enum AllowedRuleClasses {
  389. ANY = 1; // Any rule is allowed to be in this attribute
  390. SPECIFIED = 2; // Only the explicitly listed rules are allowed
  391. }
  392. required AllowedRuleClasses policy = 1;
  393. // Rule class names of rules allowed in this attribute, e.g "cc_library",
  394. // "py_binary". Only present if the allowed_rule_classes field is set to
  395. // SPECIFIED.
  396. repeated string allowed_rule_class = 2;
  397. }
  398. // This message represents a single attribute of a single rule.
  399. message AttributeDefinition {
  400. // Attribute name, i.e. "name", "srcs", "deps"
  401. required string name = 1;
  402. required Attribute.Discriminator type = 2;
  403. required bool mandatory = 3;
  404. // Only present for attributes of type LABEL and LABEL_LIST.
  405. optional AllowedRuleClassInfo allowed_rule_classes = 4;
  406. optional string documentation = 5;
  407. }
  408. message RuleDefinition {
  409. required string name = 1;
  410. // Only contains documented attributes
  411. repeated AttributeDefinition attribute = 2;
  412. optional string documentation = 3;
  413. // Only for build extensions: label to file that defines the extension
  414. optional string label = 4;
  415. }
  416. message BuildLanguage {
  417. // Only contains documented rule definitions
  418. repeated RuleDefinition rule = 1;
  419. }
  420. message Location {
  421. optional int32 start_offset = 1;
  422. optional int32 start_line = 2;
  423. optional int32 start_column = 3;
  424. optional int32 end_offset = 4;
  425. optional int32 end_line = 5;
  426. optional int32 end_column = 6;
  427. }
  428. message MakeVarBinding {
  429. required string value = 1;
  430. required string platform_set_regexp = 2;
  431. }
  432. message MakeVar {
  433. required string name = 1;
  434. repeated MakeVarBinding binding = 2;
  435. }
  436. message DEPRECATED_GlobCriteria {
  437. // List of includes (or items if this criteria did not come from a glob)
  438. repeated string include = 1;
  439. // List of exclude expressions
  440. repeated string exclude = 2;
  441. // Whether this message came from a glob
  442. optional bool glob = 3;
  443. }
  444. message Event {
  445. enum EventKind {
  446. ERROR = 1;
  447. WARNING = 2;
  448. INFO = 3;
  449. PROGRESS = 4;
  450. }
  451. required EventKind kind = 1;
  452. optional Location DEPRECATED_location = 2;
  453. optional string message = 3;
  454. }