aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2017-03-27 21:19:26 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2017-03-28 19:49:11 +0000
commitbf0b990f5c00b9fb3d60f1c54956f4a22cabc687 (patch)
treec3860429c451bcc4007827f6b3e842edda304797 /src/main/java/com
parente67b00767c9c578bf23fa77fda85a8beec0682c4 (diff)
Genrules only depend on the C++ toolchain if they have C++ make variables.
e.g.: cmd = "$(CC) foo.cc > $@" Fixes #2729 -- PiperOrigin-RevId: 151369889 MOS_MIGRATED_REVID=151369889
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java22
8 files changed, 53 insertions, 30 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
index f39b2fa768..8fedd68833 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidBinaryRule.java
@@ -27,6 +27,7 @@ import com.google.devtools.build.lib.rules.android.AndroidBinaryOnlyRule;
import com.google.devtools.build.lib.rules.android.AndroidConfiguration;
import com.google.devtools.build.lib.rules.android.AndroidRuleClasses;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
+import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
/**
@@ -45,7 +46,7 @@ public class BazelAndroidBinaryRule implements RuleDefinition {
.value(environment.getToolsLabel("//tools/android:debug_keystore")))
.add(attr(":cc_toolchain_split", BuildType.LABEL)
.cfg(AndroidRuleClasses.ANDROID_SPLIT_TRANSITION)
- .value(BazelCppRuleClasses.CC_TOOLCHAIN))
+ .value(CppRuleClasses.CC_TOOLCHAIN))
/* <!-- #BLAZE_RULE(android_binary).IMPLICIT_OUTPUTS -->
<ul>
<li><code><var>name</var>.apk</code>: An Android application
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java
index d4644ba3d5..071d5120a6 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCcIncLibraryRule.java
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder;
import com.google.devtools.build.lib.rules.cpp.CcIncLibraryRule;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
+import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
/** Rule definition for the cc_inc_library class. */
public final class BazelCcIncLibraryRule implements RuleDefinition {
@@ -31,7 +32,7 @@ public final class BazelCcIncLibraryRule implements RuleDefinition {
public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
return builder
.requiresConfigurationFragments(CppConfiguration.class)
- .add(attr(":cc_toolchain", LABEL).value(BazelCppRuleClasses.CC_TOOLCHAIN))
+ .add(attr(":cc_toolchain", LABEL).value(CppRuleClasses.CC_TOOLCHAIN))
.add(attr(":stl", LABEL).value(BazelCppRuleClasses.STL))
.build();
}
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 5889ab4c13..4374820738 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
@@ -107,28 +107,6 @@ public class BazelCppRuleClasses {
}
};
- /**
- * Label of a pseudo-filegroup that contains all crosstool and libcfiles for
- * all configurations, as specified on the command-line.
- */
- public static final String CROSSTOOL_LABEL = "//tools/defaults:crosstool";
-
- public static final LateBoundLabel<BuildConfiguration> DEFAULT_MALLOC =
- new LateBoundLabel<BuildConfiguration>() {
- @Override
- public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
- return configuration.getFragment(CppConfiguration.class).customMalloc();
- }
- };
-
- public static final LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN =
- new LateBoundLabel<BuildConfiguration>(CROSSTOOL_LABEL, CppConfiguration.class) {
- @Override
- public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
- return configuration.getFragment(CppConfiguration.class).getCcToolchainRuleLabel();
- }
- };
-
public static final LateBoundLabel<BuildConfiguration> STL =
new LateBoundLabel<BuildConfiguration>() {
@Override
@@ -194,7 +172,7 @@ public class BazelCppRuleClasses {
@SuppressWarnings("unchecked")
public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
return builder
- .add(attr(":cc_toolchain", LABEL).value(CC_TOOLCHAIN))
+ .add(attr(":cc_toolchain", LABEL).value(CppRuleClasses.CC_TOOLCHAIN))
.setPreferredDependencyPredicate(Predicates.<String>or(CPP_SOURCE, C_SOURCE, CPP_HEADER))
.build();
}
@@ -563,7 +541,7 @@ public class BazelCppRuleClasses {
.value(env.getToolsLabel("//tools/cpp:malloc"))
.allowedFileTypes()
.allowedRuleClasses("cc_library"))
- .add(attr(":default_malloc", LABEL).value(DEFAULT_MALLOC))
+ .add(attr(":default_malloc", LABEL).value(CppRuleClasses.DEFAULT_MALLOC))
/*<!-- #BLAZE_RULE($cc_binary_base).ATTRIBUTE(stamp) -->
Enable link stamping.
Whether to encode build information into the binary. Possible values:
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java
index 023634e49d..9538ea0925 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/proto/BazelCcProtoAspect.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.bazel.rules.cpp.proto;
-import static com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses.CC_TOOLCHAIN;
+import static com.google.devtools.build.lib.rules.cpp.CppRuleClasses.CC_TOOLCHAIN;
import com.google.devtools.build.lib.rules.cpp.CppSemantics;
import com.google.devtools.build.lib.rules.cpp.proto.CcProtoAspect;
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
index fafd65d6a6..ccc2c6c042 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/BazelGenRuleRule.java
@@ -20,7 +20,6 @@ import static com.google.devtools.build.lib.syntax.Type.BOOLEAN;
import com.google.devtools.build.lib.analysis.RuleDefinition;
import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.bazel.rules.cpp.BazelCppRuleClasses;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
import com.google.devtools.build.lib.rules.genrule.GenRuleBaseRule;
@@ -52,7 +51,7 @@ public final class BazelGenRuleRule implements RuleDefinition {
// TODO(bazel-team): stamping doesn't seem to work. Fix it or remove attribute.
.add(attr("stamp", BOOLEAN).value(false))
- .add(attr(":cc_toolchain", LABEL).value(BazelCppRuleClasses.CC_TOOLCHAIN))
+ .add(attr(":cc_toolchain", LABEL).value(GenRuleBaseRule.CC_TOOLCHAIN))
.add(attr(":host_jdk", LABEL).cfg(HOST).value(JavaSemantics.HOST_JDK))
.build();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
index 9ad6ba3fa1..698353a105 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
@@ -87,6 +87,28 @@ public class CppRuleClasses {
}
}
+ /**
+ * Label of a pseudo-filegroup that contains all crosstool and libcfiles for all configurations,
+ * as specified on the command-line.
+ */
+ public static final String CROSSTOOL_LABEL = "//tools/defaults:crosstool";
+
+ public static final LateBoundLabel<BuildConfiguration> DEFAULT_MALLOC =
+ new LateBoundLabel<BuildConfiguration>() {
+ @Override
+ public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
+ return configuration.getFragment(CppConfiguration.class).customMalloc();
+ }
+ };
+
+ public static final LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN =
+ new LateBoundLabel<BuildConfiguration>(CROSSTOOL_LABEL, CppConfiguration.class) {
+ @Override
+ public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
+ return configuration.getFragment(CppConfiguration.class).getCcToolchainRuleLabel();
+ }
+ };
+
// Artifacts of these types are discarded from the 'hdrs' attribute in cc rules
static final FileTypeSet DISALLOWED_HDRS_FILES = FileTypeSet.of(
ARCHIVE,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
index a81a38ff1b..8a2983ba90 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java
@@ -60,7 +60,7 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory {
private static final Pattern JDK_MAKE_VARIABLE =
Pattern.compile("\\$\\((JAVABASE|JAVA)\\)");
- protected boolean requiresCrosstool(String command) {
+ protected static boolean requiresCrosstool(String command) {
return CROSSTOOL_MAKE_VARIABLE.matcher(command).find();
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java
index 530f51b1ee..5bd7d09a7d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBaseRule.java
@@ -26,12 +26,18 @@ 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.TransitiveInfoProvider;
+import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeMap;
import com.google.devtools.build.lib.packages.BuildType;
+import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.rules.ToolchainProvider;
+import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
+import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
+import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileTypeSet;
/**
@@ -41,6 +47,22 @@ import com.google.devtools.build.lib.util.FileTypeSet;
*/
public class GenRuleBaseRule implements RuleDefinition {
+ /**
+ * Late-bound dependency on the C++ toolchain <i>iff</i> the genrule has make variables that need
+ * that toolchain.
+ */
+ public static final Attribute.LateBoundLabel<BuildConfiguration> CC_TOOLCHAIN =
+ new Attribute.LateBoundLabel<BuildConfiguration>(
+ CppRuleClasses.CROSSTOOL_LABEL, CppConfiguration.class) {
+ @Override
+ public Label resolve(Rule rule, AttributeMap attributes, BuildConfiguration configuration) {
+ return attributes != null
+ && GenRuleBase.requiresCrosstool(attributes.get("cmd", Type.STRING))
+ ? CppRuleClasses.CC_TOOLCHAIN.resolve(rule, attributes, configuration)
+ : null;
+ }
+ };
+
@Override
public RuleClass build(
RuleClass.Builder builder, RuleDefinitionEnvironment env) {