Skip to content
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

Fix J2V8 Debugger #443

Merged
merged 18 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ jobs:
keys:
- v1-dependencies-{ { checksum "package.json" }}

- run:
name: Set build type
command: |
if [ "${CIRCLE_BRANCH}" == "main" ]; then
echo "Running on main"
echo 'export BUILD_TYPE=release' >> $BASH_ENV
else
echo "Running on PR"
echo 'export BUILD_TYPE=debug' >> $BASH_ENV
fi
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved
- persist_to_workspace:
root: .
paths:
Expand All @@ -101,7 +111,7 @@ jobs:
- attach_workspace:
at: ~/player
# need to filter because //android/demo rules dont resolve
- run: bazel build --config=ci -- $(bazel query 'filter("native_bundle$", //...)')
- run: bazel build --config=ci --define build_type=$BUILD_TYPE -- $(bazel query 'filter("native_bundle$", //...)')
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved

- save_cache:
paths:
Expand Down Expand Up @@ -222,7 +232,7 @@ jobs:
at: ~/player

- run: |
bazel test --config=ci -- $(bazel query 'kind(".*_test", //...) except filter("ios|swiftui", //...)') -//android/demo:android_instrumentation_test
bazel test --config=ci --define build_type=$BUILD_TYPE -- $(bazel query 'kind(".*_test", //...) except filter("ios|swiftui", //...)') -//android/demo:android_instrumentation_test
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved

- run:
when: always
Expand Down Expand Up @@ -278,7 +288,7 @@ jobs:
command: |
circle-android wait-for-boot

- run: bazel test --config=ci -- //android/demo:android_instrumentation_test
- run: bazel test --config=ci --define build_type=$BUILD_TYPE -- //android/demo:android_instrumentation_test

- run:
when: always
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.4
0.7.42-SNAPSHOT
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("//:build_constants.bzl", "build_constants")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_aar")

build_constants()

Expand All @@ -9,6 +10,11 @@ android_sdk_repository(
api_level = 33
)

maven_aar(
name = "android_j2v8",
artifact = "com.eclipsesource.j2v8:j2v8:6.1.0",
)

bind(
name = "databinding_annotation_processor",
actual = "//:compiler_annotation_processor",
Expand Down
2 changes: 1 addition & 1 deletion android/demo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maven_main = [
"@maven//:com_afollestad_material_dialogs_core",
"@maven//:com_google_android_material_material",
#"@maven//:com_squareup_leakcanary_leakcanary_android",
"@maven//:com_github_AlexTrotsenko_j2v8_debugger",
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved
"@android_j2v8//aar",
"@maven//:com_facebook_stetho_stetho"
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class DemoPlayerViewModel(iterator: AsyncFlowIterator) : PlayerViewModel(iterato
AsyncHydrationTrackerPlugin(),
)

public val isDebug = false
sugarmanz marked this conversation as resolved.
Show resolved Hide resolved

override val config: Config = Config(
debuggable = true,
debuggable = isDebug,
)

private val _playerFlowState = MutableStateFlow<PlayerFlowState?>(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.afollestad.materialdialogs.MaterialDialog
import com.alexii.j2v8debugger.StethoHelper
import com.intuit.playerui.android.lifecycle.ManagedPlayerState
import com.intuit.playerui.android.lifecycle.PlayerViewModel
import com.intuit.playerui.android.reference.demo.lifecycle.DemoPlayerViewModel
Expand All @@ -31,7 +30,11 @@ abstract class BasePlayerFragment : PlayerFragment() {
private val currentPlayerCanvas get() = binding.playerCanvas.getChildAt(0)

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
StethoHelper.initializeDebugger(requireContext(), playerViewModel.player)
if (playerViewModel.isDebug) {
(playerViewModel.runtime as? com.alexii.j2v8debugger.ScriptSourceProvider)?.let {
com.alexii.j2v8debugger.StethoHelper.initializeDebugger(requireContext(), it)
}
}
return super.onCreateView(inflater, container, savedInstanceState)
}

Expand Down
30 changes: 26 additions & 4 deletions android/player/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load(":deps.bzl", "main_deps", "main_exports", "main_resources", "test_deps")
load(":deps.bzl", "main_deps", "main_exports", "dev_exports", "main_resources", "test_deps")
load("@build_constants//:constants.bzl", "VERSION")
load("@rules_kotlin//kotlin:android.bzl", "kt_android_library")
load("@rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options")
Expand All @@ -13,7 +13,21 @@ kt_android_library(
manifest = ":src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**"]),
resources = main_resources,
deps = main_deps,
deps = main_deps + select({
":dev": dev_exports,
":prod": main_exports,
"//conditions:default": dev_exports,
}),
)

config_setting(
name = "dev",
values = {"define": "build_type=debug"},
)

config_setting(
name = "prod",
values = {"define": "build_type=release"},
)

android_library(
Expand All @@ -22,8 +36,16 @@ android_library(
resource_files = glob(["src/main/res/**"]),
manifest = ":src/main/AndroidManifest.xml",
tags = ["maven_coordinates=com.intuit.playerui:android:aar:%s" % VERSION],
deps = main_deps,
exports = main_exports + [":player_android"],
deps = main_deps + select({
":dev": dev_exports,
":prod": main_exports,
"//conditions:default": dev_exports,
}),
exports = [":player_android"] + select({
":dev": dev_exports,
":prod": main_exports,
"//conditions:default": dev_exports,
}),
visibility = ["//visibility:public"],
)

Expand Down
6 changes: 5 additions & 1 deletion android/player/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ main_exports = [
"//jvm/j2v8:j2v8-android",
]

main_deps = main_exports + [
dev_exports = [
"//jvm/j2v8:j2v8-android-debug",
]

main_deps = [
"@maven//:androidx_databinding_viewbinding",
"@maven//:androidx_annotation_annotation",
"@maven//:androidx_core_core_ktx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.intuit.playerui.android

import android.content.Context
import android.view.View
import com.alexii.j2v8debugger.ScriptSourceProvider
import com.intuit.hooks.BailResult
import com.intuit.hooks.HookContext
import com.intuit.hooks.SyncBailHook
import com.intuit.hooks.SyncHook
import com.intuit.hooks.SyncWaterfallHook
import com.intuit.playerui.android.asset.RenderableAsset
import com.intuit.playerui.android.debug.UnsupportedScriptProvider
import com.intuit.playerui.android.extensions.Styles
import com.intuit.playerui.android.extensions.overlayStyles
import com.intuit.playerui.android.extensions.removeSelf
Expand Down Expand Up @@ -47,7 +45,7 @@ public typealias AndroidPlayerConfig = AndroidPlayer.Config
public class AndroidPlayer private constructor(
private val player: HeadlessPlayer,
override val plugins: List<Plugin> = player.plugins,
) : Player(), ScriptSourceProvider by player.runtime as? ScriptSourceProvider ?: UnsupportedScriptProvider(player.runtime) {
) : Player() {

/** Convenience constructor to provide vararg style [plugins] parameter */
public constructor(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public open class PlayerViewModel(flows: AsyncFlowIterator) : ViewModel(), Andro

protected val manager: FlowManager = FlowManager(flows)

private var runtime: Runtime<*>? = null
public var runtime: Runtime<*>? = null

private var _state = MutableStateFlow<ManagedPlayerState>(ManagedPlayerState.NotStarted)
private val _beacons = MutableSharedFlow<String>()
Expand Down
6 changes: 3 additions & 3 deletions jvm/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ load(":deps.bzl", "main_deps", "main_exports", "test_deps")
# TODO: Sources jar for src/main/kotlin includes main/kotlin
kt_player_module(
name = "core",
excluded_workspaces = {
"com_github_jetbrains_kotlin": None,
},
deploy_env = [
"@rules_kotlin//kotlin/compiler:kotlin-stdlib",
],
main_deps = main_deps,
main_exports = main_exports,
test_deps = test_deps,
Expand Down
7 changes: 7 additions & 0 deletions jvm/j2v8/BUILD
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
load("//jvm:defs.bzl", "kt_player_module")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load(":deps.bzl", "main_deps", "main_exports", "main_resources", "test_deps")
load(":defs.bzl", "j2v8_platform")

# TODO: Add core as associates and remove InternalPlayerApi?
# May require creating shared module_name space.
kt_player_module(
name = "j2v8",
main_srcs = glob(["src/main/kotlin/com/intuit/**/*.kt"]),
main_deps = main_deps,
main_exports = main_exports,
main_resources = main_resources + glob(["src/main/resources/**"]),
test_deps = test_deps,
test_package = "com.intuit.playerui.j2v8",
)

kt_jvm_library(
name = "j2v8_script_provider",
srcs = ["src/main/kotlin/com/alexii/j2v8debugger/ScriptSourceProvider.kt"]
)

j2v8_platform("macos")

j2v8_platform("linux")
Expand Down
17 changes: 13 additions & 4 deletions jvm/j2v8/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ load("//jvm:defs.bzl", "DEFAULT_GROUP", "distribution")
load("@build_constants//:constants.bzl", "VERSION")

deps = {
"macos": ["//jvm/j2v8/libs:j2v8_macos"],
"linux": ["//jvm/j2v8/libs:j2v8_linux"],
"android": ["@maven//:com_eclipsesource_j2v8_j2v8"],
"macos": [
"//jvm/j2v8/libs:j2v8_macos",
"//jvm/j2v8:j2v8_script_provider"
],
"linux": [
"//jvm/j2v8/libs:j2v8_linux",
"//jvm/j2v8:j2v8_script_provider"
],
"android": [
"@android_j2v8//aar",
"//jvm/j2v8:j2v8_script_provider"
],
"android-debug": [
"//jvm/j2v8:j2v8-android",
"@android_j2v8//aar",
"@maven//:com_github_AlexTrotsenko_j2v8_debugger",
],
"all": [
Expand Down