aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2017-11-09 18:17:16 +0100
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-11-09 18:29:30 +0100
commit9135b7bfc4245e16bd6599e22dce0ba077e0d10a (patch)
treed91317ff12b9506c1053081b7d5231306d127630
parent146bb7dc5da87d067e463508c6ae5462bbd3d511 (diff)
Remove android_instrumentation rule.
It's not needed by the new plan for android_instrumentation_test. RELNOTES: None PiperOrigin-RevId: 175166913
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentation.java164
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRule.java59
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRuleImplTest.java159
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD18
5 files changed, 0 insertions, 401 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentation.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentation.java
deleted file mode 100644
index 4559459d1e..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentation.java
+++ /dev/null
@@ -1,164 +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.rules.android;
-
-import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.FileProvider;
-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.Runfiles;
-import com.google.devtools.build.lib.analysis.RunfilesProvider;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
-import com.google.devtools.build.lib.analysis.configuredtargets.RuleConfiguredTarget.Mode;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
-import com.google.devtools.build.lib.packages.ImplicitOutputsFunction;
-import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.SafeImplicitOutputsFunction;
-import com.google.devtools.build.lib.util.FileType;
-
-/**
- * An implementation of the {@code android_instrumentation} rule.
- */
-public class AndroidInstrumentation implements RuleConfiguredTargetFactory {
-
- private static final SafeImplicitOutputsFunction TARGET_APK = ImplicitOutputsFunction
- .fromTemplates("%{name}-target.apk");
- private static final SafeImplicitOutputsFunction INSTRUMENTATION_APK =
- ImplicitOutputsFunction.fromTemplates("%{name}-instrumentation.apk");
- static final SafeImplicitOutputsFunction IMPLICIT_OUTPUTS_FUNCTION =
- ImplicitOutputsFunction.fromFunctions(TARGET_APK, INSTRUMENTATION_APK);
-
- @Override
- public ConfiguredTarget create(RuleContext ruleContext)
- throws InterruptedException, RuleErrorException {
-
- Artifact targetApk = getTargetApk(ruleContext);
- Artifact instrumentationApk = createInstrumentationApk(ruleContext);
- NestedSet<Artifact> filesToBuild =
- NestedSetBuilder.<Artifact>stableOrder().add(targetApk).add(instrumentationApk).build();
-
- RuleConfiguredTargetBuilder ruleBuilder = new RuleConfiguredTargetBuilder(ruleContext);
- return ruleBuilder
- .setFilesToBuild(filesToBuild)
- .addProvider(
- RunfilesProvider.class,
- RunfilesProvider.simple(
- new Runfiles.Builder(ruleContext.getWorkspaceName())
- .addTransitiveArtifacts(filesToBuild)
- .build()))
- .addNativeDeclaredProvider(new AndroidInstrumentationInfo(targetApk, instrumentationApk))
- .build();
- }
-
- private static boolean exactlyOneOf(boolean expression1, boolean expression2) {
- return (expression1 && !expression2) || (!expression1 && expression2);
- }
-
- /**
- * Returns the APK from the {@code target} attribute or creates one from the {@code
- * target_library} attribute.
- */
- private static Artifact getTargetApk(RuleContext ruleContext)
- throws RuleErrorException, InterruptedException {
- Artifact apk = ruleContext.getImplicitOutputArtifact(TARGET_APK);
- TransitiveInfoCollection target = ruleContext.getPrerequisite("target", Mode.TARGET);
- TransitiveInfoCollection targetLibrary =
- ruleContext.getPrerequisite("target_library", Mode.TARGET);
-
- if (!exactlyOneOf(target == null, targetLibrary == null)) {
- ruleContext.throwWithRuleError(
- "android_instrumentation requires that exactly one of the target and target_library "
- + "attributes be specified.");
- }
-
- if (target != null) {
- // target attribute is specified
- symlinkApkFromApkProviderOrFile(ruleContext, target, apk, "Symlinking target APK");
- } else {
- // target_library attribute is specified
- createApkFromLibrary(ruleContext, targetLibrary, apk);
- }
-
- return apk;
- }
-
- /**
- * Returns the APK from the {@code instrumentation} attribute or creates one from the {@code
- * instrumentation_library} attribute.
- */
- private static Artifact createInstrumentationApk(RuleContext ruleContext)
- throws RuleErrorException, InterruptedException {
- Artifact apk = ruleContext.getImplicitOutputArtifact(INSTRUMENTATION_APK);
- TransitiveInfoCollection instrumentation =
- ruleContext.getPrerequisite("instrumentation", Mode.TARGET);
- TransitiveInfoCollection instrumentationLibrary =
- ruleContext.getPrerequisite("instrumentation_library", Mode.TARGET);
-
- if (!exactlyOneOf(instrumentation == null, instrumentationLibrary == null)) {
- ruleContext.throwWithRuleError(
- "android_instrumentation requires that exactly one of the instrumentation and "
- + "instrumentation_library attributes be specified.");
- }
-
- if (instrumentation != null) {
- // instrumentation attribute is specified
- symlinkApkFromApkProviderOrFile(
- ruleContext, instrumentation, apk, "Symlinking instrumentation APK");
- } else {
- // instrumentation_library attribute is specified
- createApkFromLibrary(ruleContext, instrumentationLibrary, apk);
- }
-
- return apk;
- }
-
- // We symlink instead of simply providing the artifact as is to satisfy the implicit outputs
- // function. This allows user to refer to the APK outputs of the android_instrumentation rule by
- // the same name, whether they were built from libraries or simply symlinked from the output of
- // an android_binary rule.
- private static void symlinkApkFromApkProviderOrFile(
- RuleContext ruleContext,
- TransitiveInfoCollection transitiveInfoCollection,
- Artifact apk,
- String message) {
- Artifact existingApk;
- ApkProvider apkProvider = transitiveInfoCollection.getProvider(ApkProvider.class);
- if (apkProvider != null) {
- existingApk = apkProvider.getApk();
- } else {
- existingApk =
- Iterables.getOnlyElement(
- FileType.filter(
- transitiveInfoCollection.getProvider(FileProvider.class).getFilesToBuild(),
- AndroidRuleClasses.APK));
- }
-
- ruleContext.registerAction(
- new SymlinkAction(ruleContext.getActionOwner(), existingApk, apk, message));
- }
-
- @SuppressWarnings("unused") // TODO(b/37856762): Implement APK building from libraries.
- private static Artifact createApkFromLibrary(
- RuleContext ruleContext, TransitiveInfoCollection library, Artifact apk)
- throws RuleErrorException {
- // TODO(b/37856762): Cleanup AndroidBinary#createAndroidBinary and use it here.
- ruleContext.throwWithRuleError(
- "android_instrumentation dependencies on android_library rules are not yet supported");
- return null;
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRule.java
deleted file mode 100644
index b05c3060a6..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRule.java
+++ /dev/null
@@ -1,59 +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.rules.android;
-
-import static com.google.devtools.build.lib.packages.Attribute.attr;
-import static com.google.devtools.build.lib.packages.BuildType.LABEL;
-
-import com.google.devtools.build.lib.analysis.BaseRuleClasses;
-import com.google.devtools.build.lib.analysis.RuleDefinition;
-import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment;
-import com.google.devtools.build.lib.packages.RuleClass;
-import com.google.devtools.build.lib.packages.RuleClass.Builder;
-
-/** Rule definition for the {@code android_instrumentation} rule. */
-public class AndroidInstrumentationRule implements RuleDefinition {
- @Override
- public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
- return builder
- .setUndocumented()
- .add(
- attr("target", LABEL)
- .allowedFileTypes(AndroidRuleClasses.APK)
- .allowedRuleClasses("android_binary"))
- .add(
- attr("target_library", LABEL)
- .allowedFileTypes()
- .allowedRuleClasses("android_library"))
- .add(
- attr("instrumentation", LABEL)
- .allowedFileTypes(AndroidRuleClasses.APK)
- .allowedRuleClasses("android_binary"))
- .add(
- attr("instrumentation_library", LABEL)
- .allowedFileTypes()
- .allowedRuleClasses("android_library"))
- .setImplicitOutputsFunction(AndroidInstrumentation.IMPLICIT_OUTPUTS_FUNCTION)
- .build();
- }
-
- @Override
- public Metadata getMetadata() {
- return RuleDefinition.Metadata.builder()
- .name("android_instrumentation")
- .ancestors(BaseRuleClasses.RuleBase.class)
- .factoryClass(AndroidInstrumentation.class)
- .build();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
index d269bf361c..82a8ecdfbb 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBuildViewTestCase.java
@@ -60,7 +60,6 @@ public abstract class AndroidBuildViewTestCase extends BuildViewTestCase {
// TODO(b/35097211): Remove this once the new testing rules are released.
.addRuleDefinition(new AndroidDeviceScriptFixtureRule())
.addRuleDefinition(new AndroidHostServiceFixtureRule())
- .addRuleDefinition(new AndroidInstrumentationRule())
.addRuleDefinition(new AndroidInstrumentationTestRule())
.build();
}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRuleImplTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRuleImplTest.java
deleted file mode 100644
index 000057a83d..0000000000
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidInstrumentationRuleImplTest.java
+++ /dev/null
@@ -1,159 +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.rules.android;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.actions.SpawnAction;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/**
- * Tests for {@link AndroidInstrumentation}.
- *
- * <p>Note that this class is not named {@code AndroidInstrumentationTest} per the usual naming
- * pattern due to a conflict with the upcoming {@link AndroidInstrumentationTest} class which
- * implements the {@code android_instrumentation_test} rule.
- */
-@RunWith(JUnit4.class)
-public class AndroidInstrumentationRuleImplTest extends AndroidBuildViewTestCase {
-
- @Before
- public void createFiles() throws Exception {
- scratch.file(
- "java/com/app/BUILD",
- "android_library(",
- " name = 'lib',",
- " manifest = 'AndroidManifest.xml',",
- ")",
- "android_binary(",
- " name = 'app',",
- " manifest = 'AndroidManifest.xml',",
- " deps = [':lib'],",
- ")");
- scratch.file(
- "javatests/com/app/BUILD",
- "android_library(",
- " name = 'lib',",
- " manifest = 'AndroidManifest.xml',",
- ")",
- "android_binary(",
- " name = 'instrumentation',",
- " manifest = 'AndroidManifest.xml',",
- " deps = [':lib'],",
- ")");
- }
-
- @Test
- public void testTargetAndInstrumentationAreBinaries() throws Exception {
- scratch.file(
- "javatests/com/app/instrumentation/BUILD",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " target = '//java/com/app',",
- " instrumentation = '//javatests/com/app:instrumentation',",
- ")");
- ConfiguredTarget instrumentation = getConfiguredTarget("//javatests/com/app/instrumentation");
- assertThat(instrumentation).isNotNull();
- AndroidInstrumentationInfo instrumentationProvider =
- instrumentation.get(AndroidInstrumentationInfo.PROVIDER);
- assertThat(instrumentationProvider.getTargetApk()).isNotNull();
- assertThat(instrumentationProvider.getTargetApk().prettyPrint())
- .isEqualTo("javatests/com/app/instrumentation/instrumentation-target.apk");
- assertThat(instrumentationProvider.getInstrumentationApk()).isNotNull();
- assertThat(instrumentationProvider.getInstrumentationApk().prettyPrint())
- .isEqualTo("javatests/com/app/instrumentation/instrumentation-instrumentation.apk");
- }
-
- // TODO(b/37856762): Re-enable and expand on this test when android_instrumentation is fullly
- // implemented to build APKs from libraries.
- @Ignore
- @Test
- public void testTargetAndInstrumentationAreLibraries() throws Exception {
- scratch.file(
- "javatests/com/app/instrumentation/BUILD",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " target_library = '//java/com/app:lib',",
- " instrumentation_library = '//javatests/com/app:lib',",
- ")");
- ConfiguredTarget instrumentation = getConfiguredTarget("//javatests/com/app/instrumentation");
- assertThat(instrumentation).isNotNull();
- AndroidInstrumentationInfo instrumentationProvider =
- instrumentation.get(AndroidInstrumentationInfo.PROVIDER);
-
- Artifact targetApk = instrumentationProvider.getTargetApk();
- assertThat(targetApk).isNotNull();
- assertThat(targetApk.prettyPrint())
- .isEqualTo("javatests/com/app/instrumentation/instrumentation-target.apk");
- SpawnAction targetSpawnAction = getGeneratingSpawnAction(targetApk);
- assertThat(targetSpawnAction).isNotNull();
-
- Artifact instrumentationApk = instrumentationProvider.getInstrumentationApk();
- assertThat(instrumentationApk).isNotNull();
- assertThat(instrumentationApk.prettyPrint())
- .isEqualTo("javatests/com/app/instrumentation/instrumentation-instrumentation.apk");
- SpawnAction instrumentationSpawnAction = getGeneratingSpawnAction(instrumentationApk);
- assertThat(instrumentationSpawnAction).isNotNull();
- }
-
- @Test
- public void testInvalidAttributeCombinations() throws Exception {
- checkError(
- "javatests/com/app/instrumentation1",
- "instrumentation",
- "android_instrumentation requires that exactly one of the instrumentation and "
- + "instrumentation_library attributes be specified.",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " target = '//java/com/app',",
- ")");
- checkError(
- "javatests/com/app/instrumentation2",
- "instrumentation",
- "android_instrumentation requires that exactly one of the instrumentation and "
- + "instrumentation_library attributes be specified.",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " target = '//java/com/app',",
- " instrumentation = '//javatests/com/app:instrumentation',",
- " instrumentation_library = '//javatests/com/app:lib',",
- ")");
- checkError(
- "javatests/com/app/instrumentation3",
- "instrumentation",
- "android_instrumentation requires that exactly one of the target and target_library "
- + "attributes be specified.",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " instrumentation = '//javatests/com/app:instrumentation',",
- ")");
- checkError(
- "javatests/com/app/instrumentation4",
- "instrumentation",
- "android_instrumentation requires that exactly one of the target and target_library "
- + "attributes be specified.",
- "android_instrumentation(",
- " name = 'instrumentation',",
- " target = '//java/com/app',",
- " target_library = '//java/com/app:lib',",
- " instrumentation = '//javatests/com/app:instrumentation',",
- ")");
- }
-}
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 2e9887367f..d404030666 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
@@ -167,24 +167,6 @@ java_test(
)
java_test(
- name = "AndroidInstrumentationRuleImplTest",
- srcs = ["AndroidInstrumentationRuleImplTest.java"],
- deps = [
- ":AndroidBuildViewTestCase",
- "//src/main/java/com/google/devtools/build/lib:android-rules",
- "//src/main/java/com/google/devtools/build/lib:build-base",
- "//src/main/java/com/google/devtools/build/lib:packages-internal",
- "//src/main/java/com/google/devtools/build/lib/actions",
- "//src/main/java/com/google/devtools/build/lib/vfs",
- "//src/test/java/com/google/devtools/build/lib:analysis_testutil",
- "//src/test/java/com/google/devtools/build/lib:testutil",
- "//third_party:guava",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
name = "AndroidInstrumentationTestTest",
srcs = ["AndroidInstrumentationTestTest.java"],
tags = ["no_windows"],