From 83cb30b246ccad88c138ba0a01ba6ef40bd02d5c Mon Sep 17 00:00:00 2001 From: Anna Skrodzka <56291558+anna-skrodzka@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:21:02 +0200 Subject: [PATCH] Update protobuf (#37) * update protobuf * update WORKSPACE * JacocoInstrumenter from Argparse4j to scopt --------- Co-authored-by: anna-skrodzka --- WORKSPACE | 4 ++ .../private/phases/phase_binary_launcher.bzl | 2 +- .../phases/phase_bootstrap_compile.bzl | 5 +- .../private/phases/phase_coverage_jacoco.bzl | 8 +-- rules/private/phases/phase_test_launcher.bzl | 2 +- rules/scala/init.bzl | 3 +- rules/scala/private/doc.bzl | 2 +- rules/scala/private/repl.bzl | 2 +- rules/scala/private/scalajs.bzl | 2 +- rules/scala/workspace.bzl | 8 +-- rules/scala_proto/private/core.bzl | 5 +- rules/scalafmt/ext.bzl | 8 +-- scala/common/sbt-testing/BUILD | 2 +- .../common/sbt-testing/SubprocessRunner.scala | 2 +- scala/common/worker/BUILD | 2 +- scala/workers/common/BUILD | 2 +- scala/workers/deps/BUILD | 2 +- scala/workers/jacoco/instrumenter/BUILD | 2 +- .../instrumenter/JacocoInstrumenter.scala | 53 +++++++++---------- scala/workers/zinc/compile/BUILD | 10 ++-- scala/workers/zinc/doc/BUILD | 1 + scala/workers/zinc/repl/BUILD | 1 + tests/compile/zinc-inc/BUILD | 5 +- tests/dependencies/indirect/BUILD | 2 +- tests/format/scalafmt/BUILD | 2 +- tests/grpc/BUILD | 2 +- tests/proto/BUILD | 2 +- 27 files changed, 70 insertions(+), 71 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 4c130f6e..57cb5ca0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -126,3 +126,7 @@ scala_proto_register_toolchains() load("@annex_proto//:defs.bzl", annex_proto_pinned_maven_install = "pinned_maven_install") annex_proto_pinned_maven_install() + +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +bazel_features_deps() diff --git a/rules/private/phases/phase_binary_launcher.bzl b/rules/private/phases/phase_binary_launcher.bzl index 2b98df27..5fe467e0 100644 --- a/rules/private/phases/phase_binary_launcher.bzl +++ b/rules/private/phases/phase_binary_launcher.bzl @@ -1,8 +1,8 @@ +load("//rules/common:private/get_toolchain.bzl", "get_toolchain") load( "//rules/common:private/utils.bzl", _write_launcher = "write_launcher", ) -load("//rules/common:private/get_toolchain.bzl", "get_toolchain") # # PHASE: binary_launcher diff --git a/rules/private/phases/phase_bootstrap_compile.bzl b/rules/private/phases/phase_bootstrap_compile.bzl index a36ee825..25c83a41 100644 --- a/rules/private/phases/phase_bootstrap_compile.bzl +++ b/rules/private/phases/phase_bootstrap_compile.bzl @@ -1,10 +1,7 @@ -load( - "//rules/common:private/utils.bzl", - _strip_margin = "strip_margin", -) load( "//rules/common:private/utils.bzl", _resolve_execution_reqs = "resolve_execution_reqs", + _strip_margin = "strip_margin", ) # diff --git a/rules/private/phases/phase_coverage_jacoco.bzl b/rules/private/phases/phase_coverage_jacoco.bzl index b14bed8c..d29df5ea 100644 --- a/rules/private/phases/phase_coverage_jacoco.bzl +++ b/rules/private/phases/phase_coverage_jacoco.bzl @@ -1,11 +1,11 @@ -load( - "@rules_scala3//rules/private:coverage_replacements_provider.bzl", - _coverage_replacements_provider = "coverage_replacements_provider", -) load( "@rules_scala3//rules/common:private/utils.bzl", _resolve_execution_reqs = "resolve_execution_reqs", ) +load( + "@rules_scala3//rules/private:coverage_replacements_provider.bzl", + _coverage_replacements_provider = "coverage_replacements_provider", +) load("//rules/common:private/get_toolchain.bzl", "get_toolchain") def phase_coverage_jacoco(ctx, g): diff --git a/rules/private/phases/phase_test_launcher.bzl b/rules/private/phases/phase_test_launcher.bzl index e3f33033..f959ae06 100644 --- a/rules/private/phases/phase_test_launcher.bzl +++ b/rules/private/phases/phase_test_launcher.bzl @@ -37,7 +37,7 @@ def phase_test_launcher(ctx, g): args = ctx.actions.args() args.add("--parallel", ctx.attr.parallel) if ctx.attr.parallel_n: - args.add(ctx.attr.parallel_n, format = "--parallel-n=%s") + args.add(ctx.attr.parallel_n, format = "--parallel-n=%s") args.add("--apis", g.compile.zinc_info.apis.short_path) args.add_all(ctx.attr.frameworks, format_each = "--framework=%s") if ctx.attr.isolation == "classloader": diff --git a/rules/scala/init.bzl b/rules/scala/init.bzl index 5bb238cf..31296853 100644 --- a/rules/scala/init.bzl +++ b/rules/scala/init.bzl @@ -1,5 +1,6 @@ load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") +load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") +load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains") def rules_scala3_init(): protobuf_deps() diff --git a/rules/scala/private/doc.bzl b/rules/scala/private/doc.bzl index 6d3dcf81..fd9484be 100644 --- a/rules/scala/private/doc.bzl +++ b/rules/scala/private/doc.bzl @@ -1,9 +1,9 @@ +load("//rules/common:private/get_toolchain.bzl", "get_toolchain") load( "//rules/common:private/utils.bzl", _collect = "collect", _resolve_execution_reqs = "resolve_execution_reqs", ) -load("//rules/common:private/get_toolchain.bzl", "get_toolchain") scaladoc_private_attributes = { "_runner": attr.label( diff --git a/rules/scala/private/repl.bzl b/rules/scala/private/repl.bzl index 7581bbfe..46f9cdb7 100644 --- a/rules/scala/private/repl.bzl +++ b/rules/scala/private/repl.bzl @@ -1,5 +1,5 @@ -load("//rules/common:private/utils.bzl", "write_launcher", _collect = "collect") load("//rules/common:private/get_toolchain.bzl", "get_toolchain") +load("//rules/common:private/utils.bzl", "write_launcher", _collect = "collect") def scala_repl_implementation(ctx): toolchain = get_toolchain(ctx) diff --git a/rules/scala/private/scalajs.bzl b/rules/scala/private/scalajs.bzl index b73bcbd2..684d00c6 100644 --- a/rules/scala/private/scalajs.bzl +++ b/rules/scala/private/scalajs.bzl @@ -1,9 +1,9 @@ -load("@rules_scala3//rules:scala.bzl", "scala_library") load( "@rules_scala3//rules:providers.bzl", _ScalaConfiguration = "ScalaConfiguration", _ScalaInfo = "ScalaInfo", ) +load("@rules_scala3//rules:scala.bzl", "scala_library") def scalajs_library(name, srcs, deps = [], visibility = None, scalacopts = [], scala = None, deps_used_whitelist = []): """Make scalajs library for provided sources""" diff --git a/rules/scala/workspace.bzl b/rules/scala/workspace.bzl index e642f4af..948edc3c 100644 --- a/rules/scala/workspace.bzl +++ b/rules/scala/workspace.bzl @@ -97,13 +97,13 @@ def scala_repositories(): for dep in direct_deps: maybe(jvm_maven_import_external, name = dep[0], artifact = dep[1], artifact_sha256 = dep[2] if len(dep) == 3 else "", server_urls = repositories) - protobuf_tag = "21.12" - rules_proto_tag = "5.3.0-21.7" + protobuf_tag = "28.2" + rules_proto_tag = "6.0.2" skylib_tag = "1.5.0" rules_deps = [ ["bazel_skylib", None, "https://github.com/bazelbuild/bazel-skylib/releases/download/{v}/bazel-skylib-{v}.tar.gz".format(v = skylib_tag), "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94"], - ["com_google_protobuf", "protobuf-" + protobuf_tag, "https://github.com/protocolbuffers/protobuf/archive/v{}.tar.gz".format(protobuf_tag), "22fdaf641b31655d4b2297f9981fa5203b2866f8332d3c6333f6b0107bb320de"], - ["rules_proto", "rules_proto-" + rules_proto_tag, "https://github.com/bazelbuild/rules_proto/archive/{}.tar.gz".format(rules_proto_tag), "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd"], + ["com_google_protobuf", "protobuf-" + protobuf_tag, "https://github.com/protocolbuffers/protobuf/archive/v{}.tar.gz".format(protobuf_tag), "b2340aa47faf7ef10a0328190319d3f3bee1b24f426d4ce8f4253b6f27ce16db"], + ["rules_proto", "rules_proto-" + rules_proto_tag, "https://github.com/bazelbuild/rules_proto/archive/{}.tar.gz".format(rules_proto_tag), "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295"], ] for dep in rules_deps: maybe(http_archive, name = dep[0], strip_prefix = dep[1], url = dep[2], sha256 = dep[3] if len(dep) == 4 else "") diff --git a/rules/scala_proto/private/core.bzl b/rules/scala_proto/private/core.bzl index 912e9e87..5d43f867 100644 --- a/rules/scala_proto/private/core.bzl +++ b/rules/scala_proto/private/core.bzl @@ -1,10 +1,7 @@ -load( - "//rules/common:private/utils.bzl", - _safe_name = "safe_name", -) load( "//rules/common:private/utils.bzl", _resolve_execution_reqs = "resolve_execution_reqs", + _safe_name = "safe_name", ) scala_proto_library_private_attributes = {} diff --git a/rules/scalafmt/ext.bzl b/rules/scalafmt/ext.bzl index fa4beea4..a5719e65 100644 --- a/rules/scalafmt/ext.bzl +++ b/rules/scalafmt/ext.bzl @@ -3,15 +3,15 @@ load( "@rules_scala3//rules:providers.bzl", _ScalaRulePhase = "ScalaRulePhase", ) +load( + "//rules/private:phases.bzl", + _phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs", +) load( "//rules/scalafmt:private/test.bzl", _scala_format_attributes = "scala_format_attributes", _scala_non_default_format_attributes = "scala_non_default_format_attributes", ) -load( - "//rules/private:phases.bzl", - _phase_scalafmt_nondefault_outputs = "phase_scalafmt_nondefault_outputs", -) ext_with_non_default_format = { "attrs": _dicts.add( diff --git a/scala/common/sbt-testing/BUILD b/scala/common/sbt-testing/BUILD index 5d333c3d..7652d181 100644 --- a/scala/common/sbt-testing/BUILD +++ b/scala/common/sbt-testing/BUILD @@ -1,5 +1,5 @@ -load("//rules:scalafmt.bzl", "scala_format_test") load("//rules:scala.bzl", "scala_library") +load("//rules:scalafmt.bzl", "scala_format_test") _subprocess_srcs = ["SubprocessRunner.scala"] diff --git a/scala/common/sbt-testing/SubprocessRunner.scala b/scala/common/sbt-testing/SubprocessRunner.scala index bfd76eb0..e76d29e5 100644 --- a/scala/common/sbt-testing/SubprocessRunner.scala +++ b/scala/common/sbt-testing/SubprocessRunner.scala @@ -11,7 +11,7 @@ object SubprocessTestRunner: val request = input.readObject().asInstanceOf[TestRequest] val classLoader = ClassLoaders.sbtTestClassLoader(request.classpath.map(path => Paths.get(path).toUri.toURL)) - val loader = TestFrameworkLoader(classLoader, request.logger) + val loader = TestFrameworkLoader(classLoader) val framework = loader.load(request.framework).get val passed = ClassLoaders.withContextClassLoader(classLoader) { diff --git a/scala/common/worker/BUILD b/scala/common/worker/BUILD index 64339498..412e2f7e 100644 --- a/scala/common/worker/BUILD +++ b/scala/common/worker/BUILD @@ -1,6 +1,6 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("//scala3:defs.bzl", "worker_scala_library") load("//rules:scalafmt.bzl", "scala_format_test") +load("//scala3:defs.bzl", "worker_scala_library") proto_library( name = "worker_protocol_proto", diff --git a/scala/workers/common/BUILD b/scala/workers/common/BUILD index a4079a7c..0f516ed0 100644 --- a/scala/workers/common/BUILD +++ b/scala/workers/common/BUILD @@ -1,5 +1,5 @@ -load("//scala3:defs.bzl", "worker_scala_library") load("//rules:scalafmt.bzl", "scala_format_test") +load("//scala3:defs.bzl", "worker_scala_library") worker_scala_library( name = "common", diff --git a/scala/workers/deps/BUILD b/scala/workers/deps/BUILD index 8890ab7d..767f0818 100644 --- a/scala/workers/deps/BUILD +++ b/scala/workers/deps/BUILD @@ -1,5 +1,5 @@ -load("//scala3:defs.bzl", "worker_scala_binary") load("//rules:scalafmt.bzl", "scala_format_test") +load("//scala3:defs.bzl", "worker_scala_binary") worker_scala_binary( name = "deps", diff --git a/scala/workers/jacoco/instrumenter/BUILD b/scala/workers/jacoco/instrumenter/BUILD index 3298200c..1347258a 100644 --- a/scala/workers/jacoco/instrumenter/BUILD +++ b/scala/workers/jacoco/instrumenter/BUILD @@ -1,5 +1,5 @@ -load("//scala3:defs.bzl", "worker_scala_binary") load("//rules:scalafmt.bzl", "scala_format_test") +load("//scala3:defs.bzl", "worker_scala_binary") worker_scala_binary( name = "instrumenter", diff --git a/scala/workers/jacoco/instrumenter/JacocoInstrumenter.scala b/scala/workers/jacoco/instrumenter/JacocoInstrumenter.scala index 00f233c2..58b9e451 100644 --- a/scala/workers/jacoco/instrumenter/JacocoInstrumenter.scala +++ b/scala/workers/jacoco/instrumenter/JacocoInstrumenter.scala @@ -8,45 +8,44 @@ import java.net.URI import java.nio.file.* import java.nio.file.attribute.BasicFileAttributes import java.util.Collections -import java.util.List as JList import org.jacoco.core.instr.Instrumenter import org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator import scala.jdk.CollectionConverters.* +import scopt.OParser -object JacocoInstrumenter extends WorkerMain[Unit]: - private val argParser = - val parser = ArgumentParsers.newFor("jacoco-instrumenter").addHelp(true).fromFilePrefix("@").build - parser - .addArgument("--jar") - .action(Arguments.append) - .help("jar to instrument") - .metavar("inpath=outpath") - .nargs("+") - parser +final case class JacocoArgs(jars: Vector[(Path, Path)] = Vector.empty) + +object JacocoArgs: + private val builder = OParser.builder[JacocoArgs] + import builder.* + + private val parser = OParser.sequence( + opt[String]("jar") + .unbounded() + .required() + .action((arg, c) => c.copy(jars = c.jars :+ parseJar(arg))) + .text("Jar to instrument in the format inpath=outpath") + ) + + def apply(args: collection.Seq[String]): Option[JacocoArgs] = + OParser.parse(parser, args, JacocoArgs()) + private def parseJar(arg: String): (Path, Path) = + arg.split("=") match + case Array(in, out) => (Paths.get(in), Paths.get(out)) + case _ => sys.error(s"Expected input=output for argument: $arg") + +object JacocoInstrumenter extends WorkerMain[Unit]: override def init(args: collection.Seq[String]): Unit = () override def work(ctx: Unit, args: collection.Seq[String]): Unit = - val namespace = argParser.parseArgs(args) - - val pathPairs: List[(Path, Path)] = namespace - .getList[JList[String]]("jar") - .asScala - .flatMap(_.asScala) - .map(other => - other.split("=") match - case Array(in, out) => (Paths.get(in), Paths.get(out)) - case _ => - sys.error("expected input=output for argument: " + other) - ) - .toList + val jacocoArgs = JacocoArgs(args).getOrElse(throw IllegalArgumentException(s"Invalid arguments: ${args.mkString(" ")}")) val jacoco = new Instrumenter(new OfflineInstrumentationAccessGenerator) - pathPairs.foreach { case (inPath, outPath) => + jacocoArgs.jars.foreach { case (inPath, outPath) => val inFS = FileSystems.newFileSystem(inPath, null) - val outFS = - FileSystems.newFileSystem(URI.create("jar:" + outPath.toUri), Collections.singletonMap("create", "true")) + val outFS = FileSystems.newFileSystem(URI.create("jar:" + outPath.toUri), Collections.singletonMap("create", "true")) val roots = inFS.getRootDirectories.asScala.toList val instrumentVisitor = new SimpleFileVisitor[Path]: diff --git a/scala/workers/zinc/compile/BUILD b/scala/workers/zinc/compile/BUILD index e83b105f..13594d5c 100644 --- a/scala/workers/zinc/compile/BUILD +++ b/scala/workers/zinc/compile/BUILD @@ -1,5 +1,5 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("//rules:scala.bzl", "scala_test", "scala_library") +load("//rules:scala.bzl", "scala_library", "scala_test") load("//scala3:defs.bzl", "worker_scala_binary") proto_library( @@ -20,6 +20,7 @@ worker_scala_binary( main_class = "rules_scala.workers.zinc.compile.ZincRunner", visibility = ["//visibility:public"], deps = [ + ":diagnostics_java_proto", "@annex//:com_github_scopt_scopt_3", "@annex//:org_scala_sbt_compiler_interface", "@annex//:org_scala_sbt_util_interface", @@ -32,15 +33,16 @@ worker_scala_binary( "@rules_scala3//rules/third_party/jarhelper", "@rules_scala3//scala/common/worker", "@rules_scala3//scala/workers/common", - ":diagnostics_java_proto", ], ) scala_library( name = "lib", srcs = glob(["main/*.scala"]), + scala = "@//:zinc_3", visibility = ["//visibility:public"], deps = [ + ":diagnostics_java_proto", "@annex//:com_github_scopt_scopt_3", "@annex//:org_scala_sbt_compiler_interface", "@annex//:org_scala_sbt_util_interface", @@ -53,18 +55,16 @@ scala_library( "@rules_scala3//rules/third_party/jarhelper", "@rules_scala3//scala/common/worker", "@rules_scala3//scala/workers/common", - ":diagnostics_java_proto", ], - scala = "@//:zinc_3", ) scala_test( name = "tests", srcs = glob(["test/*.scala"]), + scala = "@//:zinc_3", deps = [ ":lib", "@annex//:org_scalameta_munit_3", "@rules_scala3//scala/workers/common", ], - scala = "@//:zinc_3", ) diff --git a/scala/workers/zinc/doc/BUILD b/scala/workers/zinc/doc/BUILD index f2f2c189..a64bc2c6 100644 --- a/scala/workers/zinc/doc/BUILD +++ b/scala/workers/zinc/doc/BUILD @@ -5,6 +5,7 @@ scala_binary( name = "doc", srcs = glob(["**/*.scala"]), jvm_flags = ["-Djava.security.manager=allow"], + main_class = "rules_scala.workers.zinc.doc.DocRunner", visibility = ["//visibility:public"], deps = [ "//scala/common/worker", diff --git a/scala/workers/zinc/repl/BUILD b/scala/workers/zinc/repl/BUILD index 01a36988..90d30886 100644 --- a/scala/workers/zinc/repl/BUILD +++ b/scala/workers/zinc/repl/BUILD @@ -4,6 +4,7 @@ load("//rules:scalafmt.bzl", "scala_format_test") scala_binary( name = "repl", srcs = glob(["**/*.scala"]), + main_class = "rules_scala.workers.zinc.repl.ReplRunner", visibility = ["//visibility:public"], runtime_deps = [ "@annex//:org_jline_jline_reader", diff --git a/tests/compile/zinc-inc/BUILD b/tests/compile/zinc-inc/BUILD index 38771469..057af7b8 100644 --- a/tests/compile/zinc-inc/BUILD +++ b/tests/compile/zinc-inc/BUILD @@ -1,6 +1,5 @@ load("@rules_scala3//rules:scala.bzl", "scala_library") - config_setting( name = "a2", values = {"define": "a2=true"}, @@ -10,8 +9,8 @@ config_setting( scala_library( name = "a", srcs = select({ - ":a2": ["A2.scala"], - "//conditions:default": ["A1.scala"], + ":a2": ["A2.scala"], + "//conditions:default": ["A1.scala"], }), ) diff --git a/tests/dependencies/indirect/BUILD b/tests/dependencies/indirect/BUILD index c7675d0f..13889797 100644 --- a/tests/dependencies/indirect/BUILD +++ b/tests/dependencies/indirect/BUILD @@ -1,5 +1,5 @@ -load("@rules_scala3//rules:scala.bzl", "scala_library") load("@rules_scala3//rules:providers.bzl", "reconfigure_deps_configuration") +load("@rules_scala3//rules:scala.bzl", "scala_library") # used_deps off reconfigure_deps_configuration( diff --git a/tests/format/scalafmt/BUILD b/tests/format/scalafmt/BUILD index 96fb5cf1..5e59e5e9 100644 --- a/tests/format/scalafmt/BUILD +++ b/tests/format/scalafmt/BUILD @@ -1,5 +1,5 @@ -load("@rules_scala3//rules:scalafmt.bzl", "scala_format_test") load("@rules_scala3//rules:scala_with_scalafmt.bzl", "scala_binary", "scala_library", "scala_test") +load("@rules_scala3//rules:scalafmt.bzl", "scala_format_test") ### scala_format_test ### scala_format_test( diff --git a/tests/grpc/BUILD b/tests/grpc/BUILD index d30f5415..5104336b 100644 --- a/tests/grpc/BUILD +++ b/tests/grpc/BUILD @@ -1,6 +1,6 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("@rules_scala3//rules:scala_proto.bzl", "scala_proto_library") load("@rules_scala3//rules:scala.bzl", "scala_library") +load("@rules_scala3//rules:scala_proto.bzl", "scala_proto_library") proto_library( name = "grpc_proto", diff --git a/tests/proto/BUILD b/tests/proto/BUILD index 855ddd1c..ea54baa8 100644 --- a/tests/proto/BUILD +++ b/tests/proto/BUILD @@ -1,6 +1,6 @@ load("@rules_proto//proto:defs.bzl", "proto_library") -load("@rules_scala3//rules:scala_proto.bzl", "scala_proto_library") load("@rules_scala3//rules:scala.bzl", "scala_library") +load("@rules_scala3//rules:scala_proto.bzl", "scala_proto_library") proto_library( name = "events_proto",