blob: d75f64a56641407f6cbb36ae4fdbdbb3a42a3903 [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(
Laszlo Csomor9a933772018-08-14 08:29:29 -0700169 attr("$test_wrapper", LABEL)
170 .cfg(HostTransition.INSTANCE)
171 .singleArtifact()
172 .value(env.getToolsLabel("//tools/test:test_wrapper")))
173 .add(
tomlua08bb892017-08-03 03:23:48 +0200174 attr("$test_runtime", LABEL_LIST)
gregce676a9572017-12-21 11:33:32 -0800175 .cfg(HostTransition.INSTANCE)
tomlua08bb892017-08-03 03:23:48 +0200176 .value(ImmutableList.of(env.getToolsLabel("//tools/test:runtime"))))
hlopko8820d3a2018-06-15 09:10:05 -0700177 .add(
178 attr("$test_setup_script", LABEL)
179 .cfg(HostTransition.INSTANCE)
180 .singleArtifact()
181 .value(env.getToolsLabel("//tools/test:test_setup")))
182 .add(
ulfjack0858ae12018-07-27 02:37:53 -0700183 attr("$xml_generator_script", LABEL)
184 .cfg(HostTransition.INSTANCE)
185 .singleArtifact()
186 .value(env.getToolsLabel("//tools/test:test_xml_generator")))
187 .add(
hlopko8820d3a2018-06-15 09:10:05 -0700188 attr("$collect_coverage_script", LABEL)
189 .cfg(HostTransition.INSTANCE)
190 .singleArtifact()
191 .value(env.getToolsLabel("//tools/test:collect_coverage")))
Lukacs Berki8f460f32016-06-29 09:14:10 +0000192 // Input files for test actions collecting code coverage
tomlua08bb892017-08-03 03:23:48 +0200193 .add(
dbabkin708b9572018-06-07 02:31:16 -0700194 attr(":coverage_support", LABEL)
195 .value(
196 coverageSupportAttribute(env.getToolsLabel(DEFAULT_COVERAGE_SUPPORT_VALUE))))
Lukacs Berki8f460f32016-06-29 09:14:10 +0000197 // Used in the one-per-build coverage report generation action.
tomlua08bb892017-08-03 03:23:48 +0200198 .add(
dbabkin2df32342018-06-07 05:19:54 -0700199 attr(":coverage_report_generator", LABEL)
gregce676a9572017-12-21 11:33:32 -0800200 .cfg(HostTransition.INSTANCE)
dbabkin2df32342018-06-07 05:19:54 -0700201 .value(
202 coverageReportGeneratorAttribute(
elenairina9438d102018-07-06 03:06:21 -0700203 env.getToolsLabel(DEFAULT_COVERAGE_REPORT_GENERATOR_VALUE))))
hlopko8820d3a2018-06-15 09:10:05 -0700204 // The target itself and run_under both run on the same machine.
205 .add(attr(":run_under", LABEL).value(RUN_UNDER).skipPrereqValidatorCheck())
jcaterd7ce6262018-06-13 10:17:30 -0700206 .executionPlatformConstraintsAllowed(ExecutionPlatformConstraintsAllowed.PER_TARGET)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100207 .build();
208 }
Googler58505032015-03-19 16:12:34 +0000209
210 @Override
211 public Metadata getMetadata() {
212 return RuleDefinition.Metadata.builder()
213 .name("$test_base_rule")
214 .type(RuleClassType.ABSTRACT)
lberki3c1c8e92017-07-13 12:25:47 +0200215 .ancestors(RootRule.class, MakeVariableExpandingRule.class)
Googler58505032015-03-19 16:12:34 +0000216 .build();
217 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100218 }
219
220 /**
mstaib188b5782018-05-16 10:13:51 -0700221 * The attribute used to list the configuration properties used by a target and its transitive
222 * dependencies. Currently only supports config_feature_flag.
223 */
224 public static final String TAGGED_TRIMMING_ATTR = "transitive_configs";
225
226 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100227 * Share common attributes across both base and Skylark base rules.
228 */
229 public static RuleClass.Builder commonCoreAndSkylarkAttributes(RuleClass.Builder builder) {
cpeyserd852e482017-09-07 22:16:06 +0200230 return PlatformSemantics.platformAttributes(builder)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100231 // The visibility attribute is special: it is a nodep label, and loading the
232 // necessary package groups is handled by {@link LabelVisitor#visitTargetVisibility}.
233 // Package groups always have the null configuration so that they are not duplicated
234 // needlessly.
cpeyserd852e482017-09-07 22:16:06 +0200235 .add(
236 attr("visibility", NODEP_LABEL_LIST)
237 .orderIndependent()
gregce676a9572017-12-21 11:33:32 -0800238 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200239 .nonconfigurable(
240 "special attribute integrated more deeply into Bazel's core logic"))
241 .add(
mstaib188b5782018-05-16 10:13:51 -0700242 attr(TAGGED_TRIMMING_ATTR, NODEP_LABEL_LIST)
243 .orderIndependent()
244 .nonconfigurable("Used in determining configuration"))
245 .add(
cpeyserd852e482017-09-07 22:16:06 +0200246 attr("deprecation", STRING)
247 .value(deprecationDefault)
248 .nonconfigurable("Used in core loading phase logic with no access to configs"))
249 .add(
250 attr("tags", STRING_LIST)
251 .orderIndependent()
252 .taggable()
253 .nonconfigurable("low-level attribute, used in TargetUtils without configurations"))
254 .add(
255 attr("generator_name", STRING)
256 .undocumented("internal")
257 .nonconfigurable("static structure of a rule"))
258 .add(
259 attr("generator_function", STRING)
260 .undocumented("internal")
261 .nonconfigurable("static structure of a rule"))
262 .add(
263 attr("generator_location", STRING)
264 .undocumented("internal")
265 .nonconfigurable("static structure of a rule"))
266 .add(
267 attr("testonly", BOOLEAN)
268 .value(testonlyDefault)
269 .nonconfigurable("policy decision: rules testability should be consistent"))
Manuel Klimek6d9fb362015-04-30 12:50:55 +0000270 .add(attr("features", STRING_LIST).orderIndependent())
gregce676a9572017-12-21 11:33:32 -0800271 .add(attr(":action_listener", LABEL_LIST)
272 .cfg(HostTransition.INSTANCE)
273 .value(ACTION_LISTENER))
cpeyserd852e482017-09-07 22:16:06 +0200274 .add(
275 attr(RuleClass.COMPATIBLE_ENVIRONMENT_ATTR, LABEL_LIST)
276 .allowedRuleClasses(EnvironmentRule.RULE_NAME)
gregce676a9572017-12-21 11:33:32 -0800277 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200278 .allowedFileTypes(FileTypeSet.NO_FILE)
279 .dontCheckConstraints()
280 .nonconfigurable(
281 "special logic for constraints and select: see ConstraintSemantics"))
282 .add(
283 attr(RuleClass.RESTRICTED_ENVIRONMENT_ATTR, LABEL_LIST)
284 .allowedRuleClasses(EnvironmentRule.RULE_NAME)
gregce676a9572017-12-21 11:33:32 -0800285 .cfg(HostTransition.INSTANCE)
cpeyserd852e482017-09-07 22:16:06 +0200286 .allowedFileTypes(FileTypeSet.NO_FILE)
287 .dontCheckConstraints()
288 .nonconfigurable(
289 "special logic for constraints and select: see ConstraintSemantics"));
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100290 }
291
Googler015e5952017-02-14 09:45:30 +0000292 public static RuleClass.Builder nameAttribute(RuleClass.Builder builder) {
293 return builder.add(attr("name", STRING).nonconfigurable("Rule name"));
294 }
295
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100296 /**
Googler015e5952017-02-14 09:45:30 +0000297 * Ancestor of every rule.
298 *
299 * <p>Adds the name attribute to every rule.
300 */
301 public static final class RootRule implements RuleDefinition {
302
303 @Override
jcater36745912018-05-01 13:20:00 -0700304 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) {
Googler015e5952017-02-14 09:45:30 +0000305 return nameAttribute(builder).build();
306 }
307
308 @Override
309 public Metadata getMetadata() {
310 return RuleDefinition.Metadata.builder()
311 .name("$root_rule")
312 .type(RuleClassType.ABSTRACT)
313 .build();
314 }
315 }
316
317 /**
318 * Common parts of some rules.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100319 */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100320 public static final class BaseRule implements RuleDefinition {
321 @Override
322 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
323 return commonCoreAndSkylarkAttributes(builder)
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100324 // Aggregates the labels of all {@link ConfigRuleClasses} rules this rule uses (e.g.
325 // keys for configurable attributes). This is specially populated in
326 // {@RuleClass#populateRuleAttributeValues}.
327 //
328 // This attribute is not needed for actual builds. Its main purpose is so query's
329 // proto/XML output includes the labels of config dependencies, so, e.g., depserver
330 // reverse dependency lookups remain accurate. These can't just be added to the
331 // attribute definitions proto/XML queries already output because not all attributes
332 // contain labels.
333 //
334 // Builds and Blaze-interactive queries don't need this because they find dependencies
335 // through direct Rule label visitation, which already factors these in.
336 .add(attr("$config_dependencies", LABEL_LIST)
337 .nonconfigurable("not intended for actual builds"))
338 .add(attr("licenses", LICENSE)
339 .nonconfigurable("Used in core loading phase logic with no access to configs"))
340 .add(attr("distribs", DISTRIBUTIONS)
341 .nonconfigurable("Used in core loading phase logic with no access to configs"))
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100342 .build();
343 }
Googler58505032015-03-19 16:12:34 +0000344
345 @Override
346 public Metadata getMetadata() {
347 return RuleDefinition.Metadata.builder()
348 .name("$base_rule")
349 .type(RuleClassType.ABSTRACT)
Googler015e5952017-02-14 09:45:30 +0000350 .ancestors(RootRule.class)
Googler58505032015-03-19 16:12:34 +0000351 .build();
352 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100353 }
354
355 /**
lberki3c1c8e92017-07-13 12:25:47 +0200356 * A rule that contains a {@code variables=} attribute to allow referencing Make variables.
357 */
358 public static final class MakeVariableExpandingRule implements RuleDefinition {
359 @Override
jcater36745912018-05-01 13:20:00 -0700360 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
lberki3c1c8e92017-07-13 12:25:47 +0200361 return builder
362 /* <!-- #BLAZE_RULE($make_variable_expanding_rule).ATTRIBUTE(toolchains) -->
363 The set of toolchains that supply <a href="${link make-variables}">"Make variables"</a>
364 that this target can use in some of its attributes. Some rules have toolchains whose Make
365 variables they can use by default.
366 <!-- #END_BLAZE_RULE.ATTRIBUTE --> */
367 .add(attr("toolchains", LABEL_LIST)
368 .allowedFileTypes(FileTypeSet.NO_FILE)
jcater191238f2018-06-19 10:17:16 -0700369 .mandatoryProviders(ImmutableList.of(TemplateVariableInfo.PROVIDER.id()))
370 .dontCheckConstraints())
lberki3c1c8e92017-07-13 12:25:47 +0200371 .build();
372 }
373
374 @Override
375 public Metadata getMetadata() {
376 return RuleDefinition.Metadata.builder()
377 .name("$make_variable_expanding_rule")
378 .type(RuleClassType.ABSTRACT)
379 .build();
380 }
381 }
382
383 /**
Googler015e5952017-02-14 09:45:30 +0000384 * Common ancestor class for some rules.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100385 */
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100386 public static final class RuleBase implements RuleDefinition {
387 @Override
jcater36745912018-05-01 13:20:00 -0700388 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100389 return builder
390 .add(attr("deps", LABEL_LIST).legacyAllowAnyFileType())
hlopko8820d3a2018-06-15 09:10:05 -0700391 .add(
392 attr("data", LABEL_LIST)
393 .allowedFileTypes(FileTypeSet.ANY_FILE)
394 .dontCheckConstraints())
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100395 .build();
396 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100397
Googler58505032015-03-19 16:12:34 +0000398 @Override
399 public Metadata getMetadata() {
400 return RuleDefinition.Metadata.builder()
401 .name("$rule")
402 .type(RuleClassType.ABSTRACT)
403 .ancestors(BaseRule.class)
404 .build();
405 }
406 }
Ulf Adams37590dc2016-10-14 11:52:00 +0000407
408 public static final ImmutableSet<String> ALLOWED_RULE_CLASSES =
409 ImmutableSet.of("filegroup", "genrule", "Fileset");
410
411 /** A base rule for all binary rules. */
412 public static final class BinaryBaseRule implements RuleDefinition {
413 @Override
jcater36745912018-05-01 13:20:00 -0700414 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Ulf Adams37590dc2016-10-14 11:52:00 +0000415 return builder
416 .add(attr("args", STRING_LIST))
417 .add(attr("output_licenses", LICENSE))
418 .add(
419 attr("$is_executable", BOOLEAN)
420 .value(true)
421 .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target"))
422 .build();
423 }
424
425 @Override
426 public Metadata getMetadata() {
427 return RuleDefinition.Metadata.builder()
428 .name("$binary_base_rule")
429 .type(RuleClassType.ABSTRACT)
lberki3c1c8e92017-07-13 12:25:47 +0200430 .ancestors(RootRule.class, MakeVariableExpandingRule.class)
Ulf Adams37590dc2016-10-14 11:52:00 +0000431 .build();
432 }
433 }
434
435 /** Rule class for rules in error. */
436 public static final class ErrorRule implements RuleDefinition {
437 @Override
jcater36745912018-05-01 13:20:00 -0700438 public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) {
Ulf Adams37590dc2016-10-14 11:52:00 +0000439 return builder.publicByDefault().build();
440 }
441
442 @Override
443 public Metadata getMetadata() {
444 return RuleDefinition.Metadata.builder()
445 .name("$error_rule")
446 .type(RuleClassType.ABSTRACT)
447 .ancestors(BaseRuleClasses.BaseRule.class)
448 .build();
449 }
450 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100451}