Skip to content

Commit

Permalink
Use nogo instead of vet
Browse files Browse the repository at this point in the history
Nogo runs directly alongside the bazel compiler. This means that the
results are cached and builds are not slowed down. Since now vet checks
are always performed if necessary, `go vet` can be removed from
hack/check.sh.
  • Loading branch information
rmohr committed Mar 15, 2019
1 parent dba9255 commit 6ea634b
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 17 deletions.
34 changes: 34 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "nogo")

nogo(
name = "nogo_vet",
config = "nogo_config.json",
visibility = ["//visibility:public"],
# These deps enable the analyses equivalent to running `go vet`.
# Passing vet = True enables only a tiny subset of these (the ones
# that are always correct).
# You can see the what `go vet` does by running `go doc cmd/vet`.
deps = [
"@org_golang_x_tools//go/analysis/passes/asmdecl:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/assign:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/atomic:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/bools:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/buildtag:go_tool_library",
# Fails on a vendored dependency, disabling for now.
# "@org_golang_x_tools//go/analysis/passes/cgocall:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/composite:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/copylock:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/httpresponse:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/loopclosure:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/lostcancel:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/nilfunc:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/printf:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/shift:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/stdmethods:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/structtag:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/tests:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/unreachable:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/unsafeptr:go_tool_library",
"@org_golang_x_tools//go/analysis/passes/unusedresult:go_tool_library",
],
)

# gazelle:prefix kubevirt.io/kubevirt
gazelle(name = "gazelle")
Expand Down
11 changes: 7 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ load(
# Additional bazel rules
http_archive(
name = "io_bazel_rules_go",
sha256 = "7be7dc01f1e0afdba6c8eb2b43d2fa01c743be1b9273ab1eaf6c233df078d705",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.16.5/rules_go-0.16.5.tar.gz",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.18.0/rules_go-0.18.0.tar.gz"],
sha256 = "301c8b39b0808c49f98895faa6aa8c92cbd605ab5ad4b6a3a652da33a1a2ba2e",
)

http_archive(
Expand Down Expand Up @@ -86,14 +86,17 @@ http_file(
)

load(
"@io_bazel_rules_go//go:def.bzl",
"@io_bazel_rules_go//go:deps.bzl",
"go_register_toolchains",
"go_rules_dependencies",
)

go_rules_dependencies()

go_register_toolchains()
go_register_toolchains(
go_version = "1.11.5",
nogo = "@//:nogo_vet",
)

load(
"@bazel_gazelle//:deps.bzl",
Expand Down
1 change: 0 additions & 1 deletion hack/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ source hack/common.sh

shfmt -i 4 -w ${KUBEVIRT_DIR}/cluster/ ${KUBEVIRT_DIR}/hack/ ${KUBEVIRT_DIR}/images/
goimports -w -local kubevirt.io ${KUBEVIRT_DIR}/cmd/ ${KUBEVIRT_DIR}/pkg/ ${KUBEVIRT_DIR}/tests/ ${KUBEVIRT_DIR}/tools
(cd ${KUBEVIRT_DIR} && go vet ./cmd/... ./pkg/... ./tests/... ./tools/...)
6 changes: 3 additions & 3 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ vms_docker_prefix=${DOCKER_PREFIX:-registry:5000/kubevirt}
vms_docker_tag=${DOCKER_TAG:-devel}
${KUBEVIRT_DIR}/tools/vms-generator/vms-generator --container-prefix=${vms_docker_prefix} --container-tag=${vms_docker_tag} --generated-vms-dir=${KUBEVIRT_DIR}/cluster/examples

protoc --proto_path=pkg/hooks/info --go_out=plugins=grpc,import_path=info:pkg/hooks/info pkg/hooks/info/api.proto
protoc --proto_path=pkg/hooks/v1alpha1 --go_out=plugins=grpc,import_path=v1alpha1:pkg/hooks/v1alpha1 pkg/hooks/v1alpha1/api.proto
protoc --proto_path=pkg/hooks/v1alpha2 --go_out=plugins=grpc,import_path=v1alpha2:pkg/hooks/v1alpha2 pkg/hooks/v1alpha2/api.proto
protoc --proto_path=pkg/hooks/info --go_out=plugins=grpc,import_path=kubevirt_hooks_info:pkg/hooks/info pkg/hooks/info/api.proto
protoc --proto_path=pkg/hooks/v1alpha1 --go_out=plugins=grpc,import_path=kubevirt_hooks_v1alpha1:pkg/hooks/v1alpha1 pkg/hooks/v1alpha1/api.proto
protoc --proto_path=pkg/hooks/v1alpha2 --go_out=plugins=grpc,import_path=kubevirt_hooks_v1alpha2:pkg/hooks/v1alpha2 pkg/hooks/v1alpha2/api.proto
102 changes: 102 additions & 0 deletions nogo_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"structtag": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"asmdecl": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"assign": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"atomic": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"bools": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"buildtag": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"cgocall": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"composites": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"copylocks": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"httpresponse": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"loopclosure": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"lostcancel": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"nilfunc": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"printf": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"shift": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"stdmethods": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"tests": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"unreachable": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"unsafeptr": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
},
"unusedresult": {
"exclude_files": {
"vendor/": "vendor doesn't pass vet"
}
}
}
4 changes: 2 additions & 2 deletions pkg/hooks/info/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/hooks/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

package info
package kubevirt_hooks_info

const OnDefineDomainHookPointName = "OnDefineDomain"
const PreCloudInitIsoHookPointName = "PreCloudInitIso"
4 changes: 2 additions & 2 deletions pkg/hooks/v1alpha1/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/hooks/v1alpha1/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
*
*/

package v1alpha1
package kubevirt_hooks_v1alpha1

const Version = "v1alpha"
4 changes: 2 additions & 2 deletions pkg/hooks/v1alpha2/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/hooks/v1alpha2/v1alpha2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
*
*/

package v1alpha2
package kubevirt_hooks_v1alpha2

const Version = "v1alpha2"

0 comments on commit 6ea634b

Please sign in to comment.