Skip to content

Commit

Permalink
Rewrite typecheck against x/tools/go/packages
Browse files Browse the repository at this point in the history
This runs much faster than before.  This change removes all of the
async status output because all of the compute time is spent inside
go/packages, with no opportunity to update the status.

Adds testdata code to prove it fails when expected.
  • Loading branch information
thockin committed Jun 26, 2020
1 parent 734f27d commit d187d7e
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 424 deletions.
2 changes: 1 addition & 1 deletion hack/verify-staticcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ while IFS='' read -r line; do
all_packages+=("./$line")
done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" |
grep "^${FOCUS:-.}" |
grep -vE "(third_party|generated|clientset_generated|hack|/_)" |
grep -vE "(third_party|generated|clientset_generated|hack|testdata|/_)" |
grep -vE "$ignore_pattern" )

failing_packages=()
Expand Down
7 changes: 3 additions & 4 deletions hack/verify-typecheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ cd "${KUBE_ROOT}"

make --no-print-directory -C "${KUBE_ROOT}" generated_files

# As of June, 2020 the typecheck tool is written in terms of go/types, but that
# library doesn't work well with modules. Guidance is to rewrite tools against
# golang.org/x/tools/go/packages. Until that is done, force this tooling to
# run in a fake GOPATH.
# As of June, 2020 the typecheck tool is written in terms of go/packages, but
# that library doesn't work well with multiple modules. Until that is done,
# force this tooling to run in a fake GOPATH.
ret=0
hack/run-in-gopath.sh \
go run test/typecheck/main.go "$@" || ret=$?
Expand Down
13 changes: 9 additions & 4 deletions test/typecheck/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# gazelle:exclude testdata
package(default_visibility = ["//visibility:public"])

load(
Expand All @@ -16,10 +17,7 @@ go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "k8s.io/kubernetes/test/typecheck",
deps = [
"//third_party/go-srcimporter:go_default_library",
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
],
deps = ["//vendor/golang.org/x/tools/go/packages:go_default_library"],
)

filegroup(
Expand All @@ -43,5 +41,12 @@ go_binary(
go_test(
name = "go_default_test",
srcs = ["main_test.go"],
# The "../../" is because $(location) gives a relative path, but
# relative to some root for which I can't find a variable. Empirically
# this is 2 levels up (since this file is 2 levels down from the repo
# root). Hack.
args = ["--go=../../$(location @go_sdk//:bin/go)"],
data = ["@go_sdk//:bin/go"] + glob(["testdata/**"]),
embed = [":go_default_library"],
deps = ["//vendor/golang.org/x/tools/go/packages:go_default_library"],
)
Loading

0 comments on commit d187d7e

Please sign in to comment.