Skip to content

Commit d187d7e

Browse files
committed
Rewrite typecheck against x/tools/go/packages
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.
1 parent 734f27d commit d187d7e

File tree

9 files changed

+386
-424
lines changed

9 files changed

+386
-424
lines changed

hack/verify-staticcheck.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ while IFS='' read -r line; do
6868
all_packages+=("./$line")
6969
done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" |
7070
grep "^${FOCUS:-.}" |
71-
grep -vE "(third_party|generated|clientset_generated|hack|/_)" |
71+
grep -vE "(third_party|generated|clientset_generated|hack|testdata|/_)" |
7272
grep -vE "$ignore_pattern" )
7373

7474
failing_packages=()

hack/verify-typecheck.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ cd "${KUBE_ROOT}"
3030

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

33-
# As of June, 2020 the typecheck tool is written in terms of go/types, but that
34-
# library doesn't work well with modules. Guidance is to rewrite tools against
35-
# golang.org/x/tools/go/packages. Until that is done, force this tooling to
36-
# run in a fake GOPATH.
33+
# As of June, 2020 the typecheck tool is written in terms of go/packages, but
34+
# that library doesn't work well with multiple modules. Until that is done,
35+
# force this tooling to run in a fake GOPATH.
3736
ret=0
3837
hack/run-in-gopath.sh \
3938
go run test/typecheck/main.go "$@" || ret=$?

test/typecheck/BUILD

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# gazelle:exclude testdata
12
package(default_visibility = ["//visibility:public"])
23

34
load(
@@ -16,10 +17,7 @@ go_library(
1617
name = "go_default_library",
1718
srcs = ["main.go"],
1819
importpath = "k8s.io/kubernetes/test/typecheck",
19-
deps = [
20-
"//third_party/go-srcimporter:go_default_library",
21-
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
22-
],
20+
deps = ["//vendor/golang.org/x/tools/go/packages:go_default_library"],
2321
)
2422

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

0 commit comments

Comments
 (0)