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

TEST ONLY #200

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ tasks:
ubuntu2004_basicapp_bzlmod:
name: "Basic app ubuntu bzlmod"
platform: ubuntu2004
name: basicapp
working_directory: examples/basicapp
build_flags:
<<: *rules_flags
Expand All @@ -135,4 +134,3 @@ tasks:
? "--enable_bzlmod"
build_targets:
- "//java/com/basicapp:basic_app"

28 changes: 28 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,31 @@ platform(
"@platforms//os:android",
],
)

# TODO: remove these alias when we no longer needs bind in WORKSPACE.bzlmod
# Because @androidsdk is not defined in WORKSPACE.bzl, where the only valid place
# we can call native function bind. Using these alias to forward the binding.
alias(
name = "androidsdk_sdk",
actual = "@androidsdk//:sdk",
)

alias(
name = "androidsdk_d8_jar_import",
actual = "@androidsdk//:d8_jar_import",
)

alias(
name = "androidsdk_dx_jar_import",
actual = "@androidsdk//:dx_jar_import",
)

alias(
name = "androidsdk_files",
actual = "@androidsdk//:files",
)

alias(
name = "androidsdk_has_android_sdk",
actual = "@androidsdk//:has_android_sdk",
)
21 changes: 20 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,23 @@ git_override(
module_name = "rules_robolectric",
remote = "https://github.com/robolectric/robolectric-bazel",
commit = "a5b25a8c27cc6add74bb01e62cd0dc72df8933ff",
)
)

android_sdk_repository_extension = use_extension("//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension")
use_repo(android_sdk_repository_extension, "androidsdk")

android_sdk_proxy_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "android_sdk_proxy_extensions")
android_sdk_proxy_extensions.configure(
has_androidsdk = "@androidsdk//:has_androidsdk",
dx_jar_import = "@androidsdk//:dx_jar_import",
android_sdk_for_testing = "@androidsdk//:files",
)
use_repo(android_sdk_proxy_extensions, "android_external")

register_toolchains("@androidsdk//:sdk-toolchain")
register_toolchains("@androidsdk//:all")

register_toolchains(
"@androidsdk//:sdk-toolchain",
"@androidsdk//:all",
)
8 changes: 8 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ load("defs_dev.bzl", "rules_android_workspace")

rules_android_workspace()

load("@bazel_tools//tools/android:android_extensions.bzl", "android_external_repository")
android_external_repository(
name = "android_external",
has_androidsdk = "@androidsdk//:has_androidsdk",
dx_jar_import = "@androidsdk//:dx_jar_import",
android_sdk_for_testing = "@androidsdk//:files",
)

register_toolchains("//toolchains/android:all")

register_toolchains("//toolchains/android_sdk:all")
Expand Down
13 changes: 7 additions & 6 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ workspace(name = "rules_android")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//rules:rules.bzl", "android_sdk_repository")

maybe(
android_sdk_repository,
name = "androidsdk",
)

maybe(
android_ndk_repository,
name = "androidndk",
)


# Temporary until we break all //external:android dependency
bind(name = "android/sdk", actual = "//:androidsdk_sdk")
bind(name = "android/dx_jar_import", actual = "//:androidsdk_dx_jar_import")
bind(name = "android_sdk_for_testing", actual = "//:androidsdk_files")
bind(name = "has_android_sdk", actual = "//:androidsdk_has_android_sdk")
28 changes: 27 additions & 1 deletion examples/basicapp/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
# Empty build file to satisfy gazelle for rules_go.
# Empty build file to satisfy gazelle for rules_go.

# TODO: remove these alias when ../..//BUILD remove them
alias(
name = "androidsdk_sdk",
actual = "@androidsdk//:sdk",
)

alias(
name = "androidsdk_d8_jar_import",
actual = "@androidsdk//:d8_jar_import",
)

alias(
name = "androidsdk_dx_jar_import",
actual = "@androidsdk//:dx_jar_import",
)

alias(
name = "androidsdk_files",
actual = "@androidsdk//:files",
)

alias(
name = "androidsdk_has_android_sdk",
actual = "@androidsdk//:has_android_sdk",
)
32 changes: 32 additions & 0 deletions examples/basicapp/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,35 @@ bazel_dep(name = "rules_jvm_external", version = "4.5")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

android_sdk_proxy_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "android_sdk_proxy_extensions")
android_sdk_proxy_extensions.configure(
has_androidsdk = "@androidsdk//:has_androidsdk",
dx_jar_import = "@androidsdk//:dx_jar_import",
android_sdk_for_testing = "@androidsdk//:files",
)
use_repo(android_sdk_proxy_extensions, "android_external")


bazel_dep(
name = "rules_android",
version = "0.1.1",
)

local_path_override(
module_name = "rules_android",
path = "../../",
)

register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)

android_sdk_repository_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension")
use_repo(android_sdk_repository_extension, "androidsdk")

register_toolchains(
"@androidsdk//:sdk-toolchain",
"@androidsdk//:all",
)
7 changes: 7 additions & 0 deletions examples/basicapp/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ register_toolchains(
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)

load("@bazel_tools//tools/android:android_extensions.bzl", "android_external_repository")
android_external_repository(
name = "android_external",
has_androidsdk = "@androidsdk//:has_androidsdk",
dx_jar_import = "@androidsdk//:dx_jar_import",
android_sdk_for_testing = "@androidsdk//:files",
)
30 changes: 12 additions & 18 deletions examples/basicapp/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
local_repository(
name = "rules_android",
path = "../..", # rules_android's WORKSPACE relative to this inner workspace
)
workspace(name = "basicapp")

load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()

load("@rules_android//rules:rules.bzl", "android_sdk_repository")
android_sdk_repository(
name = "androidsdk",
)

register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)
# local_repository(
# name = "rules_android",
# path = "../../"
# )

# load("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository")
# android_sdk_repository(name = "androidsdk")

# Temporary until we break all //external:android dependency
bind(name = "android/sdk", actual = "@//:androidsdk_sdk")
bind(name = "android/dx_jar_import", actual = "@//:androidsdk_dx_jar_import")
bind(name = "android_sdk_for_testing", actual = "//:androidsdk_files")
bind(name = "has_android_sdk", actual = "//:androidsdk_has_android_sdk")
32 changes: 32 additions & 0 deletions rules/android_sdk_repository/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,35 @@ def android_sdk_repository(

native.register_toolchains("@%s//:sdk-toolchain" % name)
native.register_toolchains("@%s//:all" % name)

def _android_sdk_repository_extension_impl(module_ctx):
root_modules = [m for m in module_ctx.modules if m.is_root and m.tags.configure]
if len(root_modules) > 1:
fail("Expected at most one root module, found {}".format(", ".join([x.name for x in root_modules])))

if root_modules:
module = root_modules[0]
else:
module = module_ctx.modules[0]

kwargs = {}
if module.tags.configure:
kwargs["api_level"] = module.tags.configure[0].api_level
kwargs["build_tools_version"] = module.tags.configure[0].build_tools_version
kwargs["path"] = module.tags.configure[0].path

_android_sdk_repository(
name = "androidsdk",
**kwargs
)

android_sdk_repository_extension = module_extension(
implementation = _android_sdk_repository_extension_impl,
tag_classes = {
"configure": tag_class(attrs = {
"path": attr.string(),
"api_level": attr.int(),
"build_tools_version": attr.string(),
}),
},
)