Skip to content

Instantly share code, notes, and snippets.

@jmhodges
Last active March 29, 2018 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmhodges/30a6d7387a363cf9b9ef8148b7f18720 to your computer and use it in GitHub Desktop.
Save jmhodges/30a6d7387a363cf9b9ef8148b7f18720 to your computer and use it in GitHub Desktop.
load("@io_bazel_rules_go//go:def.bzl", "go_context", "go_path", "go_rule")
load("@io_bazel_rules_go//go/private:providers.bzl", "GoLibrary", "GoPath")
_ERRCHECK_TOOL = "@com_github_kisielk_errcheck//:errcheck"
def _errcheck_sh_impl(ctx):
go = go_context(ctx)
gopath = ctx.attr.gopath_dep[GoPath].gopath
print("GOPATH IS ", gopath)
stdlib = go.stdlib
inputs = [ctx.file.errcheck_tool, go.go] + ctx.files.gopath_dep + stdlib.files + go.sdk_files
args = [ctx.attr.library[GoLibrary].importpath]
# We can use the go binary from the stdlib for most of the environment
# variables, but our GOPATH is specific to the library target we were given.
ctx.actions.write(
output = ctx.outputs.out_file,
is_executable = True,
content = """#!/bin/bash
echo "PWD IS $PWD"
export GOROOT=$PWD/../go_sdk &&
echo "GOROOT is $GOROOT" &&
export PATH=$GOROOT/bin:$PWD/{godir}:$PATH &&
export GOPATH=$PWD/{gopath} &&
{errcheck} {args}
""".format(
godir=go.go.short_path,
gopath=gopath,
errcheck=ctx.file.errcheck_tool.short_path,
args = " ".join(args),
)
)
return [DefaultInfo(executable=ctx.outputs.out_file, runfiles=ctx.runfiles(files=inputs, collect_data = True))]
_errcheck_sh = go_rule(
_errcheck_sh_impl,
executable = True,
attrs = {
"library": attr.label(
doc = "The target the Go library is at to look for the interfaces in. When this is set and source is not set, errcheck will use its reflect code to generate the mocks. If source is set, its dependencies will be included in the GOPATH that errcheck will be run in.",
providers = [GoLibrary],
mandatory = True,
),
"gopath_dep": attr.label(
doc = "The go_path label to use to create the GOPATH for the given library. Will be set correctly by the errcheck macro, so you don't need to set it.",
providers=[GoPath],
cfg = "data",
mandatory = True,
),
"errcheck_tool": attr.label(
doc = "The errcheck tool to run",
default = Label(_ERRCHECK_TOOL),
allow_single_file = True,
executable = True,
cfg = "host",
mandatory = False,
),
},
outputs = {"out_file": "%{name}_errcheck.sh"},
)
def errcheck(name, library, **kwargs):
gopath_name = name + "_errcheck_gopath"
errcheck_tool = _ERRCHECK_TOOL
if kwargs.get("errcheck_tool", None):
errcheck_tool = kwargs["errcheck_tool"]
go_path(
name = gopath_name,
deps = [library, errcheck_tool]
)
_errcheck_sh(
name = name,
library = library,
gopath_dep = gopath_name,
**kwargs
)
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:58:9: undeclared name: listGroups
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:11:41: undeclared name: current
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:32:9: undeclared name: lookupUser
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:41:9: undeclared name: lookupUserId
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:47:9: undeclared name: lookupGroup
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/os/user/lookup.go:53:9: undeclared name: lookupGroupId
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/net/lookup_unix.go:80:24: undeclared name: cgoLookupHost
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/net/lookup_unix.go:95:24: undeclared name: cgoLookupIP
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/net/lookup_unix.go:107:23: undeclared name: cgoLookupPort
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/net/lookup_unix.go:123:24: undeclared name: cgoLookupCNAME
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/net/lookup_unix.go:190:23: undeclared name: cgoLookupPTR
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/crypto/x509/cert_pool.go:38:9: undeclared name: loadSystemRoots
/private/var/tmp/_bazel_jmhodges/ee957dabdee1b1a9e1f2fe90369cf80f/execroot/founding/bazel-out/darwin-fastbuild/bin/go/svc/howsmyssl-billing/hberrcheck_errcheck.sh.runfiles/go_sdk/src/crypto/x509/root.go:21:32: undeclared name: loadSystemRoots
error: failed to check packages: could not type check: couldn't load packages due to errors: net, crypto/x509, os/user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment