diff options
author | Ulf Adams <ulfjack@google.com> | 2016-10-14 11:52:00 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2016-10-14 20:24:03 +0000 |
commit | 37590dcc7fcab7b99dd49e0c32568f9a32dd59a9 (patch) | |
tree | 4f7d20fca4813d50ea24ec0a06ab985367ad7eac /src/main/java/com/google/devtools | |
parent | 2b8a3a45b22fd544230434f3e4ffd6f15334adc8 (diff) |
Merge BazelBaseRuleClasses into BaseRuleClasses.
There doesn't seem to be any reason to keep them separate.
--
MOS_MIGRATED_REVID=136145734
Diffstat (limited to 'src/main/java/com/google/devtools')
7 files changed, 53 insertions, 94 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java index eb49821885..0d29c18bd2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/BaseRuleClasses.java @@ -29,6 +29,7 @@ import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.RunUnder; import com.google.devtools.build.lib.analysis.constraints.EnvironmentRule; @@ -44,7 +45,6 @@ import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; import com.google.devtools.build.lib.packages.TestSize; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileTypeSet; - import java.util.List; /** @@ -257,4 +257,47 @@ public class BaseRuleClasses { .build(); } } + + public static final ImmutableSet<String> ALLOWED_RULE_CLASSES = + ImmutableSet.of("filegroup", "genrule", "Fileset"); + + /** A base rule for all binary rules. */ + public static final class BinaryBaseRule implements RuleDefinition { + @Override + public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { + return builder + .add(attr("args", STRING_LIST)) + .add(attr("output_licenses", LICENSE)) + .add( + attr("$is_executable", BOOLEAN) + .value(true) + .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) + .build(); + } + + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("$binary_base_rule") + .type(RuleClassType.ABSTRACT) + .build(); + } + } + + /** Rule class for rules in error. */ + public static final class ErrorRule implements RuleDefinition { + @Override + public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { + return builder.publicByDefault().build(); + } + + @Override + public Metadata getMetadata() { + return RuleDefinition.Metadata.builder() + .name("$error_rule") + .type(RuleClassType.ABSTRACT) + .ancestors(BaseRuleClasses.BaseRule.class) + .build(); + } + } } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java deleted file mode 100644 index e0d3c7fa47..0000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelBaseRuleClasses.java +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 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.bazel.rules; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LICENSE; -import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; -import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; - -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.analysis.BaseRuleClasses; -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.packages.RuleClass.Builder; -import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType; - -/** - * The foundational rule templates to help in real rule construction. Only attributes truly common - * to all rules go in here. Attributes such as "out", "outs", "src" and "srcs" exhibit enough - * variation that we declare them explicitly for each rule. This leads to stricter error checking - * and prevents users from inadvertently using an attribute that doesn't actually do anything. - */ -public class BazelBaseRuleClasses { - public static final ImmutableSet<String> ALLOWED_RULE_CLASSES = - ImmutableSet.of("filegroup", "genrule", "Fileset"); - - /** - * A base rule for all binary rules. - */ - public static final class BinaryBaseRule implements RuleDefinition { - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .add(attr("args", STRING_LIST)) - .add(attr("output_licenses", LICENSE)) - .add(attr("$is_executable", BOOLEAN).value(true) - .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$binary_base_rule") - .type(RuleClassType.ABSTRACT) - .build(); - } - } - - /** - * Rule class for rules in error. - */ - public static final class ErrorRule implements RuleDefinition { - @Override - public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { - return builder - .publicByDefault() - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$error_rule") - .type(RuleClassType.ABSTRACT) - .ancestors(BaseRuleClasses.BaseRule.class) - .build(); - } - } -} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java index 41400143b8..84efaaa308 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRuleClassProvider.java @@ -247,9 +247,9 @@ public class BazelRuleClassProvider { builder.addRuleDefinition(new BaseRuleClasses.BaseRule()); builder.addRuleDefinition(new BaseRuleClasses.RuleBase()); - builder.addRuleDefinition(new BazelBaseRuleClasses.BinaryBaseRule()); + builder.addRuleDefinition(new BaseRuleClasses.BinaryBaseRule()); builder.addRuleDefinition(new BaseRuleClasses.TestBaseRule()); - builder.addRuleDefinition(new BazelBaseRuleClasses.ErrorRule()); + builder.addRuleDefinition(new BaseRuleClasses.ErrorRule()); builder.addRuleDefinition(new EnvironmentRule()); diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java index 425ad995d1..285ab18e7e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java @@ -42,7 +42,6 @@ import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; -import com.google.devtools.build.lib.bazel.rules.BazelBaseRuleClasses; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.Attribute.ConfigurationTransition; @@ -563,7 +562,7 @@ public class BazelCppRuleClasses { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("cc_binary") - .ancestors(CcBinaryBaseRule.class, BazelBaseRuleClasses.BinaryBaseRule.class) + .ancestors(CcBinaryBaseRule.class, BaseRuleClasses.BinaryBaseRule.class) .factoryClass(BazelCcBinary.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java index b88a5d7ea1..5cd254c6b0 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaBinaryRule.java @@ -17,9 +17,9 @@ package com.google.devtools.build.lib.bazel.rules.java; import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; +import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.bazel.rules.BazelBaseRuleClasses; import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.BaseJavaBinaryRule; import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.AttributeMap; @@ -84,7 +84,7 @@ public final class BazelJavaBinaryRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("java_binary") - .ancestors(BaseJavaBinaryRule.class, BazelBaseRuleClasses.BinaryBaseRule.class) + .ancestors(BaseJavaBinaryRule.class, BaseRuleClasses.BinaryBaseRule.class) .factoryClass(BazelJavaBinary.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBinaryRule.java index bf197929ba..3fd3ca2506 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPyBinaryRule.java @@ -18,9 +18,9 @@ import static com.google.devtools.build.lib.packages.Attribute.ConfigurationTran import static com.google.devtools.build.lib.packages.Attribute.attr; import static com.google.devtools.build.lib.packages.BuildType.LABEL; +import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.bazel.rules.BazelBaseRuleClasses; import com.google.devtools.build.lib.bazel.rules.python.BazelPyRuleClasses.PyBinaryBaseRule; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.rules.python.PythonConfiguration; @@ -47,7 +47,7 @@ public final class BazelPyBinaryRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("py_binary") - .ancestors(PyBinaryBaseRule.class, BazelBaseRuleClasses.BinaryBaseRule.class) + .ancestors(PyBinaryBaseRule.class, BaseRuleClasses.BinaryBaseRule.class) .factoryClass(BazelPyBinary.class) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShBinaryRule.java index 7f9ca97ccd..557ef2dc58 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/sh/BazelShBinaryRule.java @@ -13,9 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.bazel.rules.sh; +import com.google.devtools.build.lib.analysis.BaseRuleClasses; import com.google.devtools.build.lib.analysis.RuleDefinition; import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.bazel.rules.BazelBaseRuleClasses; import com.google.devtools.build.lib.bazel.rules.sh.BazelShRuleClasses.ShRule; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; @@ -33,7 +33,7 @@ public final class BazelShBinaryRule implements RuleDefinition { public Metadata getMetadata() { return RuleDefinition.Metadata.builder() .name("sh_binary") - .ancestors(ShRule.class, BazelBaseRuleClasses.BinaryBaseRule.class) + .ancestors(ShRule.class, BaseRuleClasses.BinaryBaseRule.class) .factoryClass(ShBinary.class) .build(); } |