From 947c72d699321c97518dbebe0e8ca59621b5da21 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 14 May 2024 09:12:15 -0700 Subject: [PATCH] Remove native aar_import from Bazel. RELNOTES: The native aar_import is no longer provided in Bazel. See github.com/bazelbuild/rules_android. PiperOrigin-RevId: 633606042 Change-Id: I8b3f11b909a6157d0c163645671c931a0936f873 --- .../bazel/rules/BazelRuleClassProvider.java | 4 - .../bazel/rules/android/BazelAarImport.java | 25 - .../rules/android/BazelAarImportRule.java | 69 -- .../build/lib/rules/android/AarImport.java | 562 ---------------- .../lib/rules/android/AarImportBaseRule.java | 119 ---- .../android/AndroidSdkRepositoryTest.java | 23 - .../build/lib/bazel/rules/android/BUILD | 3 - .../rules/android/SdkMavenRepositoryTest.java | 146 ----- .../lib/rules/android/AarImportTest.java | 620 ------------------ .../devtools/build/lib/rules/android/BUILD | 22 - src/test/shell/bazel/android/BUILD | 18 - .../bazel/android/aar_integration_test.sh | 187 ------ .../shell/bazel/android/android_helper.sh | 10 +- .../bazel/android/android_integration_test.sh | 15 - .../resource_processing_integration_test.sh | 9 +- src/test/shell/bazel/android/sample.aar | Bin 12475 -> 0 bytes 16 files changed, 5 insertions(+), 1827 deletions(-) delete mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java delete mode 100644 src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java delete mode 100644 src/main/java/com/google/devtools/build/lib/rules/android/AarImportBaseRule.java delete mode 100644 src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java delete mode 100644 src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java delete mode 100755 src/test/shell/bazel/android/aar_integration_test.sh delete mode 100644 src/test/shell/bazel/android/sample.aar 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 afddf662f925da..e911610732a34f 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 @@ -39,7 +39,6 @@ import com.google.devtools.build.lib.bazel.repository.LocalConfigPlatformRule; import com.google.devtools.build.lib.bazel.rules.android.AndroidNdkRepositoryRule; import com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryRule; -import com.google.devtools.build.lib.bazel.rules.android.BazelAarImportRule; import com.google.devtools.build.lib.bazel.rules.android.BazelAndroidBinaryRule; import com.google.devtools.build.lib.bazel.rules.android.BazelAndroidDeviceScriptFixture; import com.google.devtools.build.lib.bazel.rules.android.BazelAndroidHostServiceFixture; @@ -57,7 +56,6 @@ import com.google.devtools.build.lib.bazel.rules.python.BazelPythonConfiguration; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.PackageCallable; -import com.google.devtools.build.lib.rules.android.AarImportBaseRule; import com.google.devtools.build.lib.rules.android.AndroidApplicationResourceInfo; import com.google.devtools.build.lib.rules.android.AndroidAssetsInfo; import com.google.devtools.build.lib.rules.android.AndroidBinaryDataInfo; @@ -360,8 +358,6 @@ public void init(ConfiguredRuleClassProvider.Builder builder) { builder.addRuleDefinition(new AndroidLibraryBaseRule(androidNeverlinkAspect)); builder.addRuleDefinition(new BazelAndroidLibraryRule()); builder.addRuleDefinition(new BazelAndroidBinaryRule()); - builder.addRuleDefinition(new AarImportBaseRule()); - builder.addRuleDefinition(new BazelAarImportRule()); builder.addRuleDefinition(new AndroidLocalTestBaseRule()); builder.addRuleDefinition(new BazelAndroidLocalTestRule()); builder.addRuleDefinition( diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java deleted file mode 100644 index c5e1c99cf98e42..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImport.java +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 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.android; - -import com.google.devtools.build.lib.bazel.rules.java.BazelJavaSemantics; -import com.google.devtools.build.lib.rules.android.AarImport; - -/** Implementation of {@code aar_import} with Bazel semantics. */ -public class BazelAarImport extends AarImport { - public BazelAarImport() { - super(BazelJavaSemantics.INSTANCE, BazelAndroidSemantics.INSTANCE); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java deleted file mode 100644 index a08bbd38c4dd3a..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAarImportRule.java +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2016 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.android; - -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.bazel.rules.java.BazelJavaRuleClasses.JavaBaseRule; -import com.google.devtools.build.lib.packages.RuleClass; -import com.google.devtools.build.lib.rules.android.AarImportBaseRule; - -/** - * Rule definition for the {@code aar_import} rule. - */ -public final class BazelAarImportRule implements RuleDefinition { - - @Override - public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment environment) { - return builder - .removeAttribute("javacopts") - .removeAttribute("plugins") - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("aar_import") - .ancestors(AarImportBaseRule.class, JavaBaseRule.class, BazelSdkToolchainRule.class) - .factoryClass(BazelAarImport.class) - .build(); - } -} - -/* - -

- This rule allows the use of .aar files as libraries for - android_library and - android_binary rules. -

- -

Examples

- -
-    aar_import(
-        name = "google-vr-sdk",
-        aar = "gvr-android-sdk/libraries/sdk-common-1.10.0.aar",
-    )
-
-    android_binary(
-        name = "app",
-        manifest = "AndroidManifest.xml",
-        srcs = glob(["**.java"]),
-        deps = [":google-vr-sdk"],
-    )
-
- -*/ diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java b/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java deleted file mode 100644 index 6c5f7aca9f38ca..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AarImport.java +++ /dev/null @@ -1,562 +0,0 @@ -// Copyright 2016 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.rules.android; - - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.actions.ActionConflictException; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; -import com.google.devtools.build.lib.actions.ExecutionRequirements; -import com.google.devtools.build.lib.actions.ParamFileInfo; -import com.google.devtools.build.lib.actions.ParameterFile; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.FileProvider; -import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.OutputGroupInfo; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; -import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; -import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; -import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.analysis.platform.ConstraintValueInfo; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; -import com.google.devtools.build.lib.rules.android.databinding.DataBinding; -import com.google.devtools.build.lib.rules.android.databinding.DataBindingV2Provider; -import com.google.devtools.build.lib.rules.java.ImportDepsCheckActionBuilder; -import com.google.devtools.build.lib.rules.java.JavaCommon; -import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider; -import com.google.devtools.build.lib.rules.java.JavaCompilationArtifacts; -import com.google.devtools.build.lib.rules.java.JavaConfiguration; -import com.google.devtools.build.lib.rules.java.JavaConfiguration.ImportDepsCheckingLevel; -import com.google.devtools.build.lib.rules.java.JavaInfo; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput; -import com.google.devtools.build.lib.rules.java.JavaSemantics; -import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider; -import com.google.devtools.build.lib.rules.java.JavaToolchainProvider; -import com.google.devtools.build.lib.rules.java.ProguardLibrary; -import com.google.devtools.build.lib.rules.java.ProguardSpecProvider; -import com.google.devtools.build.lib.starlarkbuildapi.android.DataBindingV2ProviderApi; -import com.google.devtools.build.lib.vfs.PathFragment; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; - -/** - * An implementation for the aar_import rule. - * - *

AAR files are zip archives that contain an Android Manifest, JARs, resources, assets, native - * libraries, Proguard configuration and lint jars. Currently the aar_import rule supports AARs with - * an AndroidManifest.xml, classes.jar, libs/, res/ and jni/. Assets are not yet supported. - * - * @see AAR Format - */ -public class AarImport implements RuleConfiguredTargetFactory { - private static final String ANDROID_MANIFEST = "AndroidManifest.xml"; - private static final String MERGED_JAR = "classes_and_libs_merged.jar"; - private static final String PROGUARD_SPEC = "proguard.txt"; - - private static final ParamFileInfo WORKERS_FORCED_PARAM_FILE_INFO = - ParamFileInfo.builder(ParameterFile.ParameterFileType.UNQUOTED).setUseAlways(true).build(); - - private final JavaSemantics javaSemantics; - private final AndroidSemantics androidSemantics; - - protected AarImport(JavaSemantics javaSemantics, AndroidSemantics androidSemantics) { - this.javaSemantics = javaSemantics; - this.androidSemantics = androidSemantics; - } - - @Override - @Nullable - public ConfiguredTarget create(RuleContext ruleContext) - throws InterruptedException, RuleErrorException, ActionConflictException { - androidSemantics.checkForMigrationTag(ruleContext); - AndroidSdkProvider.verifyPresence(ruleContext); - - RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext); - Artifact aar = ruleContext.getPrerequisiteArtifact("aar"); - - Artifact allAarJars = createAarTreeArtifact(ruleContext, "jars"); - Artifact jarMergingParams = createAarArtifact(ruleContext, "jar_merging_params"); - ruleContext.registerAction( - createAarEmbeddedJarsExtractorActions(ruleContext, aar, allAarJars, jarMergingParams)); - Artifact mergedJar = createAarArtifact(ruleContext, MERGED_JAR); - ruleContext.registerAction( - createAarJarsMergingActions(ruleContext, allAarJars, mergedJar, jarMergingParams)); - - // AndroidManifest.xml is required in every AAR. - Artifact androidManifestArtifact = createAarArtifact(ruleContext, ANDROID_MANIFEST); - - SpecialArtifact resources = createAarTreeArtifact(ruleContext, "resources"); - SpecialArtifact assets = createAarTreeArtifact(ruleContext, "assets"); - SpecialArtifact databindingBrFiles = createAarTreeArtifact(ruleContext, "data-binding-br"); - SpecialArtifact databindingSetterStoreFiles = - createAarTreeArtifact(ruleContext, "data-binding-setter_store"); - ruleContext.registerAction( - createAarResourcesExtractorActions( - ruleContext, aar, resources, assets, databindingBrFiles, databindingSetterStoreFiles)); - - AndroidDataContext dataContext = androidSemantics.makeContextForNative(ruleContext); - StampedAndroidManifest manifest = AndroidManifest.forAarImport(androidManifestArtifact); - - boolean neverlink = JavaCommon.isNeverLink(ruleContext); - - ValidatedAndroidResources validatedResources = - AndroidResources.forAarImport(resources) - .process( - ruleContext, - dataContext, - manifest, - DataBinding.contextFrom(ruleContext, dataContext.getAndroidConfig()), - neverlink); - - MergedAndroidAssets mergedAssets = - AndroidAssets.forAarImport(assets) - .process(dataContext, AssetDependencies.fromRuleDeps(ruleContext, neverlink)); - - ResourceApk resourceApk = ResourceApk.of(validatedResources, mergedAssets, null, null); - - // There isn't really any use case for building an aar_import target on its own, so the files to - // build could be empty. The R class JAR and merged JARs are added here as a check for Bazel - // developers so that `bazel build java/com/my_aar_import` will fail if the resource processing - // or JAR merging steps fail. - NestedSet filesToBuild = - NestedSetBuilder.stableOrder() - .add(resourceApk.getValidatedResources().getJavaClassJar()) - .add(mergedJar) - .build(); - - Artifact nativeLibs = createAarArtifact(ruleContext, "native_libs.zip"); - ruleContext.registerAction(createAarNativeLibsFilterActions(ruleContext, aar, nativeLibs)); - - JavaRuleOutputJarsProvider.Builder jarProviderBuilder = - new JavaRuleOutputJarsProvider.Builder() - .addJavaOutput(JavaOutput.builder().setClassJar(mergedJar).build()); - - ImmutableList targets = - ImmutableList.builder() - .addAll(ruleContext.getPrerequisites("exports")) - .addAll(ruleContext.getPrerequisites("deps")) - .build(); - JavaCommon common = - new JavaCommon( - ruleContext, - javaSemantics, - /* sources = */ ImmutableList.of(), - /* compileDeps = */ targets, - /* runtimeDeps = */ targets, - /* bothDeps = */ targets); - androidSemantics.checkRule(ruleContext, common); - - JavaConfiguration javaConfig = ruleContext.getFragment(JavaConfiguration.class); - JavaCompilationArtifacts.Builder javaCompilationArtifactsBuilder = - new JavaCompilationArtifacts.Builder(); - - javaCompilationArtifactsBuilder - .addRuntimeJar(mergedJar) - .addCompileTimeJarAsFullJar(mergedJar) - // Allow direct dependents to compile against un-merged R classes - .addCompileTimeJarAsFullJar( - ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_CLASS_JAR)); - - Artifact jdepsArtifact = null; - // Don't register import deps checking actions if the level is off. Since it's off, the - // check isn't useful anyway, so don't waste resources running it. - if (javaConfig.getImportDepsCheckingLevel() != ImportDepsCheckingLevel.OFF) { - jdepsArtifact = createAarArtifact(ruleContext, "jdeps.proto"); - javaCompilationArtifactsBuilder.setCompileTimeDependencies(jdepsArtifact); - ImportDepsCheckActionBuilder.newBuilder() - .bootclasspath(getBootclasspath(ruleContext)) - .declareDeps(getCompileTimeJarsFromCollection(targets, /*isDirect=*/ true)) - .transitiveDeps(getCompileTimeJarsFromCollection(targets, /*isDirect=*/ false)) - .checkJars(NestedSetBuilder.stableOrder().add(mergedJar).build()) - .importDepsCheckingLevel(javaConfig.getImportDepsCheckingLevel()) - .jdepsOutputArtifact(jdepsArtifact) - .ruleLabel(ruleContext.getLabel()) - .buildAndRegister(ruleContext); - } - - common.setJavaCompilationArtifacts(javaCompilationArtifactsBuilder.build()); - - // We pass jdepsArtifact to create the action of extracting ANDROID_MANIFEST. Note that - // this action does not need jdepsArtifact. The only reason is that we need to check the - // dependencies of this aar_import, and we need to put its result on the build graph so that the - // dependency checking action is called. - ruleContext.registerAction( - createSingleFileExtractorActions( - ruleContext, aar, ANDROID_MANIFEST, jdepsArtifact, androidManifestArtifact)); - - JavaCompilationArgsProvider javaCompilationArgsProvider = - common.collectJavaCompilationArgs(/* isNeverLink= */ JavaCommon.isNeverLink(ruleContext)); - - // Wire up the source jar for the current target and transitive source jars from dependencies. - ImmutableList srcJars = ImmutableList.of(); - Artifact srcJar = ruleContext.getPrerequisiteArtifact("srcjar"); - NestedSetBuilder transitiveJavaSourceJarBuilder = NestedSetBuilder.stableOrder(); - if (srcJar != null) { - srcJars = ImmutableList.of(srcJar); - transitiveJavaSourceJarBuilder.add(srcJar); - } - for (TransitiveInfoCollection target : ruleContext.getPrerequisites("exports")) { - transitiveJavaSourceJarBuilder.addTransitive(JavaInfo.transitiveSourceJars(target)); - } - NestedSet transitiveJavaSourceJars = transitiveJavaSourceJarBuilder.build(); - JavaSourceJarsProvider javaSourceJarsProvider = - JavaSourceJarsProvider.create(transitiveJavaSourceJars, srcJars); - - JavaInfo.Builder javaInfoBuilder = - JavaInfo.Builder.create() - .setRuntimeJars(ImmutableList.of(mergedJar)) - .setJavaConstraints(ImmutableList.of("android")) - .setNeverlink(JavaCommon.isNeverLink(ruleContext)) - .javaCompilationArgs(javaCompilationArgsProvider) - .javaSourceJars(javaSourceJarsProvider) - .javaRuleOutputs(jarProviderBuilder.build()); - - common.addTransitiveInfoProviders( - ruleBuilder, javaInfoBuilder, filesToBuild, /*classJar=*/ null); - - DataBindingV2Provider dataBindingV2Provider = - createDatabindingProvider(ruleContext, databindingBrFiles, databindingSetterStoreFiles); - - resourceApk.addToConfiguredTargetBuilder( - ruleBuilder, - ruleContext.getLabel(), - /* includeStarlarkApiProvider = */ false, - /* isLibrary = */ true); - - ruleBuilder - .setFilesToBuild(filesToBuild) - .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) - .addNativeDeclaredProvider(dataBindingV2Provider) - .addNativeDeclaredProvider(new ProguardSpecProvider(extractProguardSpecs(ruleContext, aar))) - .addNativeDeclaredProvider( - new AndroidNativeLibsInfo( - AndroidCommon.collectTransitiveNativeLibs(ruleContext).add(nativeLibs).build())) - .addStarlarkDeclaredProvider(javaInfoBuilder.build()); - if (jdepsArtifact != null) { - // Add the deps check result so that we can unit test it. - ruleBuilder.addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, jdepsArtifact); - } - return ruleBuilder.build(); - } - - private static NestedSet getCompileTimeJarsFromCollection( - ImmutableList deps, boolean isDirect) throws RuleErrorException { - JavaCompilationArgsProvider provider = JavaCompilationArgsProvider.legacyFromTargets(deps); - return isDirect ? provider.getDirectCompileTimeJars() : provider.getTransitiveCompileTimeJars(); - } - - /** - * Collect Proguard Specs from transitives and proguard.txt if it exists in the AAR file. In the - * case the proguard.txt file does exists, we need to extract it from the AAR file - */ - private NestedSet extractProguardSpecs(RuleContext ruleContext, Artifact aar) - throws RuleErrorException { - - NestedSet proguardSpecs = - new ProguardLibrary(ruleContext).collectProguardSpecs(ImmutableSet.of("deps", "exports")); - - Artifact proguardSpecArtifact = createAarArtifact(ruleContext, PROGUARD_SPEC); - - ruleContext.registerAction( - createAarEmbeddedProguardExtractorActions(ruleContext, aar, proguardSpecArtifact)); - - NestedSetBuilder builder = NestedSetBuilder.naiveLinkOrder(); - return builder.addTransitive(proguardSpecs).add(proguardSpecArtifact).build(); - } - - private static boolean isPersistentAarExtractor(RuleContext ruleContext) { - AndroidConfiguration androidConfig = - ruleContext.getConfiguration().getFragment(AndroidConfiguration.class); - return androidConfig.persistentAarExtractor(); - } - - /** - * Returns either the worker param file or null depending on whether persistent worker mode is on. - */ - @Nullable - private static ParamFileInfo getParamFileInfo(RuleContext ruleContext) { - return isPersistentAarExtractor(ruleContext) ? WORKERS_FORCED_PARAM_FILE_INFO : null; - } - - /** Adds worker-related execution requirements if worker mode enabled. */ - private static void modifyExecutionInfo( - RuleContext ruleContext, SpawnAction.Builder actionBuilder) { - if (isPersistentAarExtractor(ruleContext)) { - ImmutableMap.Builder executionInfo = ImmutableMap.builder(); - executionInfo.putAll(ExecutionRequirements.WORKER_MODE_ENABLED); - executionInfo.put(ExecutionRequirements.REQUIRES_WORKER_PROTOCOL, "json"); - actionBuilder.setExecutionInfo(executionInfo.buildOrThrow()); - } - } - - /** - * Creates action to extract embedded Proguard.txt from an AAR. If the file is not found, an empty - * file will be created - */ - private static SpawnAction createAarEmbeddedProguardExtractorActions( - RuleContext ruleContext, Artifact aar, Artifact proguardSpecArtifact) { - SpawnAction.Builder actionBuilder = new SpawnAction.Builder(); - ParamFileInfo paramFileInfo = getParamFileInfo(ruleContext); - modifyExecutionInfo(ruleContext, actionBuilder); - return actionBuilder - .useDefaultShellEnvironment() - .setExecutable( - ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_EMBEDDED_PROGUARD_EXTACTOR)) - .setMnemonic("AarEmbeddedProguardExtractor") - .setProgressMessage("Extracting proguard.txt from %s", aar.getFilename()) - .addInput(aar) - .addOutput(proguardSpecArtifact) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("--input_aar", aar) - .addExecPath("--output_proguard_file", proguardSpecArtifact) - .build(), - paramFileInfo) - .build(ruleContext); - } - - private NestedSet getBootclasspath(RuleContext ruleContext) throws RuleErrorException { - if (AndroidCommon.getAndroidConfig(ruleContext).desugarJava8()) { - return NestedSetBuilder.stableOrder() - .addTransitive( - ruleContext - .getPrerequisite("$desugar_java8_extra_bootclasspath") - .getProvider(FileProvider.class) - .getFilesToBuild()) - .add(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar()) - .build(); - } else { - return NestedSetBuilder.stableOrder() - .add(AndroidSdkProvider.fromRuleContext(ruleContext).getAndroidJar()) - .build(); - } - } - - /** - * Creates an action to extract a file (specified by the parameter filename) from an AAR file. - * Note that the parameter jdepsOutputArtifact is not necessary for this action. Conversely, the - * action of checking dependencies for aar_import needs this action instead. Therefore we add the - * output artifact of import_deps_checker to this extraction action as input. Therefore, the - * dependency checking will run each time. - */ - private static SpawnAction createSingleFileExtractorActions( - RuleContext ruleContext, - Artifact aar, - String filename, - @Nullable Artifact jdepsOutputArtifact, - Artifact outputArtifact) { - SpawnAction.Builder builder = - new SpawnAction.Builder() - .useDefaultShellEnvironment() - .setExecutable(ruleContext.getExecutablePrerequisite(AarImportBaseRule.ZIPPER)) - .setMnemonic("AarFileExtractor") - .setProgressMessage("Extracting %s from %s", filename, aar.getFilename()) - .addInput(aar) - .addOutput(outputArtifact) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("x", aar) - .addPath("-d", outputArtifact.getExecPath().getParentDirectory()) - .addDynamicString(filename) - .build()); - if (jdepsOutputArtifact != null) { - builder.addInput(jdepsOutputArtifact); - } - return builder.build(ruleContext); - } - - private static SpawnAction createAarResourcesExtractorActions( - RuleContext ruleContext, - Artifact aar, - Artifact resourcesDir, - Artifact assetsDir, - Artifact databindingBrFiles, - Artifact databindingSetterStoreFiles) { - - SpawnAction.Builder actionBuilder = new SpawnAction.Builder(); - ParamFileInfo paramFileInfo = getParamFileInfo(ruleContext); - modifyExecutionInfo(ruleContext, actionBuilder); - return actionBuilder - .useDefaultShellEnvironment() - .setExecutable( - ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_RESOURCES_EXTRACTOR)) - .setMnemonic("AarResourcesExtractor") - .setProgressMessage("Extracting AAR Resources for %{label}") - .addInput(aar) - .addOutput(resourcesDir) - .addOutput(assetsDir) - .addOutput(databindingBrFiles) - .addOutput(databindingSetterStoreFiles) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("--input_aar", aar) - .addExecPath("--output_res_dir", resourcesDir) - .addExecPath("--output_assets_dir", assetsDir) - .addExecPath("--output_databinding_br_dir", databindingBrFiles) - .addExecPath("--output_databinding_setter_store_dir", databindingSetterStoreFiles) - .build(), - paramFileInfo) - .build(ruleContext); - } - - private static SpawnAction createAarEmbeddedJarsExtractorActions( - RuleContext ruleContext, - Artifact aar, - Artifact jarsTreeArtifact, - Artifact singleJarParamFile) { - SpawnAction.Builder actionBuilder = new SpawnAction.Builder(); - ParamFileInfo paramFileInfo = getParamFileInfo(ruleContext); - modifyExecutionInfo(ruleContext, actionBuilder); - return actionBuilder - .useDefaultShellEnvironment() - .setExecutable( - ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_EMBEDDED_JARS_EXTACTOR)) - .setMnemonic("AarEmbeddedJarsExtractor") - .setProgressMessage("Extracting classes.jar and libs/*.jar from %s", aar.getFilename()) - .addInput(aar) - .addOutput(jarsTreeArtifact) - .addOutput(singleJarParamFile) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("--input_aar", aar) - .addExecPath("--output_dir", jarsTreeArtifact) - .addExecPath("--output_singlejar_param_file", singleJarParamFile) - .build(), - paramFileInfo) - .build(ruleContext); - } - - private static SpawnAction createAarJarsMergingActions( - RuleContext ruleContext, Artifact jarsTreeArtifact, Artifact mergedJar, Artifact paramFile) - throws RuleErrorException { - SpawnAction.Builder builder = new SpawnAction.Builder().useDefaultShellEnvironment(); - FilesToRunProvider singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar(); - return builder - .setExecutable(singleJar) - .setMnemonic("AarJarsMerger") - .setProgressMessage("Merging AAR embedded jars for %{label}") - .addInput(jarsTreeArtifact) - .addOutput(mergedJar) - .addInput(paramFile) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("--output", mergedJar) - .add("--dont_change_compression") - .add("--normalize") - .addPrefixedExecPath("@", paramFile) - .build()) - .build(ruleContext); - } - - private static SpawnAction createAarNativeLibsFilterActions( - RuleContext ruleContext, Artifact aar, Artifact outputZip) throws RuleErrorException { - - String cpu = null; - // Maps a CPU name as used in an AAR to the corresponding CPU constraint. - ImmutableMap aarCpuToConstraint = - ImmutableMap.of( - "arm64-v8a", - ruleContext.getPrerequisite("$constraint_arm64", ConstraintValueInfo.PROVIDER), - "armeabi-v7a", - ruleContext.getPrerequisite("$constraint_armv7", ConstraintValueInfo.PROVIDER), - "x86", ruleContext.getPrerequisite("$constraint_x86", ConstraintValueInfo.PROVIDER), - "x86_64", - ruleContext.getPrerequisite("$constraint_x86_64", ConstraintValueInfo.PROVIDER)); - - for (Map.Entry e : aarCpuToConstraint.entrySet()) { - if (ruleContext.targetPlatformHasConstraint(e.getValue())) { - cpu = e.getKey(); - break; - } - } - - if (cpu == null) { - throw ruleContext.throwWithRuleError( - String.format( - "Target platform %s does not match one of the applicable CPU constraints for" - + " aar_import %s. Applicable CPU constraints are listed in" - + " https://blog.bazel.build/2023/11/15/android-platforms.html", - ruleContext.getToolchainContexts().getTargetPlatform().label(), - ruleContext.getLabel())); - } - - SpawnAction.Builder actionBuilder = new SpawnAction.Builder(); - ParamFileInfo paramFileInfo = getParamFileInfo(ruleContext); - modifyExecutionInfo(ruleContext, actionBuilder); - return actionBuilder - .useDefaultShellEnvironment() - .setExecutable( - ruleContext.getExecutablePrerequisite(AarImportBaseRule.AAR_NATIVE_LIBS_ZIP_CREATOR)) - .setMnemonic("AarNativeLibsFilter") - .setProgressMessage("Filtering AAR native libs by architecture for %{label}") - .addInput(aar) - .addOutput(outputZip) - .addCommandLine( - CustomCommandLine.builder() - .addExecPath("--input_aar", aar) - .add("--cpu", cpu) - .addExecPath("--output_zip", outputZip) - .build(), - paramFileInfo) - .build(ruleContext); - } - - private static DataBindingV2Provider createDatabindingProvider( - RuleContext ruleContext, - SpecialArtifact databindingBrFiles, - SpecialArtifact databindingSetterStoreFiles) { - - List> databindingProvidersFromDeps = - ruleContext.getPrerequisites("deps", DataBindingV2Provider.PROVIDER); - - Iterable> databindingProvidersFromExports = - ruleContext.getPrerequisites("exports", DataBindingV2Provider.PROVIDER); - - DataBindingV2Provider dataBindingV2Provider = - DataBindingV2Provider.createProvider( - databindingSetterStoreFiles, - /* classInfoFile= */ null, - databindingBrFiles, - ruleContext.getRule().getLabel().toString(), - // TODO: The aar's Java package isn't available during analysis (it's in the manifest - // inside the aar, or can maybe be inferred elsewhere). This is mostly used for - // constructing a nice error message if multiple android_library rules try to generate - // databinding conflicting classes into the same Java package, so it's not as important - // for aars. - /* javaPackage= */ null, - databindingProvidersFromDeps, - databindingProvidersFromExports); - - return dataBindingV2Provider; - } - - private static Artifact createAarArtifact(RuleContext ruleContext, String name) { - return ruleContext.getUniqueDirectoryArtifact( - "_aar", name, ruleContext.getBinOrGenfilesDirectory()); - } - - private static SpecialArtifact createAarTreeArtifact(RuleContext ruleContext, String name) { - PathFragment rootRelativePath = ruleContext.getUniqueDirectory("_aar/unzipped/" + name); - return ruleContext.getTreeArtifact(rootRelativePath, ruleContext.getBinOrGenfilesDirectory()); - } -} diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AarImportBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AarImportBaseRule.java deleted file mode 100644 index a802e865bec14f..00000000000000 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AarImportBaseRule.java +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2016 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.rules.android; - -import static com.google.devtools.build.lib.packages.Attribute.attr; -import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; - -import com.google.devtools.build.lib.analysis.RuleDefinition; -import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; -import com.google.devtools.build.lib.analysis.config.ExecutionTransitionFactory; -import com.google.devtools.build.lib.cmdline.Label; -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.android.AndroidRuleClasses.AndroidBaseRule; -import com.google.devtools.build.lib.rules.java.JavaConfiguration; -import com.google.devtools.build.lib.rules.java.JavaInfo; -import com.google.devtools.build.lib.rules.java.JavaSemantics; -import com.google.devtools.build.lib.util.FileType; - -/** Rule definition for the aar_import rule. */ -public class AarImportBaseRule implements RuleDefinition { - - static final String AAR_EMBEDDED_JARS_EXTACTOR = "$aar_embedded_jars_extractor"; - static final String AAR_EMBEDDED_PROGUARD_EXTACTOR = "$aar_embedded_proguard_extractor"; - static final String AAR_NATIVE_LIBS_ZIP_CREATOR = "$aar_native_libs_zip_creator"; - static final String AAR_RESOURCES_EXTRACTOR = "$aar_resources_extractor"; - static final String ZIPPER = "$zipper"; - - @Override - public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env) { - return builder - /* - The .aar file to provide to the Android targets that depend on this target. - */ - .add(attr("aar", LABEL).mandatory().allowedFileTypes(FileType.of(".aar"))) - /* - Targets to export to rules that depend on this rule. - See java_library.exports. - */ - .add( - attr("exports", LABEL_LIST) - .allowedRuleClasses("aar_import", "java_import") - .allowedFileTypes()) - /* - A JAR file that contains source code for the compiled JAR files in the AAR. - */ - .add( - attr("srcjar", LABEL) - .allowedFileTypes(JavaSemantics.SOURCE_JAR, JavaSemantics.JAR) - .direct_compile_time_input()) - .add( - attr(AAR_EMBEDDED_JARS_EXTACTOR, LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/android:aar_embedded_jars_extractor"))) - .add( - attr(AAR_EMBEDDED_PROGUARD_EXTACTOR, LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/android:aar_embedded_proguard_extractor"))) - .add( - attr(AAR_NATIVE_LIBS_ZIP_CREATOR, LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/android:aar_native_libs_zip_creator"))) - .add( - attr(AAR_RESOURCES_EXTRACTOR, LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/android:aar_resources_extractor"))) - .add( - attr("$import_deps_checker", LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/android:aar_import_deps_checker"))) - .add( - attr(ZIPPER, LABEL) - .cfg(ExecutionTransitionFactory.createFactory()) - .exec() - .value(env.getToolsLabel("//tools/zip:zipper"))) - .add( - attr("$constraint_arm64", LABEL) - .value(Label.parseCanonicalUnchecked("@platforms//cpu:arm64"))) - .add( - attr("$constraint_armv7", LABEL) - .value(Label.parseCanonicalUnchecked("@platforms//cpu:armv7"))) - .add( - attr("$constraint_x86", LABEL) - .value(Label.parseCanonicalUnchecked("@platforms//cpu:x86_32"))) - .add( - attr("$constraint_x86_64", LABEL) - .value(Label.parseCanonicalUnchecked("@platforms//cpu:x86_64"))) - .advertiseStarlarkProvider(StarlarkProviderIdentifier.forKey(JavaInfo.PROVIDER.getKey())) - .requiresConfigurationFragments(AndroidConfiguration.class, JavaConfiguration.class) - .build(); - } - - @Override - public Metadata getMetadata() { - return RuleDefinition.Metadata.builder() - .name("$aar_import_base") - .type(RuleClassType.ABSTRACT) - .ancestors(AndroidBaseRule.class) - .build(); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java index 4d2f44686cfb6b..e0b0ad03769641 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryTest.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.packages.util.ResourceLoader; import com.google.devtools.build.lib.rules.android.AndroidBuildViewTestCase; import com.google.devtools.build.lib.rules.android.AndroidSdkProvider; -import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData; import com.google.devtools.build.lib.vfs.FileSystemUtils; import org.junit.Before; import org.junit.Test; @@ -89,28 +88,6 @@ private void scratchExtrasLibrary( ""); } - @Test - public void testGeneratedAarImport() throws Exception { - scratchPlatformsDirectories(25); - scratchBuildToolsDirectories(); - scratchExtrasLibrary("extras/google/m2repository", "com.google.android", "foo", "1.0.0", "aar"); - String bazelToolsWorkspace = scratch.dir("embedded_tools").getPathString(); - FileSystemUtils.appendIsoLatin1( - scratch.resolve("WORKSPACE"), - "local_repository(name = 'bazel_tools', path = '" + bazelToolsWorkspace + "')", - "android_sdk_repository(", - " name = 'androidsdk',", - " path = '/sdk',", - ")"); - invalidatePackages(); - - ConfiguredTargetAndData aarImportTarget = - getConfiguredTargetAndData("@androidsdk//com.google.android:foo-1.0.0"); - assertThat(aarImportTarget).isNotNull(); - assertThat(aarImportTarget.getTargetForTesting().getAssociatedRule().getRuleClass()) - .isEqualTo("aar_import"); - } - @Test public void testExportsExtrasLibraryArtifacts() throws Exception { scratchPlatformsDirectories(25); diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/BUILD index a8f8286da87c50..2b0d5f1862f7f6 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/BUILD +++ b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/BUILD @@ -21,7 +21,6 @@ java_test( "AndroidNdkRepositoryTest.java", "AndroidSdkRepositoryTest.java", "BazelAndroidLocalTestTest.java", - "SdkMavenRepositoryTest.java", ], resources = [ "//tools/android:android_sdk_repository_template.bzl", @@ -35,7 +34,6 @@ java_test( "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", "//src/main/java/com/google/devtools/build/lib/bazel/rules/android", - "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/packages", "//src/main/java/com/google/devtools/build/lib/rules/android", @@ -47,7 +45,6 @@ java_test( "//src/test/java/com/google/devtools/build/lib/testutil", "//src/test/java/com/google/devtools/build/lib/testutil:JunitUtils", "//src/test/java/com/google/devtools/build/lib/testutil:TestConstants", - "//third_party:guava", "//third_party:junit4", "//third_party:truth", ], diff --git a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java deleted file mode 100644 index c95f26b0e9844d..00000000000000 --- a/src/test/java/com/google/devtools/build/lib/bazel/rules/android/SdkMavenRepositoryTest.java +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2016 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.android; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.collect.ImmutableList; -import com.google.devtools.build.lib.cmdline.Label; -import com.google.devtools.build.lib.packages.AttributeMap; -import com.google.devtools.build.lib.packages.BuildType; -import com.google.devtools.build.lib.packages.RawAttributeMapper; -import com.google.devtools.build.lib.packages.Rule; -import com.google.devtools.build.lib.packages.Type; -import com.google.devtools.build.lib.rules.android.AndroidBuildViewTestCase; -import com.google.devtools.build.lib.vfs.Path; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for {@link SdkMavenRepository}. */ -@RunWith(JUnit4.class) -public class SdkMavenRepositoryTest extends AndroidBuildViewTestCase { - Path workspaceDir; - Path repoPath; - SdkMavenRepository sdkMavenRepository; - - @Before - public void setup() throws Exception { - repoPath = scratch.dir("repo"); - workspaceDir = scratch.dir(""); - - scratch.file("repo/com/google/android/foo/1.0.0/foo.pom", - "", - " com.google.android", - " foo", - " 1.0.0", - ""); - scratch.file("repo/com/google/android/bar/1.0.0/bar.pom", - "", - " com.google.android", - " bar", - " 1.0.0", - " aar", - " ", - " ", - " com.google.android", - " foo", - " 1.0.0", - " ", - " ", - " com.google.android", - " baz", - " 1.0.0", - " ", - " ", - ""); - scratch.file("repo/com/google/android/baz/1.0.0/baz.pom", - "", - " com.google.android", - " baz", - " 1.0.0", - " par", - ""); - sdkMavenRepository = SdkMavenRepository.create(ImmutableList.of(repoPath)); - scratch.file("BUILD", - "exports_files([", - sdkMavenRepository.getExportsFiles(workspaceDir), - "])"); - } - - @Test - public void testExportsFiles() throws Exception { - assertThat(sdkMavenRepository.getExportsFiles(workspaceDir)).isEqualTo( - " 'repo/com/google/android/bar/1.0.0/bar.aar',\n" - + " 'repo/com/google/android/baz/1.0.0/baz.par',\n" - + " 'repo/com/google/android/foo/1.0.0/foo.jar',\n" - ); - } - - @Test - public void testBuildFilesWritten() throws Exception { - sdkMavenRepository.writeBuildFiles(workspaceDir); - - Path groupIdPath = scratch.resolve("com.google.android"); - assertThat(workspaceDir.getDirectoryEntries()).containsAtLeast(repoPath, groupIdPath); - - Path buildFilePath = groupIdPath.getRelative("BUILD"); - assertThat(groupIdPath.getDirectoryEntries()).containsExactly(buildFilePath); - } - - @Test - public void testGeneratedAarImport() throws Exception { - sdkMavenRepository.writeBuildFiles(workspaceDir); - Rule aarImport = - getConfiguredTargetAndData("//com.google.android:bar-1.0.0") - .getTargetForTesting() - .getAssociatedRule(); - assertThat(aarImport.getRuleClass()).isEqualTo("aar_import"); - AttributeMap attributes = RawAttributeMapper.of(aarImport); - assertThat(attributes.get("aar", BuildType.LABEL)) - .isEqualTo(Label.parseCanonicalUnchecked("//:repo/com/google/android/bar/1.0.0/bar.aar")); - assertThat(attributes.get("exports", BuildType.LABEL_LIST)) - .containsExactly(Label.parseCanonicalUnchecked("//com.google.android:foo-1.0.0")); - } - - @Test - public void testGeneratedJavaImport() throws Exception { - sdkMavenRepository.writeBuildFiles(workspaceDir); - Rule javaImport = - getConfiguredTargetAndData("//com.google.android:foo-1.0.0") - .getTargetForTesting() - .getAssociatedRule(); - assertThat(javaImport.getRuleClass()).isEqualTo("java_import"); - AttributeMap attributes = RawAttributeMapper.of(javaImport); - assertThat(attributes.get("jars", BuildType.LABEL_LIST)) - .containsExactly( - Label.parseCanonicalUnchecked("//:repo/com/google/android/foo/1.0.0/foo.jar")); - assertThat(attributes.get("exports", BuildType.LABEL_LIST)).isEmpty(); - } - - @Test - public void testGeneratedRuleForInvalidPackaging() throws Exception { - sdkMavenRepository.writeBuildFiles(workspaceDir); - Rule invalidPackagingGenrule = - getConfiguredTargetAndData("//com.google.android:baz-1.0.0") - .getTargetForTesting() - .getAssociatedRule(); - assertThat(invalidPackagingGenrule.getRuleClass()).isEqualTo("genrule"); - assertThat(RawAttributeMapper.of(invalidPackagingGenrule).get("cmd", Type.STRING)) - .isEqualTo("echo Bazel does not recognize the Maven packaging type for: " - + "\"//:repo/com/google/android/baz/1.0.0/baz.par\"; exit 1"); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java deleted file mode 100644 index adc86c4609f128..00000000000000 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AarImportTest.java +++ /dev/null @@ -1,620 +0,0 @@ -// Copyright 2016 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.rules.android; - -import static com.google.common.truth.Truth.assertThat; -import static java.util.stream.Collectors.toList; - -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.devtools.build.lib.actions.Action; -import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.CommandLineExpansionException; -import com.google.devtools.build.lib.actions.util.ActionsTestUtil; -import com.google.devtools.build.lib.analysis.ConfiguredTarget; -import com.google.devtools.build.lib.analysis.FilesToRunProvider; -import com.google.devtools.build.lib.analysis.OutputGroupInfo; -import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.analysis.configuredtargets.FileConfiguredTarget; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; -import com.google.devtools.build.lib.rules.android.databinding.DataBindingV2Provider; -import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider; -import com.google.devtools.build.lib.rules.java.JavaCompilationInfoProvider; -import com.google.devtools.build.lib.rules.java.JavaConfiguration.ImportDepsCheckingLevel; -import com.google.devtools.build.lib.rules.java.JavaInfo; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider; -import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.JavaOutput; -import com.google.devtools.build.lib.rules.java.JavaSourceJarsProvider; -import com.google.devtools.build.lib.rules.java.ProguardSpecProvider; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Tests for {@link com.google.devtools.build.lib.rules.android.AarImport}. */ -@RunWith(JUnit4.class) -public class AarImportTest extends AndroidBuildViewTestCase { - - @Before - public void setup() throws Exception { - scratch.file( - "a/BUILD", - """ - java_import( - name = "foo_src", - jars = ["foo-src.jar"], - ) - - aar_import( - name = "foo", - aar = "foo.aar", - srcjar = ":foo_src", - ) - - aar_import( - name = "baz", - aar = "baz.aar", - ) - - java_import( - name = "bar_src", - jars = ["bar-src.jar"], - ) - - aar_import( - name = "bar", - aar = "bar.aar", - srcjar = ":bar_src", - exports = [ - ":foo", - "//java:baz", - ], - deps = [":baz"], - ) - - aar_import( - name = "intermediate", - aar = "intermediate.aar", - deps = [":bar"], - ) - - aar_import( - name = "last", - aar = "last.aar", - deps = [":intermediate"], - ) - - android_library( - name = "library", - srcs = ["App.java"], - custom_package = "com.google.arrimport", - manifest = "AndroidManifest.xml", - resource_files = ["res/values/values.xml"], - deps = [":foo"], - ) - """); - scratch.file( - "java/BUILD", - """ - android_binary( - name = "app", - srcs = ["App.java"], - manifest = "AndroidManifest.xml", - deps = ["//a:bar"], - ) - - android_library( - name = "lib", - exports = ["//a:bar"], - ) - - java_import( - name = "baz", - constraints = ["android"], - jars = ["baz.jar"], - ) - """); - getAnalysisMock().ccSupport().setupCcToolchainConfigForCpu(mockToolsConfig, "armeabi-v7a"); - } - - @Test - public void proguardSpecsProvided() throws Exception { - ConfiguredTarget binaryTarget = getConfiguredTarget("//a:bar"); - - NestedSet transitiveProguardSpecs = - binaryTarget.get(ProguardSpecProvider.PROVIDER).getTransitiveProguardSpecs(); - - assertThat( - transitiveProguardSpecs.toSet().stream() - .map(Artifact::getRootRelativePathString) - .collect(Collectors.toSet())) - .containsExactly( - "a/_aar/bar/proguard.txt", "a/_aar/foo/proguard.txt", "a/_aar/baz/proguard.txt"); - } - - @Test - public void testProguardExtractor() throws Exception { - ConfiguredTarget target = getConfiguredTarget("//a:bar"); - Artifact proguardSpecsAritfact = - target.get(ProguardSpecProvider.PROVIDER).getTransitiveProguardSpecs().toList().get(0); - - Artifact aarProguardExtractor = - getDirectPrerequisite( - target, - ruleClassProvider.getToolsRepository() - + "//tools/android:aar_embedded_proguard_extractor") - .getProvider(FilesToRunProvider.class) - .getExecutable(); - - assertThat(getGeneratingSpawnAction(proguardSpecsAritfact).getArguments()) - .containsExactly( - aarProguardExtractor.getExecPathString(), - "--input_aar", - "a/bar.aar", - "--output_proguard_file", - proguardSpecsAritfact.getExecPathString()); - } - - @Test - public void aapt2RTxtProvided() throws Exception { - ConfiguredTarget libTarget = getConfiguredTarget("//a:library"); - - NestedSet transitiveCompiledSymbols = - libTarget.get(AndroidResourcesInfo.PROVIDER).getTransitiveCompiledSymbols(); - - assertThat( - transitiveCompiledSymbols.toSet().stream() - .map(Artifact::getRootRelativePathString) - .collect(Collectors.toSet())) - .containsExactly("a/foo_symbols/symbols.zip", "a/library_symbols/symbols.zip"); - - NestedSet directResources = - libTarget.get(AndroidResourcesInfo.PROVIDER).getDirectAndroidResources(); - - assertThat(directResources.toList()).hasSize(1); - - ValidatedAndroidResources resourceContainer = directResources.toList().get(0); - assertThat(resourceContainer.getAapt2RTxt()).isNotNull(); - } - - @Test - public void testResourcesProvided() throws Exception { - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo"); - - NestedSet directResources = - aarImportTarget.get(AndroidResourcesInfo.PROVIDER).getDirectAndroidResources(); - assertThat(directResources.toList()).hasSize(1); - - ValidatedAndroidResources resourceContainer = directResources.toList().get(0); - assertThat(resourceContainer.getManifest()).isNotNull(); - - Artifact resourceTreeArtifact = Iterables.getOnlyElement(resourceContainer.getResources()); - assertThat(resourceTreeArtifact.isTreeArtifact()).isTrue(); - assertThat(resourceTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/resources/foo"); - - NestedSet directAssets = - aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getDirectParsedAssets(); - assertThat(directAssets.toList()).hasSize(1); - - ParsedAndroidAssets assets = directAssets.toList().get(0); - assertThat(assets.getSymbols()).isNotNull(); - - Artifact assetsTreeArtifact = Iterables.getOnlyElement(assets.getAssets()); - assertThat(assetsTreeArtifact.isTreeArtifact()).isTrue(); - assertThat(assetsTreeArtifact.getExecPathString()).endsWith("_aar/unzipped/assets/foo"); - } - - @Test - public void testDatabindingInfoProvided() throws Exception { - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); - - DataBindingV2Provider provider = aarImportTarget.get(DataBindingV2Provider.PROVIDER); - - Artifact setterStore = provider.getSetterStores().toList().get(0); - assertThat(setterStore.isTreeArtifact()).isTrue(); - assertThat(setterStore.getExecPathString()) - .endsWith("_aar/unzipped/data-binding-setter_store/last"); - - assertThat( - provider.getTransitiveBRFiles().toList().stream() - .map(Artifact::getRootRelativePathString) - .collect(toList())) - .containsExactly( - "a/_aar/unzipped/data-binding-br/baz", - "a/_aar/unzipped/data-binding-br/foo", - "a/_aar/unzipped/data-binding-br/bar", - "a/_aar/unzipped/data-binding-br/intermediate", - "a/_aar/unzipped/data-binding-br/last"); - } - - @Test - public void testSourceJarsProvided() throws Exception { - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo"); - - Iterable srcJars = - JavaInfo.getProvider(JavaSourceJarsProvider.class, aarImportTarget).getSourceJars(); - assertThat(srcJars).hasSize(1); - Artifact srcJar = Iterables.getOnlyElement(srcJars); - assertThat(srcJar.getExecPathString()).endsWith("foo-src.jar"); - } - - @Test - public void testSourceJarsCollectedTransitively() throws Exception { - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); - - NestedSet srcJars = - JavaInfo.getProvider(JavaSourceJarsProvider.class, aarImportTarget) - .getTransitiveSourceJars(); - assertThat(ActionsTestUtil.baseArtifactNames(srcJars)) - .containsExactly("foo-src.jar", "bar-src.jar"); - } - - @Test - public void testResourcesExtractor() throws Exception { - ConfiguredTarget target = getConfiguredTarget("//a:foo"); - ValidatedAndroidResources resourceContainer = - target.get(AndroidResourcesInfo.PROVIDER).getDirectAndroidResources().toList().get(0); - - Artifact resourceTreeArtifact = resourceContainer.getResources().get(0); - Artifact aarResourcesExtractor = - getDirectPrerequisite( - target, - ruleClassProvider.getToolsRepository() + "//tools/android:aar_resources_extractor") - .getProvider(FilesToRunProvider.class) - .getExecutable(); - - ParsedAndroidAssets assets = - target.get(AndroidAssetsInfo.PROVIDER).getDirectParsedAssets().toList().get(0); - Artifact assetsTreeArtifact = assets.getAssets().get(0); - - DataBindingV2Provider dataBindingV2Provider = target.get(DataBindingV2Provider.PROVIDER); - Artifact databindingBrTreeArtifact = - dataBindingV2Provider.getTransitiveBRFiles().toList().get(0); - Artifact databindingSetterStoreTreeArtifact = - dataBindingV2Provider.getSetterStores().toList().get(0); - - assertThat(getGeneratingSpawnAction(resourceTreeArtifact).getArguments()) - .containsExactly( - aarResourcesExtractor.getExecPathString(), - "--input_aar", - "a/foo.aar", - "--output_res_dir", - resourceTreeArtifact.getExecPathString(), - "--output_assets_dir", - assetsTreeArtifact.getExecPathString(), - "--output_databinding_br_dir", - databindingBrTreeArtifact.getExecPathString(), - "--output_databinding_setter_store_dir", - databindingSetterStoreTreeArtifact.getExecPathString()); - } - - @Test - public void testDepsCheckerActionExistsForLevelError() throws Exception { - useConfiguration("--experimental_import_deps_checking=ERROR"); - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:last"); - OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.STARLARK_CONSTRUCTOR); - NestedSet outputGroup = - outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); - assertThat(outputGroup.toList()).hasSize(2); - - // We should force asset merging to happen - Artifact mergedAssetsZip = - aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); - assertThat(outputGroup.toList()).contains(mergedAssetsZip); - - // Get the other artifact from the output group - Artifact artifact = ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, "jdeps.proto"); - - assertThat(artifact.isTreeArtifact()).isFalse(); - assertThat(artifact.getExecPathString()).endsWith("_aar/last/jdeps.proto"); - - SpawnAction checkerAction = getGeneratingSpawnAction(artifact); - List arguments = checkerAction.getArguments(); - assertThat(arguments) - .containsAtLeast( - "--bootclasspath_entry", - "--classpath_entry", - "--directdep", - "--input", - "--checking_mode=error", - "--rule_label", - "//a:last", - "--jdeps_output"); - ensureArgumentsHaveClassEntryOptionWithSuffix( - arguments, "/intermediate/classes_and_libs_merged.jar"); - assertThat(arguments.stream().filter(arg -> "--classpath_entry".equals(arg)).count()) - .isEqualTo(9); // transitive classpath - assertThat(arguments.stream().filter(arg -> "--directdep".equals(arg)).count()) - .isEqualTo(2); // 1 declared dep - } - - @Test - public void testDepsCheckerActionExistsForLevelWarning() throws Exception { - checkDepsCheckerActionExistsForLevel(ImportDepsCheckingLevel.WARNING, "warning"); - } - - @Test - public void testDepsCheckerActionDoesNotExistsForLevelOff() throws Exception { - useConfiguration("--experimental_import_deps_checking=off"); - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); - OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.STARLARK_CONSTRUCTOR); - NestedSet outputGroup = - outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); - assertThat(outputGroup.toList()).hasSize(1); - assertThat(ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, "jdeps.proto")).isNull(); - } - - private void checkDepsCheckerActionExistsForLevel( - ImportDepsCheckingLevel level, String expectedCheckingMode) throws Exception { - useConfiguration("--experimental_import_deps_checking=" + level.name()); - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); - OutputGroupInfo outputGroupInfo = aarImportTarget.get(OutputGroupInfo.STARLARK_CONSTRUCTOR); - NestedSet outputGroup = - outputGroupInfo.getOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL); - assertThat(outputGroup.toList()).hasSize(2); - - // We should force asset merging to happen - Artifact mergedAssetsZip = - aarImportTarget.get(AndroidAssetsInfo.PROVIDER).getValidationResult(); - assertThat(outputGroup.toList()).contains(mergedAssetsZip); - - // Get the other artifact from the output group - Artifact artifact = ActionsTestUtil.getFirstArtifactEndingWith(outputGroup, "jdeps.proto"); - checkDepsCheckerOutputArtifact(artifact, expectedCheckingMode); - } - - private void checkDepsCheckerOutputArtifact(Artifact artifact, String expectedCheckingMode) - throws CommandLineExpansionException, InterruptedException { - assertThat(artifact.isTreeArtifact()).isFalse(); - assertThat(artifact.getExecPathString()).endsWith("_aar/bar/jdeps.proto"); - - SpawnAction checkerAction = getGeneratingSpawnAction(artifact); - List arguments = checkerAction.getArguments(); - assertThat(arguments) - .containsAtLeast( - "--bootclasspath_entry", - "--classpath_entry", - "--input", - "--rule_label", - "--jdeps_output", - "--checking_mode=" + expectedCheckingMode); - } - - /** - * Tests whether the given argument list contains an argument nameds "--classpath_entry" with a - * value that ends with the given suffix. - */ - private static void ensureArgumentsHaveClassEntryOptionWithSuffix( - List arguments, String suffix) { - assertThat(arguments).isNotEmpty(); - Iterator iterator = arguments.iterator(); - assertThat(iterator.hasNext()).isTrue(); - String prev = iterator.next(); - while (iterator.hasNext()) { - String current = iterator.next(); - if ("--classpath_entry".equals(prev) && current.endsWith(suffix)) { - return; // Success. - } - prev = current; - } - Assert.fail( - "The arguments does not have the expected --classpath_entry: The arguments are " - + arguments - + ", and the expected class entry suffix is " - + suffix); - } - - @Test - public void testNativeLibsProvided() throws Exception { - ConfiguredTarget androidLibraryTarget = getConfiguredTarget("//java:lib"); - - NestedSet nativeLibs = - androidLibraryTarget.get(AndroidNativeLibsInfo.PROVIDER).getNativeLibs(); - assertThat(nativeLibs.toList()) - .containsExactly( - ActionsTestUtil.getFirstArtifactEndingWith(nativeLibs, "foo/native_libs.zip"), - ActionsTestUtil.getFirstArtifactEndingWith(nativeLibs, "bar/native_libs.zip"), - ActionsTestUtil.getFirstArtifactEndingWith(nativeLibs, "baz/native_libs.zip")); - } - - @Test - public void testNativeLibsMakesItIntoApk() throws Exception { - scratch.file( - "java/com/google/android/hello/BUILD", - """ - aar_import( - name = "my_aar", - aar = "my_aar.aar", - ) - - android_binary( - name = "my_app", - srcs = ["HelloApp.java"], - manifest = "AndroidManifest.xml", - deps = [":my_aar"], - ) - """); - ConfiguredTarget binary = getConfiguredTarget("//java/com/google/android/hello:my_app"); - SpawnAction apkBuilderAction = - (SpawnAction) - actionsTestUtil() - .getActionForArtifactEndingWith(getFilesToBuild(binary), "my_app_unsigned.apk"); - assertThat( - Iterables.find( - apkBuilderAction.getArguments(), - Predicates.containsPattern("_aar/my_aar/native_libs.zip$"))) - .isNotEmpty(); - } - - @Test - public void testClassesJarProvided() throws Exception { - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:foo"); - - Iterable javaOutputs = - JavaInfo.getProvider(JavaRuleOutputJarsProvider.class, aarImportTarget).getJavaOutputs(); - assertThat(javaOutputs).hasSize(1); - - Artifact classesJar = javaOutputs.iterator().next().getClassJar(); - assertThat(classesJar.getFilename()).isEqualTo("classes_and_libs_merged.jar"); - - SpawnAction jarMergingAction = ((SpawnAction) getGeneratingAction(classesJar)); - assertThat(jarMergingAction.getArguments()).contains("--dont_change_compression"); - } - - @Test - public void testNoCustomJavaPackage() throws Exception { - ValidatedAndroidResources resourceContainer = - getConfiguredTarget("//a:foo") - .get(AndroidResourcesInfo.PROVIDER) - .getDirectAndroidResources() - .toList() - .get(0); - - // aar_import should not set a custom java package. Instead aapt will read the - // java package from the manifest. - assertThat(resourceContainer.getJavaPackage()).isNull(); - } - - @Test - public void testDepsPropagatesMergedAarJars() throws Exception { - Action appCompileAction = - getGeneratingAction( - ActionsTestUtil.getFirstArtifactEndingWith( - actionsTestUtil() - .artifactClosureOf(getFileConfiguredTarget("//java:app.apk").getArtifact()), - "libapp.jar")); - assertThat(appCompileAction).isNotNull(); - assertThat(ActionsTestUtil.prettyArtifactNames(appCompileAction.getInputs())) - .containsAtLeast( - "a/_aar/foo/classes_and_libs_merged.jar", - "a/_aar/bar/classes_and_libs_merged.jar", - "a/_aar/baz/classes_and_libs_merged.jar"); - } - - @Test - public void testExportsPropagatesMergedAarJars() throws Exception { - FileConfiguredTarget appTarget = getFileConfiguredTarget("//java:app.apk"); - Set artifacts = actionsTestUtil().artifactClosureOf(appTarget.getArtifact()); - - ConfiguredTarget bar = getConfiguredTarget("//a:bar"); - Artifact barClassesJar = - ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "bar/classes_and_libs_merged.jar"); - // Verify that bar/classes_and_libs_merged.jar was in the artifact closure. - assertThat(barClassesJar).isNotNull(); - assertThat(barClassesJar.getArtifactOwner().getLabel()).isEqualTo(bar.getLabel()); - - ConfiguredTarget foo = getConfiguredTarget("//a:foo"); - Artifact fooClassesJar = - ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "foo/classes_and_libs_merged.jar"); - // Verify that foo/classes_and_libs_merged.jar was in the artifact closure. - assertThat(fooClassesJar).isNotNull(); - assertThat(fooClassesJar.getArtifactOwner().getLabel()).isEqualTo(foo.getLabel()); - - ConfiguredTarget baz = getConfiguredTarget("//java:baz.jar"); - Artifact bazJar = ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "baz.jar"); - // Verify that baz.jar was in the artifact closure - assertThat(bazJar).isNotNull(); - assertThat(bazJar.getArtifactOwner().getLabel()).isEqualTo(baz.getLabel()); - } - - @Test - public void testExportsPropagatesResources() throws Exception { - FileConfiguredTarget appTarget = getFileConfiguredTarget("//java:app.apk"); - Set artifacts = actionsTestUtil().artifactClosureOf(appTarget.getArtifact()); - - ConfiguredTarget bar = getConfiguredTarget("//a:bar"); - Artifact barResources = - ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "_aar/unzipped/resources/bar"); - assertThat(barResources).isNotNull(); - assertThat(barResources.getArtifactOwner().getLabel()).isEqualTo(bar.getLabel()); - - ConfiguredTarget foo = getConfiguredTarget("//a:foo"); - Artifact fooResources = - ActionsTestUtil.getFirstArtifactEndingWith(artifacts, "_aar/unzipped/resources/foo"); - assertThat(fooResources).isNotNull(); - assertThat(fooResources.getArtifactOwner().getLabel()).isEqualTo(foo.getLabel()); - } - - @Test - public void testJavaCompilationArgsProvider() throws Exception { - useConfiguration("--experimental_import_deps_checking=ERROR"); - ConfiguredTarget aarImportTarget = getConfiguredTarget("//a:bar"); - - JavaCompilationArgsProvider provider = - JavaInfo.getProvider(JavaCompilationArgsProvider.class, aarImportTarget); - assertThat(provider).isNotNull(); - assertThat(artifactsToStrings(provider.getRuntimeJars())) - .containsExactly( - "bin a/_aar/bar/classes_and_libs_merged.jar", - "bin a/_aar/foo/classes_and_libs_merged.jar", - "bin a/_aar/baz/classes_and_libs_merged.jar", - "src java/baz.jar"); - List compileTimeJavaDependencyArtifacts = - provider.getCompileTimeJavaDependencyArtifacts().toList(); - assertThat(compileTimeJavaDependencyArtifacts).hasSize(2); - assertThat( - compileTimeJavaDependencyArtifacts.stream() - .filter(artifact -> artifact.getExecPathString().endsWith("/_aar/foo/jdeps.proto")) - .collect(Collectors.toList())) - .hasSize(1); - assertThat( - compileTimeJavaDependencyArtifacts.stream() - .filter(artifact -> artifact.getExecPathString().endsWith("/_aar/bar/jdeps.proto")) - .collect(Collectors.toList())) - .hasSize(1); - } - - @Test - public void testExportsManifest() throws Exception { - Artifact binaryMergedManifest = - getConfiguredTarget("//java:app").get(ApkInfo.PROVIDER).getMergedManifest(); - // Compare root relative path strings instead of artifacts due to difference in configuration - // caused by the Android split transition. - assertThat( - Iterables.transform( - getGeneratingAction(binaryMergedManifest).getInputs().toList(), - Artifact::getRootRelativePathString)) - .containsAtLeast(getAndroidManifest("//a:foo"), getAndroidManifest("//a:bar")); - } - - private String getAndroidManifest(String aarImport) throws Exception { - return getConfiguredTarget(aarImport) - .get(AndroidResourcesInfo.PROVIDER) - .getDirectAndroidResources() - .toList() - .get(0) - .getManifest() - .getRootRelativePathString(); - } - - @Test - public void testRClassFromAarImportInCompileClasspath() throws Exception { - Collection compilationClasspath = - JavaInfo.getProvider(JavaCompilationInfoProvider.class, getConfiguredTarget("//a:library")) - .getCompilationClasspath() - .toList(Artifact.class); - - assertThat( - compilationClasspath.stream() - .filter(artifact -> artifact.getFilename().equalsIgnoreCase("foo_resources.jar")) - .count()) - .isEqualTo(1); - } -} diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD index cde3c30b20f669..97ebd205c1f977 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD +++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD @@ -13,28 +13,6 @@ filegroup( visibility = ["//src:__subpackages__"], ) -java_test( - name = "AarImportTest", - timeout = "long", - srcs = ["AarImportTest.java"], - deps = [ - ":AndroidBuildViewTestCase", - "//src/main/java/com/google/devtools/build/lib/actions", - "//src/main/java/com/google/devtools/build/lib/actions:artifacts", - "//src/main/java/com/google/devtools/build/lib/actions:commandline_item", - "//src/main/java/com/google/devtools/build/lib/analysis:analysis_cluster", - "//src/main/java/com/google/devtools/build/lib/analysis:configured_target", - "//src/main/java/com/google/devtools/build/lib/collect/nestedset", - "//src/main/java/com/google/devtools/build/lib/rules/android", - "//src/main/java/com/google/devtools/build/lib/rules/java:java-compilation", - "//src/main/java/com/google/devtools/build/lib/rules/java:java-rules", - "//src/test/java/com/google/devtools/build/lib/actions/util", - "//third_party:guava", - "//third_party:junit4", - "//third_party:truth", - ], -) - java_test( name = "AndroidStarlarkTest", srcs = ["AndroidStarlarkTest.java"], diff --git a/src/test/shell/bazel/android/BUILD b/src/test/shell/bazel/android/BUILD index 04ab56b0530354..71a96fa085d661 100644 --- a/src/test/shell/bazel/android/BUILD +++ b/src/test/shell/bazel/android/BUILD @@ -23,7 +23,6 @@ sh_library( name = "android_helper", srcs = ["android_helper.sh"], data = [ - "sample.aar", "@bazel_tools//tools/bash/runfiles", ], ) @@ -71,23 +70,6 @@ android_sh_test( ], ) -android_sh_test( - name = "aar_integration_test", - size = "large", - srcs = ["aar_integration_test.sh"], - data = [ - ":android_helper", - "//external:android_ndk_for_testing", - "//external:android_sdk_for_testing", - "//src/test/shell/bazel:test-deps", - ], - tags = [ - # See https://github.com/bazelbuild/bazel/issues/17784. - "no-remote", - "no_windows", - ], -) - android_sh_test( name = "proguard_integration_test", size = "medium", diff --git a/src/test/shell/bazel/android/aar_integration_test.sh b/src/test/shell/bazel/android/aar_integration_test.sh deleted file mode 100755 index 25509afe25d243..00000000000000 --- a/src/test/shell/bazel/android/aar_integration_test.sh +++ /dev/null @@ -1,187 +0,0 @@ -#!/bin/bash -# -# Copyright 2017 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. - -# For these tests to run do the following: -# -# 1. Install an Android SDK from https://developer.android.com -# 2. Set the $ANDROID_HOME environment variable -# 3. Uncomment the line in WORKSPACE containing android_sdk_repository -# -# Note that if the environment is not set up as above android_integration_test -# will silently be ignored and will be shown as passing. - -# Load the test setup defined in the parent directory -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -source "${CURRENT_DIR}/android_helper.sh" \ - || { echo "android_helper.sh not found!" >&2; exit 1; } -fail_if_no_android_sdk - -source "${CURRENT_DIR}/../../integration_test_setup.sh" \ - || { echo "integration_test_setup.sh not found!" >&2; exit 1; } - -resolve_android_toolchains - -# Regression test for https://github.com/bazelbuild/bazel/issues/1928. -function test_empty_tree_artifact_action_inputs_mount_empty_directories() { - create_new_workspace - setup_android_sdk_support - cat > AndroidManifest.xml < -EOF - mkdir res - zip test.aar AndroidManifest.xml res/ - cat > BUILD < AndroidManifest.xml < -EOF - mkdir -p res/values - cat > res/values/values.xml < - - -EOF - zip test.aar AndroidManifest.xml res/values/values.xml - cat > BUILD < AndroidManifest.xml < -EOF - mkdir -p res/layout - cat > res/layout/mylayout.xml < - -EOF - - mkdir assets - echo "some asset" > assets/a - - mkdir -p jni/armeabi-v7a - echo "an armeabi-v7a so" > jni/armeabi-v7a/libjni.so - - zip example.aar AndroidManifest.xml res/layout/mylayout.xml assets/a jni/armeabi-v7a/libjni.so - - cat > BUILD < AndroidManifest.xml < -EOF - cat > BUILD < AndroidManifest.xml < -EOF - mkdir -p res/layout - cat > res/layout/mylayout.xml < - -EOF - mkdir assets - echo "some asset" > assets/a - zip example.aar AndroidManifest.xml res/layout/mylayout.xml assets/a - cat > BUILD < java/bazel/BUILD < java/bazel/AndroidManifest.xml < EOF cat > java/bazel/Lib.java < java/a/BUILD< java/bazel/BUILD <E7>B2k3yO&$mY4=vR!7yUvkSd#K;dY}@eBt_Lglv(tR92_3KG-d_vPM&s z8U{*jWyXXgC3~>I@?Jc)?a|OH6zR2Ffk(OXW^1VA_`?jp!SVB$X@hh?-y- z10shlQp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