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

Example to repro jdeps issue #855

Draft
wants to merge 3 commits into
base: master
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
45 changes: 45 additions & 0 deletions examples/jdesp_issue/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local_repository(
name = "release_archive",
path = "../../src/main/starlark/release_archive",
)

load("@release_archive//:repository.bzl", "archive_repository")

archive_repository(
name = "io_bazel_rules_kotlin",
local_path = "../..",
)

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "versions")

kotlin_repositories()

register_toolchains("//bzl:experimental_toolchain")

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

http_archive(
name = "bazel_skylib",
sha256 = versions.SKYLIB_SHA,
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/%s/bazel-skylib-%s.tar.gz" % (
versions.SKYLIB_VERSION,
versions.SKYLIB_VERSION,
)],
)

http_archive(
name = "build_bazel_rules_android",
sha256 = versions.ANDROID.SHA,
strip_prefix = "rules_android-%s" % versions.ANDROID.VERSION,
urls = ["https://github.com/bazelbuild/rules_android/archive/v%s.zip" % versions.ANDROID.VERSION],
)

load(
"@build_bazel_rules_android//android:rules.bzl",
"android_sdk_repository",
)

android_sdk_repository(
name = "androidsdk",
build_tools_version = "30.0.2",
)
25 changes: 25 additions & 0 deletions examples/jdesp_issue/bzl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@io_bazel_rules_kotlin//kotlin:core.bzl", "define_kt_toolchain", "kt_kotlinc_options")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_javac_options")

kt_kotlinc_options(
name = "default_kotlinc_options",
)

kt_javac_options(
name = "default_javac_options",
)

KOTLIN_LANGUAGE_LEVEL = "1.6"

define_kt_toolchain(
name = "experimental_toolchain",
api_version = KOTLIN_LANGUAGE_LEVEL,
# TODO(630): enable when the reduced classpath can correctly manage transitive maven dependencies.
# experimental_reduce_classpath_mode = "KOTLINBUILDER_REDUCED",
experimental_report_unused_deps = "warn",
experimental_strict_kotlin_deps = "warn",
experimental_use_abi_jars = True,
javac_options = ":default_javac_options",
kotlinc_options = ":default_kotlinc_options",
language_version = KOTLIN_LANGUAGE_LEVEL,
)
13 changes: 13 additions & 0 deletions examples/jdesp_issue/libKtAndroid1/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
name = "src_main",
srcs = glob(["src/main/kt/examples/deps/KtDummy1.kt"]),
custom_package = "examples.deps.libktandroid1",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**/*"]),
visibility = ["//visibility:public"],
deps = [
"//libKtAndroid2:src_main",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="examples.deps.libktandroid1">
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23"
android:maxSdkVersion="29" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package examples.deps.libktandroid1
import examples.deps.libktandroid2.KtDummy2

class KtDummy1{

companion object {

private val resourceId = R.string.dummy1;
}

// Fails with jdeps:
// --@io_bazel_rules_kotlin//kotlin/internal/jvm:experimental_prune_transitive_deps=True
// --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=True
// Passes without jdeps:
// --@io_bazel_rules_kotlin//kotlin/internal/jvm:experimental_prune_transitive_deps=True
// --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=False
fun returnSomeType():KtDummy2 = KtDummy2()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources translatable="false">
<string name="dummy1">Dummy</string>
</resources>
14 changes: 14 additions & 0 deletions examples/jdesp_issue/libKtAndroid2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
name = "src_main",
srcs = glob(["src/main/kt/**/*.kt"]),
custom_package = "examples.deps.libktandroid2",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**/*"]),
visibility = ["//visibility:public"],
deps = [
"//libKtAndroid3:src_main",
],
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="examples.deps.libktandroid2">
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23"
android:maxSdkVersion="29" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package examples.deps.libktandroid2
import examples.deps.libktandroid3.KtDummy3

class KtDummy2 : KtDummy3() {

companion object {

private val resourceId = R.string.dummy2;
}

override fun dummy() {
System.out.println("dummy")
}

fun foo() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources translatable="false">
<string name="dummy2">Dummy</string>
</resources>
12 changes: 12 additions & 0 deletions examples/jdesp_issue/libKtAndroid3/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@io_bazel_rules_kotlin//kotlin:android.bzl", "kt_android_library")

kt_android_library(
name = "src_main",
srcs = glob(["src/main/kt/**/*.kt"]),
custom_package = "examples.deps.libktandroid3",
manifest = "src/main/AndroidManifest.xml",
resource_files = glob(["src/main/res/**/*"]),
visibility = ["//visibility:public"],
deps = [
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="examples.deps.libktandroid3">
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="23"
android:maxSdkVersion="29" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package examples.deps.libktandroid3

open class KtDummy3 {

companion object {

private val resourceId = R.string.dummy3;
}

open fun dummy() {
System.out.println("dummy")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources translatable="false">
<string name="dummy3">Dummy</string>
</resources>
19 changes: 19 additions & 0 deletions kotlin/internal/jvm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
# limitations under the License.
exports_files(["jetbrains-deshade.jarjar"])

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

release_archive(
name = "pkg",
srcs = glob(["*.bzl"]) + ["jetbrains-deshade.jarjar"],
Expand All @@ -33,3 +35,20 @@ bzl_library(
"@build_bazel_rules_android//android",
],
)

# Kotlin strict deps can be enabled by setting the following value on the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:experimental_prune_transitive_deps=True
bool_flag(
name = "experimental_prune_transitive_deps",
build_setting_default = False,
visibility = ["//visibility:public"]
)

# Jdeps plugin can be enabled or disabled using the following flag ont the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=false
bool_flag(
name = "kotlin_deps",
build_setting_default = True, # Upstream default behavior
visibility = ["//visibility:public"],
)

17 changes: 17 additions & 0 deletions kotlin/internal/jvm/BUILD.release.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
exports_files(["jetbrains-deshade.jarjar"])

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

# Kotlin strict deps can be enabled by setting the following value on the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:experimental_prune_transitive_deps=True
bool_flag(
name = "experimental_prune_transitive_deps",
build_setting_default = False,
visibility = ["//visibility:public"]
)

# Jdeps plugin can be enabled or disabled using the following flag ont the command line
# --@io_bazel_rules_kotlin//kotlin/internal/jvm:kotlin_deps=false
bool_flag(
name = "kotlin_deps",
build_setting_default = True, # Upstream default behavior
visibility = ["//visibility:public"])
54 changes: 42 additions & 12 deletions kotlin/internal/jvm/android.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _kt_android_artifact(
enable_data_binding = False,
tags = [],
exec_properties = None,
resource_files = None,
**kwargs):
"""Delegates Android related build attributes to the native rules but uses the Kotlin builder to compile Java and
Kotlin srcs. Returns a sequence of labels that a wrapping macro should export.
Expand All @@ -40,18 +41,47 @@ def _kt_android_artifact(
# TODO(bazelbuild/rules_kotlin/issues/273): This should be retrieved from a provider.
base_deps = [_ANDROID_SDK_JAR] + deps

# TODO(bazelbuild/rules_kotlin/issues/556): replace with starlark
# buildifier: disable=native-android
native.android_library(
name = base_name,
visibility = ["//visibility:private"],
exports = base_deps,
deps = deps if enable_data_binding else [],
enable_data_binding = enable_data_binding,
tags = tags,
exec_properties = exec_properties,
**kwargs
)
exported_target_labels = [kt_name]
if "kt_prune_transitive_deps_incompatible" in tags:
# TODO(https://github.com/bazelbuild/rules_kotlin/issues/556): replace with starlark
# buildifier: disable=native-android
native.android_library(
name = base_name,
resource_files = resource_files,
exports = base_deps,
deps = deps if enable_data_binding else [],
enable_data_binding = enable_data_binding,
tags = tags,
visibility = ["//visibility:private"],
**kwargs
)
exported_target_labels.append(base_name)
elif resource_files:
# TODO(https://github.com/bazelbuild/rules_kotlin/issues/556): replace with starlark
# buildifier: disable=native-android
# Do not export deps to avoid all upstream targets to be invalidated when ABI changes.
native.android_library(
name = base_name,
resource_files = resource_files,
deps = deps,
custom_package = kwargs.get("custom_package", default = None),
manifest = kwargs.get("manifest", default = None),
enable_data_binding = enable_data_binding,
tags = tags,
visibility = ["//visibility:private"],
)
exported_target_labels.append(base_name)
else:
# No need to export this target, as it's used exclusively internally
native.android_library(
name = base_name,
exports = deps,
enable_data_binding = enable_data_binding,
tags = tags,
visibility = ["//visibility:private"],
**kwargs
)

_kt_jvm_library(
name = kt_name,
srcs = srcs,
Expand Down
Loading