Skip to content

Commit

Permalink
Update protobuf (#37)
Browse files Browse the repository at this point in the history
* update protobuf

* update WORKSPACE

* JacocoInstrumenter from Argparse4j to scopt

---------

Co-authored-by: anna-skrodzka <annaskrod@h=gmail.com>
  • Loading branch information
anna-skrodzka and anna-skrodzka authored Oct 5, 2024
1 parent 91fbd29 commit 83cb30b
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 71 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion rules/private/phases/phase_binary_launcher.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions rules/private/phases/phase_bootstrap_compile.bzl
Original file line number Diff line number Diff line change
@@ -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",
)

#
Expand Down
8 changes: 4 additions & 4 deletions rules/private/phases/phase_coverage_jacoco.bzl
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion rules/private/phases/phase_test_launcher.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
3 changes: 2 additions & 1 deletion rules/scala/init.bzl
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion rules/scala/private/doc.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion rules/scala/private/repl.bzl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rules/scala/private/scalajs.bzl
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down
8 changes: 4 additions & 4 deletions rules/scala/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
5 changes: 1 addition & 4 deletions rules/scala_proto/private/core.bzl
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down
8 changes: 4 additions & 4 deletions rules/scalafmt/ext.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion scala/common/sbt-testing/BUILD
Original file line number Diff line number Diff line change
@@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion scala/common/sbt-testing/SubprocessRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion scala/common/worker/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scala/workers/common/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scala/workers/deps/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scala/workers/jacoco/instrumenter/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
53 changes: 26 additions & 27 deletions scala/workers/jacoco/instrumenter/JacocoInstrumenter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
10 changes: 5 additions & 5 deletions scala/workers/zinc/compile/BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
)
1 change: 1 addition & 0 deletions scala/workers/zinc/doc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions scala/workers/zinc/repl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions tests/compile/zinc-inc/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@rules_scala3//rules:scala.bzl", "scala_library")


config_setting(
name = "a2",
values = {"define": "a2=true"},
Expand All @@ -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"],
}),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/dependencies/indirect/BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/format/scalafmt/BUILD
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/grpc/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/proto/BUILD
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 83cb30b

Please sign in to comment.