From bc316e3dc149789859ed835e9b7ad25be0bf6c01 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Fri, 8 Feb 2019 17:28:28 -0800 Subject: [PATCH] Add auto-defined ALL_PLATFORMS field and support for dicts in for_platforms --- build/platforms.bzl | 36 +++++++++++++++++++++++++++++++++--- build/root/BUILD.root | 7 ++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/build/platforms.bzl b/build/platforms.bzl index 898203381a..b641cd0dd4 100644 --- a/build/platforms.bzl +++ b/build/platforms.bzl @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_skylib//lib:new_sets.bzl", "sets") +load("@bazel_skylib//lib:types.bzl", "types") + # KUBE_SERVER_PLATFORMS in hack/lib/golang.sh SERVER_PLATFORMS = { "linux": [ @@ -74,6 +77,20 @@ TEST_PLATFORMS = { ], } +def _all_platforms(): + all_platforms = {} + for platforms in [CLIENT_PLATFORMS, NODE_PLATFORMS, SERVER_PLATFORMS, TEST_PLATFORMS]: + for os, archs in platforms.items(): + all_platforms[os] = sets.union( + all_platforms.setdefault(os, sets.make()), + sets.make(archs), + ) + for os, archs in all_platforms.items(): + all_platforms[os] = sets.to_list(archs) + return all_platforms + +ALL_PLATFORMS = _all_platforms() + def go_platform_constraint(os, arch): return "@io_bazel_rules_go//go/platform:%s_%s" % (os, arch) @@ -85,20 +102,32 @@ def _update_dict_for_platform_category(d, value, platforms, only_os = None): continue for arch in arches: constraint = go_platform_constraint(os, arch) - if type(value) == "list": + fmt_args = {"OS": os, "ARCH": arch} + if types.is_list(value): + # Format all items in the list, and hope there are no duplicates d.setdefault(constraint, []).extend( - [v.format(OS = os, ARCH = arch) for v in value], + [v.format(**fmt_args) for v in value], ) else: + # Don't overwrite existing value if constraint in d: fail("duplicate entry for constraint %s", constraint) - d[constraint] = value.format(OS = os, ARCH = arch) + if types.is_dict(value): + # Format dictionary values only + d[constraint] = { + dict_key: dict_value.format(**fmt_args) + for dict_key, dict_value in value.items() + } + else: + # Hopefully this is just a string + d[constraint] = value.format(**fmt_args) def for_platforms( for_client = None, for_node = None, for_server = None, for_test = None, + for_all = None, default = None, only_os = None): d = {} @@ -108,4 +137,5 @@ def for_platforms( _update_dict_for_platform_category(d, for_node, NODE_PLATFORMS, only_os) _update_dict_for_platform_category(d, for_server, SERVER_PLATFORMS, only_os) _update_dict_for_platform_category(d, for_test, TEST_PLATFORMS, only_os) + _update_dict_for_platform_category(d, for_all, ALL_PLATFORMS, only_os) return d diff --git a/build/root/BUILD.root b/build/root/BUILD.root index d0238420d5..3175eb3a50 100644 --- a/build/root/BUILD.root +++ b/build/root/BUILD.root @@ -14,6 +14,7 @@ package(default_visibility = ["//visibility:public"]) load("@io_k8s_repo_infra//defs:build.bzl", "gcs_upload") +load("//build:platforms.bzl", "for_platforms") filegroup( name = "_binary-artifacts-and-hashes", @@ -35,11 +36,11 @@ gcs_upload( "//cluster/gce/gci:gcs-release-artifacts-and-hashes", ], tags = ["manual"], - upload_paths = { - "//:_binary-artifacts-and-hashes": "bin/linux/amd64", + upload_paths = select(for_platforms(for_all = { "//build/release-tars:release-tars-and-hashes": "", "//cluster/gce/gci:gcs-release-artifacts-and-hashes": "extra/gce", - }, + "//:_binary-artifacts-and-hashes": "bin/{OS}/{ARCH}", + })), ) filegroup(