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 com.intuit.player:j2v8 transitive deps #256

Merged
merged 21 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Use embedded JDK
build --repo_env=JAVA_HOME=../bazel_tools/jdk
test --test_output=errors
coverage --combined_report=lcov

Expand All @@ -17,6 +19,7 @@ build --android_databinding_use_v3_4_args
build --android_databinding_use_androidx
build --experimental_google_legacy_api
query --experimental_google_legacy_api
sync --experimental_google_legacy_api

# Android demo app flags
build --noincremental_dexing --fat_apk_cpu=armeabi-v7a,arm64-v8a,x86,x86_64
Expand Down
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ commands:

- run: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: echo -e $GPG_KEY | gpg --import --batch
- run: |
echo -e $GPG_KEY | gpg --import --batch
echo -e "pinentry-mode loopback\npassphrase $DEPLOY_MAVEN_GPG_PASSPHRASE" > ~/.gnupg/gpg.conf
- run: |
source ~/.bashrc
bundle install
Expand Down
44 changes: 26 additions & 18 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ workspace(
},
)

load("//:build_constants.bzl", "build_constants")

build_constants()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

http_archive(
git_repository(
name = "rules_jvm_external",
branch = "maven-export-aar",
patches = [
"//patches:rules_jvm_external.default_public_visibility.patch",
],
remote = "https://github.com/sugarmanz/rules_jvm_external",
)

git_repository(
name = "rules_player",
sha256 = "c015a09ce2a5f999a89473cb9f71346c6831e27830a228ebe8f1ba25e83b77b2",
strip_prefix = "rules_player-0.10.4",
urls = ["https://github.com/player-ui/rules_player/archive/refs/tags/v0.10.4.tar.gz"],
branch = "maven-export-distribution",
remote = "https://github.com/player-ui/rules_player",
)

load("@rules_player//:workspace.bzl", "deps")
Expand Down Expand Up @@ -75,17 +87,15 @@ junit5()
######################
# Android Setup #
######################
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

grab_remote = "https://github.com/sugarmanz/grab-bazel-common.git"

grab_commit = "5326c6ba7a4e39e150c33e123134525473baffb6"
grab_commit = "35317b3d1c0da07b42af6e6a2137ebdec0ffe400"

git_repository(
name = "grab_bazel_common",
commit = grab_commit,
remote = grab_remote,
shallow_since = "1700536974 -0500",
shallow_since = "1706157787 -0500",
)

load("@grab_bazel_common//android:repositories.bzl", "bazel_common_dependencies")
Expand Down Expand Up @@ -137,12 +147,6 @@ overridden_targets = {

load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_aar")

# Because J2V8 is published as type `aar.asc`
maven_aar(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does this part work now? i noticed you removed the dep for android_binary, I'm not following how this source is fixed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat hilariously, I think this is because it's a transitive dependency of com.github.AlexTrotsenko:j2v8-debugger, so it gets pulled into the @maven workspace.

I could be wrong, and maybe it just works now, but that's the main thing that changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

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

# Because eyes androidx components is published as type `pom`
maven_aar(
name = "androidx_eyes_components",
Expand All @@ -157,6 +161,14 @@ register_toolchains("@androidndk//:all")
######################
# Maven Dependencies #
######################
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("//jvm/dependencies:deps.bzl", artifacts = "maven")
load("@rules_jvm_external//:defs.bzl", "maven_install")

Expand All @@ -183,7 +195,3 @@ maven_install(
"https://repo1.maven.org/maven2",
],
)

load("@vaticle_bazel_distribution//common:rules.bzl", "workspace_refs")

workspace_refs(name = "plugin_workspace_refs")
1 change: 0 additions & 1 deletion android/demo/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ android_binary(
multidex = "native",
deps = [
":demo_lib",
"@android_j2v8//aar",
"@maven//:androidx_databinding_databinding_common",
"@maven//:androidx_databinding_databinding_runtime",
"@maven//:org_jetbrains_kotlin_kotlin_reflect",
Expand Down
9 changes: 0 additions & 9 deletions android/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,3 @@ Make sure you have done a `bundle install`
**Possible Solution:** Check your SDK and NDK versions in SDK Manager in Android Studio. As well as your `ANDROID_HOME` and `ANDROID_NDK_HOME` in your bash or zsh profiles to make sure they are properly set.

You can also do `ls $ANDROID_HOME/platforms` and make sure that there are no versions higher than 30.



### 4. Mvn Error Message:
```
//jvm/j2v8:j2v8-android depends on @android_j2v8//aar:aar in repository @android_j2v8 which failed to fetch. no such package '@android_j2v8//aar': android_j2v8 requires mvn as a dependency. Please check your PATH.
```
Check to make sure `mvn` is installed.
`brew install maven`
12 changes: 9 additions & 3 deletions android/player/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
load(":deps.bzl", "main_deps", "main_resources", "test_deps")
load(":deps.bzl", "main_deps", "main_exports", "main_resources", "test_deps")
load("@build_constants//:constants.bzl", "VERSION")
load("//jvm:build.bzl", "distribution")
load("@grab_bazel_common//tools/databinding:databinding.bzl", "kt_db_android_library")
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",
Expand All @@ -11,13 +14,16 @@ kt_db_android_library(
manifest = ":src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**"]),
resources = main_resources,
tags = ["maven_coordinates=com.intuit.player.android:player:{pom_version}"],
tags = ["maven_coordinates=com.intuit.player.android:player:aar:%s" % VERSION],
visibility = ["//visibility:public"],
exports = main_exports,
deps = main_deps,
)

distribution(
name = "player",
lib_name = "player-databinding",
maven_coordinates = "com.intuit.player.android:player:%s" % VERSION,
)

kt_jvm_junit5_test(
Expand Down
36 changes: 36 additions & 0 deletions build_constants.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def _build_constants_impl(repository_ctx):
_BUILD_FILE = """
# DO NOT EDIT: automatically generated for _build_constants rule
filegroup(
name = 'files',
srcs = glob(['**']),
visibility = ['//visibility:public']
)
"""
repository_ctx.file("BUILD", _BUILD_FILE, False)

version = repository_ctx.read(repository_ctx.attr.version_file)

_CONSTANTS_FILE = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this building version constants for the whole repo? i'm curious to see what this looks like

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! This is what usage looks like:

load("@build_constants//:constants.bzl", "VERSION")

This is required because the new maven_publish rule requires the version to be defined within the maven_coordinates tag.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inspiration in thread:
bazel-contrib/rules_jvm_external#618

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that i'm reading this again, it's not dynamic
does this have the potential to be dynamic for constants that are shared across the platforms or will this always be hard coded

or I guess i'm asking what's the diff between this and creating that output ourselves

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure I understand what you mean. It's dynamic in the sense that it makes the version defined in our VERSION file accessible at build configuration time. We don't have to change this script every time the version changes. Typically, you're not able to read files during build configuration, only during execution.

The only thing that's hardcoded is the build_constants repository rule itself. If we want to add other things, like the APPLITOOLS_API_KEY, we could by reading the environment and stuffing into this file. Then you could have access to the key at build configuration time, and maybe even not generate certain test targets if that key doesn't exist.

# DO NOT EDIT: automatically generated for _build_constants rule
VERSION = \"{version}\"
"""

repository_ctx.file(
"constants.bzl",
_CONSTANTS_FILE.format(version = version),
False,
)

_build_constants = repository_rule(
implementation = _build_constants_impl,
attrs = {
"version_file": attr.label(
default = Label("//:VERSION"),
allow_single_file = True,
),
},
)

def build_constants():
_build_constants(name = "build_constants")
53 changes: 17 additions & 36 deletions jvm/build.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
load("@rules_player//kotlin:kt_jvm.bzl", _kt_jvm = "kt_jvm")
load("@rules_player//kotlin:distribution.bzl", _distribution = "distribution")
load("@build_constants//:constants.bzl", "VERSION")
load("//jvm/dependencies:common.bzl", common_main_deps = "main_deps", common_test_deps = "test_deps")
load("//:index.bzl", "GIT_REPO", "DOCS_URL")
load("//:index.bzl", "DOCS_URL", "GIT_REPO")

DEFAULT_GROUP = "com.intuit.player"
DEFAULT_PROJECT_NAME = "Player"
DEFAUTL_PROJECT_DESCRIPTION = "A cross-platform semantic rendering engine"
DEFAULT_DEVELOPERS = {
"sugarmanz": ["name=Jeremiah Zucker", "email=zucker.jeremiah@gmail.com"],
"brocollie08": ["name=Tony Lin"]
"sugarmanz": ["name=Jeremiah Zucker", "email=zucker.jeremiah@gmail.com"],
"brocollie08": ["name=Tony Lin"],
}
DEFAULT_RELEASE_REPO = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
DEFAULT_SNAPSHOT_REPO = "https://oss.sonatype.org/content/repositories/snapshots/"
Expand All @@ -22,14 +24,9 @@ def kt_player_module(
include_common_deps = True,

# Distribution config
group = "com.intuit.player",

# (optional)
project_name = DEFAULT_PROJECT_NAME,
project_description = DEFAUTL_PROJECT_DESCRIPTION,
project_url = DOCS_URL,
scm_url = GIT_REPO,
developers = DEFAULT_DEVELOPERS,
group = DEFAULT_GROUP,
deploy_env = None,
excluded_workspaces = None,

# Package level config
module_name = None,
Expand All @@ -53,15 +50,9 @@ def kt_player_module(
name = name,
lint_config = "//jvm:lint_config",
group = group,
release_repo = DEFAULT_RELEASE_REPO,
snapshot_repo = DEFAULT_SNAPSHOT_REPO,
version_file = "//:VERSION",
project_name = project_name,
project_description = project_description,
project_url = project_url,
scm_url = scm_url,
developers = developers,
workspace_refs = "@plugin_workspace_refs//:refs.json",
version = VERSION,
deploy_env = deploy_env,
excluded_workspaces = excluded_workspaces,
module_name = module_name,
main_opts = "//jvm:main_options",
main_srcs = main_srcs,
Expand All @@ -86,22 +77,12 @@ def kt_player_module(
def distribution(
*,
name,

# (optional)
project_name = DEFAULT_PROJECT_NAME,
project_description = DEFAUTL_PROJECT_DESCRIPTION,
project_url = DOCS_URL,
scm_url = GIT_REPO,
developers = DEFAULT_DEVELOPERS,):
maven_coordinates,
lib_name = None,
**kwargs):
_distribution(
name = name,
release_repo = DEFAULT_RELEASE_REPO,
snapshot_repo = DEFAULT_SNAPSHOT_REPO,
version_file = "//:VERSION",
project_name = project_name,
project_description = project_description,
project_url = project_url,
scm_url = scm_url,
developers = developers,
workspace_refs = "@plugin_workspace_refs//:refs.json",
maven_coordinates = maven_coordinates,
lib_name = lib_name,
**kwargs
)
3 changes: 3 additions & 0 deletions jvm/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +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,
},
main_deps = main_deps,
main_exports = main_exports,
test_deps = test_deps,
Expand Down
4 changes: 2 additions & 2 deletions jvm/core/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ main_exports = [
"//jvm:kotlin_serialization",
]
main_deps = main_exports + [
"@maven//:org_jetbrains_kotlin_kotlin_reflect"
"@maven//:org_jetbrains_kotlin_kotlin_reflect",
]
main_runtime_deps = []

# Test dependencies
test_deps = [
"//plugins/reference-assets/jvm:reference-assets",
"//plugins/reference-assets/jvm:reference-assets",
]
test_runtime_deps = []
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ public class CompletedState(override val node: Node) :

public val data: JsonElement by NodeSerializableField(JsonElement.serializer()) { JsonNull }

internal val controllers: ControllerState by NodeSerializableField(ControllerState.serializer())

// TODO: Completed state dataModel change needs rectification here
public val dataModel: DataModelWithParser by NodeSerializableField(DataModelWithParser.serializer())
public val dataModel: DataModelWithParser by lazy {
DataModelWithParser(controllers.data.node)
}

internal object Serializer : NodeWrapperSerializer<CompletedState>(::CompletedState, COMPLETED.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intuit.player.jvm.core.bridge.Node
import com.intuit.player.jvm.core.bridge.getInvokable
import com.intuit.player.jvm.core.bridge.runtime.Runtime
import com.intuit.player.jvm.core.bridge.serialization.format.RuntimeFormat
import com.intuit.player.jvm.core.data.DataController
import com.intuit.player.jvm.core.data.DataModelWithParser
import com.intuit.player.jvm.core.flow.Flow
import com.intuit.player.jvm.core.player.PlayerFlowStatus
Expand All @@ -23,6 +24,10 @@ internal class CompletedStateTest : NodeBaseTest() {
CompletedState(node)
}

private val controllerState by lazy {
ControllerState(node)
}

@MockK
private lateinit var mockDataModel: Node

Expand All @@ -35,6 +40,10 @@ internal class CompletedStateTest : NodeBaseTest() {
every { node.runtime } returns runtime
every { runtime.containsKey("getSymbol") } returns true
every { runtime.getInvokable<String?>("getSymbol") } returns Invokable { "Symbol(hello)" }
every { node.getObject("controllers") } returns node
every { node.getSerializable<Any>("controllers", any()) } returns controllerState
every { node.getObject("data") } returns node
every { node.getSerializable<Any>("data", any()) } returns DataController(node)
every { node.getSerializable("flow", Flow.serializer()) } returns Flow("flowId")
every { node.getSerializable("dataModel", DataModelWithParser.serializer()) } returns DataModelWithParser(node)
every { node.getObject("dataModel") } returns mockDataModel
Expand Down
1 change: 1 addition & 0 deletions jvm/dependencies/common.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("//jvm/dependencies:versions.bzl", "versions")

maven = [
"org.jetbrains.kotlin:kotlin-reflect:%s" % "1.7.10",
"org.jetbrains.kotlinx:kotlinx-coroutines-core:%s" % versions.kotlin.coroutines,
"org.jetbrains.kotlinx:kotlinx-serialization-json:%s" % versions.kotlin.serialization,
"com.intuit.hooks:hooks:%s" % versions.hooks,
Expand Down
3 changes: 1 addition & 2 deletions jvm/dependencies/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ load("//jvm/testutils:deps.bzl", testutils = "maven")
load("//jvm/perf:deps.bzl", perf = "maven")
load("//plugins:deps.bzl", plugins = "maven")
load("@rules_player//distribution:deps.bzl", distribution = "maven")
load("@grab_bazel_common//:workspace_defs.bzl", grab = "GRAB_BAZEL_COMMON_ARTIFACTS")

tooling = distribution + grab
tooling = distribution

maven = remove_duplicates(common + core + graaljs + j2v8 + utils + testutils + perf + plugins + tooling + android)
3 changes: 3 additions & 0 deletions jvm/j2v8/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ j2v8_platform("macos")

j2v8_platform("linux")

# TODO: These should probably be AARs?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no android specific resource here, right? I think i stripped all that out in order to fit the debugger in the jvm repo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main problem here is they rely on transitive AARs, so if you try to pull the JAR into a Gradle project, it'll technically work, but will blow up when it tries to process the transitive deps. So, the idea is to make this an Android only artifact up front to make it clearer where this is meant to be used.

That being said, I'm not sure that's a great way to do it. From looking at a lot of the Android libs, a lot of them are JARs if they don't have any bundled Android resources.

j2v8_platform("android")

j2v8_platform("android-debug")

j2v8_platform("all")
Loading