Skip to content

Commit

Permalink
Merge pull request #103 from cgruber/fix_aar_regression
Browse files Browse the repository at this point in the history
Fix a template error where an extra comma was generated, and add an android example.

Travis still fails, but it's a configuration issue with travis - this passes locally in several environments.
  • Loading branch information
cgruber authored May 11, 2020
2 parents 327ca5a + 3179d75 commit 51ef818
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
23 changes: 14 additions & 9 deletions maven/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def _fetch_artifact_impl(ctx):
if download_path in forbidden_files or not str(download_path).startswith(str(repository_root_path)):
fail("Invalid local_path: %s" % ctx.attr.local_path)
ctx.file("WORKSPACE", "workspace(name = \"{name}\")".format(name = ctx.name))

if ctx.attr.packaging == "aar":
ctx.file(
"%s/BUILD.bazel" % _DOWNLOAD_PREFIX,
Expand Down Expand Up @@ -132,15 +131,15 @@ _MAVEN_REPO_TARGET_TEMPLATE = """maven_jvm_artifact(


_MAVEN_REPO_AAR_TARGET_TEMPLATE = """
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("@{maven_rules_repository}//maven:jetifier.bzl", "jetify")
load("@build_bazel_rules_android//android:rules.bzl", "android_library"){jetify_import}
load("@{maven_rules_repository}//maven:jvm.bzl", "raw_jvm_import")
{jetify}
raw_jvm_import(
name = "{target}_jar",
jar = {classes},
deps = [{deps}],
deps = [{deps}
],
)
android_library(
Expand Down Expand Up @@ -279,12 +278,17 @@ def _aar_template_params(ctx, artifact, deps, manifest, should_jetify):
def _aar_jars(ctx, target, aar_repo, should_jetify):
if should_jetify:
return {
"jetify" :_AAR_JETIFY_TEMPLATE.format(target = target, aar_repo = aar_repo),
"classes" : """ ":{target}_jetified" """.format(target = target)
"jetify_import":
"\nload(\"@{maven_rules_repository}//maven:jetifier.bzl\", \"jetify\")".format(
maven_rules_repository = ctx.attr.maven_rules_repository
),
"jetify": _AAR_JETIFY_TEMPLATE.format(target = target, aar_repo = aar_repo),
"classes": " \":{target}_jetified\"".format(target = target)
}
return {
"jetify" : "",
"classes": """"{aar_repo}:classes.jar",""".format(aar_repo = aar_repo),
"jetify_import": "",
"jetify": "",
"classes": "\"{aar_repo}:classes.jar\"".format(aar_repo = aar_repo),
}

def _generate_maven_repository_impl(ctx):
Expand Down Expand Up @@ -613,7 +617,8 @@ def maven_repository_specification(
jetifier_excludes = DEFAULT_JETIFIER_EXCLUDED_ARTIFACTS,

# Optional list of repositories which the build rule will attempt to fetch maven artifacts and metadata.
repository_urls = ["https://repo1.maven.org/maven2"]):
repository_urls = ["https://repo1.maven.org/maven2"],
):
# Define repository rule for the jetifier tooling
if (use_jetifier):
jetifier_init()
Expand Down
26 changes: 26 additions & 0 deletions test/test_workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ load(
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "build_bazel_rules_android",
sha256 = "cd06d15dd8bb59926e4d65f9003bfc20f9da4b2519985c27e190cddc8b7a7806",
strip_prefix = "rules_android-0.1.1",
urls = ["https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip"],
)

KOTLIN_VERSION = "1.3.71"

KOTLINC_RELEASE_SHA = "7adb77dad99c6d2f7bde9f8bafe4c6244a04587a8e36e62b074d00eda9f8e74a"
Expand Down Expand Up @@ -89,6 +96,13 @@ maven_repository_specification(
"insecure": True,
"build_snippet": AUTO_VALUE_BUILD_SNIPPET_WITH_PLUGIN.format(version = "1.6.3"),
},
"androidx.core:core:1.1.0:aar": {"insecure": True},
"androidx.annotation:annotation:1.1.0": {"insecure": True},
"androidx.lifecycle:lifecycle-runtime:2.0.0:aar": {"insecure": True},
"androidx.versionedparcelable:versionedparcelable:1.1.0:aar": {"insecure": True},
"androidx.collection:collection:1.0.0": {"insecure": True},
"androidx.lifecycle:lifecycle-common:2.0.0": {"insecure": True},
"androidx.arch.core:core-common:2.0.0": {"insecure": True},
},
# Because these apply to all targets within a group, it's specified separately from the artifact list.
dependency_target_substitutes = {
Expand All @@ -99,6 +113,7 @@ maven_repository_specification(
"com.google.dagger": {"@maven//com/google/dagger:dagger": "@maven//com/google/dagger:dagger_api"},
},
jetifier_excludes = [
"androidx.*:*",
"javax.*:jsr250-api",
"com.google.code.findbugs:jsr305",
"com.google.errorprone:javac-shaded",
Expand All @@ -115,5 +130,16 @@ maven_repository_specification(
# "foo.*.bar:baz", # Groups may only have "startswith" style globbing.
# "*.bar:baz", # Groups may only have "startswith" style globbing.
],
repository_urls = [
"https://repo1.maven.org/maven2",
"https://dl.google.com/dl/android/maven2",
],
use_jetifier = True,
)

# Set up the standard android SDK repository, upon which depend a lot of the android tooling in bazel.
android_sdk_repository(
name = "androidsdk",
api_level = 29,
build_tools_version = "29.0.3",
)
14 changes: 14 additions & 0 deletions test/test_workspace/android/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

package(default_visibility = ["//:__subpackages__"])

kt_android_library(
name = "android",
custom_package = "android.blah",
srcs = ["src/main/java/blah/Blah.kt"],
manifest = "src/main/AndroidManifest.xml",
deps = [
"//java/foo",
"@maven//androidx/core"
],
)
4 changes: 4 additions & 0 deletions test/test_workspace/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="bazel.maven.repository.test"
/>
9 changes: 9 additions & 0 deletions test/test_workspace/android/src/main/java/blah/Blah.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package blah

import androidx.core.view.ViewCompat
import foo.Foo

fun useCore() {
val view: ViewCompat? = null
val foo = Foo()
}

0 comments on commit 51ef818

Please sign in to comment.