adds source debug build options

Signed-off-by: Mike Brown <brownwm@us.ibm.com>
This commit is contained in:
Mike Brown 2016-07-01 11:36:47 -05:00
parent 7823c5779d
commit 6ca905ac37
3 changed files with 28 additions and 4 deletions

View File

@ -62,6 +62,10 @@ GOLDFLAGS ?=
KUBE_GOLDFLAGS = $(GOLDFLAGS) KUBE_GOLDFLAGS = $(GOLDFLAGS)
export KUBE_GOLDFLAGS GOLDFLAGS export KUBE_GOLDFLAGS GOLDFLAGS
GOGCFLAGS ?=
KUBE_GOGCFLAGS = $(GOGCFLAGS)
export KUBE_GOGCFLAGS GOGCFLAGS
# Build code. # Build code.
# #
# Args: # Args:
@ -69,12 +73,17 @@ export KUBE_GOLDFLAGS GOLDFLAGS
# package, the build will produce executable files under $(OUT_DIR)/go/bin. # package, the build will produce executable files under $(OUT_DIR)/go/bin.
# If not specified, "everything" will be built. # If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building. # GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags to pass to 'go' when building. # GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
# #
# Example: # Example:
# make # make
# make all # make all
# make all WHAT=cmd/kubelet GOFLAGS=-v # make all WHAT=cmd/kubelet GOFLAGS=-v
# make all GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
.PHONY: all .PHONY: all
all: generated_files all: generated_files
hack/make-rules/build.sh $(WHAT) hack/make-rules/build.sh $(WHAT)
@ -107,6 +116,7 @@ verify:
# TESTS: Same as WHAT. # TESTS: Same as WHAT.
# GOFLAGS: Extra flags to pass to 'go' when building. # GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags to pass to 'go' when building. # GOLDFLAGS: Extra linking flags to pass to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
# #
# Example: # Example:
# make check # make check

View File

@ -75,8 +75,14 @@ binaries):
make make
``` ```
You may pass build options and packages to the script as necessary. To build You may pass build options and packages to the script as necessary. For example,
binaries for all platforms: to build with optimizations disabled for enabling use of source debug tools:
```sh
make GOGCFLAGS="-N -l"
```
To build binaries for all platforms:
```sh ```sh
make cross make cross

View File

@ -426,6 +426,7 @@ kube::golang::build_kube_toolchain() {
kube::log::status "Building the toolchain targets:" "${binaries[@]}" kube::log::status "Building the toolchain targets:" "${binaries[@]}"
go install "${goflags[@]:+${goflags[@]}}" \ go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${binaries[@]:+${binaries[@]}}" "${binaries[@]:+${binaries[@]}}"
} }
@ -482,6 +483,7 @@ kube::golang::build_binaries_for_platform() {
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}") local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
CGO_ENABLED=0 go build -o "${outfile}" \ CGO_ENABLED=0 go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \ "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${binary}" "${binary}"
kube::log::progress "*" kube::log::progress "*"
@ -490,6 +492,7 @@ kube::golang::build_binaries_for_platform() {
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}") local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
go build -o "${outfile}" \ go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \ "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${binary}" "${binary}"
kube::log::progress "*" kube::log::progress "*"
@ -499,11 +502,13 @@ kube::golang::build_binaries_for_platform() {
# Use go install. # Use go install.
if [[ "${#nonstatics[@]}" != 0 ]]; then if [[ "${#nonstatics[@]}" != 0 ]]; then
go install "${goflags[@]:+${goflags[@]}}" \ go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${nonstatics[@]:+${nonstatics[@]}}" "${nonstatics[@]:+${nonstatics[@]}}"
fi fi
if [[ "${#statics[@]}" != 0 ]]; then if [[ "${#statics[@]}" != 0 ]]; then
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \ CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${statics[@]:+${statics[@]}}" "${statics[@]:+${statics[@]}}"
fi fi
@ -536,12 +541,14 @@ kube::golang::build_binaries_for_platform() {
# returns true (always stale). And that's why we need to install the # returns true (always stale). And that's why we need to install the
# test package. # test package.
go install "${goflags[@]:+${goflags[@]}}" \ go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
"${testpkg}" "${testpkg}"
mkdir -p "$(dirname ${outfile})" mkdir -p "$(dirname ${outfile})"
go test -c \ go test -c \
"${goflags[@]:+${goflags[@]}}" \ "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \ -ldflags "${goldflags}" \
-o "${outfile}" \ -o "${outfile}" \
"${testpkg}" "${testpkg}"
@ -595,9 +602,10 @@ kube::golang::build_binaries() {
host_platform=$(kube::golang::host_platform) host_platform=$(kube::golang::host_platform)
# Use eval to preserve embedded quoted strings. # Use eval to preserve embedded quoted strings.
local goflags goldflags local goflags goldflags gogcflags
eval "goflags=(${KUBE_GOFLAGS:-})" eval "goflags=(${KUBE_GOFLAGS:-})"
goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)" goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)"
gogcflags="${KUBE_GOGCFLAGS:-}"
local use_go_build local use_go_build
local -a targets=() local -a targets=()