Skip to content

Commit

Permalink
adds source debug build options
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
  • Loading branch information
mikebrow committed Jul 13, 2016
1 parent 7823c57 commit 6ca905a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,28 @@ GOLDFLAGS ?=
KUBE_GOLDFLAGS = $(GOLDFLAGS)
export KUBE_GOLDFLAGS GOLDFLAGS

GOGCFLAGS ?=
KUBE_GOGCFLAGS = $(GOGCFLAGS)
export KUBE_GOGCFLAGS GOGCFLAGS

# Build code.
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under $(OUT_DIR)/go/bin.
# If not specified, "everything" will be built.
# 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:
# make
# make all
# 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
all: generated_files
hack/make-rules/build.sh $(WHAT)
Expand Down Expand Up @@ -107,6 +116,7 @@ verify:
# TESTS: Same as WHAT.
# GOFLAGS: Extra 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:
# make check
Expand Down
10 changes: 8 additions & 2 deletions docs/devel/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ binaries):
make
```

You may pass build options and packages to the script as necessary. To build
binaries for all platforms:
You may pass build options and packages to the script as necessary. For example,
to build with optimizations disabled for enabling use of source debug tools:

```sh
make GOGCFLAGS="-N -l"
```

To build binaries for all platforms:

```sh
make cross
Expand Down
10 changes: 9 additions & 1 deletion hack/lib/golang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ kube::golang::build_kube_toolchain() {

kube::log::status "Building the toolchain targets:" "${binaries[@]}"
go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${binaries[@]:+${binaries[@]}}"
}
Expand Down Expand Up @@ -482,6 +483,7 @@ kube::golang::build_binaries_for_platform() {
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
CGO_ENABLED=0 go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${binary}"
kube::log::progress "*"
Expand All @@ -490,6 +492,7 @@ kube::golang::build_binaries_for_platform() {
local outfile=$(kube::golang::output_filename_for_binary "${binary}" "${platform}")
go build -o "${outfile}" \
"${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${binary}"
kube::log::progress "*"
Expand All @@ -499,11 +502,13 @@ kube::golang::build_binaries_for_platform() {
# Use go install.
if [[ "${#nonstatics[@]}" != 0 ]]; then
go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${nonstatics[@]:+${nonstatics[@]}}"
fi
if [[ "${#statics[@]}" != 0 ]]; then
CGO_ENABLED=0 go install -installsuffix cgo "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${statics[@]:+${statics[@]}}"
fi
Expand Down Expand Up @@ -536,12 +541,14 @@ kube::golang::build_binaries_for_platform() {
# returns true (always stale). And that's why we need to install the
# test package.
go install "${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
"${testpkg}"

mkdir -p "$(dirname ${outfile})"
go test -c \
"${goflags[@]:+${goflags[@]}}" \
-gcflags "${gogcflags}" \
-ldflags "${goldflags}" \
-o "${outfile}" \
"${testpkg}"
Expand Down Expand Up @@ -595,9 +602,10 @@ kube::golang::build_binaries() {
host_platform=$(kube::golang::host_platform)

# Use eval to preserve embedded quoted strings.
local goflags goldflags
local goflags goldflags gogcflags
eval "goflags=(${KUBE_GOFLAGS:-})"
goldflags="${KUBE_GOLDFLAGS:-} $(kube::version::ldflags)"
gogcflags="${KUBE_GOGCFLAGS:-}"

local use_go_build
local -a targets=()
Expand Down

0 comments on commit 6ca905a

Please sign in to comment.