aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/SkylarkConfigApi.java
blob: e6cf44b3ad9b4e6548eb15294c978f1912c904e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2018 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.build.lib.skylarkbuildapi;

import com.google.devtools.build.lib.skylarkinterface.Param;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;


/**
 *  The "config" module of the Build API.
 *
 *  This exposes methods to describe what kind of build setting (if any) a skylark rule is using
 *  the {@code build_setting} attr of the {@code rule(...)} function.
 */
@SkylarkModule(
    name = "config",
    namespace = true,
    category = SkylarkModuleCategory.BUILTIN,
    doc = "This is a top-level module for creating build setting descriptors which describe what "
        + "kind of build setting (if any) a skylark rule is. "
        + ""
        + "<p>ex: the following rule is marked as a build setting by setting the "
        + "<code>build_setting</code> parameter of the <code>rule()</code> function. Specifically "
        + "it is a build setting of type <code>int</code> and is a <code>flag</code> which means "
        + "this build setting is callable on the command line.<br><pre class=language-python>"
        + "  my_rule = rule(\n"
        + "    implementation = _impl,\n"
        + "    build_setting = config.int(flag = True),\n"
        + "    ...\n"
        + "  )</pre>")
//TODO(juliexxia): Create formal documentation for skylark build configuration efforts (b/112545834)
public interface SkylarkConfigApi extends SkylarkValue {

  static final String FLAG_ARG = "flag";
  static final String FLAG_ARG_DOC =
      "Whether or not this build setting is callable on the command line.";

  @SkylarkCallable(
      name = "int",
      doc = "An integer-typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi intSetting(Boolean flag);

  @SkylarkCallable(
      name = "bool",
      doc = "A bool-typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi boolSetting(Boolean flag);

  @SkylarkCallable(
      name = "string",
      doc = "A string-typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi stringSetting(Boolean flag);

  @SkylarkCallable(
      name = "string_list",
      doc = "A string list-typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi stringListSetting(Boolean flag);

  @SkylarkCallable(
      name = "label",
      doc = "A label typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi labelSetting(Boolean flag);

  @SkylarkCallable(
      name = "label_list",
      doc = "A label list-typed build setting",
      parameters = {
        @Param(
            name = FLAG_ARG,
            type = Boolean.class,
            defaultValue = "False",
            doc = FLAG_ARG_DOC,
            named = true,
            positional = false)
      })
  BuildSettingApi labelListSetting(Boolean flag);

  /** The API for build setting descriptors. */
  @SkylarkModule(
      name = "BuildSetting",
      category = SkylarkModuleCategory.NONE,
      doc =
          "The descriptor for a single piece of configuration information. If configuration is a "
              + "key-value map of settings like {'cpu': 'ppc', 'copt': '-DFoo'}, this describes a "
              + "single entry in that map.")
  interface BuildSettingApi extends SkylarkValue {}
}