blob: 2bd7daf1b9b62ecd83d7950d58c3f87a8f92830e [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
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
15package com.google.devtools.build.lib.analysis;
16
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010017import static com.google.devtools.build.lib.packages.Attribute.attr;
Lukacs Berkiffa73ad2015-09-18 11:40:12 +000018import static com.google.devtools.build.lib.packages.BuildType.DISTRIBUTIONS;
19import static com.google.devtools.build.lib.packages.BuildType.LABEL;
20import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
21import static com.google.devtools.build.lib.packages.BuildType.LICENSE;
22import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST;
23import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
24import static com.google.devtools.build.lib.syntax.Type.INTEGER;
25import static com.google.devtools.build.lib.syntax.Type.STRING;
26import static com.google.devtools.build.lib.syntax.Type.STRING_LIST;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010027
Carmi Grushkoeaaa9d0d2015-11-17 01:54:45 +000028import com.google.common.annotations.VisibleForTesting;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010029import com.google.common.collect.ImmutableList;
Ulf Adams37590dc2016-10-14 11:52:00 +000030import com.google.common.collect.ImmutableSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010031import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
gregce490b0952017-07-06 18:44:38 -040032import com.google.devtools.build.lib.analysis.config.HostTransition;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010033import com.google.devtools.build.lib.analysis.config.RunUnder;
34import com.google.devtools.build.lib.analysis.constraints.EnvironmentRule;
ulfjackab21d182017-08-10 15:36:14 +020035import com.google.devtools.build.lib.analysis.test.TestConfiguration;
dbabkin708b9572018-06-07 02:31:16 -070036import com.google.devtools.build.lib.cmdline.Label;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010037import com.google.devtools.build.lib.packages.Attribute;
janakra56a6ad2018-02-02 15:52:22 -080038import com.google.devtools.build.lib.packages.Attribute.LabelLateBoundDefault;
39import com.google.devtools.build.lib.packages.Attribute.LabelListLateBoundDefault;
dbabkin708b9572018-06-07 02:31:16 -070040import com.google.devtools.build.lib.packages.Attribute.LateBoundDefault.Resolver;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010041import com.google.devtools.build.lib.packages.AttributeMap;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010042import com.google.devtools.build.lib.packages.RuleClass;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010043import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
jcaterd7ce6262018-06-13 10:17:30 -070044import com.google.devtools.build.lib.packages.RuleClass.ExecutionPlatformConstraintsAllowed;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010045import com.google.devtools.build.lib.packages.TestSize;
janakr8688b682018-03-26 09:07:11 -070046import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
Lukacs Berkiffa73ad2015-09-18 11:40:12 +000047import com.google.devtools.build.lib.syntax.Type;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010048import com.google.devtools.build.lib.util.FileTypeSet;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010049
50/**
51 * Rule class definitions used by (almost) every rule.
52 */
53public class BaseRuleClasses {
janakr8688b682018-03-26 09:07:11 -070054 @AutoCodec @AutoCodec.VisibleForSerialization
55 static final Attribute.ComputedDefault testonlyDefault =
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010056 new Attribute.ComputedDefault() {
57 @Override
58 public Object getDefault(AttributeMap rule) {
59 return rule.getPackageDefaultTestOnly();
60 }
61 };
62
janakr8688b682018-03-26 09:07:11 -070063 @AutoCodec @AutoCodec.VisibleForSerialization
64 static final Attribute.ComputedDefault deprecationDefault =
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010065 new Attribute.ComputedDefault() {
66 @Override
67 public Object getDefault(AttributeMap rule) {
68 return rule.getPackageDefaultDeprecation();
69 }
70 };
71
mstaib807a9b22017-09-19 17:06:32 +020072 // TODO(b/65746853): provide a way to do this without passing the entire configuration
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010073 /**
74 * Implementation for the :action_listener attribute.
mstaib807a9b22017-09-19 17:06:32 +020075 *
76 * <p>action_listeners are special rules; they tell the build system to add extra_actions to
77 * existing rules. As such they need an edge to every ConfiguredTarget with the limitation that
78 * they only run on the target configuration and should not operate on action_listeners and
79 * extra_actions themselves (to avoid cycles).
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080 */
janakr8688b682018-03-26 09:07:11 -070081 @AutoCodec @VisibleForTesting
janakra56a6ad2018-02-02 15:52:22 -080082 static final LabelListLateBoundDefault<?> ACTION_LISTENER =
83 LabelListLateBoundDefault.fromTargetConfiguration(
mstaib807a9b22017-09-19 17:06:32 +020084 BuildConfiguration.class,
mstaib807a9b22017-09-19 17:06:32 +020085 (rule, attributes, configuration) -> configuration.getActionListeners());
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010086
dbabkin708b9572018-06-07 02:31:16 -070087 public static final String DEFAULT_COVERAGE_SUPPORT_VALUE = "//tools/test:coverage_support";
88
89 @AutoCodec
90 static final Resolver<TestConfiguration, Label> COVERAGE_SUPPORT_CONFIGURATION_RESOLVER =
91 (rule, attributes, configuration) -> configuration.getCoverageSupport();
92
93 public static LabelLateBoundDefault<TestConfiguration> coverageSupportAttribute(
94 Label defaultValue) {
95 return LabelLateBoundDefault.fromTargetConfiguration(
96 TestConfiguration.class, defaultValue, COVERAGE_SUPPORT_CONFIGURATION_RESOLVER);
97 }
98
dbabkin2df32342018-06-07 05:19:54 -070099 public static final String DEFAULT_COVERAGE_REPORT_GENERATOR_VALUE =
100 "//tools/test:coverage_report_generator";
101
102 @AutoCodec
103 static final Resolver<TestConfiguration, Label> COVERAGE_REPORT_GENERATOR_CONFIGURATION_RESOLVER =
104 (rule, attributes, configuration) -> configuration.getCoverageReportGenerator();
105
106 public static LabelLateBoundDefault<TestConfiguration> coverageReportGeneratorAttribute(
107 Label defaultValue) {
108 return LabelLateBoundDefault.fromTargetConfiguration(
109 TestConfiguration.class, defaultValue, COVERAGE_REPORT_GENERATOR_CONFIGURATION_RESOLVER);
110 }
111
mstaib807a9b22017-09-19 17:06:32 +0200112 // TODO(b/65746853): provide a way to do this without passing the entire configuration
113 /** Implementation for the :run_under attribute. */
janakr8688b682018-03-26 09:07:11 -0700114 @AutoCodec
janakra56a6ad2018-02-02 15:52:22 -0800115 public static final LabelLateBoundDefault<?> RUN_UNDER =
116 LabelLateBoundDefault.fromTargetConfiguration(
mstaib807a9b22017-09-19 17:06:32 +0200117 BuildConfiguration.class,
118 null,
119 (rule, attributes, configuration) -> {
120 RunUnder runUnder = configuration.getRunUnder();
121 return runUnder != null ? runUnder.getLabel() : null;
122 });
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100123
124 /**
125 * A base rule for all test rules.
126 */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100127 public static final class TestBaseRule implements RuleDefinition {
128 @Override
jcater36745912018-05-01 13:20:00 -0700129 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100130 return builder
tomlua08bb892017-08-03 03:23:48 +0200131 .requiresConfigurationFragments(TestConfiguration.class)
132 .add(
133 attr("size", STRING)
134 .value("medium")
135 .taggable()
136 .nonconfigurable("policy decision: should be consistent across configurations"))
137 .add(
138 attr("timeout", STRING)
139 .taggable()
140 .nonconfigurable("policy decision: should be consistent across configurations")
141 .value(
142 new Attribute.ComputedDefault() {
143 @Override
144 public Object getDefault(AttributeMap rule) {
145 TestSize size = TestSize.getTestSize(rule.get("size", Type.STRING));
146 if (size != null) {
147 String timeout = size.getDefaultTimeout().toString();
148 if (timeout != null) {
149 return timeout;
150 }
151 }
152 return "illegal";
153 }
154 }))
155 .add(
156 attr("flaky", BOOLEAN)
157 .value(false)
158 .taggable()
159 .nonconfigurable("policy decision: should be consistent across configurations"))
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100160 .add(attr("shard_count", INTEGER).value(-1))
tomlua08bb892017-08-03 03:23:48 +0200161 .add(
162 attr("local", BOOLEAN)
163 .value(false)
164 .taggable()
165 .nonconfigurable("policy decision: should be consistent across configurations"))
Greg Estren547295a2016-08-18 22:01:29 +0000166 .add(attr("args", STRING_LIST))
Lukacs Berki8f460f32016-06-29 09:14:10 +0000167 // Input files for every test action
tomlua08bb892017-08-03 03:23:48 +0200168 .add(
169 attr("$test_runtime", LABEL_LIST)
gregce676a9572017-12-21 11:33:32 -0800170 .cfg(HostTransition.INSTANCE)
tomlua08bb892017-08-03 03:23:48 +0200171 .value(ImmutableList.of(env.getToolsLabel("//tools/test:runtime"))))
hlopko8820d3a2018-06-15 09:10:05 -0700172 .add(
173 attr("$test_setup_script", LABEL)
174 .cfg(HostTransition.INSTANCE)
175 .singleArtifact()
176 .value(env.getToolsLabel("//tools/test:test_setup")))
177 .add(
ulfjack0858ae12018-07-27 02:37:53 -0700178 attr("$xml_generator_script", LABEL)
179 .cfg(HostTransition.INSTANCE)
180 .singleArtifact()
181 .value(env.getToolsLabel("//tools/test:test_xml_generator")))
182 .add(
hlopko8820d3a2018-06-15 09:10:05 -0700183 attr("$collect_coverage_script", LABEL)
184 .cfg(HostTransition.INSTANCE)
185 .singleArtifact()
186 .value(env.getToolsLabel("//tools/test:collect_coverage")))
Lukacs Berki8f460f32016-06-29 09:14:10 +0000187 // Input files for test actions collecting code coverage
tomlua08bb892017-08-03 03:23:48 +0200188 .add(
dbabkin708b9572018-06-07 02:31:16 -0700189 attr(":coverage_support", LABEL)
190 .value(
191 coverageSupportAttribute(env.getToolsLabel(DEFAULT_COVERAGE_SUPPORT_VALUE))))
Lukacs Berki8f460f32016-06-29 09:14:10 +0000192 // Used in the one-per-build coverage report generation action.
tomlua08bb892017-08-03 03:23:48 +0200193 .add(
dbabkin2df32342018-06-07 05:19:54 -0700194 attr(":coverage_report_generator", LABEL)
gregce676a9572017-12-21 11:33:32 -0800195 .cfg(HostTransition.INSTANCE)
dbabkin2df32342018-06-07 05:19:54 -0700196 .value(
197 coverageReportGeneratorAttribute(
elenairina9438d102018-07-06 03:06:21 -0700198 env.getToolsLabel(DEFAULT_COVERAGE_REPORT_GENERATOR_VALUE))))
hlopko8820d3a2018-06-15 09:10:05 -0700199 // The target itself and run_under both run on the same machine.
200 .add(attr(":run_under", LABEL).value(RUN_UNDER).skipPrereqValidatorCheck())
jcaterd7ce6262018-06-13 10:17:30 -0700201 .executionPlatformConstraintsAllowed(ExecutionPlatformConstraintsAllowed.PER_TARGET)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100202 .build();
203 }
Googler58505032015-03-19 16:12:34 +0000204
205 @Override
206 public Metadata getMetadata() {
207 return RuleDefinition.Metadata.builder()
208 .name("$test_base_rule")
209 .type(RuleClassType.ABSTRACT)
lberki3c1c8e92017-07-13 12:25:47 +0200210 .ancestors(RootRule.class, MakeVariableExpandingRule.class)
Googler58505032015-03-19 16:12:34 +0000211 .build();
212 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100213 }
214
215 /**
mstaib188b5782018-05-16 10:13:51 -0700216 * The attribute used to list the configuration properties used by a target and its transitive
217 * dependencies. Currently only supports config_feature_flag.
218 */
219 public static final String TAGGED_TRIMMING_ATTR = "transitive_configs";
220
221 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100222 * Share common attributes across both base and Skylark base rules.
223 */
224 public static RuleClass.Builder commonCoreAndSkylarkAttributes(RuleClass.Builder builder) {
cpeyserd852e482017-09-07 22:16:06 +0200225 return PlatformSemantics.platformAttributes(builder)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100226 // The visibility attribute is special: it is a nodep label, and loading the
227 // necessary package groups is handled by {@link LabelVisitor#visitTargetVisibility}.
228 // Package groups always have the null configuration so that they are not duplicated
229 // needlessly.
cpeyserd852e482017-09-07 22:16:06 +0200230 .add(
231 attr("visibility", NODEP_LABEL_LIST)
232 .orderIndependent()
gregce676a9572017-12-21 11:33:32 -0800233 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200234 .nonconfigurable(
235 "special attribute integrated more deeply into Bazel's core logic"))
236 .add(
mstaib188b5782018-05-16 10:13:51 -0700237 attr(TAGGED_TRIMMING_ATTR, NODEP_LABEL_LIST)
238 .orderIndependent()
239 .nonconfigurable("Used in determining configuration"))
240 .add(
cpeyserd852e482017-09-07 22:16:06 +0200241 attr("deprecation", STRING)
242 .value(deprecationDefault)
243 .nonconfigurable("Used in core loading phase logic with no access to configs"))
244 .add(
245 attr("tags", STRING_LIST)
246 .orderIndependent()
247 .taggable()
248 .nonconfigurable("low-level attribute, used in TargetUtils without configurations"))
249 .add(
250 attr("generator_name", STRING)
251 .undocumented("internal")
252 .nonconfigurable("static structure of a rule"))
253 .add(
254 attr("generator_function", STRING)
255 .undocumented("internal")
256 .nonconfigurable("static structure of a rule"))
257 .add(
258 attr("generator_location", STRING)
259 .undocumented("internal")
260 .nonconfigurable("static structure of a rule"))
261 .add(
262 attr("testonly", BOOLEAN)
263 .value(testonlyDefault)
264 .nonconfigurable("policy decision: rules testability should be consistent"))
Manuel Klimek6d9fb362015-04-30 12:50:55 +0000265 .add(attr("features", STRING_LIST).orderIndependent())
gregce676a9572017-12-21 11:33:32 -0800266 .add(attr(":action_listener", LABEL_LIST)
267 .cfg(HostTransition.INSTANCE)
268 .value(ACTION_LISTENER))
cpeyserd852e482017-09-07 22:16:06 +0200269 .add(
270 attr(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, LABEL_LIST)
271 .allowedRuleClasses(EnvironmentRule.RULE_NAME)
gregce676a9572017-12-21 11:33:32 -0800272 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200273 .allowedFileTypes(FileTypeSet.NO_FILE)
274 .dontCheckConstraints()
275 .nonconfigurable(
276 "special logic for constraints and select: see ConstraintSemantics"))
277 .add(
278 attr(RuleClass.RESTRICTED_ENVIRONMENT_ATTR, LABEL_LIST)
279 .allowedRuleClasses(EnvironmentRule.RULE_NAME)
gregce676a9572017-12-21 11:33:32 -0800280 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200281 .allowedFileTypes(FileTypeSet.NO_FILE)
282 .dontCheckConstraints()
283 .nonconfigurable(
284 "special logic for constraints and select: see ConstraintSemantics"));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100285 }
286
Googler015e5952017-02-14 09:45:30 +0000287 public static RuleClass.Builder nameAttribute(RuleClass.Builder builder) {
288 return builder.add(attr("name", STRING).nonconfigurable("Rule name"));
289 }
290
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100291 /**
Googler015e5952017-02-14 09:45:30 +0000292 * Ancestor of every rule.
293 *
294 * <p>Adds the name attribute to every rule.
295 */
296 public static final class RootRule implements RuleDefinition {
297
298 @Override
jcater36745912018-05-01 13:20:00 -0700299 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
Googler015e5952017-02-14 09:45:30 +0000300 return nameAttribute(builder).build();
301 }
302
303 @Override
304 public Metadata getMetadata() {
305 return RuleDefinition.Metadata.builder()
306 .name("$root_rule")
307 .type(RuleClassType.ABSTRACT)
308 .build();
309 }
310 }
311
312 /**
313 * Common parts of some rules.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100314 */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100315 public static final class BaseRule implements RuleDefinition {
316 @Override
317 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
318 return commonCoreAndSkylarkAttributes(builder)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100319 // Aggregates the labels of all {@link ConfigRuleClasses} rules this rule uses (e.g.
320 // keys for configurable attributes). This is specially populated in
321 // {@RuleClass#populateRuleAttributeValues}.
322 //
323 // This attribute is not needed for actual builds. Its main purpose is so query's
324 // proto/XML output includes the labels of config dependencies, so, e.g., depserver
325 // reverse dependency lookups remain accurate. These can't just be added to the
326 // attribute definitions proto/XML queries already output because not all attributes
327 // contain labels.
328 //
329 // Builds and Blaze-interactive queries don't need this because they find dependencies
330 // through direct Rule label visitation, which already factors these in.
331 .add(attr("$config_dependencies", LABEL_LIST)
332 .nonconfigurable("not intended for actual builds"))
333 .add(attr("licenses", LICENSE)
334 .nonconfigurable("Used in core loading phase logic with no access to configs"))
335 .add(attr("distribs", DISTRIBUTIONS)
336 .nonconfigurable("Used in core loading phase logic with no access to configs"))
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100337 .build();
338 }
Googler58505032015-03-19 16:12:34 +0000339
340 @Override
341 public Metadata getMetadata() {
342 return RuleDefinition.Metadata.builder()
343 .name("$base_rule")
344 .type(RuleClassType.ABSTRACT)
Googler015e5952017-02-14 09:45:30 +0000345 .ancestors(RootRule.class)
Googler58505032015-03-19 16:12:34 +0000346 .build();
347 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100348 }
349
350 /**
lberki3c1c8e92017-07-13 12:25:47 +0200351 * A rule that contains a {@code variables=} attribute to allow referencing Make variables.
352 */
353 public static final class MakeVariableExpandingRule implements RuleDefinition {
354 @Override
jcater36745912018-05-01 13:20:00 -0700355 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
lberki3c1c8e92017-07-13 12:25:47 +0200356 return builder
357 /* <!-- #BLAZE_RULE($make_variable_expanding_rule).ATTRIBUTE(toolchains) -->
358 The set of toolchains that supply <a href="${link make-variables}">"Make variables"</a>
359 that this target can use in some of its attributes. Some rules have toolchains whose Make
360 variables they can use by default.
361 <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
362 .add(attr("toolchains", LABEL_LIST)
363 .allowedFileTypes(FileTypeSet.NO_FILE)
jcater191238f2018-06-19 10:17:16 -0700364 .mandatoryProviders(ImmutableList.of(TemplateVariableInfo.PROVIDER.id()))
365 .dontCheckConstraints())
lberki3c1c8e92017-07-13 12:25:47 +0200366 .build();
367 }
368
369 @Override
370 public Metadata getMetadata() {
371 return RuleDefinition.Metadata.builder()
372 .name("$make_variable_expanding_rule")
373 .type(RuleClassType.ABSTRACT)
374 .build();
375 }
376 }
377
378 /**
Googler015e5952017-02-14 09:45:30 +0000379 * Common ancestor class for some rules.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100380 */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100381 public static final class RuleBase implements RuleDefinition {
382 @Override
jcater36745912018-05-01 13:20:00 -0700383 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100384 return builder
385 .add(attr("deps", LABEL_LIST).legacyAllowAnyFileType())
hlopko8820d3a2018-06-15 09:10:05 -0700386 .add(
387 attr("data", LABEL_LIST)
388 .allowedFileTypes(FileTypeSet.ANY_FILE)
389 .dontCheckConstraints())
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100390 .build();
391 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100392
Googler58505032015-03-19 16:12:34 +0000393 @Override
394 public Metadata getMetadata() {
395 return RuleDefinition.Metadata.builder()
396 .name("$rule")
397 .type(RuleClassType.ABSTRACT)
398 .ancestors(BaseRule.class)
399 .build();
400 }
401 }
Ulf Adams37590dc2016-10-14 11:52:00 +0000402
403 public static final ImmutableSet<String> ALLOWED_RULE_CLASSES =
404 ImmutableSet.of("filegroup", "genrule", "Fileset");
405
406 /** A base rule for all binary rules. */
407 public static final class BinaryBaseRule implements RuleDefinition {
408 @Override
jcater36745912018-05-01 13:20:00 -0700409 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Ulf Adams37590dc2016-10-14 11:52:00 +0000410 return builder
411 .add(attr("args", STRING_LIST))
412 .add(attr("output_licenses", LICENSE))
413 .add(
414 attr("$is_executable", BOOLEAN)
415 .value(true)
416 .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target"))
417 .build();
418 }
419
420 @Override
421 public Metadata getMetadata() {
422 return RuleDefinition.Metadata.builder()
423 .name("$binary_base_rule")
424 .type(RuleClassType.ABSTRACT)
lberki3c1c8e92017-07-13 12:25:47 +0200425 .ancestors(RootRule.class, MakeVariableExpandingRule.class)
Ulf Adams37590dc2016-10-14 11:52:00 +0000426 .build();
427 }
428 }
429
430 /** Rule class for rules in error. */
431 public static final class ErrorRule implements RuleDefinition {
432 @Override
jcater36745912018-05-01 13:20:00 -0700433 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Ulf Adams37590dc2016-10-14 11:52:00 +0000434 return builder.publicByDefault().build();
435 }
436
437 @Override
438 public Metadata getMetadata() {
439 return RuleDefinition.Metadata.builder()
440 .name("$error_rule")
441 .type(RuleClassType.ABSTRACT)
442 .ancestors(BaseRuleClasses.BaseRule.class)
443 .build();
444 }
445 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100446}