Skip to content

Commit

Permalink
Makefile: split tools installation
Browse files Browse the repository at this point in the history
Split the installation of required tools into dedicated .install.$tool
targets and only install them if they're absent.  Remove the sudo call
when installing golangci-lint by properly setting GOBIN.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Dec 4, 2019
1 parent 69ad243 commit d1ee25f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ script: >
-e GOCACHE=/tmp/gocache
-v /etc/passwd:/etc/passwd -v /etc/sudoers:/etc/sudoers -v /etc/sudoers.d:/etc/sudoers.d
-v /var/run:/var/run:z -v $HOME/gopath:/gopath:Z
-w /gopath/src/github.com/containers/image image-test bash -c "PATH=$PATH:/gopath/bin make cross tools .gitvalidation validate test test-skopeo SUDO=sudo BUILDTAGS=\"$BUILDTAGS\""
-w /gopath/src/github.com/containers/image image-test bash -c "PATH=$PATH:/gopath/bin make cross tools test test-skopeo SUDO=sudo BUILDTAGS=\"$BUILDTAGS\""
41 changes: 26 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ SKOPEO_BRANCH = master
# Set SUDO=sudo to run container integration tests using sudo.
SUDO =

GOBIN := $(shell go env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(GOPATH)/bin
endif

# when cross compiling _for_ a Darwin or windows host, then we must use openpgp
BUILD_TAGS_WINDOWS_CROSS = containers_image_openpgp
BUILD_TAGS_DARWIN_CROSS = containers_image_openpgp
Expand All @@ -24,6 +29,8 @@ GOMD2MAN ?= $(shell command -v go-md2man || echo '$(GOBIN)/go-md2man')
MANPAGES_MD = $(wildcard docs/*.5.md)
MANPAGES ?= $(MANPAGES_MD:%.md=%)

export PATH := $(PATH):${GOBIN}

# On macOS, (brew install gpgme) installs it within /usr/local, but /usr/local/include is not in the default search path.
# Rather than hard-code this directory, use gpgme-config. Sadly that must be done at the top-level user
# instead of locally in the gpgme subpackage, because cgo supports only pkg-config, not general shell scripts,
Expand Down Expand Up @@ -52,18 +59,26 @@ cross:
GOOS=windows $(MAKE) build BUILDTAGS="$(BUILDTAGS) $(BUILD_TAGS_WINDOWS_CROSS)"
GOOS=darwin $(MAKE) build BUILDTAGS="$(BUILDTAGS) $(BUILD_TAGS_DARWIN_CROSS)"

tools: tools.timestamp
tools: .install.gitvalidation .install.golangci-lint .install.golint

.install.gitvalidation:
if [ ! -x "$(GOBIN)/git-validation" ]; then \
GO111MODULE="off" go get $(BUILDFLAGS) github.com/vbatts/git-validation; \
fi

tools.timestamp: Makefile
@GO111MODULE="off" go get -u $(BUILDFLAGS) golang.org/x/lint/golint
.install.golangci-lint:
if [ ! -x "$(GOBIN)/golangci-lint" ]; then \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sudo sh -s -- -b $(GOBIN)/ v1.21.0; \
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOBIN) v1.21.0; \
fi

.install.golint:
# Note, golint is only needed for Skopeo's tests.
if [ ! -x "$(GOBIN)/golint" ]; then \
GO111MODULE="off" go get -u $(BUILDFLAGS) golang.org/x/lint/golint; \
fi
@GO111MODULE="off" go get $(BUILDFLAGS) github.com/vbatts/git-validation
@touch tools.timestamp

clean:
rm -rf tools.timestamp $(MANPAGES)
rm -rf $(MANPAGES)

test:
@$(GPGME_ENV) GO111MODULE="on" go test $(BUILDFLAGS) -cover ./...
Expand Down Expand Up @@ -93,19 +108,15 @@ validate: lint
@test -z "$$(gofmt -s -l . | grep -ve '^vendor' | tee /dev/stderr)"

lint:
@out="$$(GO111MODULE="on" golangci-lint run)"; \
if [ -n "$$out" ]; then \
echo "$$out"; \
exit 1; \
fi
$(GOBIN)/golangci-lint run --build-tags "$(BUILDTAGS)"

# When this is running in travis, it will only check the travis commit range
.gitvalidation:
@which git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found. Consider 'make clean && make tools'" && false)
@which $(GOBIN)/git-validation > /dev/null 2>/dev/null || (echo "ERROR: git-validation not found. Consider 'make clean && make tools'" && false)
ifeq ($(TRAVIS),true)
git-validation -q -run DCO,short-subject,dangling-whitespace
$(GOBIN)/git-validation -q -run DCO,short-subject,dangling-whitespace
else
git fetch -q "https://github.com/containers/image.git" "refs/heads/master"
upstream="$$(git rev-parse --verify FETCH_HEAD)" ; \
git-validation -q -run DCO,short-subject,dangling-whitespace -range $$upstream..HEAD
$(GOBIN)/git-validation -q -run DCO,short-subject,dangling-whitespace -range $$upstream..HEAD
endif

0 comments on commit d1ee25f

Please sign in to comment.