Build and install from GOPATH

* Rename 'vendor/src' -> 'vendor'
  * Ignore vendor/ instead of vendor/src/ for lint
* Rename 'cmd/client' -> 'cmd/ocic' to make it 'go install'able
* Rename 'cmd/server' -> 'cmd/ocid' to make it 'go install'able
* Update Makefile to build and install from GOPATH
* Update tests to locate ocid/ocic in GOPATH/bin
* Search for binaries in GOPATH/bin instead of PATH
* Install tools using `go get -u`, so they are updated on each run

Signed-off-by: Jonathan Yu <jawnsy@redhat.com>
This commit is contained in:
Jonathan Yu 2017-01-17 11:57:35 -08:00
parent 9da2882d49
commit 6c9628cdb1
No known key found for this signature in database
GPG key ID: F3C2F688A21CB648
1111 changed files with 70 additions and 61 deletions

4
.gitignore vendored
View file

@ -1,13 +1,9 @@
/ocid
/ocic
/kpod
conmon/conmon conmon/conmon
conmon/conmon.o conmon/conmon.o
pause/pause pause/pause
pause/pause.o pause/pause.o
/docs/*.[158] /docs/*.[158]
/docs/*.[158].gz /docs/*.[158].gz
vendor/src/github.com/kubernetes-incubator/cri-o
ocid.conf ocid.conf
*.orig *.orig
*.rej *.rej

View file

@ -5,12 +5,12 @@ set -o nounset
set -o pipefail set -o pipefail
for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*'); do for d in $(find . -type d -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*'); do
gometalinter \ ${GOPATH}/bin/gometalinter \
--exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \ --exclude='error return value not checked.*(Close|Log|Print).*\(errcheck\)$' \
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \ --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$' \
--exclude='duplicate of.*_test.go.*\(dupl\)$' \ --exclude='duplicate of.*_test.go.*\(dupl\)$' \
--exclude='cmd\/client\/.*\.go.*\(dupl\)$' \ --exclude='cmd\/client\/.*\.go.*\(dupl\)$' \
--exclude='vendor\/src\/.*' \ --exclude='vendor\/.*' \
--exclude='server\/seccomp\/.*\.go.*$' \ --exclude='server\/seccomp\/.*\.go.*$' \
--disable=aligncheck \ --disable=aligncheck \
--disable=gotype \ --disable=gotype \

View file

@ -4,18 +4,13 @@ PROJECT := github.com/kubernetes-incubator/cri-o
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null) GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
OCID_IMAGE := ocid_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN)) OCID_IMAGE := ocid_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN))
OCID_LINK := ${CURDIR}/vendor/src/github.com/kubernetes-incubator/cri-o
OCID_LINK_DIR := ${CURDIR}/vendor/src/github.com/kubernetes-incubator
OCID_INSTANCE := ocid_dev OCID_INSTANCE := ocid_dev
SYSTEM_GOPATH := ${GOPATH}
PREFIX ?= ${DESTDIR}/usr/local PREFIX ?= ${DESTDIR}/usr/local
BINDIR ?= ${PREFIX}/bin BINDIR ?= ${PREFIX}/bin
LIBEXECDIR ?= ${PREFIX}/libexec LIBEXECDIR ?= ${PREFIX}/libexec
MANDIR ?= ${PREFIX}/share/man MANDIR ?= ${PREFIX}/share/man
ETCDIR ?= ${DESTDIR}/etc ETCDIR ?= ${DESTDIR}/etc
ETCDIR_OCID ?= ${ETCDIR}/ocid ETCDIR_OCID ?= ${ETCDIR}/ocid
GO_MD2MAN ?= $(shell which go-md2man)
export GOPATH := ${CURDIR}/vendor
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
@ -26,21 +21,20 @@ default: help
help: help:
@echo "Usage: make <target>" @echo "Usage: make <target>"
@echo @echo
@echo " * 'install' - Install binaries to system locations"
@echo " * 'binaries' - Build ocid, conmon and ocic" @echo " * 'binaries' - Build ocid, conmon and ocic"
@echo " * 'integration' - Execute integration tests" @echo " * 'integration' - Execute integration tests"
@echo " * 'clean' - Clean artifacts" @echo " * 'clean' - Clean artifacts"
@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"
lint: ${OCID_LINK} lint:
@which gometalinter > /dev/null 2>/dev/null || (echo "ERROR: gometalinter not found. Consider 'make install.tools' target" && false) ifndef GOPATH
$(error GOPATH is not set)
endif
@echo "checking lint" @echo "checking lint"
@./.tool/lint @./.tool/lint
${OCID_LINK}:
mkdir -p ${OCID_LINK_DIR}
ln -sfn ${CURDIR} ${OCID_LINK}
gofmt: gofmt:
@./hack/verify-gofmt.sh @./hack/verify-gofmt.sh
@ -50,24 +44,30 @@ conmon:
pause: pause:
make -C $@ make -C $@
GO_SRC = $(shell find . -name \*.go) ocid:
ocid: $(GO_SRC) | ${OCID_LINK} ifndef GOPATH
$(GO) build --tags "$(BUILDTAGS)" -o $@ ./cmd/server/ $(error GOPATH is not set)
endif
$(GO) install \
-tags "$(BUILDTAGS)" \
$(PROJECT)/cmd/ocid
ocic: $(GO_SRC) | ${OCID_LINK} ocic:
$(GO) build -o $@ ./cmd/client/ ifndef GOPATH
$(error GOPATH is not set)
endif
$(GO) install $(PROJECT)/cmd/ocic
kpod: $(GO_SRC) | ${OCID_LINK} kpod:
$(GO) build -o $@ ./cmd/kpod/ ifndef GOPATH
$(error GOPATH is not set)
endif
$(GO) install $(PROJECT)/cmd/kpod
ocid.conf: ocid ocid.conf: ocid
./ocid --config="" config --default > ocid.conf $(GOPATH)/bin/ocid --config="" config --default > ocid.conf
clean: clean:
rm -f ocid.conf
rm -f ocic ocid
rm -f kpod
rm -f ${OCID_LINK}
rm -f docs/*.1 docs/*.5 docs/*.8 rm -f docs/*.1 docs/*.5 docs/*.8
find . -name \*~ -delete find . -name \*~ -delete
find . -name \#\* -delete find . -name \#\* -delete
@ -92,23 +92,32 @@ MANPAGES_MD := $(wildcard docs/*.md)
MANPAGES := $(MANPAGES_MD:%.md=%) MANPAGES := $(MANPAGES_MD:%.md=%)
docs/%.1: docs/%.1.md docs/%.1: docs/%.1.md
@which go-md2man > /dev/null 2>/dev/null || (echo "ERROR: go-md2man not found. Consider 'make install.tools' target" && false) ifndef GOPATH
$(GO_MD2MAN) -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(error GOPATH is not set)
endif
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs/%.5: docs/%.5.md docs/%.5: docs/%.5.md
@which go-md2man > /dev/null 2>/dev/null || (echo "ERROR: go-md2man not found. Consider 'make install.tools' target" && false) ifndef GOPATH
$(GO_MD2MAN) -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(error GOPATH is not set)
endif
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs/%.8: docs/%.8.md docs/%.8: docs/%.8.md
@which go-md2man > /dev/null 2>/dev/null || (echo "ERROR: go-md2man not found. Consider 'make install.tools' target" && false) ifndef GOPATH
$(GO_MD2MAN) -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@ $(error GOPATH is not set)
endif
$(GOPATH)/bin/go-md2man -in $< -out $@.tmp && touch $@.tmp && mv $@.tmp $@
docs: $(MANPAGES) docs: $(MANPAGES)
install: install:
install -D -m 755 kpod $(BINDIR)/kpod ifndef GOPATH
install -D -m 755 ocid $(BINDIR)/ocid $(error GOPATH is not set)
install -D -m 755 ocic $(BINDIR)/ocic endif
install -D -m 755 $(GOPATH)/bin/ocid $(BINDIR)/ocid
install -D -m 755 $(GOPATH)/bin/ocic $(BINDIR)/ocic
install -D -m 755 $(GOPATH)/bin/kpod $(BINDIR)/kpod
install -D -m 755 conmon/conmon $(LIBEXECDIR)/ocid/conmon install -D -m 755 conmon/conmon $(LIBEXECDIR)/ocid/conmon
install -D -m 755 pause/pause $(LIBEXECDIR)/ocid/pause install -D -m 755 pause/pause $(LIBEXECDIR)/ocid/pause
install -d -m 755 $(MANDIR)/man1 install -d -m 755 $(MANDIR)/man1
@ -130,8 +139,10 @@ install.systemd:
install -D -m 644 contrib/systemd/ocid.service $(PREFIX)/lib/systemd/system/ocid.service install -D -m 644 contrib/systemd/ocid.service $(PREFIX)/lib/systemd/system/ocid.service
uninstall: uninstall:
rm -f $(BINDIR)/{ocid,ocic} rm -f $(BINDIR)/ocid
rm -f $(LIBEXECDIR)/ocid/{conmon,pause} rm -f $(BINDIR)/ocic
rm -f $(LIBEXECDIR)/ocid/conmon
rm -f $(LIBEXECDIR)/ocid/pause
for i in $(filter %.1,$(MANPAGES)); do \ for i in $(filter %.1,$(MANPAGES)); do \
rm -f $(MANDIR)/man8/$$(basename $${i}); \ rm -f $(MANDIR)/man8/$$(basename $${i}); \
done done
@ -145,11 +156,13 @@ 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: .gitvalidation:
@which git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found. Consider 'make install.tools' target" && false) ifndef GOPATH
$(error GOPATH is not set)
endif
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/ -v -run DCO,short-subject -range $(EPOCH_TEST_COMMIT)..HEAD
endif endif
.PHONY: install.tools .PHONY: install.tools
@ -157,14 +170,14 @@ endif
install.tools: .install.gitvalidation .install.gometalinter .install.md2man install.tools: .install.gitvalidation .install.gometalinter .install.md2man
.install.gitvalidation: .install.gitvalidation:
GOPATH=${SYSTEM_GOPATH} go get github.com/vbatts/git-validation go get -u github.com/vbatts/git-validation
.install.gometalinter: .install.gometalinter:
GOPATH=${SYSTEM_GOPATH} go get github.com/alecthomas/gometalinter go get -u github.com/alecthomas/gometalinter
GOPATH=${SYSTEM_GOPATH} gometalinter --install $(GOPATH)/bin/gometalinter --install
.install.md2man: .install.md2man:
GOPATH=${SYSTEM_GOPATH} go get github.com/cpuguy83/go-md2man go get -u github.com/cpuguy83/go-md2man
.PHONY: \ .PHONY: \
binaries \ binaries \

View file

@ -10,9 +10,9 @@ TESTDATA="${INTEGRATION_ROOT}/testdata"
OCID_ROOT=${OCID_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)} OCID_ROOT=${OCID_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)}
# Path of the ocid binary. # Path of the ocid binary.
OCID_BINARY=${OCID_BINARY:-${OCID_ROOT}/cri-o/ocid} OCID_BINARY=${OCID_BINARY:-${GOPATH}/bin/ocid}
# Path of the ocic binary. # Path of the ocic binary.
OCIC_BINARY=${OCIC_BINARY:-${OCID_ROOT}/cri-o/ocic} OCIC_BINARY=${OCIC_BINARY:-${GOPATH}/bin/ocic}
# Path of the conmon binary. # Path of the conmon binary.
CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/cri-o/conmon/conmon} CONMON_BINARY=${CONMON_BINARY:-${OCID_ROOT}/cri-o/conmon/conmon}
# Path of the pause binary. # Path of the pause binary.

Some files were not shown because too many files have changed in this diff Show more