Skip to content

Commit

Permalink
Clean up OSS BUILD files for Android tools
Browse files Browse the repository at this point in the history
All of the tools under src/tools/j/c/g/devtools/build/android now compile.

PiperOrigin-RevId: 684538728
Change-Id: Ic50545cc02c3b38f860f742f15d3d98f8aa289f1
  • Loading branch information
ted-xie authored and copybara-github committed Oct 10, 2024
1 parent b975477 commit 4dc0485
Show file tree
Hide file tree
Showing 26 changed files with 968 additions and 951 deletions.
45 changes: 40 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ git_override(
rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
use_repo(rules_java_toolchains, "remote_java_tools")

bazel_dep(name = "protobuf", version = "3.19.0", repo_name = "com_google_protobuf")
bazel_dep(name = "protobuf", version = "28.2", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_jvm_external", version = "6.2")
bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "rules_robolectric", version = "4.11.1", repo_name = "robolectric")
Expand All @@ -34,6 +34,8 @@ bazel_dep(name = "rules_go", version = "0.48.0", repo_name = "io_bazel_rules_go"
bazel_dep(name = "gazelle", version = "0.28.0", repo_name = "bazel_gazelle")
bazel_dep(name = "abseil-py", version = "1.4.0", repo_name = "py_absl")

bazel_dep(name = "bazel_worker_java", version = "0.0.1")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")

go_sdk.download(version = "1.22.4")
Expand All @@ -58,7 +60,7 @@ python.toolchain(
)

# proto-related dependency setup
bazel_dep(name = "rules_proto", version = "6.0.0", repo_name = "rules_proto")
bazel_dep(name = "rules_proto", version = "6.0.2", repo_name = "rules_proto")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
Expand All @@ -69,29 +71,62 @@ maven.install(
"androidx.privacysandbox.tools:tools-apipackager:1.0.0-alpha06",
"androidx.test:core:1.6.0-alpha01",
"androidx.test.ext:junit:1.2.0-alpha01",
"com.android.tools.build:apksig:8.3.0-alpha18",
"org.gradle:gradle-core:4.2.1",
"com.android.tools.build:bundletool:1.15.5",
"com.android.tools:desugar_jdk_libs_minimal:2.0.4",
"com.android.tools:desugar_jdk_libs_configuration_minimal:2.0.4",
"com.android.tools:desugar_jdk_libs_nio:2.0.4",
"com.android.tools:desugar_jdk_libs_configuration_nio:2.0.4",
"com.android.tools.build:gradle:8.2.0-alpha15",
"com.android.tools.build:gradle:8.7.0",
"org.bouncycastle:bcprov-jdk18on:1.77",
"org.hamcrest:hamcrest-core:2.2",
"org.robolectric:robolectric:4.10.3",
"com.google.flogger:flogger:0.8",
"com.google.guava:guava:32.1.2-jre",
"com.google.protobuf:protobuf-java-util:3.9.2",
"com.google.truth:truth:1.1.5",
"info.picocli:picocli:4.7.4",
"jakarta.inject:jakarta.inject-api:2.0.1",
"junit:junit:4.13.2",
"com.beust:jcommander:1.82",
"com.google.protobuf:protobuf-java:4.28.2",
"com.google.code.findbugs:jsr305:3.0.2",
"androidx.databinding:databinding-compiler:8.7.0",
"org.ow2.asm:asm:9.6",
"org.ow2.asm:asm-commons:9.6",
"org.ow2.asm:asm-tree:9.6",
"org.ow2.asm:asm-util:9.6",
"com.android.tools.layoutlib:layoutlib-api:30.1.3",
"com.android:zipflinger:8.7.0",
"com.android.tools.build:manifest-merger:30.1.3",
"com.android:signflinger:8.7.0",
"com.android.tools.build:aapt2-proto:8.6.1-11315950",
"com.android.tools.analytics-library:protos:30.1.3",
"com.android.tools.analytics-library:shared:30.1.3",
"com.android.tools.analytics-library:tracker:30.1.3",
"com.android.tools:annotations:30.1.3",
"com.android.tools.build:apksig:8.7.0",
"com.android.tools.build:apkzlib:8.7.0",
"com.android.tools.build:builder:8.7.0",
"com.android.tools.build:builder-model:8.7.0",
"com.google.auto.value:auto-value:1.11.0",
"com.google.auto.value:auto-value-annotations:1.11.0",
"com.google.auto:auto-common:1.2.2",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.errorprone:error_prone_annotations:2.33.0",
"com.google.errorprone:error_prone_type_annotations:2.33.0",
"com.google.errorprone:error_prone_check_api:2.33.0",
"com.google.errorprone:error_prone_core:2.33.0",
],
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
"https://repo.gradle.org/gradle/libs-releases",
],
# To generate, run:
# REPIN=1 bazelisk run --enable_bzlmod @rules_android_maven//:pin
lock_file = "//:rules_android_maven_install.json",
# lock_file = "//:rules_android_maven_install.json",
use_starlark_android_rules = True,
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
)
Expand Down
37 changes: 35 additions & 2 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,58 @@ def rules_android_workspace():
"androidx.privacysandbox.tools:tools-apipackager:1.0.0-alpha06",
"androidx.test:core:1.6.0-alpha01",
"androidx.test.ext:junit:1.2.0-alpha01",
"com.android.tools.build:apksig:8.3.0-alpha18",
"org.gradle:gradle-core:4.2.1",
"com.android.tools.build:bundletool:1.15.5",
"com.android.tools:desugar_jdk_libs_minimal:2.0.4",
"com.android.tools:desugar_jdk_libs_configuration_minimal:2.0.4",
"com.android.tools:desugar_jdk_libs_nio:2.0.4",
"com.android.tools:desugar_jdk_libs_configuration_nio:2.0.4",
"com.android.tools.build:gradle:8.2.0-alpha15",
"com.android.tools.build:gradle:8.7.0",
"org.bouncycastle:bcprov-jdk18on:1.77",
"org.hamcrest:hamcrest-core:2.2",
"org.robolectric:robolectric:4.10.3",
"com.google.flogger:flogger:0.8",
"com.google.guava:guava:32.1.2-jre",
"com.google.protobuf:protobuf-java-util:3.9.2",
"com.google.truth:truth:1.1.5",
"info.picocli:picocli:4.7.4",
"jakarta.inject:jakarta.inject-api:2.0.1",
"junit:junit:4.13.2",
"com.beust:jcommander:1.82",
"com.google.protobuf:protobuf-java:4.28.2",
"com.google.code.findbugs:jsr305:3.0.2",
"androidx.databinding:databinding-compiler:8.7.0",
"org.ow2.asm:asm:9.6",
"org.ow2.asm:asm-commons:9.6",
"org.ow2.asm:asm-tree:9.6",
"org.ow2.asm:asm-util:9.6",
"com.android.tools.layoutlib:layoutlib-api:30.1.3",
"com.android:zipflinger:8.7.0",
"com.android.tools.build:manifest-merger:30.1.3",
"com.android:signflinger:8.7.0",
"com.android.tools.build:aapt2-proto:8.6.1-11315950",
"com.android.tools.analytics-library:protos:30.1.3",
"com.android.tools.analytics-library:shared:30.1.3",
"com.android.tools.analytics-library:tracker:30.1.3",
"com.android.tools:annotations:30.1.3",
"com.android.tools.build:apksig:8.7.0",
"com.android.tools.build:apkzlib:8.7.0",
"com.android.tools.build:builder:8.7.0",
"com.android.tools.build:builder-model:8.7.0",
"com.google.auto.value:auto-value:1.11.0",
"com.google.auto.value:auto-value-annotations:1.11.0",
"com.google.auto:auto-common:1.2.2",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
"com.google.errorprone:error_prone_annotations:2.33.0",
"com.google.errorprone:error_prone_type_annotations:2.33.0",
"com.google.errorprone:error_prone_check_api:2.33.0",
"com.google.errorprone:error_prone_core:2.33.0",
],
repositories = [
"https://repo1.maven.org/maven2",
"https://maven.google.com",
"https://repo.gradle.org/gradle/libs-releases",
],
use_starlark_android_rules = True,
aar_import_bzl_label = "@rules_android//rules:rules.bzl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,19 +252,6 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
.put(640, Density.XXXHIGH)
.buildOrThrow();

// NO-BAZEL-EXPORT BEGIN
// Use a fully-qualified class reference as this is not available on bazel
private static final ImmutableMap<
Configuration.GrammaticalGender, com.android.resources.GrammaticalGender>
GRAMMATICAL_GENDER_MAP =
ImmutableMap.of(
Configuration.GrammaticalGender.GRAM_GENDER_NEUTER,
com.android.resources.GrammaticalGender.NEUTER,
Configuration.GrammaticalGender.GRAM_GENDER_FEMININE,
com.android.resources.GrammaticalGender.FEMININE,
Configuration.GrammaticalGender.GRAM_GENDER_MASCULINE,
com.android.resources.GrammaticalGender.MASCULINE);
// NO-BAZEL-EXPORT END

private final boolean includeFileContentsForValidation;

Expand Down Expand Up @@ -529,14 +516,6 @@ private static List<String> convertToQualifiers(Configuration protoConfig) {
configuration.setVersionQualifier(new VersionQualifier(protoConfig.getSdkVersion()));
}

// NO-BAZEL-EXPORT BEGIN
// Use a fully-qualified class reference as this is not available on bazel
if (GRAMMATICAL_GENDER_MAP.containsKey(protoConfig.getGrammaticalGender())) {
configuration.setGrammaticalGenderQualifier(
new com.android.ide.common.resources.configuration.GrammaticalGenderQualifier(
GRAMMATICAL_GENDER_MAP.get(protoConfig.getGrammaticalGender())));
}
// NO-BAZEL-EXPORT END

return Arrays.stream(configuration.getQualifiers())
.map(ResourceQualifier::getFolderSegment)
Expand Down
176 changes: 176 additions & 0 deletions src/tools/java/com/google/devtools/build/android/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Actions for Android rules.

load("@rules_java//java:defs.bzl", "java_binary", "java_import", "java_library")

package(default_visibility = ["//visibility:public"])

# Used by //src/test/shell/bazel/android:android_integration_test
java_binary(
name = "ResourceProcessorBusyBox",
main_class = "com.google.devtools.build.android.ResourceProcessorBusyBox",
runtime_deps = [
":android_builder_lib",
],
)

java_binary(
name = "ZipFilterAction",
# Memory consumption of SingleJar is about 250 bytes per entry in the output file. Unfortunately,
# the JVM tends to kill the process with an OOM long before we're at the limit. In the most
# recent example, 400 MB of memory was enough for about 500,000 entries.
jvm_flags = ["-Xmx1600m"],
main_class = "com.google.devtools.build.android.ZipFilterAction",
visibility = ["//visibility:private"],
runtime_deps = [":android_builder_lib"],
)

genrule(
name = "zip_jar_gen",
srcs = ["@android_tools//:all_android_tools_deploy.jar"],
outs = ["zip.jar"],
cmd = "unzip -q $< 'com/google/devtools/build/zip/*.class' && zip $@ $$(find . -name \"*.class\")",
)

java_import(
name = "zip_jar",
jars = [":zip_jar_gen"],
)

genrule(
name = "singlejar_jar_gen",
srcs = ["@android_tools//:all_android_tools_deploy.jar"],
outs = ["singlejar.jar"],
cmd = "unzip -q $< 'com/google/devtools/build/singlejar/*.class' && zip $@ $$(find . -name \"*.class\")",
)

java_import(
name = "singlejar_jar",
jars = [":singlejar_jar_gen"],
)

genrule(
name = "databinding_exec_jar_gen",
srcs = ["@android_tools//:all_android_tools_deploy.jar"],
outs = ["databinding_exec.jar"],
cmd = "unzip -q $< 'android/databinding/*.class' && zip $@ $$(find . -name \"*.class\")",
)

java_import(
name = "databinding_exec_jar",
jars = [":databinding_exec_jar_gen"],
)

java_library(
name = "android_databinding_wrapper_lib",
srcs = [
"AndroidDataBindingWrapper.java",
"ProcessXmlOptionsWrapper.java",
],
deps = [
":databinding_exec_jar",
],
)

java_library(
name = "android_builder_lib",
srcs = glob(
[
"*.java",
"xml/*.java",
"aapt2/*.java",
],
exclude = [
"AndroidOptionsUtils.java",
"DependencyInfo.java",
"CompatShellQuotedParamsFileProcessor.java",
"AndroidDataBindingWrapper.java",
"ProcessXmlOptionsWrapper.java",
],
),
javacopts = [
"--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED",
],
exports = [
# Separated out to avoid a dependency cycle with resources/, but it logically belongs here.
":dependency_info",
],
deps = [
":android_common_30_1_3",
":android_common_jar",
":android_databinding_wrapper_lib",
":android_options_utils",
":dependency_info",
":singlejar_jar",
":zip_jar",
"//src/tools/java/com/google/devtools/build/android/junctions",
"//src/tools/java/com/google/devtools/build/android/proto:resources_java_proto",
"//src/tools/java/com/google/devtools/build/android/proto:serialize_format_java_pb",
"//src/tools/java/com/google/devtools/build/android/resources",
"//src/tools/java/com/google/devtools/build/android/ziputils:ziputils_lib",
"//tools/android:autovalue",
"@bazel_tools//src/main/protobuf:worker_protocol_java_proto",
"@bazel_worker_java//src/main/java/com/google/devtools/build/lib/worker:work_request_handlers",
"@rules_android_maven//:com_beust_jcommander",
"@rules_android_maven//:com_google_code_findbugs_jsr305",
"@rules_android_maven//:com_google_errorprone_error_prone_annotations",
"@rules_android_maven//:com_google_guava_guava",
"@rules_android_maven//:com_google_protobuf_protobuf_java",
"@rules_android_maven//:org_gradle_gradle_core",
],
)

java_library(
name = "dependency_info",
srcs = ["DependencyInfo.java"],
visibility = [":__subpackages__"],
deps = [
"//tools/android:autovalue",
],
)

genrule(
name = "android_common_jar_gen",
srcs = ["@android_tools//:all_android_tools_deploy.jar"],
outs = ["android_common_exec.jar"],
cmd = "unzip -q $< 'com/android/*.class' && zip $@ $$(find . -name \"*.class\")",
)

java_import(
name = "android_common_jar",
jars = [
":android_common_jar_gen",
],
)

java_library(
name = "android_common_30_1_3",
runtime_deps = [
":android_common_jar",
"@rules_android_maven//:com_android_tools_build_aapt2_proto",
"@rules_android_maven//:org_ow2_asm_asm",
"@rules_android_maven//:org_ow2_asm_asm_commons",
"@rules_android_maven//:org_ow2_asm_asm_tree",
"@rules_android_maven//:org_ow2_asm_asm_util",
],
)

java_library(
name = "android_options_utils",
srcs = [
"AndroidOptionsUtils.java",
"CompatShellQuotedParamsFilePreProcessor.java",
],
visibility = [
"//src/test/java/com/google/devtools/build/android:__pkg__",
"//src/tools/java/com/google/devtools/build/android/desugar/scan:__pkg__",
"//src/tools/java/com/google/devtools/build/android/dexer:__pkg__",
"//src/tools/java/com/google/devtools/build/android/idlclass:__pkg__",
"//src/tools/java/com/google/devtools/build/android/r8:__pkg__",
"//src/tools/java/com/google/devtools/build/android/ziputils:__pkg__",
],
deps = [
"@rules_android_maven//:com_beust_jcommander",
"@rules_android_maven//:com_google_code_findbugs_jsr305",
"@rules_android_maven//:com_google_guava_guava",
],
)
Loading

0 comments on commit 4dc0485

Please sign in to comment.