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

Android library publishing support #344

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

sugarmanz
Copy link
Contributor

What is the goal of this PR?

Add publishing support for android_library targets (#233)

What are the changes implemented in this PR?

First, the rules, assemblers, and scripts need to take into account other packaging types. Determining the packaging type and passing that info along via the providers was the necessary first step.

Second, the JarAssembler.kt file only supported packaging a JAR. Rather than duplicate the script for AAR support, I added support directly in that file to reuse a lot of the same logic used to assemble JARs. There is one TODO left surrounding duplicate entries, but I believe that might be something related to my specific project.

Third, handling the Android SDK and neverlink dependencies. In order to be able to perform the aggregate_dependency_info aspect, the Android SDK target needed to be handled. It is a specific rule type baked into the Bazel codebase. I wasn't really sure how to determine the rule type within the aspect, so I just hardcoded the label as something to ignore (gross, I know). Additionally, a third party ruleset I use for databinding support had an additional java_library that captured the Android SDK. Luckily, this was marked as neverlink, so I was able to key off of that attribute to avoid capturing the Android SDK from that target in the transitive closure. That should be a decent strategy to follow since the artifacts we're assembling probably shouldn't include neverlink dependencies that were just used to compile.

@@ -88,12 +97,14 @@ def _generate_class_jar(ctx, pom_file):
maven_coordinates = _parse_maven_coordinates(target[JarInfo].name)

jar = None
if hasattr(target, "files") and target.files.to_list() and target.files.to_list()[0].extension == "jar":
if (_is_android_library(target)):
jar = target[AndroidLibraryAarInfo].aar
Copy link
Member

Choose a reason for hiding this comment

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

The information we need here is only the path to the JAR/AAR file.

Is there any way we could retrieve this in a way that is generic to both Java JARs and Android AARs, without requiring a check for _is_android_library? Since ideally we would like to keep this rule as generalised as possible.

@@ -301,6 +327,7 @@ assemble_maven = rule(

MavenDeploymentInfo = provider(
fields = {
'packaging': 'The type of target to publish (jar, war, aar, etc.)',
Copy link
Member

Choose a reason for hiding this comment

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

Given that we are deploying either a JAR or an AAR file, I think it would be more intuitive if we simply read the extension of the file being passed into the deploy_maven rule (instead of relying on a new field in MavenDeploymentInfo) to determine the packaging used in deploy.py.

null
}
keys.contains(entry.name) -> {
// TODO: Investigate why I'm getting duplicates
Copy link
Member

Choose a reason for hiding this comment

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

How serious is this? Can we remove it?

@@ -28,17 +28,20 @@ import java.io.BufferedInputStream
import java.io.BufferedOutputStream
Copy link
Member

Choose a reason for hiding this comment

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

It's cool that this AAR support is added with minimal code change! However, I think the domains of Java and Android are conceptually different (even though Android uses Java code extensively.) As such, I would propose:

  • Rename this file (and class) to Assembler. Given that we are in the maven package, that's unambiguous. Assembler should contain all the logic common to both JAR and AAR.
  • Introduce two inner classes of Assembler: Jar and Aar, which encapsulate the JAR and AAR-specific code. (They will, presumably, need a reference to the Assembler class in their constructors.)

@sugarmanz
Copy link
Contributor Author

Apologies for the delay. I'll be able to revisit this PR in a little while. Just want to reassure that it is my goal to get this merged to help provide broader publishing support to the community 😄

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

Successfully merging this pull request may close these issues.

2 participants