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

Add support for Kotlin JARs with inlined functions, and an Android Kotlin example app #69

Merged
merged 13 commits into from
Mar 26, 2019

Conversation

jin
Copy link
Member

@jin jin commented Mar 18, 2019

This PR adds support for Kotlin-built jars, tests, and an Android Kotlin example app.

I added the tests and app into the macOS and Linux CI configuration. rules_kotlin does not yet work on Windows (bazelbuild/rules_kotlin#179), so the Windows failure in the CI is expected. We exclude the Kotlin unit tests for Windows in this PR so postsubmit is expected to be green.

Kotlin-sourced jars can contain metadata of inlined functions (inline fun ...), and regular java_import will strip these away with ijar, causing builds to fail. See https://github.com/bazelbuild/rules_jvm_external/pull/69/files#diff-90e077b9f9533f17dcef14f92cbae44c for the error message. To get around that, we create a simple no_ijar_java_import rule for internal use during the BUILD generation.

To detect whether a JAR is Kotlin-sourced, we run jar tf on jars during BUILD file generation, and check for the existence of kotlin_module files. If it exists, we use the no_ijar_java_import rule class. If it does, we use the regular java_import, which has support for interface jars for more parallelizable downstream Java compilation.

Fixes #59

@jin jin changed the title Add an Android Kotlin example app Add support for Kotlin JARs and an Android Kotlin example app Mar 18, 2019
@jin jin changed the title Add support for Kotlin JARs and an Android Kotlin example app Add support for Kotlin JARs with inlined functions, and an Android Kotlin example app Mar 18, 2019
coursier.bzl Outdated Show resolved Hide resolved
@jin jin force-pushed the kotlin branch 2 times, most recently from 5eaab01 to 9b22178 Compare March 18, 2019 19:52
@jin jin marked this pull request as ready for review March 19, 2019 00:27
@jin jin requested a review from dkelmer as a code owner March 19, 2019 00:27
@jin
Copy link
Member Author

jin commented Mar 19, 2019

Excellent idea from @davidsantiago: perhaps we should generate, by default, no_ijar_java_import targets instead (or alongside the regular java_import targets), and let users opt into java_import if they want to use ijar. This way, there is no ambiguity on whether there was ijar processing on the imported jars.

@jin
Copy link
Member Author

jin commented Mar 25, 2019

As discussed offline, let's go with completely replacing java_import with its no-ijar counterpart.

@@ -382,7 +389,7 @@ def _coursier_fetch_impl(repository_ctx):
cmd = _generate_coursier_command(repository_ctx)
cmd.extend(["fetch"])
cmd.extend(artifact_coordinates)
cmd.extend(["--artifact-type", ",".join(_COURSIER_PACKAGING_TYPES)])
cmd.extend(["--artifact-type", ",".join(_COURSIER_PACKAGING_TYPES + ["src"])])
Copy link
Member Author

Choose a reason for hiding this comment

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

drive-by fix to add src back into the fetch_sources branch.

# Then this artifact is an rdep :-)
reverse_deps.append(maybe_rdep)
return reverse_deps
reverse_deps = []
Copy link
Member Author

Choose a reason for hiding this comment

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

drive by formatting fix.

@@ -44,4 +44,9 @@ platforms:
# TODO(jin): fix long paths issue on Windows
# - "//examples:app"
test_targets:
- "--"
Copy link
Contributor

Choose a reason for hiding this comment

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

what does the "--" do?

Copy link
Member Author

Choose a reason for hiding this comment

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

allows using the target subtraction syntax -//:target

- "//tests/unit/..."
# TODO(jin): Concurrent download problems on macOS
# https://github.com/bazelbuild/rules_jvm_external/issues/54
- "-//tests/unit/kotlin/..."
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI: had to disable the test on the Mac too, due to network / race problems in #54

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 maybe the CI can't resolve more than one maven_install repository concurrently?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, that's exactly it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants