Skip to content

Commit

Permalink
Fix J2V8 Debugger (#443)
Browse files Browse the repository at this point in the history
* separate out placeholder class from j2v8 core

* fix temurin package location

* don't use android-j2v8 target for debugger dep

* try debug directly

* deploy_env over excluded_workspace

* wrong target

* select export based on build type

* bazelrc build ci + release and option rename

* deps also need to change

* select for wrapped library as well

* working

* fi

* add ScriptSourceProvider back for release builds

* lint

* player.player public

* determine branch then move flag to bazelrc local

* revert version
  • Loading branch information
brocollie08 authored Jul 30, 2024
1 parent 20b2248 commit 7e8ca9c
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 34 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ jobs:
echo "build --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local
echo "test --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local
echo "coverage --remote_header=x-buildbuddy-api-key=${BUILDBUDDY_API_KEY}" >> .bazelrc.local
if [ "${CIRCLE_BRANCH}" == "main" ]; then
echo "Running on main"
echo 'build:ci --define build_type=release' >> .bazelrc.local
else
echo "Running on PR"
echo 'build:ci --define build_type=debug' >> .bazelrc.local
fi
- persist_to_workspace:
root: .
paths:
Expand Down
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",
"@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

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.player.player.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 @@ -45,9 +43,9 @@ public typealias AndroidPlayerConfig = AndroidPlayer.Config
* [HeadlessPlayer] and [injectDefaultPlugins].
*/
public class AndroidPlayer private constructor(
private val player: HeadlessPlayer,
public 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.

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

0 comments on commit 7e8ca9c

Please sign in to comment.