From 73f62deb34113bacf64d848c9bcfa94b0620fe17 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Wed, 21 Apr 2021 15:55:12 -0700 Subject: [PATCH] Add support for Bazel LTS version 3.0.0 (#639) --- .bazelci/presubmit.yml | 31 ++++++----- .bazelversion | 2 +- WORKSPACE | 16 ++---- k8s/k8s.bzl | 113 +++++++++++++++++++++++------------------ k8s/k8s_go_deps.bzl | 17 +++---- 5 files changed, 91 insertions(+), 88 deletions(-) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index cc586ee7..25fc6f38 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -8,7 +8,7 @@ buildifier: # TODO (suvanjan): Re-enable once issues are fixed. warnings: "attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,confusing-name,constant-glob,ctx-actions,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,function-docstring,git-repository,http-archive,integer-division,load,load-on-top,module-docstring,name-conventions,native-build,native-package,no-effect,out-of-order-load,output-group,package-name,package-on-top,positional-args,redefined-variable,repository-name,same-origin-load,string-iteration,unreachable,unsorted-dict-items,unused-variable" platforms: - ubuntu1604: + ubuntu1804: build_targets: - "--" - "..." @@ -18,7 +18,7 @@ platforms: - "-//images/gcloud-bazel:gcloud-layer" test_targets: - "..." - ubuntu1804: + ubuntu2004: build_targets: - "--" - "..." @@ -29,12 +29,6 @@ platforms: test_targets: - "..." macos: - shell_commands: - # create a python2 symlink - # see https://github.com/bazelbuild/continuous-integration/issues/854 - # TODO(nlopezgi): remove once issue above is fixed - - mkdir /tmp/bin - - ln -s /usr/bin/python2.7 /tmp/bin/python2 build_targets: - "--" - "..." @@ -44,15 +38,20 @@ platforms: - "-//images/gcloud-bazel:gcloud-layer" build_flags: - "--verbose_failures" - # add the python2 symlink to the PATH - # see https://github.com/bazelbuild/continuous-integration/issues/854 - # TODO(nlopezgi): remove once issue above is fixed - - "--action_env=PATH=/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/tmp/bin/" test_targets: - "..." test_flags: - "--verbose_failures" - # add the python2 symlink to the PATH - # see https://github.com/bazelbuild/continuous-integration/issues/854 - # TODO(nlopezgi): remove once issue above is fixed - - "--action_env=PATH=/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/tmp/bin/" + min_supported_version: + name: "Minimum Supported Version" + bazel: "2.2.0" + platform: ubuntu1604 + build_targets: + - "--" + - "..." + - "-//images/gcloud-bazel:gcloud_push" + - "-//images/gcloud-bazel:gcloud_installer" + - "-//images/gcloud-bazel:gcloud_install" + - "-//images/gcloud-bazel:gcloud-layer" + test_targets: + - "..." diff --git a/.bazelversion b/.bazelversion index ccbccc3d..4a36342f 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -2.2.0 +3.0.0 diff --git a/WORKSPACE b/WORKSPACE index 3a5e70fb..af898748 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -59,19 +59,13 @@ load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() # Only needed if using the packaging rules. -load("@rules_python//python:pip.bzl", "pip3_import", "pip_repositories") +load("@rules_python//python:pip.bzl", "pip_install") -pip_repositories() - -pip3_import( +pip_install( name = "py_deps", requirements = "//:requirements.txt", ) -load("@py_deps//:requirements.bzl", "pip_install") - -pip_install() - http_archive( name = "com_github_grpc_grpc", sha256 = "f880ebeb2ccf0e47721526c10dd97469200e40b5f101a0d9774eb69efa0bd07a", @@ -87,15 +81,11 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps") grpc_extra_deps() -pip3_import( +pip_install( name = "grpc_python_dependencies", requirements = "@com_github_grpc_grpc//:requirements.bazel.txt", ) -load("@grpc_python_dependencies//:requirements.bzl", _grpc_pip_install = "pip_install") - -_grpc_pip_install() - # upb_deps and apple_rules_dependencies are needed for grpc load("@upb//bazel:workspace_deps.bzl", "upb_deps") diff --git a/k8s/k8s.bzl b/k8s/k8s.bzl index b65cda00..d9153111 100644 --- a/k8s/k8s.bzl +++ b/k8s/k8s.bzl @@ -14,21 +14,15 @@ """Rules for manipulation of K8s constructs.""" load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//toolchains/kubectl:kubectl_configure.bzl", "kubectl_configure") load(":with-defaults.bzl", _k8s_defaults = "k8s_defaults") k8s_defaults = _k8s_defaults -def k8s_repositories(): - """Download dependencies of k8s rules.""" - - excludes = native.existing_rules().keys() +_com_github_yaml_pyyaml_build_file = """\ +load("@rules_python//python:defs.bzl", "py_binary", "py_library") - if "com_github_yaml_pyyaml" not in excludes: - # Used by utilities for roundtripping yaml. - http_archive( - name = "com_github_yaml_pyyaml", - build_file_content = """ py_library( name = "yaml", srcs = glob(["lib/yaml/*.py"]), @@ -46,11 +40,21 @@ py_library( ], visibility = ["//visibility:public"], ) -""", - sha256 = "e9df8412ddabc9c21b4437ee138875b95ebb32c25f07f962439e16005152e00e", - strip_prefix = "pyyaml-5.1.2", - urls = ["https://github.com/yaml/pyyaml/archive/5.1.2.zip"], - ) +""" + +# buildifier: disable=unnamed-macro +def k8s_repositories(): + """Download dependencies of k8s rules.""" + + # Used by utilities for roundtripping yaml. + maybe( + http_archive, + name = "com_github_yaml_pyyaml", + build_file_content = _com_github_yaml_pyyaml_build_file, + sha256 = "e9df8412ddabc9c21b4437ee138875b95ebb32c25f07f962439e16005152e00e", + strip_prefix = "pyyaml-5.1.2", + urls = ["https://github.com/yaml/pyyaml/archive/5.1.2.zip"], + ) # Register the default kubectl toolchain targets for supported platforms # note these work with the autoconfigured toolchain @@ -60,38 +64,49 @@ py_library( "@io_bazel_rules_k8s//toolchains/kubectl:kubectl_osx_toolchain", "@io_bazel_rules_k8s//toolchains/kubectl:kubectl_windows_toolchain", ) - if "io_bazel_rules_go" not in excludes: - http_archive( - name = "io_bazel_rules_go", - sha256 = "ac03931e56c3b229c145f1a8b2a2ad3e8d8f1af57e43ef28a26123362a1e3c7e", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.4/rules_go-v0.24.4.tar.gz", - "https://github.com/bazelbuild/rules_go/releases/download/v0.24.4/rules_go-v0.24.4.tar.gz", - ], - ) - if "bazel_gazelle" not in excludes: - http_archive( - name = "bazel_gazelle", - sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz", - ], - ) - if "io_bazel_rules_docker" not in excludes: - http_archive( - name = "io_bazel_rules_docker", - sha256 = "6287241e033d247e9da5ff705dd6ef526bac39ae82f3d17de1b69f8cb313f9cd", - strip_prefix = "rules_docker-0.14.3", - urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.14.3/rules_docker-v0.14.3.tar.gz"], - ) - if "bazel_skylib" not in excludes: - http_archive( - name = "bazel_skylib", - sha256 = "7ac0fa88c0c4ad6f5b9ffb5e09ef81e235492c873659e6bb99efb89d11246bcb", - strip_prefix = "bazel-skylib-1.0.3", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/1.0.3.tar.gz"], - ) - if "k8s_config" not in excludes: - # WORKSPACE target to configure the kubectl tool - kubectl_configure(name = "k8s_config", build_srcs = False) + + maybe( + http_archive, + name = "io_bazel_rules_go", + sha256 = "52d0a57ea12139d727883c2fef03597970b89f2cc2a05722c42d1d7d41ec065b", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.13/rules_go-v0.24.13.tar.gz", + "https://github.com/bazelbuild/rules_go/releases/download/v0.24.13/rules_go-v0.24.13.tar.gz", + ], + ) + + maybe( + http_archive, + name = "bazel_gazelle", + sha256 = "222e49f034ca7a1d1231422cdb67066b885819885c356673cb1f72f748a3c9d4", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.3/bazel-gazelle-v0.22.3.tar.gz", + ], + ) + + maybe( + http_archive, + name = "io_bazel_rules_docker", + sha256 = "f4a39a410da7e497a7ccd19e28c69c93a851d6adb76798355a0c8ba9855e9b75", + strip_prefix = "rules_docker-e15c9ebf203b7fa708e69ff5f1cdcf427d7edf6f", + # `master` as of 2021-02-04 + urls = [ + "https://github.com/bazelbuild/rules_docker/archive/e15c9ebf203b7fa708e69ff5f1cdcf427d7edf6f.zip", + ], + ) + + maybe( + http_archive, + name = "bazel_skylib", + sha256 = "7ac0fa88c0c4ad6f5b9ffb5e09ef81e235492c873659e6bb99efb89d11246bcb", + strip_prefix = "bazel-skylib-1.0.3", + urls = ["https://github.com/bazelbuild/bazel-skylib/archive/1.0.3.tar.gz"], + ) + + # WORKSPACE target to configure the kubectl tool + maybe( + kubectl_configure, + name = "k8s_config", + build_srcs = False, + ) diff --git a/k8s/k8s_go_deps.bzl b/k8s/k8s_go_deps.bzl index 862aff1b..d41f73a6 100644 --- a/k8s/k8s_go_deps.bzl +++ b/k8s/k8s_go_deps.bzl @@ -14,6 +14,7 @@ """Macro to load Go package dependencies of Go binaries in this repository.""" load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load( "@io_bazel_rules_docker//repositories:go_repositories.bzl", rules_docker_go_deps = "go_deps", @@ -36,12 +37,10 @@ def deps(): rules_docker_repositories() rules_docker_go_deps() - excludes = native.existing_rules().keys() - - if "com_github_google_go_cmp" not in excludes: - go_repository( - name = "com_github_google_go_cmp", - importpath = "github.com/google/go-cmp", - sum = "h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=", - version = "v0.3.1", - ) + maybe( + go_repository, + name = "com_github_google_go_cmp", + importpath = "github.com/google/go-cmp", + sum = "h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=", + version = "v0.3.1", + )