Skip to content

Commit

Permalink
Split jettifies so that maven_install doesn't call rules_java
Browse files Browse the repository at this point in the history
  • Loading branch information
comius committed Sep 30, 2023
1 parent 94aa5a8 commit 1243532
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 84 deletions.
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bzl_library(
"//private/rules:java_export.bzl",
"//private/rules:javadoc.bzl",
"//private/rules:jetifier.bzl",
"//private/rules:jetifier_rules.bzl",
"//private/rules:jetifier_maven_map.bzl",
"//private/rules:jvm_import.bzl",
"//private/rules:maven_bom.bzl",
Expand Down
12 changes: 0 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ load(
"COURSIER_CLI_SHA256",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/6.3.1/rules_java-6.3.1.tar.gz",
],
sha256 = "117a1227cdaf813a20a1bba78a9f2d8fb30841000c33e2f2d2a640bd224c9282",
)
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
rules_java_dependencies()
rules_java_toolchains()

http_file(
name = COURSIER_CLI_HTTP_FILE_NAME,
sha256 = COURSIER_CLI_SHA256,
Expand Down
2 changes: 1 addition & 1 deletion coursier.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _BUILD = """
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@rules_jvm_external//private/rules:jvm_import.bzl", "jvm_import")
load("@rules_jvm_external//private/rules:jetifier.bzl", "jetify_aar_import", "jetify_jvm_import")
load("@rules_jvm_external//private/rules:jetifier_rules.bzl", "jetify_aar_import", "jetify_jvm_import")
{aar_import_statement}
{imports}
Expand Down
71 changes: 0 additions & 71 deletions private/rules/jetifier.bzl
Original file line number Diff line number Diff line change
@@ -1,76 +1,5 @@
load("//:specs.bzl", "parse")
load(":jetifier_maven_map.bzl", "jetifier_maven_map")
load(":jvm_import.bzl", "jvm_import")

_DEPRECATION_MESSAGE = "Please update your dependencies to no longer require jetification."

def _jetify_impl(ctx):
srcs = ctx.attr.srcs
outfiles = []
for src in srcs:
for artifact in src.files.to_list():
jetified_outfile = ctx.actions.declare_file("jetified_" + artifact.basename, sibling = artifact)
jetify_args = ctx.actions.args()
jetify_args.add("-l", "error")
jetify_args.add("-o", jetified_outfile)
jetify_args.add("-i", artifact)
jetify_args.add("-timestampsPolicy", "keepPrevious")
ctx.actions.run(
mnemonic = "Jetify",
inputs = [artifact],
outputs = [jetified_outfile],
progress_message = "Jetifying {}".format(artifact.owner),
executable = ctx.executable._jetifier,
arguments = [jetify_args],
)
outfiles.append(jetified_outfile)

return [DefaultInfo(files = depset(outfiles))]

jetify = rule(
attrs = {
"srcs": attr.label_list(allow_files = [".jar", ".aar"]),
"_jetifier": attr.label(
executable = True,
default = Label("@rules_jvm_external//third_party/jetifier"),
cfg = "exec",
),
},
implementation = _jetify_impl,
)

def jetify_aar_import(name, aar, _aar_import = None, visibility = None, **kwargs):
jetify(
name = "jetified_" + name,
deprecation = _DEPRECATION_MESSAGE,
srcs = [aar],
visibility = visibility,
)

if not _aar_import:
_aar_import = native.aar_import

_aar_import(
name = name,
aar = ":jetified_" + name,
visibility = visibility,
**kwargs
)

def jetify_jvm_import(name, jars, visibility = None, **kwargs):
jetify(
name = "jetified_" + name,
deprecation = _DEPRECATION_MESSAGE,
srcs = jars,
visibility = visibility,
)

jvm_import(
name = name,
jars = [":jetified_" + name],
visibility = visibility,
**kwargs
)

def jetify_maven_coord(group, artifact, version):
"""
Expand Down
72 changes: 72 additions & 0 deletions private/rules/jetifier_rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
load(":jvm_import.bzl", "jvm_import")

_DEPRECATION_MESSAGE = "Please update your dependencies to no longer require jetification."

def _jetify_impl(ctx):
srcs = ctx.attr.srcs
outfiles = []
for src in srcs:
for artifact in src.files.to_list():
jetified_outfile = ctx.actions.declare_file("jetified_" + artifact.basename, sibling = artifact)
jetify_args = ctx.actions.args()
jetify_args.add("-l", "error")
jetify_args.add("-o", jetified_outfile)
jetify_args.add("-i", artifact)
jetify_args.add("-timestampsPolicy", "keepPrevious")
ctx.actions.run(
mnemonic = "Jetify",
inputs = [artifact],
outputs = [jetified_outfile],
progress_message = "Jetifying {}".format(artifact.owner),
executable = ctx.executable._jetifier,
arguments = [jetify_args],
)
outfiles.append(jetified_outfile)

return [DefaultInfo(files = depset(outfiles))]

jetify = rule(
attrs = {
"srcs": attr.label_list(allow_files = [".jar", ".aar"]),
"_jetifier": attr.label(
executable = True,
default = Label("@rules_jvm_external//third_party/jetifier"),
cfg = "exec",
),
},
implementation = _jetify_impl,
)

def jetify_aar_import(name, aar, _aar_import = None, visibility = None, **kwargs):
jetify(
name = "jetified_" + name,
deprecation = _DEPRECATION_MESSAGE,
srcs = [aar],
visibility = visibility,
)

if not _aar_import:
_aar_import = native.aar_import

_aar_import(
name = name,
aar = ":jetified_" + name,
visibility = visibility,
**kwargs
)

def jetify_jvm_import(name, jars, visibility = None, **kwargs):
jetify(
name = "jetified_" + name,
deprecation = _DEPRECATION_MESSAGE,
srcs = jars,
visibility = visibility,
)

jvm_import(
name = name,
jars = [":jetified_" + name],
visibility = visibility,
**kwargs
)

9 changes: 9 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ _DEFAULT_REPOSITORIES = [
]

def rules_jvm_external_deps(repositories = _DEFAULT_REPOSITORIES):
maybe(
http_archive,
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/6.3.1/rules_java-6.3.1.tar.gz",
],
sha256 = "117a1227cdaf813a20a1bba78a9f2d8fb30841000c33e2f2d2a640bd224c9282",
)

maybe(
http_archive,
name = "bazel_skylib",
Expand Down
4 changes: 4 additions & 0 deletions setup.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
load("@rules_jvm_external_deps//:defs.bzl", "pinned_maven_install")
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

def rules_jvm_external_setup():
rules_java_dependencies()
rules_java_toolchains()

bazel_skylib_workspace()
pinned_maven_install()

0 comments on commit 1243532

Please sign in to comment.