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