-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android MVVM Module + Android Player test package restructure #307
base: main
Are you sure you want to change the base?
Changes from all commits
1220260
2010395
3480126
2f21b7b
bb5538f
c7708c7
79b6ff7
57ae6ad
2d614c6
c85cace
a25e786
48bdb92
9e0bd03
eb53a56
1b80a07
585bc4b
484867d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
load(":deps.bzl", "main_deps", "test_deps") | ||
load("@build_constants//:constants.bzl", "VERSION") | ||
load("//jvm:build.bzl", "distribution") | ||
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
load("@junit//junit5-jupiter-starter-bazel:junit5.bzl", "kt_jvm_junit5_test") | ||
load("@rules_player//kotlin:lint.bzl", "lint") | ||
load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") | ||
|
||
kt_db_android_library( | ||
name = "player-mvvm", | ||
srcs = glob(["src/main/java/**/*.kt"]), | ||
custom_package = "com.intuit.playerui.android.mvvm", | ||
manifest = ":src/main/AndroidManifest.xml", | ||
resource_files = glob(["src/main/res/**"]), | ||
tags = ["maven_coordinates=com.intuit.playerui.android:player-mvvm:aar:%s" % VERSION], | ||
visibility = ["//visibility:public"], | ||
deps = main_deps, | ||
) | ||
|
||
distribution( | ||
name = "player-mvvm", | ||
lib_name = "player-mvvm-databinding", | ||
maven_coordinates = "com.intuit.playerui.android:player-mvvm:%s" % VERSION, | ||
) | ||
|
||
kt_jvm_junit5_test( | ||
name = "player-mvvm-tests", | ||
srcs = glob(["src/test/java/**/*.kt"]), | ||
kotlinc_opts = "//jvm:test_options", | ||
associates = ["//android/player:player-associates"], | ||
test_package = "com.intuit.playerui.android.mvvm", | ||
deps = [ | ||
"//android/player:player", | ||
":player-mvvm", | ||
"//android/player/src/test/java/android/util:android_utils_stub", | ||
"//android/player/src/test/java/com/intuit/playerui/android/utils:android_test_utils", | ||
"//android/player/src/test/java/com/intuit/playerui/android/utils:android_log_util" | ||
] + test_deps, | ||
) | ||
|
||
lint( | ||
name = "player-mvvm", | ||
srcs = glob(["src/**/*.kt"]), | ||
lint_config = "//jvm:lint_config", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
load("//jvm/dependencies:versions.bzl", "versions") | ||
load("@rules_player//maven:parse_coordinates.bzl", "parse_coordinates") | ||
|
||
maven = [ | ||
# UI helpers | ||
"androidx.core:core-ktx:%s" % versions.androidx.core, | ||
"androidx.appcompat:appcompat:%s" % versions.androidx.appcompat, | ||
"androidx.transition:transition:%s" % versions.androidx.transition, | ||
|
||
# Lifecycle | ||
"androidx.lifecycle:lifecycle-runtime-ktx:%s" % versions.androidx.lifecycle, | ||
"androidx.lifecycle:lifecycle-viewmodel-ktx:%s" % versions.androidx.lifecycle, | ||
|
||
# Default fallback | ||
"androidx.constraintlayout:constraintlayout:%s" % versions.androidx.constraintlayout, | ||
] | ||
|
||
main_deps = parse_coordinates(maven) + [ | ||
# JVM plugin deps | ||
"//android/player:player", | ||
"//plugins/coroutines/jvm:coroutines", | ||
] | ||
|
||
main_resources = [ | ||
# TS core deps | ||
"//plugins/partial-match-fingerprint/core:PartialMatchFingerprintPlugin_Bundles", | ||
"//core/partial-match-registry:Registry_Bundles", | ||
] | ||
|
||
test_deps = [ | ||
"@grab_bazel_common//tools/test:mockable-android-jar", | ||
"@maven//:io_mockk_mockk", | ||
"@maven//:org_jetbrains_kotlinx_kotlinx_coroutines_test", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.intuit.player.android.mvvm"> | ||
<uses-sdk android:minSdkVersion="14" /> | ||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ load("@build_constants//:constants.bzl", "VERSION") | |
load("//jvm:build.bzl", "distribution") | ||
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library") | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
load("@junit//junit5-jupiter-starter-bazel:junit5.bzl", "kt_jvm_junit5_test") | ||
load("//android/player:build.bzl", "kt_player_test") | ||
load("@rules_player//kotlin:lint.bzl", "lint") | ||
load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library") | ||
|
||
|
@@ -26,13 +26,26 @@ distribution( | |
maven_coordinates = "com.intuit.playerui:android:%s" % VERSION, | ||
) | ||
|
||
kt_jvm_junit5_test( | ||
kt_player_test( | ||
name = "player-tests", | ||
srcs = glob(["src/test/java/**"]), | ||
associates = [":player-kotlin"], | ||
kotlinc_opts = "//jvm:test_options", | ||
test_package = "com.intuit.playerui.android", | ||
deps = [":player"] + test_deps, | ||
srcs = [ | ||
"src/test/java/com/intuit/playerui/android/AndroidPlayerTest.kt", | ||
"src/test/java/com/intuit/playerui/android/AssetContextTest.kt", | ||
"src/test/java/com/intuit/playerui/android/BrokenAssetTest.kt" | ||
] | ||
) | ||
|
||
filegroup( | ||
name = "manifest", | ||
srcs = ["src/main/AndroidManifest.xml"], | ||
visibility = ["//visibility:public"] | ||
) | ||
|
||
kt_jvm_library( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a terrible workaround for internals in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in this commit this actually encapsulates everything, so then i can move |
||
name = "player-associates", | ||
srcs = glob(["src/main/java/**/*.kt"]) + [":player-stubs_binding.srcjar"], | ||
deps = main_deps + ["@grab_bazel_common//tools/android:android_sdk", ":player-r-classes"], | ||
visibility = ["//visibility:public"] | ||
) | ||
|
||
lint( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@junit//junit5-jupiter-starter-bazel:junit5.bzl", "kt_jvm_junit5_test") | ||
load("@rules_player//kotlin:lint.bzl", "lint") | ||
load("//android/player:deps.bzl", "test_deps") | ||
|
||
def kt_player_test( | ||
name, | ||
srcs = [], | ||
associates = [], | ||
deps = []): | ||
kt_jvm_junit5_test( | ||
name = name, | ||
srcs = srcs, | ||
associates = ["//android/player:player-associates"], | ||
kotlinc_opts = "//jvm:test_options", | ||
test_package = "com.intuit.playerui.android", | ||
deps = deps + [ | ||
"//android/player:player", | ||
"//android/player/src/test/java/android/util:android_utils_stub", | ||
"//android/player/src/test/java/com/intuit/playerui/android/utils:android_test_utils", | ||
"//android/player/src/test/java/com/intuit/playerui/android/utils:android_log_util"] + test_deps, | ||
) | ||
|
||
lint( | ||
name = name, | ||
srcs = native.glob(["**/*.kt"]), | ||
lint_config = "//jvm:lint_config", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") | ||
load("//android/player:deps.bzl", "test_deps") | ||
|
||
kt_jvm_library( | ||
name = "android_utils_stub", | ||
srcs = ["Log.kt"], | ||
deps = ["//android/player:player"], | ||
visibility = ["//visibility:public"] | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("//android/player:build.bzl", "kt_player_test") | ||
|
||
kt_player_test( | ||
name = "extensions-tests", | ||
srcs = [ | ||
"CoroutineTestDispatcherExtension.kt", | ||
"IntoKtTest.kt" | ||
], | ||
) | ||
|
||
exports_files(["CoroutineTestDispatcherExtension.kt"]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("//android/player:build.bzl", "kt_player_test") | ||
|
||
kt_player_test( | ||
name = "logger-tests", | ||
srcs = [ | ||
"AndroidLoggerTest.kt" | ||
], | ||
associates = ["//android/player:player-associates"] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first two are not great because the test target should really be in the test package, but it's moved here because of the associates line below, allowing the tests to access internal player API.
the
BrokenAssetTest
is really bad since i had to move it out of the original package, otherwise i couldn't reference it as a source. It's really the same problem trying to access internal APIthe main problem here is
:player-kotlin
target is created as an intermediate target by the db android macro, and the visibility isn't marked as public so it can only be used from this package. The end result target does not meet the requirements to be used as an associateI could either modify the grab rules or we need to write some hack, maybe wrapper library to expose
:player-kotlin
? Is there a better way