Skip to content

Commit

Permalink
Support path mapping and better support cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
jjudd committed Oct 12, 2024
1 parent 43e2a76 commit 65f5417
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ startup --expand_configs_in_place

common:ci --color=yes

common --experimental_output_paths=off

build --strategy=worker,sandboxed,local
build --verbose_failures

Expand Down
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ workspace(name = "rules_play_routes")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# rules_java
http_archive(
name = "rules_java",
sha256 = "6f3ce0e9fba979a844faba2d60467843fbf5191d8ca61fa3d2ea17655b56bb8c",
Expand All @@ -17,11 +18,11 @@ rules_java_dependencies()
register_toolchains("//:repository_default_toolchain_21_definition")

# rules_jvm_external
rules_jvm_external_version = "6.2"
rules_jvm_external_version = "6.4"

http_archive(
name = "rules_jvm_external",
sha256 = "aa39ecd47e16d5870eba817fe71476802bc371fe2724a2ddee565992df55f4af",
sha256 = "8c92f7c7a57273c692da459f70bd72464c87442e86b9e0b495950a7c554c254f",
strip_prefix = "rules_jvm_external-{}".format(rules_jvm_external_version),
type = "zip",
url = "https://github.com/bazelbuild/rules_jvm_external/archive/{}.zip".format(rules_jvm_external_version),
Expand Down
7 changes: 6 additions & 1 deletion play-routes-compiler-cli/CommandLinePlayRoutesCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rulesplayroutes.routes

import com.google.devtools.build.buildjar.jarhelper.JarCreator
import higherkindness.rules_scala.common.error.AnnexWorkerError
import higherkindness.rules_scala.common.interrupt.InterruptUtil
import higherkindness.rules_scala.common.worker.WorkerMain
import higherkindness.rules_scala.common.sandbox.SandboxUtil
import java.io.{File, PrintStream}
Expand Down Expand Up @@ -121,6 +122,7 @@ object CommandLinePlayRoutesCompiler extends WorkerMain[Unit] {
config.outputDirectory.toFile(),
) match {
case Right(generatedFiles) =>
InterruptUtil.throwIfInterrupted()
generatedFiles.foreach { f =>
stripHeader(f.getPath)
}
Expand Down Expand Up @@ -159,9 +161,12 @@ object CommandLinePlayRoutesCompiler extends WorkerMain[Unit] {
val config = parser(workDir).parse(
readArgsFromArgFiles(args), Config()
).getOrElse(throw new AnnexWorkerError(1))
InterruptUtil.throwIfInterrupted()

compilePlayRoutes(config, out) match {
case Success(_) => generateJar(config)
case Success(_) =>
InterruptUtil.throwIfInterrupted()
generateJar(config)
case Failure(e) => throw new AnnexWorkerError(1, "Failed to compile play routes", e)
}
}
Expand Down
1 change: 1 addition & 0 deletions play-routes-compiler-cli/play-routes-compiler-cli.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def generate_play_routes_compiler_targets(scala_version):
"@play_routes_compiler_cli_{}//:com_google_protobuf_protobuf_java".format(scala_version_underscore),
"@play_routes_compiler_cli_{}//:org_playframework_play_routes_compiler_{}".format(scala_version_underscore, scala_version_underscore),
"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/error",
"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/interrupt",
"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/sandbox",
"@rules_scala_annex//src/main/scala/higherkindness/rules_scala/common/worker",
],
Expand Down
7 changes: 3 additions & 4 deletions play-routes/play-routes.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load("//play-routes-toolchain:transitions.bzl", "play_routes_toolchain_transition", "reset_play_routes_toolchain_transition")

"""Play Routes rules
Expand Down Expand Up @@ -28,11 +27,10 @@ def _format_import_arg(import_arg):

def _impl(ctx):
output_dir = ctx.actions.declare_directory("play_routes_{}".format(_sanitize_string_for_usage(ctx.attr.name)))
paths = [f.path for f in ctx.files.srcs]
args = ctx.actions.args()
args.add(output_dir.path)
args.add_all([output_dir], expand_directories = False)
args.add(ctx.outputs.srcjar)
args.add_all([",".join(paths)])
args.add_joined(ctx.files.srcs, join_with = ",")

if ctx.attr.include_play_imports:
args.add_all(play_imports, map_each = _format_import_arg)
Expand Down Expand Up @@ -64,6 +62,7 @@ def _impl(ctx):
"supports-multiplex-workers": "1",
"supports-multiplex-sandboxing": "1",
"supports-worker-cancellation": "1",
"supports-path-mapping": "1",
},
progress_message = "Compiling play routes %{label}",
use_default_shell_env = True,
Expand Down

0 comments on commit 65f5417

Please sign in to comment.