aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Stephen Twigg <twigg@google.com>2017-05-22 17:38:49 +0200
committerGravatar Irina Iancu <elenairina@google.com>2017-05-22 18:05:46 +0200
commit7e91ad631a660ae12a2b8dcfb8ba42574a7a76d3 (patch)
treea0254cb65c9531bbccc99466991be18798e10665 /src/main
parent512d56280adc6ef7639fcd4801e31fc513a26bb7 (diff)
Loosen java_library.exports and java_import.*
java_library.exports and java_import.runtime_deps|exports|deps will now accept any label from a rule that has a JavaProvider declared provider. Note that java_library.deps|runtime_deps already had this feature and this simply extends that privilege. This relies on the fact that both those targets (via JavaCommon) are simply searching for jars via JavaProvider anyway. Added test for passing a custom Skylark rule (that provides a JavaProvider) can successfully be added to the deps, runtime_deps, and exports of java_library, java_import, and java_binary (where appropriate). Added integration tests for java_library.exports|runtime_deps (the basic sandwich already tests deps) and java_import.exports|runtime_deps. Note that custom Skylark rules are still unable to provide or propagate a JavaNativeLibraryProvider, which results from a cc dependency. Also, the deps argument for java_import is somewhat odd. Change-Id: I7b2c19c6b99516ce524e8c82193d0c73e2d66530 PiperOrigin-RevId: 156740729
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) -->