cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 1 | // Copyright 2018 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 | package com.google.devtools.build.lib.skylarkbuildapi; |
| 16 | |
| 17 | import com.google.common.collect.ImmutableList; |
| 18 | import com.google.devtools.build.lib.cmdline.Label; |
adonovan | bc74d1d | 2020-04-30 12:08:31 -0700 | [diff] [blame] | 19 | import com.google.devtools.build.lib.collect.nestedset.Depset; |
jcater | 880b5f7 | 2019-12-06 07:49:43 -0800 | [diff] [blame] | 20 | import com.google.devtools.build.lib.skylarkbuildapi.core.ProviderApi; |
| 21 | import com.google.devtools.build.lib.skylarkbuildapi.core.StructApi; |
| 22 | import com.google.devtools.build.lib.skylarkbuildapi.core.TransitiveInfoCollectionApi; |
jcater | 5bd6369 | 2019-12-13 08:58:16 -0800 | [diff] [blame] | 23 | import com.google.devtools.build.lib.skylarkbuildapi.platform.ConstraintValueInfoApi; |
juliexxia | 0a0a13b | 2020-04-21 15:55:00 -0700 | [diff] [blame] | 24 | import com.google.devtools.build.lib.skylarkbuildapi.platform.ExecGroupCollectionApi; |
jcater | eaf2b54 | 2019-12-06 09:21:31 -0800 | [diff] [blame] | 25 | import com.google.devtools.build.lib.skylarkbuildapi.platform.ToolchainContextApi; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 26 | import com.google.devtools.build.lib.syntax.ClassObject; |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 27 | import com.google.devtools.build.lib.syntax.Dict; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 28 | import com.google.devtools.build.lib.syntax.EvalException; |
Googler | 641bdf7 | 2019-11-12 10:32:26 -0800 | [diff] [blame] | 29 | import com.google.devtools.build.lib.syntax.NoneType; |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 30 | import com.google.devtools.build.lib.syntax.Sequence; |
laurentlb | 6659b4c | 2019-02-18 07:23:36 -0800 | [diff] [blame] | 31 | import com.google.devtools.build.lib.syntax.StarlarkSemantics.FlagIdentifier; |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.syntax.StarlarkThread; |
Googler | 34f7058 | 2019-11-25 12:27:34 -0800 | [diff] [blame] | 33 | import com.google.devtools.build.lib.syntax.StarlarkValue; |
Googler | cfd681f | 2019-11-11 07:24:02 -0800 | [diff] [blame] | 34 | import com.google.devtools.build.lib.syntax.Tuple; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 35 | import javax.annotation.Nullable; |
adonovan | b017468 | 2020-05-18 16:01:53 -0700 | [diff] [blame] | 36 | import net.starlark.java.annot.Param; |
| 37 | import net.starlark.java.annot.ParamType; |
| 38 | import net.starlark.java.annot.StarlarkBuiltin; |
| 39 | import net.starlark.java.annot.StarlarkDocumentationCategory; |
| 40 | import net.starlark.java.annot.StarlarkMethod; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 41 | |
| 42 | /** Interface for a context object given to rule implementation functions. */ |
gregce | 220a1c8 | 2020-05-01 10:19:52 -0700 | [diff] [blame] | 43 | @StarlarkBuiltin( |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 44 | name = "ctx", |
gregce | 220a1c8 | 2020-05-01 10:19:52 -0700 | [diff] [blame] | 45 | category = StarlarkDocumentationCategory.BUILTIN, |
Googler | 34f7058 | 2019-11-25 12:27:34 -0800 | [diff] [blame] | 46 | doc = |
| 47 | "A context object that is passed to the implementation function for a rule or aspect. It" |
| 48 | + " provides access to the information and methods needed to analyze the current" |
| 49 | + " target.<p>In particular, it lets the implementation function access the current" |
| 50 | + " target's label, attributes, configuration, and the providers of its dependencies." |
| 51 | + " It has methods for declaring output files and the actions that produce them." |
| 52 | + "<p>Context objects essentially live for the duration of the call to the" |
| 53 | + " implementation function. It is not useful to access these objects outside of their" |
Googler | 510d9e1 | 2019-12-01 07:39:55 -0800 | [diff] [blame] | 54 | + " associated function. See the <a" |
Googler | 34f7058 | 2019-11-25 12:27:34 -0800 | [diff] [blame] | 55 | + " href='../rules.$DOC_EXT#implementation-function'>Rules page</a> for more " |
| 56 | + "information.") |
gregce | d281df7 | 2020-05-11 12:27:06 -0700 | [diff] [blame] | 57 | public interface StarlarkRuleContextApi<ConstraintValueT extends ConstraintValueInfoApi> |
jcater | 5bd6369 | 2019-12-13 08:58:16 -0800 | [diff] [blame] | 58 | extends StarlarkValue { |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 59 | |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 60 | String DOC_NEW_FILE_TAIL = |
| 61 | "Does not actually create a file on the file system, just declares that some action will do" |
| 62 | + " so. You must create an action that generates the file. If the file should be visible" |
| 63 | + " to other rules, declare a rule output instead when possible. Doing so enables Blaze" |
| 64 | + " to associate a label with the file that rules can refer to (allowing finer" |
| 65 | + " dependency control) instead of referencing the whole rule."; |
| 66 | String EXECUTABLE_DOC = |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 67 | "A <code>struct</code> containing executable files defined in <a " |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 68 | + "href='attr.html#label'>label type attributes</a> marked as <a " |
| 69 | + "href='attr.html#label.executable'><code>executable=True</code><a>. The struct " |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 70 | + "fields correspond to the attribute names. Each value in the struct is either a <a " |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 71 | + "href='File.html'><code>File</code></a> or <code>None</code>. If an optional " |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 72 | + "attribute is not specified in the rule then the corresponding struct value is " |
| 73 | + "<code>None</code>. If a label type is not marked as <code>executable=True</code>, no " |
| 74 | + "corresponding struct field is generated. <a " |
| 75 | + "href=\"https://github.com/bazelbuild/examples/blob/master/rules/actions_run/" |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 76 | + "execute.bzl\">See example of use</a>."; |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 77 | String FILES_DOC = |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 78 | "A <code>struct</code> containing files defined in <a href='attr.html#label'>label</a>" |
| 79 | + " or <a href='attr.html#label_list'>label list</a> type attributes. The struct" |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 80 | + " fields correspond to the attribute names. The struct values are <code>list</code> of" |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 81 | + " <a href='File.html'><code>File</code></a>s. It is a shortcut for:<pre" |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 82 | + " class=language-python>[f for t in ctx.attr.<ATTR> for f in t.files]</pre> In" |
| 83 | + " other words, use <code>files</code> to access the <a" |
| 84 | + " href=\"../rules.$DOC_EXT#requesting-output-files\">default outputs</a> of a" |
| 85 | + " dependency. <a" |
| 86 | + " href=\"https://github.com/bazelbuild/examples/blob/master/rules/depsets/foo.bzl\">See" |
| 87 | + " example of use</a>."; |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 88 | String FILE_DOC = |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 89 | "A <code>struct</code> containing files defined in <a href='attr.html#label'>label type" |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 90 | + " attributes</a> marked as <a" |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 91 | + " href='attr.html#label.allow_single_file'><code>allow_single_file</code></a>. The" |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 92 | + " struct fields correspond to the attribute names. The struct value is always a <a" |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 93 | + " href='File.html'><code>File</code></a> or <code>None</code>. If an optional" |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 94 | + " attribute is not specified in the rule then the corresponding struct value is" |
| 95 | + " <code>None</code>. If a label type is not marked as <code>allow_single_file</code>," |
| 96 | + " no corresponding struct field is generated. It is a shortcut for:<pre" |
| 97 | + " class=language-python>list(ctx.attr.<ATTR>.files)[0]</pre>In other words, use" |
| 98 | + " <code>file</code> to access the (singular) <a" |
| 99 | + " href=\"../rules.$DOC_EXT#requesting-output-files\">default output</a> of a" |
| 100 | + " dependency. <a" |
| 101 | + " href=\"https://github.com/bazelbuild/examples/blob/master/rules/expand_template/hello.bzl\">See" |
| 102 | + " example of use</a>."; |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 103 | String ATTR_DOC = |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 104 | "A struct to access the values of the <a href='../rules.$DOC_EXT#attributes'>attributes</a>. " |
| 105 | + "The values are provided by the user (if not, a default value is used). The attributes " |
| 106 | + "of the struct and the types of their values correspond to the keys and values of the " |
cparsons | 7191595 | 2019-10-31 09:05:36 -0700 | [diff] [blame] | 107 | + "<a href='globals.html#rule.attrs'><code>attrs</code> dict</a> provided to the <a " |
| 108 | + "href='globals.html#rule'><code>rule</code> function</a>. <a " |
Googler | 057a5e6 | 2019-09-24 16:09:29 -0700 | [diff] [blame] | 109 | + "href=\"https://github.com/bazelbuild/examples/blob/master/rules/attributes/" |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 110 | + "printer.bzl\">See example of use</a>."; |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 111 | String SPLIT_ATTR_DOC = |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 112 | "A struct to access the values of attributes with split configurations. If the attribute is " |
| 113 | + "a label list, the value of split_attr is a dict of the keys of the split (as strings) " |
| 114 | + "to lists of the ConfiguredTargets in that branch of the split. If the attribute is a " |
| 115 | + "label, then the value of split_attr is a dict of the keys of the split (as strings) " |
| 116 | + "to single ConfiguredTargets. Attributes with split configurations still appear in the " |
| 117 | + "attr struct, but their values will be single lists with all the branches of the split " |
| 118 | + "merged together."; |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 119 | String OUTPUTS_DOC = |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 120 | "A pseudo-struct containing all the predeclared output files, represented by " |
| 121 | + "<a href='File.html'><code>File</code></a> objects. See the " |
| 122 | + "<a href='../rules.$DOC_EXT#files'>Rules page</a> for more information and examples." |
| 123 | + "<p>This field does not exist on aspect contexts, since aspects do not have " |
| 124 | + "predeclared outputs." |
| 125 | + "<p>The fields of this object are defined as follows. It is an error if two outputs " |
| 126 | + "produce the same field name or have the same label." |
| 127 | + "<ul>" |
| 128 | + "<li>If the rule declares an <a href='globals.html#rule.outputs'><code>outputs</code>" |
| 129 | + "</a> dict, then for every entry in the dict, there is a field whose name is the key " |
| 130 | + "and whose value is the corresponding <code>File</code>." |
| 131 | + "<li>For every attribute of type <a href='attr.html#output'><code>attr.output</code>" |
| 132 | + "</a> that the rule declares, there is a field whose name is the attribute's name. " |
| 133 | + "If the target specified a label for that attribute, then the field value is the " |
| 134 | + "corresponding <code>File</code>; otherwise the field value is <code>None</code>." |
| 135 | + "<li>For every attribute of type <a href='attr.html#output_list'><code>attr.output_list" |
| 136 | + "</code></a> that the rule declares, there is a field whose name is the attribute's " |
| 137 | + "name. The field value is a list of <code>File</code> objects corresponding to the " |
| 138 | + "labels given for that attribute in the target, or an empty list if the attribute was " |
| 139 | + "not specified in the target." |
| 140 | + "<li><b>(Deprecated)</b> If the rule is marked <a href='globals.html#rule.executable'>" |
Googler | 8c1b44f | 2018-08-28 07:51:45 -0700 | [diff] [blame] | 141 | + "<code>executable</code></a> or <a href='globals.html#rule.test'><code>test</code>" |
| 142 | + "</a>, there is a field named <code>\"executable\"</code>, which is the default " |
| 143 | + "executable. It is recommended that instead of using this, you pass another file " |
| 144 | + "(either predeclared or not) to the <code>executable</code> arg of " |
Googler | 20a6ac7 | 2019-03-07 07:23:11 -0800 | [diff] [blame] | 145 | + "<a href='DefaultInfo.html'><code>DefaultInfo</code></a>." |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 146 | + "</ul>"; |
| 147 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 148 | @StarlarkMethod( |
Googler | 20a6ac7 | 2019-03-07 07:23:11 -0800 | [diff] [blame] | 149 | name = "default_provider", |
| 150 | structField = true, |
| 151 | doc = "Deprecated. Use <a href=\"DefaultInfo.html\">DefaultInfo</a> instead.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 152 | ProviderApi getDefaultProvider(); |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 153 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 154 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 155 | name = "actions", |
| 156 | structField = true, |
| 157 | doc = "Contains methods for declaring output files and the actions that produce them.") |
gregce | ff94123 | 2020-04-21 08:03:32 -0700 | [diff] [blame] | 158 | StarlarkActionFactoryApi actions(); |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 159 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 160 | @StarlarkMethod( |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 161 | name = "created_actions", |
Googler | 34f7058 | 2019-11-25 12:27:34 -0800 | [diff] [blame] | 162 | doc = |
| 163 | "For rules with <a href=\"globals.html#rule._skylark_testable\">_skylark_testable</a>" |
| 164 | + " set to <code>True</code>, this returns an <a" |
| 165 | + " href=\"globals.html#Actions\">Actions</a> provider representing all actions" |
| 166 | + " created so far for the current rule. For all other rules, returns" |
| 167 | + " <code>None</code>. Note that the provider is not updated when subsequent actions" |
| 168 | + " are created, so you will have to call this function again if you wish to inspect" |
| 169 | + " them. <br/><br/>This is intended to help write tests for rule-implementation" |
| 170 | + " helper functions, which may take in a <code>ctx</code> object and create actions" |
| 171 | + " on it.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 172 | StarlarkValue createdActions() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 173 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 174 | @StarlarkMethod(name = "attr", structField = true, doc = ATTR_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 175 | StructApi getAttr() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 176 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 177 | @StarlarkMethod(name = "split_attr", structField = true, doc = SPLIT_ATTR_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 178 | StructApi getSplitAttr() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 179 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 180 | @StarlarkMethod(name = "executable", structField = true, doc = EXECUTABLE_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 181 | StructApi getExecutable() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 182 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 183 | @StarlarkMethod(name = "file", structField = true, doc = FILE_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 184 | StructApi getFile() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 185 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 186 | @StarlarkMethod(name = "files", structField = true, doc = FILES_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 187 | StructApi getFiles() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 188 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 189 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 190 | name = "workspace_name", |
| 191 | structField = true, |
| 192 | doc = "Returns the workspace name as defined in the WORKSPACE file.") |
| 193 | String getWorkspaceName() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 194 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 195 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 196 | name = "label", |
| 197 | structField = true, |
| 198 | doc = "The label of the target currently being analyzed.") |
| 199 | Label getLabel() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 200 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 201 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 202 | name = "fragments", |
| 203 | structField = true, |
| 204 | doc = "Allows access to configuration fragments in target configuration.") |
| 205 | FragmentCollectionApi getFragments() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 206 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 207 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 208 | name = "host_fragments", |
| 209 | structField = true, |
| 210 | doc = "Allows access to configuration fragments in host configuration.") |
| 211 | FragmentCollectionApi getHostFragments() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 212 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 213 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 214 | name = "configuration", |
| 215 | structField = true, |
| 216 | doc = |
| 217 | "Returns the default configuration. See the <a href=\"configuration.html\">" |
| 218 | + "configuration</a> type for more details.") |
| 219 | BuildConfigurationApi getConfiguration() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 220 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 221 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 222 | name = "host_configuration", |
| 223 | structField = true, |
| 224 | doc = |
| 225 | "Returns the host configuration. See the <a href=\"configuration.html\">" |
| 226 | + "configuration</a> type for more details.") |
| 227 | BuildConfigurationApi getHostConfiguration() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 228 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 229 | @StarlarkMethod( |
juliexxia | 1f332e0 | 2018-10-31 14:20:55 -0700 | [diff] [blame] | 230 | name = "build_setting_value", |
| 231 | structField = true, |
juliexxia | 1f332e0 | 2018-10-31 14:20:55 -0700 | [diff] [blame] | 232 | doc = |
| 233 | "<b>Experimental. This field is experimental and subject to change at any time. Do not " |
| 234 | + "depend on it.</b> <p>Returns the value of the build setting that is represented " |
| 235 | + "by the current target. It is an error to access this field for rules that do not " |
| 236 | + "set the <code>build_setting</code> attribute in their rule definition.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 237 | Object getBuildSettingValue() throws EvalException; |
juliexxia | 1f332e0 | 2018-10-31 14:20:55 -0700 | [diff] [blame] | 238 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 239 | @StarlarkMethod( |
laurentlb | 7dcad73 | 2018-10-25 05:17:20 -0700 | [diff] [blame] | 240 | name = "coverage_instrumented", |
| 241 | doc = |
| 242 | "Returns whether code coverage instrumentation should be generated when performing " |
| 243 | + "compilation actions for this rule or, if <code>target</code> is provided, the " |
| 244 | + "rule specified by that Target. (If a non-rule or a Starlark rule Target is " |
| 245 | + "provided, this returns False.) Checks if the sources of the current rule " |
| 246 | + "(if no Target is provided) or the sources of Target should be instrumented " |
| 247 | + "based on the --instrumentation_filter and " |
| 248 | + "--instrument_test_targets config settings. " |
Googler | f7dd5c2 | 2019-11-13 08:16:20 -0800 | [diff] [blame] | 249 | + "This differs from <code>coverage_enabled</code> in the " |
laurentlb | 7dcad73 | 2018-10-25 05:17:20 -0700 | [diff] [blame] | 250 | + "<a href=\"configuration.html\">configuration</a>, which notes whether coverage " |
| 251 | + "data collection is enabled for the entire run, but not whether a specific " |
| 252 | + "target should be instrumented.", |
| 253 | parameters = { |
| 254 | @Param( |
| 255 | name = "target", |
| 256 | type = TransitiveInfoCollectionApi.class, |
| 257 | defaultValue = "None", |
| 258 | noneable = true, |
| 259 | named = true, |
| 260 | doc = "A Target specifying a rule. If not provided, defaults to the current rule.") |
| 261 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 262 | boolean instrumentCoverage(Object targetUnchecked) throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 263 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 264 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 265 | name = "features", |
| 266 | structField = true, |
laurentlb | 186062e | 2020-05-14 08:36:59 -0700 | [diff] [blame] | 267 | doc = |
| 268 | "Returns the set of features that are explicitly enabled by the user for this rule. " |
| 269 | + "<a href=\"https://github.com/bazelbuild/examples/blob/master/rules/" |
| 270 | + "features/rule.bzl\">See example of use</a>.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 271 | ImmutableList<String> getFeatures() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 272 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 273 | @StarlarkMethod( |
plf | 2ad044c | 2018-05-28 01:08:04 -0700 | [diff] [blame] | 274 | name = "disabled_features", |
| 275 | structField = true, |
| 276 | doc = "Returns the set of features that are explicitly disabled by the user for this rule.") |
| 277 | ImmutableList<String> getDisabledFeatures() throws EvalException; |
| 278 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 279 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 280 | name = "bin_dir", |
| 281 | structField = true, |
| 282 | doc = "The root corresponding to bin directory.") |
| 283 | FileRootApi getBinDirectory() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 284 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 285 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 286 | name = "genfiles_dir", |
| 287 | structField = true, |
| 288 | doc = "The root corresponding to genfiles directory.") |
| 289 | FileRootApi getGenfilesDirectory() throws EvalException; |
| 290 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 291 | @StarlarkMethod(name = "outputs", structField = true, doc = OUTPUTS_DOC) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 292 | ClassObject outputs() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 293 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 294 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 295 | name = "rule", |
| 296 | structField = true, |
| 297 | doc = |
| 298 | "Returns rule attributes descriptor for the rule that aspect is applied to." |
| 299 | + " Only available in aspect implementation functions.") |
gregce | 4893ee3 | 2020-04-27 11:53:54 -0700 | [diff] [blame] | 300 | StarlarkAttributesCollectionApi rule() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 301 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 302 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 303 | name = "aspect_ids", |
| 304 | structField = true, |
| 305 | doc = |
| 306 | "Returns a list ids for all aspects applied to the target." |
| 307 | + " Only available in aspect implementation functions.") |
| 308 | ImmutableList<String> aspectIds() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 309 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 310 | @StarlarkMethod( |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 311 | name = "var", |
| 312 | structField = true, |
| 313 | doc = "Dictionary (String to String) of configuration variables.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 314 | Dict<String, String> var() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 315 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 316 | @StarlarkMethod( |
jcater | eaf2b54 | 2019-12-06 09:21:31 -0800 | [diff] [blame] | 317 | name = "toolchains", |
| 318 | structField = true, |
juliexxia | 0a0a13b | 2020-04-21 15:55:00 -0700 | [diff] [blame] | 319 | doc = "Toolchains for the default exec group of this rule.") |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 320 | ToolchainContextApi toolchains() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 321 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 322 | @StarlarkMethod( |
jcater | 0a1e9eb | 2019-12-17 09:58:38 -0800 | [diff] [blame] | 323 | name = "target_platform_has_constraint", |
| 324 | doc = "Returns true if the given constraint value is part of the current target platform.", |
| 325 | parameters = { |
| 326 | @Param( |
| 327 | name = "constraintValue", |
| 328 | positional = true, |
| 329 | named = false, |
| 330 | type = ConstraintValueInfoApi.class, |
| 331 | doc = "The constraint value to check the target platform against.") |
| 332 | }) |
| 333 | boolean targetPlatformHasConstraint(ConstraintValueT constraintValue); |
| 334 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 335 | @StarlarkMethod( |
juliexxia | 0a0a13b | 2020-04-21 15:55:00 -0700 | [diff] [blame] | 336 | name = "exec_groups", |
| 337 | structField = true, |
| 338 | enableOnlyWithFlag = FlagIdentifier.EXPERIMENTAL_EXEC_GROUPS, |
| 339 | // TODO(b/151742236) update this doc when this becomes non-experimental. |
| 340 | doc = |
| 341 | "<i>experimental</i> A collection of the execution groups available for this rule," |
| 342 | + " indexed by their name. Access with <code>ctx.exec_groups[name_of_group]</code>.") |
| 343 | ExecGroupCollectionApi execGroups() throws EvalException; |
| 344 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 345 | @StarlarkMethod( |
Googler | 42720ad | 2019-09-18 10:33:21 -0700 | [diff] [blame] | 346 | name = "tokenize", |
| 347 | doc = "Splits a shell command into a list of tokens.", |
| 348 | // TODO(cparsons): Look into flipping this to true. |
| 349 | documented = false, |
| 350 | parameters = { |
| 351 | @Param( |
| 352 | name = "option", |
| 353 | positional = true, |
| 354 | named = false, |
| 355 | type = String.class, |
| 356 | doc = "The string to split."), |
| 357 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 358 | Sequence<String> tokenize(String optionString) throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 359 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 360 | @StarlarkMethod( |
Googler | 42720ad | 2019-09-18 10:33:21 -0700 | [diff] [blame] | 361 | name = "expand", |
| 362 | doc = |
| 363 | "Expands all references to labels embedded within a string for all files using a mapping " |
| 364 | + "from definition labels (i.e. the label in the output type attribute) to files. " |
| 365 | + "Deprecated.", |
| 366 | // TODO(cparsons): Look into flipping this to true. |
| 367 | documented = false, |
| 368 | parameters = { |
| 369 | @Param( |
| 370 | name = "expression", |
| 371 | positional = true, |
| 372 | named = false, |
| 373 | type = String.class, |
| 374 | doc = "The string expression to expand."), |
| 375 | @Param( |
| 376 | name = "files", |
| 377 | positional = true, |
| 378 | named = false, |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 379 | type = Sequence.class, |
Googler | 42720ad | 2019-09-18 10:33:21 -0700 | [diff] [blame] | 380 | doc = "The list of files."), |
| 381 | @Param( |
| 382 | name = "label_resolver", |
| 383 | positional = true, |
| 384 | named = false, |
| 385 | type = Label.class, |
| 386 | doc = "The label resolver."), |
| 387 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 388 | String expand( |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 389 | @Nullable String expression, |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 390 | Sequence<?> artifacts, // <FileT> |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 391 | Label labelResolver) |
Googler | 42720ad | 2019-09-18 10:33:21 -0700 | [diff] [blame] | 392 | throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 393 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 394 | @StarlarkMethod( |
cparsons | 238e344 | 2018-10-24 09:41:02 -0700 | [diff] [blame] | 395 | name = "new_file", |
| 396 | doc = |
| 397 | "DEPRECATED. Use <a href=\"actions.html#declare_file\">ctx.actions.declare_file</a>. <br>" |
| 398 | + "Creates a file object. There are four possible signatures to this method:<br><ul>" |
| 399 | + "" |
| 400 | + "<li>new_file(filename): Creates a file object with the given filename in the " |
| 401 | + "current package.</li>" |
| 402 | + "" |
| 403 | + "<li>new_file(file_root, filename): Creates a file object with the given " |
| 404 | + "filename under the given file root.</li>" |
| 405 | + "" |
| 406 | + "<li>new_file(sibling_file, filename): Creates a file object in the same " |
| 407 | + "directory as the given sibling file.</li>" |
| 408 | + "" |
| 409 | + "<li>new_file(file_root, sibling_file, suffix): Creates a file object with same " |
| 410 | + "base name of the sibling_file but with different given suffix, under the given " |
| 411 | + "file root.</li></ul> <br>" |
| 412 | + DOC_NEW_FILE_TAIL, |
| 413 | parameters = { |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 414 | @Param( |
| 415 | name = "var1", |
| 416 | allowedTypes = { |
| 417 | @ParamType(type = String.class), |
| 418 | @ParamType(type = FileRootApi.class), |
| 419 | @ParamType(type = FileApi.class), |
| 420 | }, |
| 421 | doc = ""), |
| 422 | @Param( |
| 423 | name = "var2", |
| 424 | allowedTypes = { |
| 425 | @ParamType(type = String.class), |
| 426 | @ParamType(type = FileApi.class), |
| 427 | }, |
| 428 | defaultValue = "unbound", |
| 429 | doc = ""), |
| 430 | @Param( |
| 431 | name = "var3", |
| 432 | allowedTypes = { |
| 433 | @ParamType(type = String.class), |
| 434 | }, |
| 435 | defaultValue = "unbound", |
| 436 | doc = "") |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 437 | }) |
| 438 | FileApi newFile(Object var1, Object var2, Object var3) throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 439 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 440 | @StarlarkMethod( |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 441 | name = "check_placeholders", |
| 442 | documented = false, |
| 443 | parameters = { |
| 444 | @Param( |
| 445 | name = "template", |
| 446 | positional = true, |
| 447 | named = false, |
| 448 | type = String.class, |
| 449 | doc = "The template."), |
| 450 | @Param( |
| 451 | name = "allowed_placeholders", |
| 452 | positional = true, |
| 453 | named = false, |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 454 | type = Sequence.class, |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 455 | doc = "The allowed placeholders."), |
| 456 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 457 | boolean checkPlaceholders(String template, Sequence<?> allowedPlaceholders) // <String> |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 458 | throws EvalException; |
| 459 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 460 | @StarlarkMethod( |
cparsons | 88d1cae | 2018-06-22 15:12:00 -0700 | [diff] [blame] | 461 | name = "expand_make_variables", |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 462 | doc = |
| 463 | "<b>Deprecated.</b> Use <a href=\"ctx.html#var\">ctx.var</a> to access the variables " |
| 464 | + "instead.<br>Returns a string after expanding all references to \"Make " |
| 465 | + "variables\". The " |
| 466 | + "variables must have the following format: <code>$(VAR_NAME)</code>. Also, " |
Googler | 8c1b44f | 2018-08-28 07:51:45 -0700 | [diff] [blame] | 467 | + "<code>$$VAR_NAME</code> expands to <code>$VAR_NAME</code>. " |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 468 | + "Examples:" |
| 469 | + "<pre class=language-python>\n" |
| 470 | + "ctx.expand_make_variables(\"cmd\", \"$(MY_VAR)\", {\"MY_VAR\": \"Hi\"}) " |
| 471 | + "# == \"Hi\"\n" |
| 472 | + "ctx.expand_make_variables(\"cmd\", \"$$PWD\", {}) # == \"$PWD\"\n" |
| 473 | + "</pre>" |
| 474 | + "Additional variables may come from other places, such as configurations. Note " |
cparsons | 73a7c90 | 2018-06-25 10:09:55 -0700 | [diff] [blame] | 475 | + "that this function is experimental.", |
| 476 | parameters = { |
| 477 | @Param( |
| 478 | name = "attribute_name", |
| 479 | positional = true, |
| 480 | named = false, |
| 481 | type = String.class, |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 482 | doc = "The attribute name. Used for error reporting."), |
cparsons | 73a7c90 | 2018-06-25 10:09:55 -0700 | [diff] [blame] | 483 | @Param( |
| 484 | name = "command", |
| 485 | positional = true, |
| 486 | named = false, |
| 487 | type = String.class, |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 488 | doc = |
| 489 | "The expression to expand. It can contain references to " + "\"Make variables\"."), |
cparsons | 73a7c90 | 2018-06-25 10:09:55 -0700 | [diff] [blame] | 490 | @Param( |
| 491 | name = "additional_substitutions", |
| 492 | positional = true, |
| 493 | named = false, |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 494 | type = Dict.class, |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 495 | doc = "Additional substitutions to make beyond the default make variables."), |
| 496 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 497 | String expandMakeVariables( |
cparsons | 0451e58 | 2019-10-21 16:10:45 -0700 | [diff] [blame] | 498 | String attributeName, |
| 499 | String command, |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 500 | final Dict<?, ?> additionalSubstitutions) // <String, String> |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 501 | throws EvalException; |
| 502 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 503 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 504 | name = "info_file", |
| 505 | structField = true, |
| 506 | documented = false, |
| 507 | doc = |
| 508 | "Returns the file that is used to hold the non-volatile workspace status for the " |
| 509 | + "current build request.") |
| 510 | FileApi getStableWorkspaceStatus() throws InterruptedException, EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 511 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 512 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 513 | name = "version_file", |
| 514 | structField = true, |
| 515 | documented = false, |
| 516 | doc = |
| 517 | "Returns the file that is used to hold the volatile workspace status for the " |
| 518 | + "current build request.") |
| 519 | FileApi getVolatileWorkspaceStatus() throws InterruptedException, EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 520 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 521 | @StarlarkMethod( |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 522 | name = "build_file_path", |
| 523 | structField = true, |
| 524 | documented = true, |
| 525 | doc = "Returns path to the BUILD file for this rule, relative to the source root.") |
| 526 | String getBuildFileRelativePath() throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 527 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 528 | @StarlarkMethod( |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 529 | name = "action", |
| 530 | doc = |
| 531 | "DEPRECATED. Use <a href=\"actions.html#run\">ctx.actions.run()</a> or" |
| 532 | + " <a href=\"actions.html#run_shell\">ctx.actions.run_shell()</a>. <br>" |
| 533 | + "Creates an action that runs an executable or a shell command." |
| 534 | + " You must specify either <code>command</code> or <code>executable</code>.\n" |
| 535 | + "Actions and genrules are very similar, but have different use cases. Actions are " |
| 536 | + "used inside rules, and genrules are used inside macros. Genrules also have make " |
| 537 | + "variable expansion.", |
| 538 | parameters = { |
| 539 | @Param( |
| 540 | name = "outputs", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 541 | type = Sequence.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 542 | generic1 = FileApi.class, |
| 543 | named = true, |
| 544 | positional = false, |
| 545 | doc = "List of the output files of the action."), |
| 546 | @Param( |
| 547 | name = "inputs", |
| 548 | allowedTypes = { |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 549 | @ParamType(type = Sequence.class), |
Googler | d21a0d1 | 2019-11-21 13:52:30 -0800 | [diff] [blame] | 550 | @ParamType(type = Depset.class), |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 551 | }, |
| 552 | generic1 = FileApi.class, |
| 553 | defaultValue = "[]", |
| 554 | named = true, |
| 555 | positional = false, |
| 556 | doc = "List of the input files of the action."), |
| 557 | @Param( |
| 558 | name = "executable", |
| 559 | type = Object.class, |
| 560 | allowedTypes = { |
| 561 | @ParamType(type = FileApi.class), |
| 562 | @ParamType(type = String.class), |
Googler | 641bdf7 | 2019-11-12 10:32:26 -0800 | [diff] [blame] | 563 | @ParamType(type = NoneType.class), |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 564 | }, |
| 565 | noneable = true, |
| 566 | defaultValue = "None", |
| 567 | named = true, |
| 568 | positional = false, |
| 569 | doc = "The executable file to be called by the action."), |
| 570 | @Param( |
| 571 | name = "tools", |
| 572 | allowedTypes = { |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 573 | @ParamType(type = Sequence.class), |
Googler | d21a0d1 | 2019-11-21 13:52:30 -0800 | [diff] [blame] | 574 | @ParamType(type = Depset.class), |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 575 | }, |
| 576 | generic1 = FileApi.class, |
| 577 | defaultValue = "unbound", |
| 578 | named = true, |
| 579 | positional = false, |
| 580 | doc = |
| 581 | "List of the any tools needed by the action. Tools are inputs with additional " |
| 582 | + "runfiles that are automatically made available to the action."), |
| 583 | @Param( |
| 584 | name = "arguments", |
| 585 | allowedTypes = { |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 586 | @ParamType(type = Sequence.class), |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 587 | }, |
| 588 | defaultValue = "[]", |
| 589 | named = true, |
| 590 | positional = false, |
| 591 | doc = |
| 592 | "Command line arguments of the action. Must be a list of strings or actions.args() " |
| 593 | + "objects."), |
| 594 | @Param( |
| 595 | name = "mnemonic", |
| 596 | type = String.class, |
| 597 | noneable = true, |
| 598 | defaultValue = "None", |
| 599 | named = true, |
| 600 | positional = false, |
| 601 | doc = "A one-word description of the action, e.g. CppCompile or GoLink."), |
| 602 | @Param( |
| 603 | name = "command", |
| 604 | type = Object.class, |
| 605 | allowedTypes = { |
| 606 | @ParamType(type = String.class), |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 607 | @ParamType(type = Sequence.class, generic1 = String.class), |
Googler | 641bdf7 | 2019-11-12 10:32:26 -0800 | [diff] [blame] | 608 | @ParamType(type = NoneType.class), |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 609 | }, |
| 610 | noneable = true, |
| 611 | defaultValue = "None", |
| 612 | named = true, |
| 613 | positional = false, |
| 614 | doc = |
| 615 | "Shell command to execute. It is usually preferable to " |
| 616 | + "use <code>executable</code> instead. " |
| 617 | + "Arguments are available with <code>$1</code>, <code>$2</code>, etc."), |
| 618 | @Param( |
| 619 | name = "progress_message", |
| 620 | type = String.class, |
| 621 | noneable = true, |
| 622 | defaultValue = "None", |
| 623 | named = true, |
| 624 | positional = false, |
| 625 | doc = |
| 626 | "Progress message to show to the user during the build, " |
| 627 | + "e.g. \"Compiling foo.cc to create foo.o\"."), |
| 628 | @Param( |
| 629 | name = "use_default_shell_env", |
| 630 | type = Boolean.class, |
| 631 | defaultValue = "False", |
| 632 | named = true, |
| 633 | positional = false, |
| 634 | doc = "Whether the action should use the built in shell environment or not."), |
| 635 | @Param( |
| 636 | name = "env", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 637 | type = Dict.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 638 | noneable = true, |
| 639 | defaultValue = "None", |
| 640 | named = true, |
| 641 | positional = false, |
| 642 | doc = "Sets the dictionary of environment variables."), |
| 643 | @Param( |
| 644 | name = "execution_requirements", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 645 | type = Dict.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 646 | noneable = true, |
| 647 | defaultValue = "None", |
| 648 | named = true, |
| 649 | positional = false, |
| 650 | doc = |
| 651 | "Information for scheduling the action. See " |
| 652 | + "<a href=\"$BE_ROOT/common-definitions.html#common.tags\">tags</a> " |
| 653 | + "for useful keys."), |
| 654 | @Param( |
| 655 | // TODO(bazel-team): The name here isn't accurate anymore. This is technically |
| 656 | // experimental, |
| 657 | // so folks shouldn't be too attached, but consider renaming to be more accurate/opaque. |
| 658 | name = "input_manifests", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 659 | type = Sequence.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 660 | noneable = true, |
| 661 | defaultValue = "None", |
| 662 | named = true, |
| 663 | positional = false, |
| 664 | doc = |
| 665 | "(Experimental) sets the input runfiles metadata; " |
| 666 | + "they are typically generated by resolve_command.") |
| 667 | }, |
| 668 | allowReturnNones = true, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 669 | useStarlarkThread = true) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 670 | NoneType action( |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 671 | Sequence<?> outputs, |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 672 | Object inputs, |
| 673 | Object executableUnchecked, |
| 674 | Object toolsUnchecked, |
| 675 | Object arguments, |
| 676 | Object mnemonicUnchecked, |
| 677 | Object commandUnchecked, |
| 678 | Object progressMessage, |
| 679 | Boolean useDefaultShellEnv, |
| 680 | Object envUnchecked, |
| 681 | Object executionRequirementsUnchecked, |
| 682 | Object inputManifestsUnchecked, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 683 | StarlarkThread thread) |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 684 | throws EvalException; |
| 685 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 686 | @StarlarkMethod( |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 687 | name = "expand_location", |
| 688 | doc = |
| 689 | "Expands all <code>$(location ...)</code> templates in the given string by replacing " |
| 690 | + "<code>$(location //x)</code> with the path of the output file of target //x. " |
| 691 | + "Expansion only works for labels that point to direct dependencies of this rule or " |
| 692 | + "that are explicitly listed in the optional argument <code>targets</code>. " |
| 693 | + "<br/><br/>" |
| 694 | // |
| 695 | + "<code>$(location ...)</code> will cause an error if the referenced target has " |
| 696 | + "multiple outputs. In this case, please use <code>$(locations ...)</code> since it " |
| 697 | + "produces a space-separated list of output paths. It can be safely used for a " |
| 698 | + "single output file, too." |
| 699 | + "<br/><br/>" |
| 700 | // |
| 701 | + "This function is useful to let the user specify a command in a BUILD file (like" |
| 702 | + " for <code>genrule</code>). In other cases, it is often better to manipulate" |
| 703 | + " labels directly.", |
| 704 | parameters = { |
| 705 | @Param(name = "input", type = String.class, doc = "String to be expanded."), |
| 706 | @Param( |
| 707 | name = "targets", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 708 | type = Sequence.class, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 709 | generic1 = TransitiveInfoCollectionApi.class, |
| 710 | defaultValue = "[]", |
| 711 | named = true, |
| 712 | doc = "List of targets for additional lookup information."), |
| 713 | }, |
| 714 | allowReturnNones = true, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 715 | useStarlarkThread = true) |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 716 | String expandLocation(String input, Sequence<?> targets, StarlarkThread thread) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 717 | throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 718 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 719 | @StarlarkMethod( |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 720 | name = "file_action", |
| 721 | doc = |
| 722 | "DEPRECATED. Use <a href =\"actions.html#write\">ctx.actions.write</a> instead. <br>" |
| 723 | + "Creates a file write action.", |
| 724 | parameters = { |
| 725 | @Param(name = "output", type = FileApi.class, named = true, doc = "The output file."), |
| 726 | @Param( |
| 727 | name = "content", |
| 728 | type = String.class, |
| 729 | named = true, |
| 730 | doc = "The contents of the file."), |
| 731 | @Param( |
| 732 | name = "executable", |
| 733 | type = Boolean.class, |
| 734 | defaultValue = "False", |
| 735 | named = true, |
| 736 | doc = "Whether the output file should be executable (default is False).") |
| 737 | }, |
| 738 | allowReturnNones = true, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 739 | useStarlarkThread = true) |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 740 | NoneType fileAction(FileApi output, String content, Boolean executable, StarlarkThread thread) |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 741 | throws EvalException; |
| 742 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 743 | @StarlarkMethod( |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 744 | name = "runfiles", |
| 745 | doc = "Creates a runfiles object.", |
| 746 | parameters = { |
| 747 | @Param( |
| 748 | name = "files", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 749 | type = Sequence.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 750 | generic1 = FileApi.class, |
| 751 | named = true, |
| 752 | defaultValue = "[]", |
| 753 | doc = "The list of files to be added to the runfiles."), |
| 754 | // TODO(bazel-team): If we have a memory efficient support for lazy list containing |
| 755 | // NestedSets we can remove this and just use files = [file] + list(set) |
| 756 | // Also, allow empty set for init |
| 757 | @Param( |
| 758 | name = "transitive_files", |
Googler | d21a0d1 | 2019-11-21 13:52:30 -0800 | [diff] [blame] | 759 | type = Depset.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 760 | generic1 = FileApi.class, |
| 761 | noneable = true, |
| 762 | defaultValue = "None", |
| 763 | named = true, |
| 764 | doc = |
| 765 | "The (transitive) set of files to be added to the runfiles. The depset should " |
| 766 | + "use the <code>default</code> order (which, as the name implies, is the " |
| 767 | + "default)."), |
| 768 | @Param( |
| 769 | name = "collect_data", |
| 770 | type = Boolean.class, |
| 771 | defaultValue = "False", |
| 772 | named = true, |
| 773 | doc = |
cparsons | 354a6fe | 2019-11-12 13:41:06 -0800 | [diff] [blame] | 774 | "<b>Use of this parameter is not recommended. See " |
| 775 | + "<a href=\"../rules.html#runfiles\">runfiles guide</a></b>. " |
| 776 | + "<p>Whether to collect the data " |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 777 | + "runfiles from the dependencies in srcs, data and deps attributes."), |
| 778 | @Param( |
| 779 | name = "collect_default", |
| 780 | type = Boolean.class, |
| 781 | defaultValue = "False", |
| 782 | named = true, |
| 783 | doc = |
cparsons | 354a6fe | 2019-11-12 13:41:06 -0800 | [diff] [blame] | 784 | "<b>Use of this parameter is not recommended. See " |
| 785 | + "<a href=\"../rules.html#runfiles\">runfiles guide</a></b>. " |
| 786 | + "<p>Whether to collect the default " |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 787 | + "runfiles from the dependencies in srcs, data and deps attributes."), |
| 788 | @Param( |
| 789 | name = "symlinks", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 790 | type = Dict.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 791 | defaultValue = "{}", |
| 792 | named = true, |
| 793 | doc = "The map of symlinks to be added to the runfiles, prefixed by workspace name."), |
| 794 | @Param( |
| 795 | name = "root_symlinks", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 796 | type = Dict.class, |
Sam Rawlins | 71d0f6c | 2018-06-07 07:25:49 -0700 | [diff] [blame] | 797 | defaultValue = "{}", |
| 798 | named = true, |
| 799 | doc = "The map of symlinks to be added to the runfiles.") |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 800 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 801 | RunfilesApi runfiles( |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 802 | Sequence<?> files, |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 803 | Object transitiveFiles, |
| 804 | Boolean collectData, |
| 805 | Boolean collectDefault, |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 806 | Dict<?, ?> symlinks, |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 807 | Dict<?, ?> rootSymlinks) |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 808 | throws EvalException; |
| 809 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 810 | @StarlarkMethod( |
laszlocsomor | ee197c6 | 2019-05-08 23:48:33 -0700 | [diff] [blame] | 811 | name = "resolve_command", |
| 812 | // TODO(bazel-team): The naming here isn't entirely accurate (input_manifests is no longer |
| 813 | // manifests), but this is experimental/should be opaque to the end user. |
| 814 | doc = |
| 815 | "<i>(Experimental)</i> Returns a tuple <code>(inputs, command, input_manifests)</code>" |
| 816 | + " of the list of resolved inputs, the argv list for the resolved command, and the" |
| 817 | + " runfiles metadata required to run the command, all of them suitable for passing" |
| 818 | + " as the same-named arguments of the <code>ctx.action</code> method.<br/><b>Note" |
| 819 | + " for Windows users</b>: this method requires Bash (MSYS2). Consider using" |
| 820 | + " <code>resolve_tools()</code> instead (if that fits your needs).", |
| 821 | parameters = { |
| 822 | @Param( |
| 823 | name = "command", |
| 824 | type = String.class, // string |
| 825 | defaultValue = "''", |
| 826 | named = true, |
| 827 | positional = false, |
| 828 | doc = "Command to resolve."), |
| 829 | @Param( |
| 830 | name = "attribute", |
| 831 | type = String.class, // string |
| 832 | defaultValue = "None", |
| 833 | noneable = true, |
| 834 | named = true, |
| 835 | positional = false, |
| 836 | doc = "Name of the associated attribute for which to issue an error, or None."), |
| 837 | @Param( |
| 838 | name = "expand_locations", |
| 839 | type = Boolean.class, |
| 840 | defaultValue = "False", |
| 841 | named = true, |
| 842 | positional = false, |
| 843 | doc = |
| 844 | "Shall we expand $(location) variables? See <a" |
| 845 | + " href=\"#expand_location\">ctx.expand_location()</a> for more details."), |
| 846 | @Param( |
| 847 | name = "make_variables", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 848 | type = Dict.class, // dict(string, string) |
laszlocsomor | ee197c6 | 2019-05-08 23:48:33 -0700 | [diff] [blame] | 849 | noneable = true, |
| 850 | defaultValue = "None", |
| 851 | named = true, |
| 852 | positional = false, |
| 853 | doc = "Make variables to expand, or None."), |
| 854 | @Param( |
| 855 | name = "tools", |
| 856 | defaultValue = "[]", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 857 | type = Sequence.class, |
laszlocsomor | ee197c6 | 2019-05-08 23:48:33 -0700 | [diff] [blame] | 858 | generic1 = TransitiveInfoCollectionApi.class, |
| 859 | named = true, |
| 860 | positional = false, |
| 861 | doc = "List of tools (list of targets)."), |
| 862 | @Param( |
| 863 | name = "label_dict", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 864 | type = Dict.class, |
laszlocsomor | ee197c6 | 2019-05-08 23:48:33 -0700 | [diff] [blame] | 865 | defaultValue = "{}", |
| 866 | named = true, |
| 867 | positional = false, |
| 868 | doc = |
| 869 | "Dictionary of resolved labels and the corresponding list of Files " |
| 870 | + "(a dict of Label : list of Files)."), |
| 871 | @Param( |
| 872 | name = "execution_requirements", |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 873 | type = Dict.class, |
laszlocsomor | ee197c6 | 2019-05-08 23:48:33 -0700 | [diff] [blame] | 874 | defaultValue = "{}", |
| 875 | named = true, |
| 876 | positional = false, |
| 877 | doc = |
| 878 | "Information for scheduling the action to resolve this command. See " |
| 879 | + "<a href=\"$BE_ROOT/common-definitions.html#common.tags\">tags</a> " |
| 880 | + "for useful keys."), |
| 881 | }, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 882 | useStarlarkThread = true) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 883 | Tuple<Object> resolveCommand( |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 884 | String command, |
| 885 | Object attributeUnchecked, |
| 886 | Boolean expandLocations, |
| 887 | Object makeVariablesUnchecked, |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 888 | Sequence<?> tools, |
Googler | a9c9363 | 2019-11-13 10:48:07 -0800 | [diff] [blame] | 889 | Dict<?, ?> labelDictUnchecked, |
| 890 | Dict<?, ?> executionRequirementsUnchecked, |
Googler | a3421e2 | 2019-09-26 06:48:32 -0700 | [diff] [blame] | 891 | StarlarkThread thread) |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 892 | throws EvalException; |
Laszlo Csomor | 52446a1 | 2019-01-24 07:40:50 -0800 | [diff] [blame] | 893 | |
gregce | 8345b79 | 2020-05-15 13:23:29 -0700 | [diff] [blame] | 894 | @StarlarkMethod( |
Laszlo Csomor | 52446a1 | 2019-01-24 07:40:50 -0800 | [diff] [blame] | 895 | name = "resolve_tools", |
| 896 | doc = |
| 897 | "Returns a tuple <code>(inputs, input_manifests)</code> of the depset of resolved inputs" |
| 898 | + " and the runfiles metadata required to run the tools, both of them suitable for" |
| 899 | + " passing as the same-named arguments of the <code>ctx.actions.run</code> method." |
| 900 | + "<br/><br/>In contrast to <code>ctx.resolve_command</code>, this method does not" |
| 901 | + " require that Bash be installed on the machine, so it's suitable for rules built" |
| 902 | + " on Windows.", |
| 903 | parameters = { |
| 904 | @Param( |
| 905 | name = "tools", |
| 906 | defaultValue = "[]", |
Googler | 4871cb0 | 2019-11-12 17:16:42 -0800 | [diff] [blame] | 907 | type = Sequence.class, |
Laszlo Csomor | 52446a1 | 2019-01-24 07:40:50 -0800 | [diff] [blame] | 908 | generic1 = TransitiveInfoCollectionApi.class, |
| 909 | named = true, |
| 910 | positional = false, |
| 911 | doc = "List of tools (list of targets)."), |
adonovan | 7891d3b | 2020-01-22 12:40:50 -0800 | [diff] [blame] | 912 | }) |
jcater | 3ecaa49 | 2019-12-09 16:26:00 -0800 | [diff] [blame] | 913 | Tuple<Object> resolveTools(Sequence<?> tools) throws EvalException; |
cparsons | abbb900 | 2018-05-11 11:54:17 -0700 | [diff] [blame] | 914 | } |