aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java30
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java34
3 files changed, 42 insertions, 26 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
index 377db909e1..281605fd48 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaImportRule.java
@@ -44,26 +44,32 @@ public final class BazelJavaImportRule implements RuleDefinition {
The list of other libraries to be linked in to the target.
See <a href="${link java_library.deps}">java_library.deps</a>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("deps", LABEL_LIST)
- .allowedRuleClasses(ALLOWED_DEPS)
- .allowedFileTypes() // none allowed
- .validityPredicate(ANY_EDGE))
+ .add(
+ attr("deps", LABEL_LIST)
+ .allowedRuleClasses(ALLOWED_DEPS)
+ .allowedFileTypes() // none allowed
+ .validityPredicate(ANY_EDGE)
+ .mandatoryProvidersList(BazelJavaRuleClasses.MANDATORY_JAVA_PROVIDER_ONLY))
/* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(exports) -->
Targets to make available to users of this rule.
See <a href="${link java_library.exports}">java_library.exports</a>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("exports", LABEL_LIST)
- .allowedRuleClasses(ALLOWED_DEPS)
- .allowedFileTypes() // none allowed
- .validityPredicate(ANY_EDGE))
+ .add(
+ attr("exports", LABEL_LIST)
+ .allowedRuleClasses(ALLOWED_DEPS)
+ .allowedFileTypes() // none allowed
+ .validityPredicate(ANY_EDGE)
+ .mandatoryProvidersList(BazelJavaRuleClasses.MANDATORY_JAVA_PROVIDER_ONLY))
/* <!-- #BLAZE_RULE(java_import).ATTRIBUTE(runtime_deps) -->
Libraries to make available to the final binary or test at runtime only.
See <a href="${link java_library.runtime_deps}">java_library.runtime_deps</a>.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr("runtime_deps", LABEL_LIST)
- .allowedFileTypes(JavaSemantics.JAR)
- .allowedRuleClasses(ALLOWED_DEPS)
- .skipAnalysisTimeFileTypeCheck())
+ .add(
+ attr("runtime_deps", LABEL_LIST)
+ .allowedFileTypes(JavaSemantics.JAR)
+ .allowedRuleClasses(ALLOWED_DEPS)
+ .mandatoryProvidersList(BazelJavaRuleClasses.MANDATORY_JAVA_PROVIDER_ONLY)
+ .skipAnalysisTimeFileTypeCheck())
.advertiseProvider(JavaSourceInfoProvider.class)
.build();
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
index 6f1e81016c..4039821c19 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java
@@ -115,8 +115,8 @@ public final class BazelJavaLibraryRule implements RuleDefinition {
.add(
attr("exports", LABEL_LIST)
.allowedRuleClasses(BazelJavaRuleClasses.ALLOWED_RULES_IN_DEPS)
- .allowedFileTypes(/*May not have files in exports!*/ ))
-
+ .allowedFileTypes(/*May not have files in exports!*/ )
+ .mandatoryProvidersList(BazelJavaRuleClasses.MANDATORY_JAVA_PROVIDER_ONLY))
/* <!-- #BLAZE_RULE(java_library).ATTRIBUTE(neverlink) -->
Whether this library should only be used for compilation and not at runtime.
Useful if the library will be provided by the runtime environment during execution. Examples
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
index 363f6ae20a..e8f200474a 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaRuleClasses.java
@@ -75,6 +75,26 @@ public class BazelJavaRuleClasses {
JavaSemantics.JAVA_LIBRARY_SOURCE_JAR);
/**
+ * Meant to be an element of {@code mandatoryProvidersLists} in order to accept rules providing
+ * a {@link JavaProvider} through an attribute. Other providers can be included in
+ * {@code mandatoryProvidersLists} as well.
+ */
+ public static final ImmutableList<SkylarkProviderIdentifier> CONTAINS_JAVA_PROVIDER =
+ ImmutableList.of(SkylarkProviderIdentifier.forKey(JavaProvider.JAVA_PROVIDER.getKey()));
+
+ public static final ImmutableList<SkylarkProviderIdentifier> CONTAINS_CC_LINK_PARAMS =
+ ImmutableList.of(
+ SkylarkProviderIdentifier.forKey(CcLinkParamsProvider.CC_LINK_PARAMS.getKey()));
+
+ /**
+ * Meant to be the value of {@code mandatoryProvidersLists} in order for the rule to provide only
+ * a {@link JavaProvider} through an attribute.
+ */
+ public static final ImmutableList<ImmutableList<SkylarkProviderIdentifier>>
+ MANDATORY_JAVA_PROVIDER_ONLY = ImmutableList.of(CONTAINS_JAVA_PROVIDER);
+
+
+ /**
* Common attributes for rules that depend on ijar.
*/
public static final class IjarBaseRule implements RuleDefinition {
@@ -158,13 +178,7 @@ public class BazelJavaRuleClasses {
.allowedFileTypes(JavaSemantics.JAR)
.allowedRuleClasses(ALLOWED_RULES_IN_DEPS)
.mandatoryProvidersList(
- ImmutableList.of(
- ImmutableList.of(
- SkylarkProviderIdentifier.forKey(
- CcLinkParamsProvider.CC_LINK_PARAMS.getKey())),
- ImmutableList.of(
- SkylarkProviderIdentifier.forKey(
- JavaProvider.JAVA_PROVIDER.getKey()))))
+ ImmutableList.of(CONTAINS_CC_LINK_PARAMS, CONTAINS_JAVA_PROVIDER))
.skipAnalysisTimeFileTypeCheck())
/* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(runtime_deps) -->
Libraries to make available to the final binary or test at runtime only.
@@ -177,11 +191,7 @@ public class BazelJavaRuleClasses {
attr("runtime_deps", LABEL_LIST)
.allowedFileTypes(JavaSemantics.JAR)
.allowedRuleClasses(ALLOWED_RULES_IN_DEPS)
- .mandatoryProvidersList(
- ImmutableList.of(
- ImmutableList.of(
- SkylarkProviderIdentifier.forKey(
- JavaProvider.JAVA_PROVIDER.getKey()))))
+ .mandatoryProvidersList(MANDATORY_JAVA_PROVIDER_ONLY)
.skipAnalysisTimeFileTypeCheck())
/* <!-- #BLAZE_RULE($java_rule).ATTRIBUTE(srcs) -->