aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java
diff options
context:
space:
mode:
authorGravatar asteinb <asteinb@google.com>2018-04-09 12:05:34 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-09 12:06:47 -0700
commit5a722f3333e32a5b1bdad401c7121079d4a803c3 (patch)
treeea1d9e1fbae100b6dbe52142747f80395992b235 /src/test/java
parent3827f0a6bdd11dc63df57dc81d7df921bec7ba1f (diff)
Remove overly optimistic decoupled manifest processing
In earlier changes, I introduced an idealised manifest processing pipeline that has no relation to what's currently being used. Instead, we should start with independent manifest processing that keeps the current behavior. We can migrate to new functionality later, time permitting. Keep some methods that will be the basis for a reasonable decoupled manifest processing implementation. RELNOTES: none PiperOrigin-RevId: 192164028
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java96
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestTest.java158
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD31
4 files changed, 1 insertions, 286 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java
deleted file mode 100644
index 8c912cbb10..0000000000
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestInfoTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2018 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.analysis.util.BuildViewTestCase;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests that the AndroidManifestInfo can be moved between Native and Skylark code */
-@RunWith(JUnit4.class)
-public class AndroidManifestInfoTest extends BuildViewTestCase {
- @Test
- public void testGetProvider() throws Exception {
- AndroidManifestInfo info =
- getInfoFromSkylark("manifest=manifest, package='some.pkg', is_dummy=True");
-
- assertThat(info.getManifest()).isNotNull();
- assertThat(info.getManifest().getFilename()).isEqualTo("AndroidManifest.xml");
- assertThat(info.getPackage()).isEqualTo("some.pkg");
- assertThat(info.isDummy()).isTrue();
- }
-
- @Test
- public void testGetProvider_isDummyOptional() throws Exception {
- AndroidManifestInfo info = getInfoFromSkylark("manifest=manifest, package='some.pkg'");
-
- assertThat(info.getManifest()).isNotNull();
- assertThat(info.getManifest().getFilename()).isEqualTo("AndroidManifest.xml");
- assertThat(info.getPackage()).isEqualTo("some.pkg");
- assertThat(info.isDummy()).isFalse();
- }
-
- @Test
- public void testGetProviderInSkylark() throws Exception {
- scratch.file(
- "java/skylark/test/rule.bzl",
- "def impl(ctx):",
- " manifest = ctx.actions.declare_file('AndroidManifest.xml')",
- " ctx.actions.write(manifest, 'some values')",
- " info = AndroidManifestInfo(manifest=manifest, package='some.pkg', is_dummy=True)",
- // Prove that we can access the fields of the provider within Skylark by making a new
- // provider from the contents of the current one.
- " return [AndroidManifestInfo(",
- " manifest=info.manifest, package=info.package, is_dummy=info.is_dummy)]",
- "test_rule = rule(implementation=impl)");
-
- AndroidManifestInfo copied =
- scratchConfiguredTarget(
- "java/skylark/test",
- "rule",
- "load(':rule.bzl', 'test_rule')",
- "test_rule(name='rule')")
- .get(AndroidManifestInfo.PROVIDER);
-
- assertThat(copied).isNotNull();
- assertThat(copied.getManifest()).isNotNull();
- assertThat(copied.getManifest().getFilename()).isEqualTo("AndroidManifest.xml");
- assertThat(copied.getPackage()).isEqualTo("some.pkg");
- assertThat(copied.isDummy()).isTrue();
- }
-
- private AndroidManifestInfo getInfoFromSkylark(String infoArgs) throws Exception {
- scratch.file(
- "java/skylark/test/rule.bzl",
- "def impl(ctx):",
- " manifest = ctx.actions.declare_file('AndroidManifest.xml')",
- " ctx.actions.write(manifest, 'some values')",
- " return [AndroidManifestInfo(" + infoArgs + ")]",
- "test_rule = rule(implementation=impl)");
-
- AndroidManifestInfo info =
- scratchConfiguredTarget(
- "java/skylark/test",
- "rule",
- "load(':rule.bzl', 'test_rule')",
- "test_rule(name='rule')")
- .get(AndroidManifestInfo.PROVIDER);
- assertThat(info).isNotNull();
-
- return info;
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestTest.java
deleted file mode 100644
index eda59fd95b..0000000000
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidManifestTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright 2018 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 com.google.devtools.build.lib.testutil.MoreAsserts.assertThrows;
-
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.ConfiguredTarget;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
-import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
-import com.google.devtools.build.lib.events.StoredEventHandler;
-import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
-import java.io.IOException;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests the AndroidManifest class */
-@RunWith(JUnit4.class)
-public class AndroidManifestTest extends BuildViewTestCase {
- private static final String DEFAULT_PATH = "prefix/java/com/google/foo/bar";
- private static final String DEFAULT_PACKAGE = "com.google.foo.bar";
-
- @Test
- public void testGetDefaultPackage() throws Exception {
- RuleContext ctx = makeContext();
- assertThat(AndroidManifest.getDefaultPackage(ctx)).isEqualTo(DEFAULT_PACKAGE);
- ctx.assertNoErrors();
- }
-
- @Test
- public void testGetDefaultPackage_NoJavaDir() throws Exception {
- RuleContext ctx = makeContext("notjava/com/google/foo/bar");
- AndroidManifest.getDefaultPackage(ctx);
- assertThrows(RuleErrorException.class, ctx::assertNoErrors);
- }
-
- @Test
- public void testIsDummy() throws Exception {
- RuleContext ctx = makeContext();
- assertThat(AndroidManifest.of(ctx, /* manifest = */ null, DEFAULT_PACKAGE).isDummy()).isTrue();
- assertThat(AndroidManifest.of(ctx, ctx.createOutputArtifact(), DEFAULT_PACKAGE).isDummy())
- .isFalse();
- }
-
- @Test
- public void testStampAndMergeWith_NoDeps() throws Exception {
- AndroidManifest manifest = AndroidManifest.empty(makeContext());
-
- StampedAndroidManifest stamped = manifest.stampAndMergeWith(ImmutableList.of());
- assertThat(stamped).isNotEqualTo(manifest);
- assertThat(stamped.getPackage()).isEqualTo(DEFAULT_PACKAGE);
- assertThat(stamped.getManifest()).isNotNull();
- assertThat(stamped.isDummy()).isTrue();
-
- // The merge should still do a stamp, so future stamping should be a no-op.
- assertThat(stamped).isSameAs(stamped.stamp());
- }
-
- @Test
- public void testStampAndMergeWith_NoProviders() throws Exception {
- AndroidManifest manifest = AndroidManifest.empty(makeContext());
-
- AndroidManifest merged = manifest.stampAndMergeWith(getDeps("[]"));
-
- assertThat(merged.getManifest()).isNotNull();
- assertThat(merged.isDummy()).isTrue();
- assertThat(merged.getPackage()).isEqualTo(DEFAULT_PACKAGE);
-
- // The merge should still do a stamp, so future stamping should be a no-op.
- assertThat(merged).isSameAs(merged.stamp());
- }
-
- @Test
- public void testStampAndMergeWith_DummyProviders() throws Exception {
- AndroidManifest manifest = AndroidManifest.empty(makeContext());
-
- AndroidManifest merged =
- manifest.stampAndMergeWith(
- getDeps("[AndroidManifestInfo(manifest=manifest, package='com.pkg', is_dummy=True)]"));
-
- assertThat(merged.getManifest()).isNotNull();
- assertThat(merged.isDummy()).isTrue();
- assertThat(merged.getPackage()).isEqualTo(DEFAULT_PACKAGE);
-
- // The merge should still do a stamp, so future stamping should be a no-op.
- assertThat(merged).isSameAs(merged.stamp());
- }
-
- @Test
- public void testStampAndMergeWith() throws Exception {
- AndroidManifest manifest = AndroidManifest.empty(makeContext());
-
- AndroidManifest merged =
- manifest.stampAndMergeWith(
- getDeps("[AndroidManifestInfo(manifest=manifest, package='com.pkg', is_dummy=False)]"));
-
- // Merging results in a new, non-dummy manifest with the same package
- assertThat(merged).isNotEqualTo(manifest);
- assertThat(merged.getManifest()).isNotNull();
- assertThat(merged.getPackage()).isEqualTo(manifest.getPackage());
- assertThat(merged.isDummy()).isFalse();
-
- // Merging should implicitly stamp
- assertThat(merged).isSameAs(merged.stamp());
- }
-
- private ImmutableList<ConfiguredTarget> getDeps(String returnList)
- throws IOException, LabelSyntaxException {
- scratch.file(
- "skylark/rule.bzl",
- "def impl(ctx):",
- " manifest = ctx.actions.declare_file(ctx.attr.name + 'AndroidManifest.xml')",
- " ctx.actions.write(manifest, 'some values')",
- " return " + returnList,
- "test_rule = rule(implementation=impl)");
-
- scratch.file(
- "skylark/BUILD",
- "load(':rule.bzl', 'test_rule')",
- "test_rule(name='dep1')",
- "test_rule(name='dep2')",
- "test_rule(name='dep3')");
-
- return ImmutableList.of(
- getConfiguredTarget("//skylark:dep1"),
- getConfiguredTarget("//skylark:dep2"),
- getConfiguredTarget("//skylark:dep3"));
- }
-
- private RuleContext makeContext() throws Exception {
- return makeContext(DEFAULT_PATH);
- }
-
- private RuleContext makeContext(String pkg) throws Exception {
- // Use BuildView's getRuleContextForTesting method, rather than BuildViewTestCase's
- // getRuleContext method, to avoid the StubEventHandler used by the latter, which prevents us
- // from declaring new artifacts within code called from the test.
- return view.getRuleContextForTesting(
- scratchConfiguredTarget(pkg, "lib", "android_library(name = 'lib')"),
- new StoredEventHandler(),
- masterConfig);
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java
index fdb5794913..cf25120a8e 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidResourcesTest.java
@@ -291,7 +291,7 @@ public class AndroidResourcesTest extends ResourceTestBase {
new AndroidResources(
resources, AndroidResources.getResourceRoots(ruleContext, resources, "resource_files"));
StampedAndroidManifest manifest =
- new StampedAndroidManifest(ruleContext, getManifest(), "some.java.pkg", false);
+ new StampedAndroidManifest(getManifest(), "some.java.pkg");
ParsedAndroidResources parsed = raw.parse(ruleContext, manifest);
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 6eab50b80f..f00d1e9941 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
@@ -333,37 +333,6 @@ java_library(
)
java_test(
- name = "AndroidManifestInfoTest",
- srcs = ["AndroidManifestInfoTest.java"],
- runtime_deps = ["//src/test/java/com/google/devtools/build/lib:testutil"],
- deps = [
- "//src/main/java/com/google/devtools/build/lib:android-rules",
- "//src/main/java/com/google/devtools/build/lib:build-base",
- "//src/test/java/com/google/devtools/build/lib:analysis_testutil",
- "//third_party:junit4",
- "//third_party:truth",
- ],
-)
-
-java_test(
- name = "AndroidManifestTest",
- srcs = ["AndroidManifestTest.java"],
- runtime_deps = ["//src/test/java/com/google/devtools/build/lib:testutil"],
- deps = [
- "//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:events",
- "//src/main/java/com/google/devtools/build/lib:packages-internal",
- "//src/main/java/com/google/devtools/build/lib/cmdline",
- "//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 = "AndroidDataConverterTest",
srcs = ["AndroidDataConverterTest.java"],
runtime_deps = ["//src/test/java/com/google/devtools/build/lib:testutil"],