Skip to content

Commit

Permalink
Migrates to Bazel 5.0 & Kotlin 1.6.
Browse files Browse the repository at this point in the history
This is early work to migrate the codebase to Bazel 5.x (and maybe 6.x),
as well as Kotlin to 1.6 (and maybe 1.7). The Kotlin migration is needed
due to an incompatibility with older rules_kotlin and Bazel 5.x. Other
dependencies needed updating, as well, including Dagger and rules_java.
Issue #1535 is being fixed as part of these upgrades.

As part of working through the Dagger issues that were encountered, it
was noticed that the codebase was actually setting up Dagger
incorrectly. This has been corrected: the codebase now defines a single
top-level dagger_rules().

This commit is not yet the final solution--the build doesn't yet work
and requires investigation before the rest of the work can be completed.

This commit partly continues the migration work from #4092 though it's
not yet finished. What remains includes:
- Migrating to latest Bazel & Kotlin versions
- If possible, modularize all third-party deps like oppia-proto-api
- Enable strict Kotlin & Java deps
- Enable warnings-as-errors for Kotlin & Java (and fix all issues)
- Ensure Guava-Android is used instead of JRE
- Resolve all Maven conflicts
- Remove dependence on Oppia's custom Android tools
- Remove support on legacy D8 (needs verification)
- Remove disabling incremental dexing (for faster builds)
- Disabling header compilation being disabled (for faster builds)
  • Loading branch information
BenHenning committed Feb 28, 2023
1 parent b7f0588 commit b05b3e4
Show file tree
Hide file tree
Showing 145 changed files with 1,512 additions and 1,519 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ build --android_databinding_use_v3_4_args \
--experimental_android_databinding_v2 \
--java_header_compilation=false \
--noincremental_dexing \
--define=android_standalone_dexing_tool=d8_compat_dx \
--android_databinding_use_androidx

# Show all test output by default (for better debugging).
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
5.0.0
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

load("//:build_flavors.bzl", "AVAILABLE_FLAVORS", "define_oppia_aab_binary_flavor", "transform_android_manifest")
load("//:version.bzl", "MAJOR_VERSION", "MINOR_VERSION", "OPPIA_DEV_KITKAT_VERSION_CODE", "OPPIA_DEV_VERSION_CODE")
load("@dagger//:workspace_defs.bzl", "dagger_rules")

# This is exported here since config/ isn't a Bazel package.
exports_files(["config/kitkat_main_dex_class_list.txt"])
Expand Down Expand Up @@ -136,3 +137,5 @@ package_group(
define_oppia_aab_binary_flavor(flavor = flavor)
for flavor in AVAILABLE_FLAVORS
]

dagger_rules()
23 changes: 12 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ load("//third_party:versions.bzl", "HTTP_DEPENDENCY_VERSIONS", "get_maven_depend
android_sdk_repository(
name = "androidsdk",
api_level = 31,
build_tools_version = "29.0.2",
build_tools_version = "32.0.0",
)

# Add support for JVM rules: https://github.com/bazelbuild/rules_jvm_external
Expand All @@ -30,16 +30,17 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % HTTP_DEPENDENCY_VERSIONS["rules_kotlin"]["version"]],
)

# TODO(#1535): Remove once rules_kotlin is released because these lines become unnecessary
load("@io_bazel_rules_kotlin//kotlin:dependencies.bzl", "kt_download_local_dev_dependencies")
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")

kt_download_local_dev_dependencies()

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()
# TODO: Verify if 1.7.20 is actually needed.
kotlin_repositories(
compiler_release = kotlinc_version(
release = "1.7.20",
sha256 = "5e3c8d0f965410ff12e90d6f8dc5df2fc09fd595a684d514616851ce7e94ae7d",
),
)

kt_register_toolchains()
register_toolchains("//third_party/kotlin:toolchain")

# The proto_compiler and proto_java_toolchain bindings load the protos rules needed for the model
# module while helping us avoid the unnecessary compilation of protoc. Referecences:
Expand Down Expand Up @@ -141,9 +142,9 @@ git_repository(
# min target SDK version to be compatible with Oppia.
git_repository(
name = "kotlitex",
commit = "6b7db8ff9e0f4a70bdaa25f482143e038fd0c301",
commit = "e261bfe6025f802534e204d3aa2991b86c4c2107",
remote = "https://github.com/oppia/kotlitex",
shallow_since = "1647554845 -0700",
shallow_since = "1673477742 -0800",
)

bind(
Expand Down
9 changes: 0 additions & 9 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ order to build with Bazel.
- All binding adapters must be written in Java.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library")
load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml")
Expand Down Expand Up @@ -612,7 +611,6 @@ kt_android_library(
srcs = LISTENERS,
custom_package = "org.oppia.android.app",
deps = [
":dagger",
"//domain/src/main/java/org/oppia/android/domain/audio:cellular_audio_dialog_controller",
"//model/src/main/proto:arguments_java_proto_lite",
"//model/src/main/proto:question_java_proto_lite",
Expand Down Expand Up @@ -657,7 +655,6 @@ kt_android_library(
srcs = ANNOTATIONS,
custom_package = "org.oppia.android.app",
deps = [
":dagger",
"//app/src/main/java/org/oppia/android/app/activity:activity_scope",
"//app/src/main/java/org/oppia/android/app/fragment:fragment_scope",
],
Expand All @@ -675,7 +672,6 @@ kt_android_library(
],
deps = [
":annotations",
":dagger",
":listeners",
":resources",
"//app/src/main/java/org/oppia/android/app/shim:intent_factory_shim",
Expand Down Expand Up @@ -719,7 +715,6 @@ android_library(
enable_data_binding = True,
manifest = "src/main/DatabindingAdaptersManifest.xml",
deps = [
":dagger",
":resources",
":view_models",
"//app/src/main/java/org/oppia/android/app/translation:app_language_activity_injector_provider",
Expand Down Expand Up @@ -758,7 +753,6 @@ kt_android_library(
visibility = ["//visibility:public"],
deps = [
":binding_adapters",
":dagger",
":databinding_resources",
":resources",
":view_models",
Expand Down Expand Up @@ -835,7 +829,6 @@ kt_android_library(
# keep sorted
TEST_DEPS = [
":app",
":dagger",
":resources",
":test_deps",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand Down Expand Up @@ -995,5 +988,3 @@ android_library(
"//third_party:io_fabric_sdk_android_fabric",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Constructs for setting up activity routing support in the Dagger graph.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

# TODO(#59): Define these exported files as separate libraries from top-level targets.
Expand All @@ -19,11 +18,9 @@ kt_android_library(
],
visibility = ["//:oppia_api_visibility"],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:arguments_java_proto_lite",
"//third_party:androidx_appcompat_appcompat",
"//utility/src/main/java/org/oppia/android/util/logging:console_logger",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Dagger graph.
Specific application implementations can be found in subpackages.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand Down Expand Up @@ -82,7 +81,6 @@ kt_android_library(
"ApplicationStartupListenerModule.kt",
],
deps = [
":dagger",
"//app",
"//domain/src/main/java/org/oppia/android/domain/oppialogger:startup_listener",
],
Expand Down Expand Up @@ -135,5 +133,3 @@ android_library(
"//utility/src/main/java/org/oppia/android/util/parser/image:repository_glide_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for alpha builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,7 +13,7 @@ kt_android_library(
visibility = ["//:oppia_binary_visibility"],
deps = [
":alpha_build_flavor_module",
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -35,9 +34,7 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/alpha:__pkg__",
],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:version_java_proto_lite",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ This package contains the root application definitions for a Kenya user study sp
of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,7 +13,6 @@ kt_android_library(
],
visibility = ["//:oppia_binary_visibility"],
deps = [
":dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -25,5 +23,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for beta builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,7 +16,6 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/beta:__pkg__",
],
deps = [
":dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -27,5 +25,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ there are specially defined top-level build flavors which will select their corr
application configuration.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -21,7 +20,6 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/dev:__pkg__",
],
deps = [
":dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -31,5 +29,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:debug_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for general availability builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,7 +16,6 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/ga:__pkg__",
],
deps = [
":dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -27,5 +25,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ This package contains testing utilities that may be needed to set up the root ap
testing environments.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,9 +13,7 @@ kt_android_library(
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:version_java_proto_lite",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test-only utilities corresponding to app notices.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand Down Expand Up @@ -30,5 +29,3 @@ kt_android_library(
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test-only utilities corresponding to BottomSheetOptionsMenu.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,5 +16,3 @@ kt_android_library(
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
],
)

dagger_rules()
5 changes: 0 additions & 5 deletions app/src/main/java/org/oppia/android/app/shim/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Temporary shims for providing indirection in the Bazel build graph to unblock mo
parts of the app layer.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

IMPL_FILES = [
Expand Down Expand Up @@ -59,7 +58,6 @@ kt_android_library(
name = "impl",
srcs = UPDATED_IMPL_FILES,
deps = [
":dagger",
":intent_factory_shim",
":view_binding_shim",
"//app:databinding_resources",
Expand All @@ -76,11 +74,8 @@ kt_android_library(
],
visibility = ["//:oppia_prod_module_visibility"],
deps = [
":dagger",
":impl",
":intent_factory_shim",
":view_binding_shim",
],
)

dagger_rules()
Loading

0 comments on commit b05b3e4

Please sign in to comment.