Skip to content

Commit

Permalink
Separate building play_routes to a helper to allow remote builds (#39)
Browse files Browse the repository at this point in the history
* Separate building play_routes to a helper to allow remote builds

* Update play-routes/play-routes-helper.sh

Co-authored-by: Max Vorobev <vmax0770@gmail.com>

Co-authored-by: David Neil <dvd.neil1@gmail.com>
  • Loading branch information
vmax and DavidANeil authored Jul 24, 2020
1 parent 325472d commit 61bd14f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/lemur_rsa

target/
/.ijwb
6 changes: 6 additions & 0 deletions play-routes/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ bzl_library(
name = "jdk_toolchain_utils",
srcs = ["@bazel_tools//tools/jdk:toolchain_utils.bzl"],
)

sh_binary(
name = "play-routes-helper",
srcs = ["play-routes-helper.sh"],
visibility = ["//visibility:public"]
)
17 changes: 17 additions & 0 deletions play-routes/play-routes-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

OUTPUT_DIR=$(mktemp -d)

PREFIX=$1
OUTPUT_SRCJAR=$2
ZIPPER_PATH=$3
shift 3


# substitute output path and execute the compiler command
${*/REPLACE_ME_OUTPUT_PATH/$OUTPUT_DIR}

# produce resulting source jar
$ZIPPER_PATH c $OUTPUT_SRCJAR META-INF/= $(find -L $OUTPUT_DIR -type f | while read v; do echo "$PREFIX"${v#"$OUTPUT_DIR"}=$v; done)
33 changes: 16 additions & 17 deletions play-routes/play-routes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ def _format_import_args(imports):
return ["--routesImport={}".format(i) for i in imports]

def _impl(ctx):
gendir = ctx.actions.declare_directory(
gendir_base_path + "/" + _sanitize_string_for_usage(ctx.attr.name)
)
prefix = ctx.label.package + "/" + gendir_base_path + "/" + _sanitize_string_for_usage(ctx.attr.name)
paths = [f.path for f in ctx.files.srcs]
args = [gendir.path] + [",".join(paths)]
args = ["REPLACE_ME_OUTPUT_PATH"] + [",".join(paths)]

if ctx.attr.include_play_imports:
args = args + _format_import_args(play_imports)
Expand All @@ -49,20 +47,16 @@ def _impl(ctx):

ctx.actions.run(
inputs = ctx.files.srcs,
outputs = [gendir],
arguments = args,
progress_message = "Compiling play routes",
executable = ctx.executable.play_routes_compiler,
)

# TODO: something more portable
ctx.actions.run_shell(
inputs = [gendir],
outputs = [ctx.outputs.srcjar],
arguments = [ctx.executable._zipper.path, gendir.path, gendir.short_path, ctx.outputs.srcjar.path],
command = """$1 c $4 META-INF/= $(find -L $2 -type f | while read v; do echo ${v#"${2%$3}"}=$v; done)""",
progress_message = "Bundling compiled play routes into srcjar",
tools = [ctx.executable._zipper],
arguments = [
prefix,
ctx.outputs.srcjar.path,
ctx.executable._zipper.path,
ctx.executable.play_routes_compiler.path,
] + args,
progress_message = "Compiling play routes",
executable = ctx.executable._play_route_helper,
tools = [ctx.executable.play_routes_compiler, ctx.executable._zipper]
)

play_routes = rule(
Expand Down Expand Up @@ -103,6 +97,11 @@ play_routes = rule(
allow_files = True,
default = Label("//external:default-play-routes-compiler-cli"),
),
"_play_route_helper": attr.label(
executable = True,
cfg = "host",
default = Label("@io_bazel_rules_play_routes//play-routes:play-routes-helper"),
),
"_zipper": attr.label(cfg = "host", default = "@bazel_tools//tools/zip:zipper", executable = True),
},
outputs = {
Expand Down

0 comments on commit 61bd14f

Please sign in to comment.