blob: 932afb361d213cd1d7460257c742a5e71ecb4012 [file] [log] [blame]
cparsons6df5ec32018-04-17 14:09:54 -07001// 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
cparsons981f65b2018-04-23 12:04:09 -070015package com.google.devtools.build.lib.skylarkbuildapi;
cparsons6df5ec32018-04-17 14:09:54 -070016
cparsons6df5ec32018-04-17 14:09:54 -070017import com.google.devtools.build.lib.syntax.EvalException;
Googlera3421e22019-09-26 06:48:32 -070018import com.google.devtools.build.lib.syntax.StarlarkThread;
adonovanb0174682020-05-18 16:01:53 -070019import net.starlark.java.annot.Param;
20import net.starlark.java.annot.StarlarkGlobalLibrary;
21import net.starlark.java.annot.StarlarkMethod;
cparsons6df5ec32018-04-17 14:09:54 -070022
gregcead752cc2020-04-10 10:32:59 -070023/** A collection of global Starlark build API functions that belong in the global namespace. */
gregce8345b792020-05-15 13:23:29 -070024@StarlarkGlobalLibrary
gregce5c8a5f52020-05-13 10:35:36 -070025public interface StarlarkBuildApiGlobals {
cparsons6df5ec32018-04-17 14:09:54 -070026
gregce8345b792020-05-15 13:23:29 -070027 @StarlarkMethod(
cparsonsb380dc92018-12-05 13:57:39 -080028 name = "configuration_field",
gregce5c8a5f52020-05-13 10:35:36 -070029 // TODO(cparsons): Provide a link to documentation for available StarlarkConfigurationFields.
cparsonsb380dc92018-12-05 13:57:39 -080030 doc =
31 "References a late-bound default value for an attribute of type "
32 + "<a href=\"attr.html#label\">label</a>. A value is 'late-bound' if it requires "
33 + "the configuration to be built before determining the value. Any attribute using "
34 + "this as a value must <a href=\"../rules.html#private-attributes\">be private</a>. "
35 + "<p>Example usage: "
36 + "<p>Defining a rule attribute: <br><pre class=language-python>"
37 + "'_foo': attr.label(default=configuration_field(fragment='java', "
38 + "name='toolchain'))</pre>"
39 + "<p>Accessing in rule implementation: <br><pre class=language-python>"
40 + " def _rule_impl(ctx):\n"
41 + " foo_info = ctx.attr._foo\n"
42 + " ...</pre>",
43 parameters = {
cparsons6df5ec32018-04-17 14:09:54 -070044 @Param(
45 name = "fragment",
46 type = String.class,
47 named = true,
cparsonsb380dc92018-12-05 13:57:39 -080048 doc = "The name of a configuration fragment which contains the late-bound value."),
cparsons6df5ec32018-04-17 14:09:54 -070049 @Param(
50 name = "name",
51 type = String.class,
52 named = true,
53 doc = "The name of the value to obtain from the configuration fragment."),
cparsonsb380dc92018-12-05 13:57:39 -080054 },
Googlera3421e22019-09-26 06:48:32 -070055 useStarlarkThread = true)
adonovan7891d3b2020-01-22 12:40:50 -080056 LateBoundDefaultApi configurationField(String fragment, String name, StarlarkThread thread)
57 throws EvalException;
cparsons6df5ec32018-04-17 14:09:54 -070058}