Skip to content

Instantly share code, notes, and snippets.

@excavador
Created October 20, 2017 11:21
Show Gist options
  • Save excavador/b3434f5ba82e1050f6a22ca525271487 to your computer and use it in GitHub Desktop.
Save excavador/b3434f5ba82e1050f6a22ca525271487 to your computer and use it in GitHub Desktop.
GAZELLE = "//:gazelle"
GVT = "//vendor/github.com/FiloSottile/gvt:gvt"
WORKSPACE = "//:WORKSPACE"
def _gvt_impl(ctx):
result = ctx.new_file(ctx.label.name)
gazelle = ctx.attr._gazelle.files.to_list()[0]
gvt = ctx.attr._gvt.files.to_list()[0]
workspace = ctx.attr._workspace.files.to_list()[0]
print(ctx.attr._gazelle)
ctx.file_action(output=result, executable=True, content="""#!/bin/bash
set -ux
WORKSPACE=$(dirname $(readlink {workspace}))
GVT=$(realpath {gvt})
GAZELLE=$(realpath {gazelle})
cd $WORKSPACE
$GVT $@
cd $(dirname $GAZELLE)
$GAZELLE
""".format(
gazelle=gazelle.short_path,
gvt=gvt.short_path,
workspace=workspace.short_path
))
return [DefaultInfo(runfiles=ctx.runfiles([gvt, workspace, gazelle]))]
gvt = rule(
implementation=_gvt_impl,
executable=True,
attrs = {
"_gazelle": attr.label(cfg = "host", executable = True, default = Label(GAZELLE)),
"_gvt": attr.label(cfg = "host", allow_single_file=True, executable = True, default = Label(GVT)),
"_workspace": attr.label(allow_single_file = True, default = Label(WORKSPACE)),
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment