Skip to content

Commit

Permalink
Remove top level resources and assets from android_local_test.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dkelmer authored and Copybara-Service committed Feb 23, 2018
1 parent 040cd66 commit 32243cb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,15 +135,6 @@ public RuleClass build(Builder builder, RuleDefinitionEnvironment environment) {
you will likely need to use <code>test_class</code> as well.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
.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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Artifact> assets = ImmutableList.builder();
ImmutableList.Builder<PathFragment> assetRoots = ImmutableList.builder();

Expand All @@ -158,13 +164,19 @@ public static LocalResourceContainer forAssetsAndResources(
}

ImmutableList<Artifact> 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");
}

/**
Expand Down

0 comments on commit 32243cb

Please sign in to comment.