Skip to content

Instantly share code, notes, and snippets.

@alexeagle
Last active September 12, 2017 14:24
Show Gist options
  • Save alexeagle/d7c57183f548c428469bec6ec4113419 to your computer and use it in GitHub Desktop.
Save alexeagle/d7c57183f548c428469bec6ec4113419 to your computer and use it in GitHub Desktop.
sh_binary(
name = "sh",
srcs = [":repro.sh"],
data = [":some_data"],
)
load(":rule.bzl", "my_rule")
my_rule(name = "a")
#!/usr/bin/env bash
set -e
# Locate runfiles
case "$0" in
/*) self="$0" ;;
*) self="$PWD/$0" ;;
esac
while true; do
if [[ -e "$self.runfiles" ]]; then
RUNFILES="$self.runfiles"
break
fi
if [[ $self == *.runfiles/* ]]; then
RUNFILES="${self%%.runfiles/*}.runfiles"
# don't break; this is a last resort for case 6b
fi
if [[ ! -L "$self" ]]; then
break;
fi
readlink="$(readlink "$self")"
if [[ "$readlink" = /* ]]; then
self="$readlink"
else
# resolve relative symlink
self="${self%%/*}/$readlink"
fi
done
if [[ -z "$RUNFILES" ]]; then
echo " >>>> FAIL: RUNFILES environment variable is not set. <<<<" >&2
exit 1
fi
echo "hello world"
echo "writing to $1"
find ${RUNFILES}*
# Uses the symlinks under runfiles, doesn't work on windows
cat ${RUNFILES}/__main__/some_data > $1
# BUG: this file is missing
# comment out this line and it works on Mac/Linux
ls ${RUNFILES}_manifest
exit 0
def _my_rule(ctx):
ctx.actions.run(
inputs = [ctx.executable.compiler],
outputs = [ctx.outputs.foo],
executable = ctx.executable.compiler,
arguments = [ctx.outputs.foo.path])
return struct()
my_rule = rule(
implementation = _my_rule,
attrs = {
"compiler": attr.label(
default = Label("//:sh"),
cfg="host",
executable=True, allow_files=True)
},
outputs = {
"foo": "foo.txt",
}
)
needed at runtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment