From 3625a9455c0cce7f074d125e700f70a8ce7ed91f Mon Sep 17 00:00:00 2001 From: James Judd Date: Wed, 25 Sep 2024 12:51:20 -0600 Subject: [PATCH] !fixup PR feedback. --- .bazelrc | 9 ++++- README.md | 5 +++ .../CommandLinePlayRoutesCompiler.scala | 8 ++-- play-routes-toolchain/transitions.bzl | 4 +- play-routes/play-routes.bzl | 4 ++ test_workspace.bzl | 39 +++++++------------ workspace.bzl | 5 ++- 7 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.bazelrc b/.bazelrc index c186464..07bff5a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,15 +2,22 @@ startup --expand_configs_in_place common:ci --color=yes +common --experimental_output_paths=off + +build --strategy=worker,sandboxed,local +build --verbose_failures + +build --sandbox_debug +build --incompatible_strict_action_env build --experimental_worker_multiplex_sandboxing build --experimental_worker_cancellation +build --worker_sandboxing build --java_language_version="21" build --java_runtime_version="remotejdk_21" build --tool_java_language_version="21" build --tool_java_runtime_version="remotejdk_21" -build:ci --verbose_failures build:ci --sandbox_debug build:ci --spawn_strategy=standalone build:ci --genrule_strategy=standalone diff --git a/README.md b/README.md index 0d6d71a..dff72e2 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,11 @@ rules_jvm_external_deps() load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup") rules_jvm_external_setup() +load( + "//:workspace.bzl", + "play_routes_compiler_cli_2_13_repositories", + "play_routes_compiler_cli_3_repositories", +) play_routes_compiler_cli_3_repositories() load("@play_routes_compiler_cli_3//:defs.bzl", play_routes_compiler_cli_3_pinned_maven_install = "pinned_maven_install") play_routes_compiler_cli_3_pinned_maven_install() diff --git a/play-routes-compiler-cli/CommandLinePlayRoutesCompiler.scala b/play-routes-compiler-cli/CommandLinePlayRoutesCompiler.scala index 3bfb6ac..8fae971 100644 --- a/play-routes-compiler-cli/CommandLinePlayRoutesCompiler.scala +++ b/play-routes-compiler-cli/CommandLinePlayRoutesCompiler.scala @@ -5,6 +5,7 @@ import higherkindness.rules_scala.common.error.AnnexWorkerError import higherkindness.rules_scala.common.worker.WorkerMain import higherkindness.rules_scala.common.sandbox.SandboxUtil import java.io.{File, PrintStream} +import java.lang.Class import java.nio.file.{Files, Path, Paths} import play.routes.compiler._ import play.routes.compiler.RoutesCompiler.RoutesCompilerTask @@ -38,7 +39,7 @@ object CommandLinePlayRoutesCompiler extends WorkerMain[Unit] { arg[Path]("").required().action { (outputDirectory, config) => config.outputDirectory = SandboxUtil.getSandboxPath(workDir, outputDirectory) config - }.text("directory to output compiled routes to") + }.text("directory to output compiled routes to before packaging them in a JAR") arg[Path]("").required().action { (outputSrcJar, config) => config.outputSrcJar = SandboxUtil.getSandboxPath(workDir, outputSrcJar) @@ -63,10 +64,11 @@ object CommandLinePlayRoutesCompiler extends WorkerMain[Unit] { } else { routesGeneratorClassString + "$" } - val clazz = java.lang.Class.forName(name, true, getClass.getClassLoader) + val clazz = Class.forName(name) + // val clazz = java.lang.Class.forName(name, true, getClass.getClassLoader) clazz.getField("MODULE$").get(null).asInstanceOf[RoutesGenerator] } catch { - case e: Exception => { + case e @ (_:Exception | _:LinkageError | _:ExceptionInInitializerError) => { throw new Exception( s"Could not instantiate a routes generator from the given class: ${routesGeneratorClassString}", e, diff --git a/play-routes-toolchain/transitions.bzl b/play-routes-toolchain/transitions.bzl index 6d0c0b4..6cc4ec6 100644 --- a/play-routes-toolchain/transitions.bzl +++ b/play-routes-toolchain/transitions.bzl @@ -8,9 +8,7 @@ def _play_routes_toolchain_transition_impl(settings, attr): """Update the rules_play_routes toolchain to the overridden value. Store The original value, so it can be reset on the outgoing transition. """ - if attr.play_routes_toolchain_name == "": - return {} - elif settings[toolchain_setting_key] == attr.play_routes_toolchain_name: + if attr.play_routes_toolchain_name == "" or attr.play_routes_toolchain_name == settings[toolchain_setting_key]: # Do nothing when the attribute value is what the setting currently is # otherwise needlessly change build settings by modifying the setting # we store the original value in diff --git a/play-routes/play-routes.bzl b/play-routes/play-routes.bzl index 26f3130..e88a887 100644 --- a/play-routes/play-routes.bzl +++ b/play-routes/play-routes.bzl @@ -76,6 +76,10 @@ def _impl(ctx): ), ] +# If you add any labels or label_lists, you will need to add the +# reset_play_routes_toolchain_transition outgoing transition to it. Otherwise +# you'll end up needlessly changing build config and causing an explosion in +# size for the build graph. play_routes = rule( implementation = _impl, doc = "Compiles Play routes files templates to Scala sources files.", diff --git a/test_workspace.bzl b/test_workspace.bzl index ae4fabe..eff1a5e 100644 --- a/test_workspace.bzl +++ b/test_workspace.bzl @@ -8,35 +8,22 @@ play_version = "3.0.4" specs2_version = "4.20.8" def play_routes_test_3_repositories(): - maven_install( - name = "play_routes_test_3", - artifacts = [ - "org.specs2:specs2-common_3:{}".format(specs2_version), - "org.specs2:specs2-core_3:{}".format(specs2_version), - "org.specs2:specs2-matcher_3:{}".format(specs2_version), - "org.playframework:play_3:{}".format(play_version), - "org.playframework:play-test_3:{}".format(play_version), - "org.playframework:play-specs2_3:{}".format(play_version), - ], - repositories = [ - "https://repo.maven.apache.org/maven2", - "https://maven-central.storage-download.googleapis.com/maven2", - "https://mirror.bazel.build/repo1.maven.org/maven2", - ], - fetch_sources = True, - maven_install_json = "@rules_play_routes//:play_routes_test_3_install.json", - ) + play_routes_test_repositories(scala_version = "3") def play_routes_test_2_13_repositories(): + play_routes_test_repositories(scala_version = "2.13") + +def play_routes_test_repositories(scala_version): + scala_version_underscore = scala_version.replace(".", "_") maven_install( - name = "play_routes_test_2_13", + name = "play_routes_test_{}".format(scala_version_underscore), artifacts = [ - "org.specs2:specs2-common_2.13:{}".format(specs2_version), - "org.specs2:specs2-core_2.13:{}".format(specs2_version), - "org.specs2:specs2-matcher_2.13:{}".format(specs2_version), - "org.playframework:play_2.13:{}".format(play_version), - "org.playframework:play-test_2.13:{}".format(play_version), - "org.playframework:play-specs2_2.13:{}".format(play_version), + "org.specs2:specs2-common_{}:{}".format(scala_version, specs2_version), + "org.specs2:specs2-core_{}:{}".format(scala_version, specs2_version), + "org.specs2:specs2-matcher_{}:{}".format(scala_version, specs2_version), + "org.playframework:play_{}:{}".format(scala_version, play_version), + "org.playframework:play-test_{}:{}".format(scala_version, play_version), + "org.playframework:play-specs2_{}:{}".format(scala_version, play_version), ], repositories = [ "https://repo.maven.apache.org/maven2", @@ -44,5 +31,5 @@ def play_routes_test_2_13_repositories(): "https://mirror.bazel.build/repo1.maven.org/maven2", ], fetch_sources = True, - maven_install_json = "@rules_play_routes//:play_routes_test_2_13_install.json", + maven_install_json = "@rules_play_routes//:play_routes_test_{}_install.json".format(scala_version_underscore), ) diff --git a/workspace.bzl b/workspace.bzl index 18e8ce7..ecb7f66 100644 --- a/workspace.bzl +++ b/workspace.bzl @@ -9,12 +9,13 @@ load("//scala:version.bzl", "scala_2_13_version", "scala_3_version") play_version = "3.0.4" zinc_version = "1.10.1" protobuf_version = "3.19.4" +scopt_version = "4.1.0" def play_routes_compiler_cli_3_repositories(): maven_install( name = "play_routes_compiler_cli_3", artifacts = [ - "com.github.scopt:scopt_3:4.1.0", + "com.github.scopt:scopt_3:{}".format(scopt_version), "com.google.protobuf:protobuf-java:{}".format(protobuf_version), "org.playframework:play-routes-compiler_3:{}".format(play_version), "org.scala-lang:scala3-compiler_3:{}".format(scala_3_version), @@ -36,7 +37,7 @@ def play_routes_compiler_cli_2_13_repositories(): maven_install( name = "play_routes_compiler_cli_2_13", artifacts = [ - "com.github.scopt:scopt_2.13:4.1.0", + "com.github.scopt:scopt_2.13:{}".format(scopt_version), "com.google.protobuf:protobuf-java:{}".format(protobuf_version), "org.playframework:play-routes-compiler_2.13:{}".format(play_version), "org.scala-lang:scala-compiler:{}".format(scala_2_13_version),