Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dep v0.4.1 in kubernetes/test-infra #6443

Merged
merged 10 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_prefix")
load("@io_kubernetes_build//defs:run_in_workspace.bzl", "workspace_binary")

go_prefix("k8s.io/test-infra")

Expand All @@ -22,6 +23,11 @@ filegroup(
visibility = ["//:__subpackages__"],
)

workspace_binary(
name = "dep",
cmd = "//vendor/github.com/golang/dep/cmd/dep",
)

filegroup(
name = "all-srcs",
srcs = [
Expand Down
90 changes: 88 additions & 2 deletions Gopkg.lock

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

13 changes: 13 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Gopkg.toml for k8s.io/test-infra

# Updating this list likely also requires updating hack/prune-libraries.sh.
required = [
"github.com/golang/dep/cmd/dep"
]

[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"
Expand All @@ -17,3 +22,11 @@
# https://github.com/docker/docker-ce/blob/17.12/components/cli/vendor.conf
# to update this check https://github.com/docker/docker-ce/blob/<tag>/components/cli/vendor.conf
revision = "5e5fadb3c0201553929d4a6ea8dc8f9d8a1e56fe"

[[constraint]]
name = "github.com/golang/dep"
version = "v0.4.1"

[prune]
unused-packages = true
go-tests = true
8 changes: 7 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ go_register_toolchains(

git_repository(
name = "io_bazel_rules_k8s",
remote = "https://github.com/bazelbuild/rules_k8s.git",
commit = "3756369d4920033c32c12d16207e8ee14fee1b18",
remote = "https://github.com/bazelbuild/rules_k8s.git",
)

http_archive(
Expand All @@ -35,6 +35,12 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_docker/archive/3caf72f166f8b6b0e529442477a74871ad4d35e9.tar.gz"],
)

git_repository(
name = "io_kubernetes_build",
commit = "4ce715fbe67d8fbed05ec2bb47a148e754100a4b",
remote = "https://github.com/kubernetes/repo-infra.git",
)

load("@io_bazel_rules_docker//docker:docker.bzl", "docker_repositories", "docker_pull")

docker_repositories()
Expand Down
21 changes: 14 additions & 7 deletions docs/dep.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ Go 1.8 or newer to compile.
You can follow the [setup instructions](https://github.com/golang/dep#setup) to
set up `dep` in your local environment.

test-infra is currently using dep 0.4.1. This version has also been vendored
into the repository. You can run the vendored version using `bazel run`; for
example, run
```console
$ bazel run //:dep -- ensure -add example.org/foo/bar
```
to add a new dependency.

## Changing dependencies

You can use the `dep` instructions for [adding](https://github.com/golang/dep#adding-a-dependency),
[updating](https://github.com/golang/dep#updating-dependencies) or
[removing](https://github.com/golang/dep#removing-dependencies) a dependency.
You can use the `dep` instructions for
[adding](https://golang.github.io/dep/docs/daily-dep.html#adding-a-new-dependency),
[updating](https://golang.github.io/dep/docs/daily-dep.html#updating-dependencies) or
[removing](https://golang.github.io/dep/docs/daily-dep.html#using-dep-ensure) a dependency.

Once you've updated, make sure to run:
```
dep prune
hack/update-bazel.sh
hack/update-deps.sh
```

To prune unneeded deps, and then update all the bazel files that `dep` blows away.
This will generate necessary Bazel BUILD files and will also remove any
unused libraries that dep fails to prune.

## Tips

Expand Down
10 changes: 9 additions & 1 deletion hack/prune-libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ set -o nounset
set -o errexit
set -o pipefail

# This list is used for rules in vendor/ which may not have any explicit
# dependencies outside of vendor, e.g. helper commands we have vendored.
# It should probably match the list in Gopkg.toml.
REQUIRED=(
//vendor/github.com/golang/dep/cmd/dep:dep
)

unused-go-libraries() {
# Find all the go_library rules in vendor except those that something outside
# of vendor eventually depends on.
bazel query 'kind("go_library rule", //vendor/... -deps(//... -//vendor/...))'
required_items=( "${REQUIRED[@]/#/+ }" )
bazel query "kind('go_library rule', //vendor/... -deps(//... -//vendor/... ${required_items[@]}))"
}

# Output this:source.go that:file.txt sources of //this //that targets
Expand Down
6 changes: 0 additions & 6 deletions hack/update-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ TESTINFRA_ROOT=$(git rev-parse --show-toplevel)
cd ${TESTINFRA_ROOT}
TMP_GOPATH=$(mktemp -d)

# no unit tests in vendor
# previously we used godeps which did this, but `dep` does not handle this
# properly yet. some of these tests don't build well. see:
# ref: https://github.com/kubernetes/test-infra/pull/5411
find ${TESTINFRA_ROOT}/vendor/ -name "*_test.go" -delete

# manually remove BUILD file for k8s.io/apimachinery/pkg/util/sets/BUILD if it
# exists; there is a specific set-gen rule that breaks importing
# ref: https://github.com/kubernetes/kubernetes/blob/4e2f5e2212b05a305435ef96f4b49dc0932e1264/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD#L23-L49
Expand Down
39 changes: 8 additions & 31 deletions hack/update-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,17 @@ set -o errexit
set -o pipefail
set -o xtrace

# Remove //foo:something references from bar/BUILD
# Remove //vendor/golang.org/x/text/internal:go_default_library deps
#
# Unused text/gen.go file imports text/internal, which prevents dep prune from
# removing it. However text/internal package references a text/language package
# which has been pruned.
#
# Fix by deleting this dependency. The target won't build correctly, but it
# won't anyway because text/language doesn't exist, and it will get pruned by
# hack/prune-libraries.sh
#
# Usage:
# remove-text-internal
drop-dep() {
local path
path="$(dirname "${BASH_SOURCE}")/../$2/BUILD"
if [[ ! -f ${path} ]]; then
return 0
fi
sed -i -e "\|//$1:go_default_library|d" "$path"
}
TESTINFRA_ROOT=$(git rev-parse --show-toplevel)
cd "${TESTINFRA_ROOT}"

trap 'echo "FAILED" >&2' ERR
pushd "$(dirname "${BASH_SOURCE}")/.."
dep ensure -v
dep prune -v
bazel run //:dep -- ensure -v
# dep itself has a problematic testdata directory with infinite symlinks which
# makes bazel sad: https://github.com/golang/dep/pull/1412
# dep should probably be removing it, but it doesn't:
# https://github.com/golang/dep/issues/1580
rm -rf vendor/github.com/golang/dep/internal/fs/testdata
hack/update-bazel.sh
drop-dep vendor/golang.org/x/text/language vendor/golang.org/x/text/internal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

drop-dep vendor/google.golang.org/api/transport/grpc vendor/google.golang.org/api/transport
drop-dep vendor/github.com/golang/protobuf/protoc-gen-go/grpc vendor/github.com/golang/protobuf/protoc-gen-go
drop-dep vendor/github.com/golang/protobuf/protoc-gen-go/generator vendor/github.com/golang/protobuf/protoc-gen-go
drop-dep vendor/github.com/golang/protobuf/protoc-gen-go vendor/github.com/golang/protobuf/protoc-gen-go
drop-dep vendor/github.com/docker/distribution/context vendor/github.com/docker/distribution
drop-dep vendor/github.com/docker/docker/pkg/term vendor/github.com/docker/docker/cli
hack/prune-libraries.sh --fix
hack/update-bazel.sh # Update child :all-srcs in case parent was deleted
echo SUCCESS
9 changes: 1 addition & 8 deletions hack/verify-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,9 @@ kazel_diff=$("${TMP_GOPATH}/bin/kazel" \
-print-diff \
-root="${TESTINFRA_ROOT}")

# check if there are vendor/*_test.go
# previously we used godeps which did this, but `dep` does not handle this
# properly yet. some of these tests don't build well. see:
# ref: https://github.com/kubernetes/test-infra/pull/5411
vendor_tests=$(find ${TESTINFRA_ROOT}/vendor/ -name "*_test.go" | wc -l)

if [[ -n "${gazelle_diff}" || -n "${kazel_diff}" || "${vendor_tests}" -ne "0" ]]; then
if [[ -n "${gazelle_diff}" || -n "${kazel_diff}" ]]; then
echo "${gazelle_diff}"
echo "${kazel_diff}"
echo "number of vendor/*_test.go: ${vendor_tests} (want: 0)"
echo
echo "Run ./hack/update-bazel.sh"
exit 1
Expand Down
9 changes: 9 additions & 0 deletions jobs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11658,6 +11658,15 @@
"sig-testing"
]
},
"pull-test-infra-verify-deps": {
"args": [
"./hack/verify-deps.sh"
],
"scenario": "execute",
"sigOwners": [
"sig-testing"
]
},
"pull-test-infra-verify-gofmt": {
"args": [
"./hack/verify-gofmt.sh"
Expand Down
Loading