Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate building play_routes to a helper to allow remote builds #39

Merged
merged 2 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
)
19 changes: 19 additions & 0 deletions play-routes/play-routes-helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -e

OUTPUT_DIR=$(mktemp -d)

PREFIX=$1
shift
OUTPUT_SRCJAR=$1
shift
ZIPPER_PATH=$1
shift
vmax marked this conversation as resolved.
Show resolved Hide resolved


# 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