Skip to content

Commit

Permalink
[feature] Add manifest and resourceFolders to AndroidBuildTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
gottagofaster236 authored and Space Team committed Feb 9, 2024
1 parent 0cc0014 commit 2989f70
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
19 changes: 17 additions & 2 deletions aspects/rules/android/android_info.bzl
Expand Up @@ -17,13 +17,27 @@ def extract_android_info(target, ctx, dep_targets, **kwargs):
manifest = None
if AndroidIdeInfo in target:
android_ide_info = target[AndroidIdeInfo]
manifest = file_location(target[AndroidIdeInfo].manifest)
manifest = file_location(android_ide_info.manifest)

resources = []
resource_folders_set = {}
if hasattr(ctx.rule.attr, "resource_files"):
for resource in ctx.rule.attr.resource_files:
for resource_file in resource.files.to_list():
resources.append(file_location(resource_file))
resource_file_location = file_location(resource_file)
resources.append(resource_file_location)
resource_source_dir_relative_path = android_common.resource_source_directory(resource_file)
if resource_source_dir_relative_path == None:
continue
resource_source_dir_location = struct(
relative_path = resource_source_dir_relative_path,
is_source = resource_file_location.is_source,
is_external = resource_file_location.is_external,
root_execution_path_fragment = resource_file_location.root_execution_path_fragment,
)

# Add to set
resource_folders_set[resource_source_dir_location] = None

kotlin_target_id = None
if ctx.rule.kind == "android_library" and str(target.label).endswith("_base") and not ctx.rule.attr.srcs:
Expand All @@ -36,6 +50,7 @@ def extract_android_info(target, ctx, dep_targets, **kwargs):
android_jar = android_jar,
manifest = manifest,
resources = resources,
resource_folders = resource_folders_set.keys(),
kotlin_target_id = kotlin_target_id,
)

Expand Down
Expand Up @@ -15,5 +15,7 @@ public enum class AndroidTargetType(public val value: Int) {
public data class AndroidBuildTarget(
val androidJar: URI,
val androidTargetType: AndroidTargetType,
val manifest: URI?,
val resourceFolders: List<URI>,
var jvmBuildTarget: JvmBuildTarget? = null,
)
Expand Up @@ -480,14 +480,8 @@ class BazelProjectMapper(
private fun resolveAndroidResources(target: TargetInfo): Set<URI> {
if (!target.hasAndroidTargetInfo()) return emptySet()
val androidTargetInfo = target.androidTargetInfo

if (!androidTargetInfo.hasManifest()) return emptySet()

if (target.kind == "android_binary") {
// This is a hack because the Android plugin wants a folder as opposed to the manifest file itself
return setOf(bazelPathsResolver.resolve(target.androidTargetInfo.manifest).parent.toUri())
}

return bazelPathsResolver
.resolveUris(listOf(target.androidTargetInfo.manifest) + target.androidTargetInfo.resourcesList).toSet()
}
Expand Down
Expand Up @@ -20,6 +20,8 @@ class AndroidLanguagePlugin(
AndroidBuildTarget(
androidJar = androidJar,
androidTargetType = androidTargetType,
manifest = manifest,
resourceFolders = resourceFolders,
)
}
moduleData.javaModule?.let { javaLanguagePlugin.toJvmBuildTarget(it) }?.let {
Expand All @@ -35,10 +37,20 @@ class AndroidLanguagePlugin(

val androidTargetInfo = targetInfo.androidTargetInfo
val androidJar = bazelPathsResolver.resolveUri(androidTargetInfo.androidJar)
val manifest = if (androidTargetInfo.hasManifest()) {
bazelPathsResolver.resolveUri(androidTargetInfo.manifest)
} else {
null
}
val resources = bazelPathsResolver.resolveUris(androidTargetInfo.resourcesList)
val resourceFolders = bazelPathsResolver.resolveUris(androidTargetInfo.resourceFoldersList)

return AndroidModule(
androidJar = androidJar,
androidTargetType = getAndroidTargetType(targetInfo),
manifest = manifest,
resources = resources,
resourceFolders = resourceFolders,
javaModule = javaLanguagePlugin.resolveModule(targetInfo),
)
}
Expand Down
Expand Up @@ -8,5 +8,8 @@ import java.net.URI
data class AndroidModule(
val androidJar: URI,
val androidTargetType: AndroidTargetType,
val manifest: URI?,
val resources: List<URI>,
val resourceFolders: List<URI>,
val javaModule: JavaModule?,
) : LanguageData
Expand Up @@ -99,7 +99,8 @@ message AndroidTargetInfo {
FileLocation android_jar = 1;
FileLocation manifest = 2;
repeated FileLocation resources = 3;
string kotlin_target_id = 4;
repeated FileLocation resource_folders = 4;
string kotlin_target_id = 5;
}

message TargetInfo {
Expand Down

0 comments on commit 2989f70

Please sign in to comment.