From 59e2a09549bd4aba945c9978942fa1b13dd88574 Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Wed, 24 Jul 2019 09:55:29 -0700 Subject: [PATCH] Update bazel to 2.2.0 --- build/code_generation.bzl | 15 +-- build/code_generation_test.bzl | 8 +- build/root/.bazelrc | 17 ++-- build/root/.bazelversion | 2 +- build/root/WORKSPACE | 97 ++++++++----------- .../k8s.io/apimachinery/pkg/util/sets/BUILD | 2 +- 6 files changed, 61 insertions(+), 80 deletions(-) diff --git a/build/code_generation.bzl b/build/code_generation.bzl index 2b13dc3f01f..cee4cad1411 100644 --- a/build/code_generation.bzl +++ b/build/code_generation.bzl @@ -15,6 +15,7 @@ load("//build:kazel_generated.bzl", "go_prefix", "tags_values_pkgs") load("//build:openapi.bzl", "openapi_vendor_prefix") load("@io_k8s_repo_infra//defs:go.bzl", "go_genrule") +load("@bazel_skylib//lib:paths.bzl", "paths") def bazel_go_library(pkg): """Returns the Bazel label for the Go library for the provided package. @@ -41,8 +42,10 @@ def go_pkg(pkg): ... ) """ - count = 1 - return go_prefix + "/" + pkg.replace("staging/src/", "vendor/", count) + for prefix in ["staging/src", "vendor"]: + if pkg.startswith(prefix): + return paths.relativize(pkg, prefix) + return paths.join(go_prefix, pkg) def openapi_deps(): deps = [ @@ -73,18 +76,18 @@ def gen_openapi(outs, output_pkg, include_pkgs = [], exclude_pkgs = []): # the generator must run from the repo root inside the generated GOPATH. # All of bazel's $(location)s are relative to the original working directory, however. cmd = " ".join([ - "cd $$GOPATH/src/" + go_prefix + ";", - "$$GO_GENRULE_EXECROOT/$(location //vendor/k8s.io/kube-openapi/cmd/openapi-gen)", + "$(location //vendor/k8s.io/kube-openapi/cmd/openapi-gen)", "--v 1", "--logtostderr", - "--go-header-file $$GO_GENRULE_EXECROOT/$(location //" + openapi_vendor_prefix + "hack/boilerplate:boilerplate.generatego.txt)", + "--go-header-file $(location //" + openapi_vendor_prefix + "hack/boilerplate:boilerplate.generatego.txt)", "--output-file-base zz_generated.openapi", "--output-package " + output_pkg, "--report-filename tmp_api_violations.report", "--input-dirs " + ",".join([go_pkg(pkg) for pkg in tags_values_pkgs["openapi-gen"]["true"] if applies(pkg, include_pkgs, True) and not applies(pkg, exclude_pkgs, False)]), - "&& cp $$GOPATH/src/" + output_pkg + "/zz_generated.openapi.go $$GO_GENRULE_EXECROOT/$(location :zz_generated.openapi.go)", + "&& cp $$GOPATH/src/" + output_pkg + "/zz_generated.openapi.go $(location :zz_generated.openapi.go)", "&& rm tmp_api_violations.report", ]), go_deps = openapi_deps(), tools = ["//vendor/k8s.io/kube-openapi/cmd/openapi-gen"], + message = "GenOpenAPI", ) diff --git a/build/code_generation_test.bzl b/build/code_generation_test.bzl index 04a89e06bbc..ad0955456cb 100644 --- a/build/code_generation_test.bzl +++ b/build/code_generation_test.bzl @@ -24,7 +24,7 @@ def _bazel_go_library_test_impl(ctx): ] for input, expected in test_cases: asserts.equals(env, expected, bazel_go_library(input)) - unittest.end(env) + return unittest.end(env) bazel_go_library_test = unittest.make(_bazel_go_library_test_impl) @@ -32,12 +32,12 @@ def _go_pkg_test_impl(ctx): env = unittest.begin(ctx) test_cases = [ ("pkg/kubectl/util", "k8s.io/kubernetes/pkg/kubectl/util"), - ("vendor/some/third/party", "k8s.io/kubernetes/vendor/some/third/party"), - ("staging/src/k8s.io/apimachinery/api", "k8s.io/kubernetes/vendor/k8s.io/apimachinery/api"), + ("vendor/some/third/party", "some/third/party"), + ("staging/src/k8s.io/apimachinery/api", "k8s.io/apimachinery/api"), ] for input, expected in test_cases: asserts.equals(env, expected, go_pkg(input)) - unittest.end(env) + return unittest.end(env) go_pkg_test = unittest.make(_go_pkg_test_impl) diff --git a/build/root/.bazelrc b/build/root/.bazelrc index fcd7256f01b..a3214b818ad 100644 --- a/build/root/.bazelrc +++ b/build/root/.bazelrc @@ -40,19 +40,18 @@ build:cross:darwin_amd64 --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd build:cross:windows_386 --platforms=@io_bazel_rules_go//go/toolchain:windows_386 build:cross:windows_amd64 --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 -# We enable cgo cross-compilation for Linux, but need to use our custom crosstool. -build:repo_infra_crosstool --crosstool_top=@io_k8s_repo_infra//tools:toolchain --compiler=gcc -build:cross:linux_386 --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_386 -build:cross:linux_amd64 --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 --cpu=amd64 -build:cross:linux_arm --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_arm --cpu=arm -build:cross:linux_arm64 --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 --cpu=arm64 -build:cross:linux_ppc64le --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64le --cpu=ppc64le -build:cross:linux_s390x --config=repo_infra_crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_s390x --cpu=s390x +# These cross-compilation targets are most likely non-functional. +build:crosstool --compiler=gcc +build:cross:linux_386 --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_386 +build:cross:linux_amd64 --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 --cpu=amd64 +build:cross:linux_arm --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_arm --cpu=arm +build:cross:linux_arm64 --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 --cpu=arm64 +build:cross:linux_ppc64le --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_ppc64le --cpu=ppc64le +build:cross:linux_s390x --config=crosstool --platforms=@io_bazel_rules_go//go/toolchain:linux_s390x --cpu=s390x # --config=remote-cache enables a remote bazel cache # Note needs a --remote_instance_name=projects/PROJ/instances/default_instance flag build:remote-cache --remote_cache=remotebuildexecution.googleapis.com -build:remote-cache --tls_enabled=true build:remote-cache --remote_timeout=3600 build:remote-cache --auth_enabled=true diff --git a/build/root/.bazelversion b/build/root/.bazelversion index fda96dcf630..ccbccc3dc62 100644 --- a/build/root/.bazelversion +++ b/build/root/.bazelversion @@ -1 +1 @@ -0.23.2 +2.2.0 diff --git a/build/root/WORKSPACE b/build/root/WORKSPACE index 9c45836d100..b5857e78b29 100644 --- a/build/root/WORKSPACE +++ b/build/root/WORKSPACE @@ -3,75 +3,54 @@ workspace(name = "io_k8s_kubernetes") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") load("//build:workspace_mirror.bzl", "mirror") -http_archive( - name = "bazel_toolchains", - sha256 = "3a6ffe6dd91ee975f5d5bc5c50b34f58e3881dfac59a7b7aba3323bd8f8571a8", - strip_prefix = "bazel-toolchains-92dd8a7", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/92dd8a7.tar.gz", - "https://github.com/bazelbuild/bazel-toolchains/archive/92dd8a7.tar.gz", - ], -) - -load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") - -rbe_autoconfig( - name = "rbe_default", - base_container_digest = "sha256:677c1317f14c6fd5eba2fd8ec645bfdc5119f64b3e5e944e13c89e0525cc8ad1", - digest = "sha256:b7c2e7a18968b9df2db43eda722c5ae592aafbf774ba2766074a9c96926743d8", - registry = "gcr.io", - repository = "k8s-testimages/bazel-krte", - # tag = "latest", -) - -http_archive( - name = "bazel_skylib", - sha256 = "eb5c57e4c12e68c0c20bc774bfbc60a568e800d025557bc4ea022c6479acc867", - strip_prefix = "bazel-skylib-0.6.0", - urls = mirror("https://github.com/bazelbuild/bazel-skylib/archive/0.6.0.tar.gz"), -) - -load("@bazel_skylib//lib:versions.bzl", "versions") - -versions.check(minimum_bazel_version = "0.23.0") - -http_archive( - name = "io_k8s_repo_infra", - sha256 = "f6d65480241ec0fd7a0d01f432938b97d7395aeb8eefbe859bb877c9b4eafa56", - strip_prefix = "repo-infra-9f4571ad7242bf3ec4b47365062498c2528f9a5f", - urls = mirror("https://github.com/kubernetes/repo-infra/archive/9f4571ad7242bf3ec4b47365062498c2528f9a5f.tar.gz"), -) - http_archive( name = "io_bazel_rules_go", - sha256 = "62bedd372f125fe62c16c0cc2ad9d7a2b6a1171d639933a5651a729fdce497fc", - urls = mirror("https://github.com/bazelbuild/rules_go/releases/download/v0.20.7/rules_go-v0.20.7.tar.gz"), + sha256 = "142dd33e38b563605f0d20e89d9ef9eda0fc3cb539a14be1bdb1350de2eda659", + urls = mirror("https://github.com/bazelbuild/rules_go/releases/download/v0.22.2/rules_go-v0.22.2.tar.gz"), ) load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies") go_rules_dependencies() -# The version of rules_go we're using here is no longer supported, so -# we must manually download a newer version of the go sdk. -go_download_sdk( - name = "go_sdk", - sdks = { - "darwin_amd64": ("go1.13.9.darwin-amd64.tar.gz", "450e59538ed5d3f2b165ba5107530afce6e8e89c6cc5c90a0cbf0a58846ef3b1"), - "freebsd_386": ("go1.13.9.freebsd-386.tar.gz", "6b75a5a46ebbdf06aa5023f2bd0ad7e9e37389125468243368d5795e1c15c9cd"), - "freebsd_amd64": ("go1.13.9.freebsd-amd64.tar.gz", "87716246da52c193226df44031aaf45e45ebfc23e01bdc845311c1b560e76e2b"), - "linux_386": ("go1.13.9.linux-386.tar.gz", "a2744aa2ddc68d888e9f65c2cbe4c8b527b139688ce232ead90dc2961f8d51a8"), - "linux_amd64": ("go1.13.9.linux-amd64.tar.gz", "f4ad8180dd0aaf7d7cda7e2b0a2bf27e84131320896d376549a7d849ecf237d7"), - "linux_arm64": ("go1.13.9.linux-arm64.tar.gz", "b53cb466d7986e5e17a3d4c196bc95df08a35968eced5efd7e128387a246c46e"), - "linux_arm": ("go1.13.9.linux-armv6l.tar.gz", "a3c2941a1fde8692514ece7e2180a0e3ca70609f52756a66bc0ab68c63572361"), - "linux_ppc64le": ("go1.13.9.linux-ppc64le.tar.gz", "90beb01962202f332be0a7c8dad2db3d30242759ba863db3f36c45d241940efc"), - "linux_s390x": ("go1.13.9.linux-s390x.tar.gz", "a40949aaf55912b06df8fda511c33fde3e52d377706bdc095332652c1ad225e3"), - "windows_386": ("go1.13.9.windows-386.zip", "e22406377448f1aea2dd1517327e5ae452d826c0c7624b3511d5af510c57b69a"), - "windows_amd64": ("go1.13.9.windows-amd64.zip", "cf066aabdf4d83c251aaace14b57a35aafffd1fa67d54d907f27fb31e470a135"), - }, +go_register_toolchains( + go_version = "1.13.9", ) -go_register_toolchains() +http_archive( + name = "io_k8s_repo_infra", + sha256 = "a6ca952e365600a17f56f0fc8e41016e1d13cfb2b74c0c29bad6bdba3e3d8a4d", + strip_prefix = "repo-infra-0.0.3", + urls = mirror("https://github.com/kubernetes/repo-infra/archive/v0.0.3.tar.gz"), +) + +load("@io_k8s_repo_infra//:load.bzl", repo_infra_repositories = "repositories") + +repo_infra_repositories() + +load("@io_k8s_repo_infra//:repos.bzl", repo_infra_go_repositories = "go_repositories", repo_infra_configure = "configure") + +repo_infra_configure( + minimum_bazel_version = "2.2.0", + rbe_name = None, +) + +repo_infra_go_repositories() + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +load("@bazel_toolchains//rules:rbe_repo.bzl", "rbe_autoconfig") + +rbe_autoconfig( + name = "rbe_default", + base_container_digest = "sha256:b4dad0bfc4951d619229ab15343a311f2415a16ef83bcaa55b44f4e2bf1cf635", + digest = "sha256:b28ddaf98c6e0bb840c5fded3c0a899a7db45bb44f69859f16c37be092bfcb4e", + registry = "marketplace.gcr.io", + repository = "google/bazel", + # tag = "2.2.0", +) http_archive( name = "io_bazel_rules_docker", diff --git a/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD b/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD index 0c4c00d7251..24e30d00170 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD +++ b/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD @@ -38,7 +38,7 @@ go_genrule( ], cmd = """ $(location //vendor/k8s.io/code-generator/cmd/set-gen) \ - --input-dirs k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types \ + --input-dirs k8s.io/apimachinery/pkg/util/sets/types \ --output-base $$(dirname $$(dirname $(location :byte.go))) \ --go-header-file $(location //hack/boilerplate:boilerplate.generatego.txt) \ --output-package sets