Add auto-defined ALL_PLATFORMS field and support for dicts in for_platforms

pull/564/head
Jeff Grafton 2019-02-08 17:28:28 -08:00
parent dfdfc2e5b8
commit bc316e3dc1
2 changed files with 37 additions and 6 deletions

View File

@ -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

View File

@ -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(