Convert go_binary linkstamp to x_defs

pull/6/head
Jeff Grafton 2017-06-05 16:37:19 -07:00
parent 14e1889372
commit 64bd79fad7
14 changed files with 73 additions and 10 deletions

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "cloud-controller-manager", name = "cloud-controller-manager",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -8,12 +8,13 @@ load(
"go_library", "go_library",
"go_test", "go_test",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "hyperkube", name = "hyperkube",
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_test( go_test(

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kube-apiserver", name = "kube-apiserver",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kube-controller-manager", name = "kube-controller-manager",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kube-proxy", name = "kube-proxy",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kubeadm", name = "kubeadm",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -5,6 +5,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kubectl", name = "kubectl",
@ -15,11 +16,11 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
visibility = [ visibility = [
"//build/visible_to:COMMON_release", "//build/visible_to:COMMON_release",
], ],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -7,12 +7,13 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kubelet", name = "kubelet",
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -118,12 +118,15 @@ kube::version::ldflag() {
local key=${1} local key=${1}
local val=${2} local val=${2}
# If you update these, also update the list pkg/version/def.bzl.
echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}" echo "-X ${KUBE_GO_PACKAGE}/pkg/version.${key}=${val}"
echo "-X ${KUBE_GO_PACKAGE}/vendor/k8s.io/client-go/pkg/version.${key}=${val}" echo "-X ${KUBE_GO_PACKAGE}/vendor/k8s.io/client-go/pkg/version.${key}=${val}"
} }
# Prints the value that needs to be passed to the -ldflags parameter of go build # Prints the value that needs to be passed to the -ldflags parameter of go build
# in order to set the Kubernetes based on the git tree status. # in order to set the Kubernetes based on the git tree status.
# IMPORTANT: if you update any of these, also update the lists in
# pkg/version/def.bzl and hack/print-workspace-status.sh.
kube::version::ldflags() { kube::version::ldflags() {
kube::version::get_version_vars kube::version::get_version_vars

View File

@ -29,6 +29,8 @@ kube::version::get_version_vars
# instead of volatile-status.txt. # instead of volatile-status.txt.
# Stamped rules will be retriggered by changes to stable-status.txt, but not by # Stamped rules will be retriggered by changes to stable-status.txt, but not by
# changes to volatile-status.txt. # changes to volatile-status.txt.
# IMPORTANT: the camelCase vars should match the lists in hack/lib/version.sh
# and pkg/version/def.bzl.
cat <<EOF cat <<EOF
STABLE_BUILD_GIT_COMMIT ${KUBE_GIT_COMMIT-} STABLE_BUILD_GIT_COMMIT ${KUBE_GIT_COMMIT-}
STABLE_BUILD_SCM_STATUS ${KUBE_GIT_TREE_STATE-} STABLE_BUILD_SCM_STATUS ${KUBE_GIT_TREE_STATE-}

24
pkg/version/def.bzl Normal file
View File

@ -0,0 +1,24 @@
# Implements hack/lib/version.sh's kube::version::ldflags() for Bazel.
def version_x_defs():
# This should match the list of packages in kube::version::ldflag
stamp_pkgs = [
"k8s.io/kubernetes/pkg/version",
# In hack/lib/version.sh, this has a vendor/ prefix. That isn't needed here?
"k8s.io/client-go/pkg/version",
]
# This should match the list of vars in kube::version::ldflags
# It should also match the list of vars set in hack/print-workspace-status.sh.
stamp_vars = [
"buildDate",
"gitCommit",
"gitMajor",
"gitMinor",
"gitTreeState",
"gitVersion",
]
# Generate the cross-product.
x_defs = {}
for pkg in stamp_pkgs:
for var in stamp_vars:
x_defs["%s.%s" % (pkg, var)] = "{%s}" % var
return x_defs

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kube-scheduler", name = "kube-scheduler",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(

View File

@ -0,0 +1,24 @@
# Implements hack/lib/version.sh's kube::version::ldflags() for Bazel.
def version_x_defs():
# This should match the list of packages in kube::version::ldflag
stamp_pkgs = [
"k8s.io/kubernetes/pkg/version",
# In hack/lib/version.sh, this has a vendor/ prefix. That isn't needed here?
"k8s.io/client-go/pkg/version",
]
# This should match the list of vars in kube::version::ldflags
# It should also match the list of vars set in hack/print-workspace-status.sh.
stamp_vars = [
"buildDate",
"gitCommit",
"gitMajor",
"gitMinor",
"gitTreeState",
"gitVersion",
]
# Generate the cross-product.
x_defs = {}
for pkg in stamp_pkgs:
for var in stamp_vars:
x_defs["%s.%s" % (pkg, var)] = "{%s}" % var
return x_defs

View File

@ -7,6 +7,7 @@ load(
"go_binary", "go_binary",
"go_library", "go_library",
) )
load("//vendor/k8s.io/client-go/pkg/version:def.bzl", "version_x_defs")
go_binary( go_binary(
name = "kube-aggregator", name = "kube-aggregator",
@ -17,8 +18,8 @@ go_binary(
"-static", "-static",
], ],
library = ":go_default_library", library = ":go_default_library",
linkstamp = "k8s.io/kubernetes/pkg/version",
tags = ["automanaged"], tags = ["automanaged"],
x_defs = version_x_defs(),
) )
go_library( go_library(