Skip to content

Commit

Permalink
Bazel 7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredNeil committed Dec 11, 2023
1 parent d396b91 commit 096e1b9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04]
bazel_version: [5.0.0, 6.3.2]
bazel_version: [6.3.2, 7.0.0]
steps:
- uses: actions/checkout@v3
- run: ./scripts/ci.sh build
Expand Down
4 changes: 2 additions & 2 deletions rules/private/phases/phase_binary_launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def phase_binary_launcher(ctx, g):
ctx,
"{}/".format(ctx.label.name),
ctx.outputs.bin,
g.javainfo.java_info.transitive_runtime_deps,
g.javainfo.java_info.transitive_runtime_jars,
jvm_flags = [ctx.expand_location(f, ctx.attr.data) for f in ctx.attr.jvm_flags],
main_class = main_class,
)
Expand All @@ -35,7 +35,7 @@ def phase_binary_launcher(ctx, g):
files = inputs + files,
transitive_files = depset(
order = "default",
transitive = [ctx.attr._target_jdk[java_common.JavaRuntimeInfo].files, g.javainfo.java_info.transitive_runtime_deps],
transitive = [ctx.attr._target_jdk[java_common.JavaRuntimeInfo].files, g.javainfo.java_info.transitive_runtime_jars],
),
collect_default = True,
),
Expand Down
8 changes: 4 additions & 4 deletions rules/private/phases/phase_test_launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def phase_test_launcher(ctx, g):

test_jars = depset(direct = [
coverage_replacements[jar] if jar in coverage_replacements else jar
for jar in g.javainfo.java_info.transitive_runtime_deps.to_list()
for jar in g.javainfo.java_info.transitive_runtime_jars.to_list()
])
runner_jars = depset(transitive = [ctx.attr.runner[JavaInfo].transitive_runtime_deps, coverage_runner_jars])
runner_jars = depset(transitive = [ctx.attr.runner[JavaInfo].transitive_runtime_jars, coverage_runner_jars])
all_jars = [test_jars, runner_jars]

args = ctx.actions.args()
Expand All @@ -40,10 +40,10 @@ def phase_test_launcher(ctx, g):
if ctx.attr.isolation == "classloader":
shared_deps = java_common.merge(_collect(JavaInfo, ctx.attr.shared_deps))
args.add("--isolation", "classloader")
args.add_all("--shared_classpath", shared_deps.transitive_runtime_deps, map_each = _test_launcher_short_path)
args.add_all("--shared_classpath", shared_deps.transitive_runtime_jars, map_each = _test_launcher_short_path)
elif ctx.attr.isolation == "process":
subprocess_executable = ctx.actions.declare_file("{}/subprocess".format(ctx.label.name))
subprocess_runner_jars = ctx.attr.subprocess_runner[JavaInfo].transitive_runtime_deps
subprocess_runner_jars = ctx.attr.subprocess_runner[JavaInfo].transitive_runtime_jars
all_jars.append(subprocess_runner_jars)
files += _write_launcher(
ctx,
Expand Down
4 changes: 4 additions & 0 deletions rules/scala.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def make_scala_library(*extras):
*[extra["outputs"] for extra in extras]
),
implementation = _scala_library_implementation,
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
)

scala_library = make_scala_library()
Expand Down Expand Up @@ -302,6 +303,7 @@ To run the program: `bazel run <target>`
*[extra["outputs"] for extra in extras]
),
implementation = _scala_binary_implementation,
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
)

scala_binary = make_scala_binary()
Expand Down Expand Up @@ -365,6 +367,7 @@ To build and run a specific test: `bazel test <target> --test_filter=<filter_exp
),
test = True,
implementation = _scala_test_implementation,
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
)

scala_test = make_scala_test()
Expand Down Expand Up @@ -417,6 +420,7 @@ To run: `bazel run <target>`
"bin": "%{name}-bin",
},
implementation = _scala_repl_implementation,
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"],
)

scala_import = rule(
Expand Down
4 changes: 2 additions & 2 deletions rules/scala/private/doc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def scaladoc_implementation(ctx):
classpath = depset(transitive = [dep[JavaInfo].transitive_deps for dep in ctx.attr.deps])
compiler_classpath = depset(
transitive =
[scompiler_classpath.transitive_runtime_deps] +
[dep[JavaInfo].transitive_runtime_deps for dep in ctx.attr.compiler_deps],
[scompiler_classpath.transitive_runtime_jars] +
[dep[JavaInfo].transitive_runtime_jars for dep in ctx.attr.compiler_deps],
)

srcs = [file for file in ctx.files.srcs if file.extension.lower() in ["java", "scala"]]
Expand Down
6 changes: 3 additions & 3 deletions rules/scala/private/repl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def scala_repl_implementation(ctx):
_collect(JavaInfo, scala_configuration.compiler_classpath),
)

classpath = depset(transitive = [dep[JavaInfo].transitive_runtime_deps for dep in ctx.attr.deps])
runner_classpath = ctx.attr._runner[JavaInfo].transitive_runtime_deps
classpath = depset(transitive = [dep[JavaInfo].transitive_runtime_jars for dep in ctx.attr.deps])
runner_classpath = ctx.attr._runner[JavaInfo].transitive_runtime_jars

args = ctx.actions.args()
args.add("--compiler_bridge", zinc_configuration.compiler_bridge.short_path)
Expand All @@ -42,7 +42,7 @@ def scala_repl_implementation(ctx):

files = depset(
[args_file, zinc_configuration.compiler_bridge] + launcher_files,
transitive = [classpath, runner_classpath, scompiler_classpath.transitive_runtime_deps],
transitive = [classpath, runner_classpath, scompiler_classpath.transitive_runtime_jars],
)
return [
DefaultInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ object DepsRunner extends WorkerMain[Unit] {
case _ => throw new Exception(s"Unexpected case in DepsRunner")
}
val labelToPaths = groups.toMap
def pathsForLabel(depLabel: String) = Seq(depLabel, s"@${depLabel}", depLabel.stripPrefix("@")).collect(labelToPaths).flatten
val usedPaths = Files.readAllLines(namespace.get[File]("used").toPath).asScala.toSet

val remove = if (namespace.getBoolean("check_used") == true) {
val usedWhitelist = namespace.getList[String]("used_whitelist").asScala.map(_.tail).toList
directLabels
.diff(usedWhitelist)
.filterNot(label => labelToPaths.getOrElse(label, labelToPaths(s"@$label")).exists(usedPaths))
.filterNot(label => pathsForLabel(label).exists(usedPaths))
} else Nil
remove.foreach { depLabel =>
out.println(s"Target '$depLabel' not used, please remove it from the deps.")
Expand All @@ -76,9 +77,7 @@ object DepsRunner extends WorkerMain[Unit] {

val add = if (namespace.getBoolean("check_direct") == true) {
val unusedWhitelist = namespace.getList[String]("unused_whitelist").asScala.map(_.tail).toList
(usedPaths -- (directLabels :++ unusedWhitelist).flatMap { label =>
labelToPaths.getOrElse(label, labelToPaths(s"@$label"))
})
(usedPaths -- (directLabels :++ unusedWhitelist).flatMap(pathsForLabel))
.flatMap { path =>
groups.collectFirst { case (label, paths) if paths(path) => label }.orElse {
System.err.println(s"Warning: There is a reference to $path, but no dependency of $label provides it")
Expand Down

0 comments on commit 096e1b9

Please sign in to comment.