build: create a local GOPATH if none specified

Instead of requiring the developer to set up their own GOPATH somewhere,
do like Kubernetes and OpenShift Origin do:

git clone xxxxx
cd xxxxx
make

by creating an _output/ directory and linking the local source tree
into it, and setting that to be the GOPATH.

Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
Dan Williams 2017-03-27 15:53:33 -05:00
parent 93b1ff5207
commit 9c44933b58
5 changed files with 54 additions and 50 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
/.artifacts/ /.artifacts/
/_output/
/conmon/conmon /conmon/conmon
/conmon/conmon.o /conmon/conmon.o
/docs/*.[158] /docs/*.[158]

View file

@ -14,6 +14,17 @@ ETCDIR_OCID ?= ${ETCDIR}/ocid
BUILDTAGS := selinux seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) BUILDTAGS := selinux seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh)
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
unexport GOBIN
endif
GOPKGDIR := $(GOPATH)/src/$(PROJECT)
GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)")
# Update VPATH so make finds .gopathok
VPATH := $(VPATH):$(GOPATH)
all: binaries ocid.conf docs all: binaries ocid.conf docs
default: help default: help
@ -28,14 +39,14 @@ help:
@echo " * 'lint' - Execute the source code linter" @echo " * 'lint' - Execute the source code linter"
@echo " * 'gofmt' - Verify the source code gofmt" @echo " * 'gofmt' - Verify the source code gofmt"
.PHONY: check-gopath .gopathok:
ifeq ("$(wildcard $(GOPKGDIR))","")
check-gopath: mkdir -p "$(GOPKGBASEDIR)"
ifndef GOPATH ln -s "$(CURDIR)" "$(GOPKGBASEDIR)"
$(error GOPATH is not set)
endif endif
touch "$(GOPATH)/.gopathok"
lint: check-gopath lint: .gopathok
@echo "checking lint" @echo "checking lint"
@./.tool/lint @./.tool/lint
@ -48,30 +59,34 @@ conmon:
pause: pause:
$(MAKE) -C $@ $(MAKE) -C $@
bin2img: bin2img: .gopathok $(wildcard test/bin2img/*.go)
$(MAKE) -C test/$@ BUILDTAGS="$(BUILDTAGS)" go build -tags "$(BUILDTAGS)" -o test/bin2img/$@ $(PROJECT)/test/bin2img
copyimg: copyimg: .gopathok $(wildcard test/copyimg/*.go)
$(MAKE) -C test/$@ BUILDTAGS="$(BUILDTAGS)" go build -tags "$(BUILDTAGS)" -o test/copyimg/$@ $(PROJECT)/test/copyimg
checkseccomp: check-gopath checkseccomp: .gopathok $(wildcard test/checkseccomp/*.go)
$(MAKE) -C test/$@ go build -o test/checkseccomp/$@ $(PROJECT)/test/checkseccomp
ocid: check-gopath ocid: .gopathok
$(GO) build -o $@ \ $(GO) build -o $@ \
-tags "$(BUILDTAGS)" \ -tags "$(BUILDTAGS)" \
$(PROJECT)/cmd/ocid $(PROJECT)/cmd/ocid
ocic: check-gopath ocic: .gopathok
$(GO) build -o $@ $(PROJECT)/cmd/ocic $(GO) build -o $@ $(PROJECT)/cmd/ocic
kpod: check-gopath kpod: .gopathok
$(GO) build -o $@ $(PROJECT)/cmd/kpod $(GO) build -o $@ $(PROJECT)/cmd/kpod
ocid.conf: ocid ocid.conf: ocid
./ocid --config="" config --default > ocid.conf ./ocid --config="" config --default > ocid.conf
clean: clean:
ifneq ($(GOPATH),)
rm -f "$(GOPATH)/.gopathok"
endif
rm -rf _output
rm -f docs/*.1 docs/*.5 docs/*.8 rm -f docs/*.1 docs/*.5 docs/*.8
rm -fr test/testdata/redis-image rm -fr test/testdata/redis-image
find . -name \*~ -delete find . -name \*~ -delete
@ -79,9 +94,9 @@ clean:
rm -f ocic ocid kpod rm -f ocic ocid kpod
make -C conmon clean make -C conmon clean
make -C pause clean make -C pause clean
make -C test/bin2img clean rm -f test/bin2img/bin2img
make -C test/copyimg clean rm -f test/copyimg/copyimg
make -C test/checkseccomp clean rm -f test/checkseccomp/checkseccomp
ocidimage: ocidimage:
docker build -t ${OCID_IMAGE} . docker build -t ${OCID_IMAGE} .
@ -100,18 +115,18 @@ binaries: ocid ocic kpod conmon pause bin2img copyimg checkseccomp
MANPAGES_MD := $(wildcard docs/*.md) MANPAGES_MD := $(wildcard docs/*.md)
MANPAGES := $(MANPAGES_MD:%.md=%) MANPAGES := $(MANPAGES_MD:%.md=%)
docs/%.1: docs/%.1.md check-gopath docs/%.1: docs/%.1.md .gopathok
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs/%.5: docs/%.5.md check-gopath docs/%.5: docs/%.5.md .gopathok
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs/%.8: docs/%.8.md check-gopath docs/%.8: docs/%.8.md .gopathok
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs: $(MANPAGES) docs: $(MANPAGES)
install: check-gopath install: .gopathok
install -D -m 755 ocid $(BINDIR)/ocid install -D -m 755 ocid $(BINDIR)/ocid
install -D -m 755 ocic $(BINDIR)/ocic install -D -m 755 ocic $(BINDIR)/ocic
install -D -m 755 kpod $(BINDIR)/kpod install -D -m 755 kpod $(BINDIR)/kpod
@ -152,26 +167,32 @@ uninstall:
.PHONY: .gitvalidation .PHONY: .gitvalidation
# When this is running in travis, it will only check the travis commit range # When this is running in travis, it will only check the travis commit range
.gitvalidation: check-gopath .gitvalidation: .gopathok
ifeq ($(TRAVIS),true) ifeq ($(TRAVIS),true)
git-validation -q -run DCO,short-subject $(GOPATH)/bin/git-validation -q -run DCO,short-subject
else else
git-validation -v -run DCO,short-subject -range $(EPOCH_TEST_COMMIT)..HEAD $(GOPATH)/bin/git-validation -v -run DCO,short-subject -range $(EPOCH_TEST_COMMIT)..HEAD
endif endif
.PHONY: install.tools .PHONY: install.tools
install.tools: .install.gitvalidation .install.gometalinter .install.md2man install.tools: .install.gitvalidation .install.gometalinter .install.md2man
.install.gitvalidation: check-gopath .install.gitvalidation: .gopathok
go get -u github.com/vbatts/git-validation if [ ! -x "$(GOPATH)/bin/git-validation" ]; then \
go get -u github.com/vbatts/git-validation; \
fi
.install.gometalinter: check-gopath .install.gometalinter: .gopathok
go get -u github.com/alecthomas/gometalinter if [ ! -x "$(GOPATH)/bin/gometalinter" ]; then \
$(GOPATH)/bin/gometalinter --install go get -u github.com/alecthomas/gometalinter; \
$(GOPATH)/bin/gometalinter --install; \
fi
.install.md2man: check-gopath .install.md2man: .gopathok
go get -u github.com/cpuguy83/go-md2man if [ ! -x "$(GOPATH)/bin/go-md2man" ]; then \
go get -u github.com/cpuguy83/go-md2man; \
fi
.PHONY: \ .PHONY: \
bin2img \ bin2img \

View file

@ -1,6 +0,0 @@
bin2img: $(wildcard *.go)
go build -tags "$(BUILDTAGS)" -o $@
.PHONY: clean
clean:
rm -f bin2img

View file

@ -1,6 +0,0 @@
checkseccomp: $(wildcard *.go)
go build -o $@
.PHONY: clean
clean:
rm -f checkseccomp

View file

@ -1,6 +0,0 @@
copyimg: $(wildcard *.go)
go build -tags "$(BUILDTAGS)" -o $@
.PHONY: clean
clean:
rm -f copyimg