|
15 | 15 | package com.google.devtools.build.lib.starlarkbuildapi;
|
16 | 16 |
|
17 | 17 | import com.google.devtools.build.docgen.annot.DocCategory;
|
| 18 | +import com.google.devtools.build.lib.cmdline.Label; |
18 | 19 | import net.starlark.java.annot.Param;
|
19 | 20 | import net.starlark.java.annot.ParamType;
|
20 | 21 | import net.starlark.java.annot.StarlarkBuiltin;
|
@@ -241,6 +242,38 @@ NoneType exportsFiles(Sequence<?> srcs, Object visibility, Object licenses, Star
|
241 | 242 | useStarlarkThread = true)
|
242 | 243 | String repositoryName(StarlarkThread thread) throws EvalException;
|
243 | 244 |
|
| 245 | + @StarlarkMethod( |
| 246 | + name = "package_relative_label", |
| 247 | + doc = |
| 248 | + "Converts the input string into a <a href='Label'>Label</a> object, in the context of the" |
| 249 | + + " package currently being initialized (that is, the <code>BUILD</code> file for" |
| 250 | + + " which the current macro is executing). If the input is already a" |
| 251 | + + " <code>Label</code>, it is returned unchanged.<p>This function may only be called" |
| 252 | + + " while evaluating a BUILD file and the macros it directly or indirectly calls; it" |
| 253 | + + " may not be called in (for instance) a rule implementation function. <p>The result" |
| 254 | + + " of this function is the same <code>Label</code> value as would be produced by" |
| 255 | + + " passing the given string to a label-valued attribute of a target declared in the" |
| 256 | + + " BUILD file. <p><i>Usage note:</i> The difference between this function and <a" |
| 257 | + + " href='Label#Label'>Label()</a></code> is that <code>Label()</code> uses the" |
| 258 | + + " context of the package of the <code>.bzl</code> file that called it, not the" |
| 259 | + + " package of the <code>BUILD</code> file. Use <code>Label()</code> when you need to" |
| 260 | + + " refer to a fixed target that is hardcoded into the macro, such as a compiler. Use" |
| 261 | + + " <code>package_relative_label()</code> when you need to normalize a label string" |
| 262 | + + " supplied by the BUILD file to a <code>Label</code> object. (There is no way to" |
| 263 | + + " convert a string to a <code>Label</code> in the context of a package other than" |
| 264 | + + " the BUILD file or the calling .bzl file. For that reason, outer macros should" |
| 265 | + + " always prefer to pass Label objects to inner macros rather than label strings.)", |
| 266 | + parameters = { |
| 267 | + @Param( |
| 268 | + name = "input", |
| 269 | + allowedTypes = {@ParamType(type = String.class), @ParamType(type = Label.class)}, |
| 270 | + doc = |
| 271 | + "The input label string or Label object. If a Label object is passed, it's" |
| 272 | + + " returned as is.") |
| 273 | + }, |
| 274 | + useStarlarkThread = true) |
| 275 | + Label packageRelativeLabel(Object input, StarlarkThread thread) throws EvalException; |
| 276 | + |
244 | 277 | @StarlarkMethod(
|
245 | 278 | name = "subpackages",
|
246 | 279 | doc =
|
|
0 commit comments