Skip to content

Commit

Permalink
Prepare Blaze tests to use the Java 11 language level
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 343920254
  • Loading branch information
cushon authored and copybara-github committed Nov 23, 2020
1 parent 8b8c615 commit bb1e635
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.Type;
import com.google.devtools.build.lib.rules.java.BootClassPathInfo;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;

/** Implementation of the {@code android_sdk} rule. */
Expand Down Expand Up @@ -71,6 +72,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
Artifact sourceProperties = ruleContext.getHostPrerequisiteArtifact("source_properties");
Artifact shrinkedAndroidJar = ruleContext.getPrerequisiteArtifact("shrinked_android_jar");
Artifact mainDexClasses = ruleContext.getPrerequisiteArtifact("main_dex_classes");
BootClassPathInfo system = ruleContext.getPrerequisite("system", BootClassPathInfo.PROVIDER);

if (ruleContext.hasErrors()) {
return null;
Expand All @@ -95,7 +97,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
apkSigner,
proguard,
zipalign,
/* system= */ null);
system);

return new RuleConfiguredTargetBuilder(ruleContext)
.addNativeDeclaredProvider(sdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClass.Builder.RuleClassType;
import com.google.devtools.build.lib.packages.StarlarkProviderIdentifier;
import com.google.devtools.build.lib.rules.java.BootClassPathInfo;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaRuleClasses.JavaToolchainBaseRule;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
Expand Down Expand Up @@ -133,6 +134,10 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
.cfg(ExecutionTransitionFactory.create())
.allowedFileTypes(ANY_FILE)
.exec())
.add(
attr("system", LABEL)
.allowedFileTypes()
.mandatoryProviders(BootClassPathInfo.PROVIDER.id()))
.advertiseStarlarkProvider(
StarlarkProviderIdentifier.forKey(AndroidSdkProvider.PROVIDER.getKey()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,6 @@ public Label getJavaToolchainLabel(JavaToolchainStarlarkApiProviderApi toolchain

@Override
public ProviderApi getBootClassPathInfo() {
// No implementation in Bazel. This method not callable in Starlark except through
// (discouraged) use of --experimental_google_legacy_api.
return null;
return BootClassPathInfo.PROVIDER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,6 @@ JavaInfoT addCompileTimeJavaDependencyArtifacts(
@StarlarkMethod(
name = "BootClassPathInfo",
doc = "The provider used to supply bootclasspath information",
structField = true,
enableOnlyWithFlag = BuildLanguageOptions.EXPERIMENTAL_GOOGLE_LEGACY_API)
structField = true)
ProviderApi getBootClassPathInfo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import static com.google.common.base.Verify.verifyNotNull;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.prettyArtifactNames;
import static com.google.devtools.build.lib.rules.java.JavaCompileActionTestHelper.getClasspath;
import static com.google.devtools.build.lib.rules.java.JavaCompileActionTestHelper.getCompileTimeDependencyArtifacts;
Expand Down Expand Up @@ -628,7 +629,9 @@ public void testExportsWithStrictJavaDepsFlag() throws Exception {
JavaCompileAction javacAction =
(JavaCompileAction) getGeneratingActionForLabel("//java/exports:libc.jar");

assertThat(prettyArtifactNames(getInputs(javacAction, getDirectJars(javacAction))))
assertThat(
prettyArtifactNames(getInputs(javacAction, getDirectJars(javacAction))).stream()
.filter(a -> !a.equals("tools/android/bootclasspath_android_only_auxiliary.jar")))
.containsExactly("java/exports/libb-hjar.jar", "java/exports/liba-hjar.jar");
assertNoEvents();
}