Last active
September 12, 2017 14:24
-
-
Save alexeagle/d7c57183f548c428469bec6ec4113419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sh_binary( | |
name = "sh", | |
srcs = [":repro.sh"], | |
data = [":some_data"], | |
) | |
load(":rule.bzl", "my_rule") | |
my_rule(name = "a") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
needed at runtime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment