Skip to content

Commit

Permalink
Use a wrapper script which calls mkdir to work around bazelbuild/baze…
Browse files Browse the repository at this point in the history
…l#6393.

This allows rules_swig to function under remote builds.

Bug: 168150587
Change-Id: I79cc96a4a6119d1d8d286d83fd4807152e722403
  • Loading branch information
SanjayVas committed Oct 23, 2020
1 parent ad4f1bc commit c207f4e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion java/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _java_wrap_cc_impl(ctx):
java_files_dir = ctx.actions.declare_directory("java_files")

swig_args = ctx.actions.args()
swig_args.add_all([java_files_dir], expand_directories = False)
swig_args.add("swig")
swig_args.add("-c++")
swig_args.add("-java")
swig_args.add("-package", ctx.attr.package)
Expand All @@ -64,7 +66,7 @@ def _java_wrap_cc_impl(ctx):
ctx.actions.run(
outputs = [outfile, java_files_dir],
inputs = depset([src], transitive = header_sets),
executable = "swig",
executable = ctx.executable._mkdir_wrapper,
arguments = [swig_args],
mnemonic = "SwigCompile",
)
Expand Down Expand Up @@ -106,6 +108,11 @@ It's expected that the `swig` binary exists in the host's path.
default = Label("@bazel_tools//tools/jdk:current_java_runtime"),
providers = [java_common.JavaRuntimeInfo],
),
"_mkdir_wrapper": attr.label(
default = Label("//tools:mkdir_wrapper"),
executable = True,
cfg = "exec",
),
},
)

Expand Down
8 changes: 8 additions & 0 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package(default_visibility = [
"//visibility:public",
])

sh_binary(
name = "mkdir_wrapper",
srcs = ["mkdir_wrapper.sh"],
)
13 changes: 13 additions & 0 deletions tools/mkdir_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Wrapper which creates the directory specified as $1, then executing the
# command in $2 with the remaining arguments.
#
# This is to work around https://github.com/bazelbuild/bazel/issues/6393

readonly directory="$1"
readonly command="$2"
shift 2

mkdir -p "${directory}"
exec "${command}" "$@"

0 comments on commit c207f4e

Please sign in to comment.