Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Makefile: Use 'go install ...' for the install target (#949)
Browse files Browse the repository at this point in the history
GOBIN (documented in [1]) defaults to DIR/bin, but it's a configurable
variable in its own right.  The old logic was just looking at GOPATH,
though, and not respecting GOBIN.

This commit updates our install target to lean on Go's build caching
(instead of using Make's dependency trees) to ensure a fresh-enough
build lands in the appropriate directory.  This approach relies on Go
1.10+ to avoid [2], but we've required Go 1.10+ since b859ebf
(Documentation/development: Bump minimum Go version to 1.10,
2018-04-03, #955).

For the build documentation, I've switched to 'go env GOPATH' to get
the (platform-specific [1]) default value when the environment
variable is not set.  And I've used cut [3] (instead of the awk [4]
the Makefile used to use) to pull out the first component of GOPATH.
Both are in POSIX, but cut is a simpler tool for this particular
problem.

[1]: https://golang.org/cmd/go/#hdr-GOPATH_environment_variable
[2]: golang/go#18981
[3]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html
[4]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html
  • Loading branch information
wking authored and rphillips committed Apr 3, 2018
1 parent 5f286e9 commit dbf0b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Documentation/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
## Requirements

* Go 1.10+
* Configured [GOPATH](http://golang.org/doc/code.html#GOPATH)

## Building

First, clone the repo into the proper location in your $GOPATH:
First, clone the repo into the proper location in your [`GOPATH`][GOPATH]:

```
go get -u github.com/kubernetes-incubator/bootkube
cd $GOPATH/src/github.com/kubernetes-incubator/bootkube
cd $(go env GOPATH | cut -d: -f1)/src/github.com/kubernetes-incubator/bootkube
```

Then build:
Expand Down Expand Up @@ -71,3 +70,5 @@ Commenting on the PR:
* `coreosbot run e2e checkpointer`: can be used to specifically test new checkpointer code.
* This will build a new checkpointer image from the PR, and includes that image as part of the checkpointer daemonset.
* `coreosbot run conformance`: run upstream Kubernetes conformance tests

[GOPATH]: https://golang.org/cmd/go/#hdr-GOPATH_environment_variable
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export PATH:=$(PATH):$(PWD)
SHELL:=$(shell which bash)
LOCAL_OS:=$(shell uname | tr A-Z a-z)
GOFILES:=$(shell find . -name '*.go' | grep -v -E '(./vendor)')
GOPATH_BIN:=$(shell echo ${GOPATH} | awk 'BEGIN { FS = ":" }; { print $1 }')/bin
GOPATH ?= $(shell go env GOPATH)
PRIMARY_GOPATH ?= $(shell echo ${GOPATH} | cut -d : -f 1)
GOBIN ?= $(PRIMARY_GOPATH)/bin
LDFLAGS=-X github.com/kubernetes-incubator/bootkube/pkg/version.Version=$(shell $(CURDIR)/build/git-version.sh)
TERRAFORM:=$(shell command -v terraform 2> /dev/null)

Expand Down Expand Up @@ -41,7 +43,7 @@ endif
@go test -v $(shell go list ./... | grep -v '/vendor/\|/e2e')

install: _output/bin/$(LOCAL_OS)/bootkube
cp $< $(GOPATH_BIN)
cp $< $(GOBIN)

_output/bin/%: GOOS=$(word 1, $(subst /, ,$*))
_output/bin/%: GOARCH=$(word 2, $(subst /, ,$*))
Expand Down

0 comments on commit dbf0b6a

Please sign in to comment.