Skip to content

Instantly share code, notes, and snippets.

@nikhedonia
Created July 11, 2018 13:47
Show Gist options
  • Save nikhedonia/3e804fe2916d3a8033a0909428b469ac to your computer and use it in GitHub Desktop.
Save nikhedonia/3e804fe2916d3a8033a0909428b469ac to your computer and use it in GitHub Desktop.
def test_tree(name, path):
genrule(
name = name,
out = ".",
srcs = [path],
cmd = "cp -r $SRCS/* $OUT"
)
return ":"+name
def sh_cxx_test(
name,
tree = False,
**kwargs):
target = name
binTarget = "bin-" + name
shTarget = "sh-" + name
runTarget = "run-" + name
cxx_binary(
binTarget,
**kwargs
)
genrule(
name = runTarget,
out = "run.sh",
srcs = [],
cmd = "&&".join([
"echo '%s' > $OUT" % "\n".join([
"#!/bin/bash",
"cd $(location %s)" % tree if tree else "cd $BUCK_PROJECT_ROOT/__default__/gen",
"exec $(location :%s)" % binTarget
]),
"chmod +x $OUT"
])
)
sh_binary(
name = shTarget,
main = ":run-"+target,
resources = []
)
sh_test(
name = target,
test = ":sh-"+target,
visibility = ["PUBLIC"],
)
return ":"+target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment