mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Add auto-defined ALL_PLATFORMS field and support for dicts in for_platforms
This commit is contained in:
parent
dfdfc2e5b8
commit
bc316e3dc1
@ -12,6 +12,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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
|
# KUBE_SERVER_PLATFORMS in hack/lib/golang.sh
|
||||||
SERVER_PLATFORMS = {
|
SERVER_PLATFORMS = {
|
||||||
"linux": [
|
"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):
|
def go_platform_constraint(os, arch):
|
||||||
return "@io_bazel_rules_go//go/platform:%s_%s" % (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
|
continue
|
||||||
for arch in arches:
|
for arch in arches:
|
||||||
constraint = go_platform_constraint(os, arch)
|
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(
|
d.setdefault(constraint, []).extend(
|
||||||
[v.format(OS = os, ARCH = arch) for v in value],
|
[v.format(**fmt_args) for v in value],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
# Don't overwrite existing value
|
||||||
if constraint in d:
|
if constraint in d:
|
||||||
fail("duplicate entry for constraint %s", constraint)
|
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(
|
def for_platforms(
|
||||||
for_client = None,
|
for_client = None,
|
||||||
for_node = None,
|
for_node = None,
|
||||||
for_server = None,
|
for_server = None,
|
||||||
for_test = None,
|
for_test = None,
|
||||||
|
for_all = None,
|
||||||
default = None,
|
default = None,
|
||||||
only_os = None):
|
only_os = None):
|
||||||
d = {}
|
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_node, NODE_PLATFORMS, only_os)
|
||||||
_update_dict_for_platform_category(d, for_server, SERVER_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_test, TEST_PLATFORMS, only_os)
|
||||||
|
_update_dict_for_platform_category(d, for_all, ALL_PLATFORMS, only_os)
|
||||||
return d
|
return d
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
load("@io_k8s_repo_infra//defs:build.bzl", "gcs_upload")
|
load("@io_k8s_repo_infra//defs:build.bzl", "gcs_upload")
|
||||||
|
load("//build:platforms.bzl", "for_platforms")
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "_binary-artifacts-and-hashes",
|
name = "_binary-artifacts-and-hashes",
|
||||||
@ -35,11 +36,11 @@ gcs_upload(
|
|||||||
"//cluster/gce/gci:gcs-release-artifacts-and-hashes",
|
"//cluster/gce/gci:gcs-release-artifacts-and-hashes",
|
||||||
],
|
],
|
||||||
tags = ["manual"],
|
tags = ["manual"],
|
||||||
upload_paths = {
|
upload_paths = select(for_platforms(for_all = {
|
||||||
"//:_binary-artifacts-and-hashes": "bin/linux/amd64",
|
|
||||||
"//build/release-tars:release-tars-and-hashes": "",
|
"//build/release-tars:release-tars-and-hashes": "",
|
||||||
"//cluster/gce/gci:gcs-release-artifacts-and-hashes": "extra/gce",
|
"//cluster/gce/gci:gcs-release-artifacts-and-hashes": "extra/gce",
|
||||||
},
|
"//:_binary-artifacts-and-hashes": "bin/{OS}/{ARCH}",
|
||||||
|
})),
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
Loading…
Reference in New Issue
Block a user