From 32243cbe980ebea1e09d60f0cccbb27cc0d40175 Mon Sep 17 00:00:00 2001 From: dannark Date: Thu, 22 Feb 2018 22:15:42 -0800 Subject: [PATCH] Remove top level resources and assets from android_local_test. android_local_test should not allow specifying resources and assets on the rule itself. If a user wants to add test specific resources/assets then they should wrap them in an android_library and add it to the deps of the android_local_test. RELNOTES: None PiperOrigin-RevId: 186724709 --- .../build/lib/rules/android/AndroidCommon.java | 7 +++++-- .../rules/android/AndroidLocalTestBaseRule.java | 10 ---------- .../lib/rules/android/LocalResourceContainer.java | 14 +++++++++++++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java index 7d2bb6a7c774be..871e36263c3a28 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java @@ -792,8 +792,11 @@ private Runfiles getRunfiles() { } public static PathFragment getAssetDir(RuleContext ruleContext) { - return PathFragment.create( - ruleContext.attributes().get(ResourceType.ASSETS.getAttribute() + "_dir", Type.STRING)); + if (ruleContext.attributes().has(ResourceType.ASSETS.getAttribute() + "_dir")) { + return PathFragment.create( + ruleContext.attributes().get(ResourceType.ASSETS.getAttribute() + "_dir", Type.STRING)); + } + return PathFragment.EMPTY_FRAGMENT; } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBaseRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBaseRule.java index 068b5de5525f3f..fa6074ea33f36e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBaseRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestBaseRule.java @@ -16,7 +16,6 @@ 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_KEYED_STRING_DICT; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; import static com.google.devtools.build.lib.rules.android.AndroidRuleClasses.getAndroidSdkLabel; import static com.google.devtools.build.lib.syntax.Type.STRING; import static com.google.devtools.build.lib.syntax.Type.STRING_DICT; @@ -136,15 +135,6 @@ public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) { you will likely need to use test_class as well. */ .add(attr("custom_package", STRING)) - .add( - attr("resource_files", LABEL_LIST) - .allowedFileTypes(FileTypeSet.ANY_FILE) - .undocumented("soon to be unsupported behavior")) - .add(attr("assets_dir", STRING).undocumented("soon to be unsupported behavior")) - .add( - attr("assets", LABEL_LIST) - .allowedFileTypes(FileTypeSet.ANY_FILE) - .undocumented("soon to be unsupported behavior")) .build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java index e1c0a4b1e4b75a..68806fcf936498 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java @@ -132,6 +132,12 @@ private static void validateManifest(RuleContext ruleContext) throws RuleErrorEx public static LocalResourceContainer forAssetsAndResources( RuleContext ruleContext, String assetsAttr, PathFragment assetsDir, String resourcesAttr) throws RuleErrorException { + + if (!hasLocalResourcesAttributes(ruleContext)) { + return new LocalResourceContainer( + ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of()); + } + ImmutableList.Builder assets = ImmutableList.builder(); ImmutableList.Builder assetRoots = ImmutableList.builder(); @@ -158,13 +164,19 @@ public static LocalResourceContainer forAssetsAndResources( } ImmutableList resources = - getResources(ruleContext.getPrerequisites(resourcesAttr, Mode.TARGET, FileProvider.class)); + getResources( + ruleContext.getPrerequisites(resourcesAttr, Mode.TARGET, FileProvider.class)); return new LocalResourceContainer( resources, getResourceRoots(ruleContext, resources, resourcesAttr), assets.build(), assetRoots.build()); + + } + + private static boolean hasLocalResourcesAttributes(RuleContext ruleContext) { + return ruleContext.attributes().has("assets") || ruleContext.attributes().has("resource_files"); } /**