Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Makefiles, make golangci-lint work again #1615

Merged
merged 8 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ lint_task:
build_script: |
apt-get update
apt-get install -y libbtrfs-dev libdevmapper-dev
test_script: make TAGS=regex_precompile local-validate && make lint && make clean
test_script: |
make TAGS=regex_precompile local-validate
make lint
make clean


# Update metadata on VM images referenced by this repository state
Expand Down
60 changes: 0 additions & 60 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,8 @@ run:
deadline: 5m
skip-dirs-use-default: true
linters:
enable-all: true
disable:
- cyclop
- deadcode
- dogsled
- dupl
- errcheck
- errname
- errorlint
- exhaustive
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofumpt
- golint
- gomnd
- gosec
- gosimple
- govet
- ifshort
- ineffassign
- interfacer
- interfacebloat
- ireturn
- lll
- maintidx
- maligned
- misspell
- musttag
- nakedret
- nestif
- nlreturn
- nolintlint
- nonamedreturns
- nosnakecase
- paralleltest
- prealloc
- predeclared
- rowserrcheck
- scopelint
- staticcheck
- structcheck
- stylecheck
- tagliatelle
- testpackage
- thelper
- unconvert
- unparam
- varcheck
- varnamelen
- wastedassign
- whitespace
- wrapcheck
- wsl
44 changes: 19 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
export GO111MODULE=off
export GOPROXY=https://proxy.golang.org

.PHONY: \
all \
binary \
clean \
codespell \
containers-storage \
cross \
default \
docs \
gccgo \
help \
install \
install.docs \
install.tools \
lint \
local-binary \
local-cross \
local-gccgo \
local-test \
local-test-integration \
local-test-unit \
local-validate \
lint \
vendor
test-integration \
test-unit \
validate \
vendor \
vendor-in-container
kolyshkin marked this conversation as resolved.
Show resolved Hide resolved

PACKAGE := github.com/containers/storage
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g")
EPOCH_TEST_COMMIT := 0418ebf59f9e1f564831c0ba9378b7f8e40a1c73
NATIVETAGS :=
AUTOTAGS := $(shell ./hack/btrfs_tag.sh) $(shell ./hack/libdm_tag.sh) $(shell ./hack/libsubid_tag.sh)
BUILDFLAGS := -tags "$(AUTOTAGS) $(TAGS)" $(FLAGS)
GO ?= go
TESTFLAGS := $(shell $(GO) test -race $(BUILDFLAGS) ./pkg/stringutils 2>&1 > /dev/null && echo -race)

# Go module support: set `-mod=vendor` to use the vendored sources
ifeq ($(shell $(GO) help mod >/dev/null 2>&1 && echo true), true)
GO:=GO111MODULE=on $(GO)
MOD_VENDOR=-mod=vendor
endif

default all: local-binary docs local-validate local-cross ## validate all checks, build and cross-build\nbinaries and docs

clean: ## remove all built files
$(RM) -f containers-storage containers-storage.* docs/*.1 docs/*.5

sources := $(wildcard *.go cmd/containers-storage/*.go drivers/*.go drivers/*/*.go internal/*/*.go pkg/*/*.go pkg/*/*/*.go types/*.go)
containers-storage: $(sources) ## build using gc on the host
$(GO) build $(MOD_VENDOR) -compiler gc $(BUILDFLAGS) ./cmd/containers-storage
containers-storage: ## build using gc on the host
$(GO) build -compiler gc $(BUILDFLAGS) ./cmd/containers-storage

codespell:
codespell -S Makefile,build,buildah,buildah.spec,imgtype,copy,AUTHORS,bin,vendor,.git,go.sum,CHANGELOG.md,changelog.txt,seccomp.json,.cirrus.yml,"*.xz,*.gz,*.tar,*.tgz,*ico,*.png,*.1,*.5,*.orig,*.rej" -L worl,flate,uint,iff,od,ERRO -w

binary local-binary: containers-storage

local-gccgo gccgo: ## build using gccgo on the host
GCCGO=$(PWD)/hack/gccgo-wrapper.sh $(GO) build $(MOD_VENDOR) -compiler gccgo $(BUILDFLAGS) -o containers-storage.gccgo ./cmd/containers-storage
GCCGO=$(PWD)/hack/gccgo-wrapper.sh $(GO) build -compiler gccgo $(BUILDFLAGS) -o containers-storage.gccgo ./cmd/containers-storage

local-cross cross: ## cross build the binaries for arm, darwin, and freebsd
@for target in linux/amd64 linux/386 linux/arm linux/arm64 linux/ppc64 linux/ppc64le linux/s390x linux/mips linux/mipsle linux/mips64 linux/mips64le darwin/amd64 windows/amd64 freebsd/amd64 freebsd/arm64 ; do \
os=`echo $${target} | cut -f1 -d/` ; \
arch=`echo $${target} | cut -f2 -d/` ; \
suffix=$${os}.$${arch} ; \
echo env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $(GO) build $(MOD_VENDOR) -compiler gc -tags \"$(NATIVETAGS) $(TAGS)\" $(FLAGS) -o containers-storage.$${suffix} ./cmd/containers-storage ; \
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $(GO) build $(MOD_VENDOR) -compiler gc -tags "$(NATIVETAGS) $(TAGS)" $(FLAGS) -o containers-storage.$${suffix} ./cmd/containers-storage || exit 1 ; \
echo env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $(GO) build -compiler gc -tags \"$(NATIVETAGS) $(TAGS)\" $(FLAGS) -o containers-storage.$${suffix} ./cmd/containers-storage ; \
env CGO_ENABLED=0 GOOS=$${os} GOARCH=$${arch} $(GO) build -compiler gc -tags "$(NATIVETAGS) $(TAGS)" $(FLAGS) -o containers-storage.$${suffix} ./cmd/containers-storage || exit 1 ; \
done

docs: install.tools ## build the docs on the host
Expand All @@ -66,7 +63,7 @@ docs: install.tools ## build the docs on the host
local-test: local-binary local-test-unit local-test-integration ## build the binaries and run the tests

local-test-unit test-unit: local-binary ## run the unit tests on the host (requires\nsuperuser privileges)
@$(GO) test -count 1 $(MOD_VENDOR) $(BUILDFLAGS) $(TESTFLAGS) $(shell $(GO) list ./... | grep -v ^$(PACKAGE)/vendor)
@$(GO) test -count 1 $(BUILDFLAGS) $(TESTFLAGS) ./...

local-test-integration test-integration: local-binary ## run the integration tests on the host (requires\nsuperuser privileges)
@cd tests; ./test_runner.bash
Expand All @@ -78,9 +75,6 @@ local-validate validate: install.tools ## validate DCO and gofmt on the host
install.tools:
$(MAKE) -C tests/tools

$(FFJSON):
$(MAKE) -C tests/tools

install.docs: docs
$(MAKE) -C docs install

Expand Down
2 changes: 2 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ MANINSTALLDIR=${PREFIX}/share/man
MANPAGES_MD = $(wildcard docs/*.5.md)
MANPAGES ?= $(MANPAGES_MD:%.md=%)

.PHONY: docs
docs: $(patsubst %.md,%.1,$(filter-out %.5.md,$(wildcard *.md))) containers-storage.conf.5

%.1: %.md
Expand All @@ -12,6 +13,7 @@ docs: $(patsubst %.md,%.1,$(filter-out %.5.md,$(wildcard *.md))) containers-stor
containers-storage.conf.5: containers-storage.conf.5.md
$(GOMD2MAN) -in $^ -out $@

.PHONY: install
install:
install -d -m 755 ${MANINSTALLDIR}/man5
install -m 644 *.5 ${MANINSTALLDIR}/man5/
19 changes: 6 additions & 13 deletions tests/tools/Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
export GO111MODULE=off

GO := go

BUILDDIR := build

all: $(BUILDDIR)

.PHONY: vendor
vendor:
export GO111MODULE=on \
$(GO) mod tidy && \
$(GO) mod vendor && \
$(GO) mod verify
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify

define go-build
$(shell cd `pwd` && $(GO) build -o $(BUILDDIR)/$(shell basename $(1)) $(1))
$(shell cd `pwd` && $(GO) build -mod=vendor -o $(BUILDDIR)/$(shell basename $(1)) $(1))
@echo > /dev/null
endef

Expand All @@ -33,9 +29,6 @@ $(BUILDDIR)/git-validation:
$(BUILDDIR)/go-md2man:
$(call go-build,./vendor/github.com/cpuguy83/go-md2man)

$(BUILDDIR)/golangci-lint: VERSION=v1.51.2
$(BUILDDIR)/golangci-lint:
export \
VERSION=v1.51.2 \
URL=https://raw.githubusercontent.com/golangci/golangci-lint \
BINDIR=$(BUILDDIR) && \
curl -sfL $$URL/$$VERSION/install.sh | sh -s $$VERSION
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/$(VERSION)/install.sh | sh -s -- -b ./$(BUILDDIR) $(VERSION)
9 changes: 8 additions & 1 deletion tests/tools/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module github.com/containers/storage/tests/tools

go 1.13
go 1.18

require (
github.com/cpuguy83/go-md2man v1.0.10
github.com/vbatts/git-validation v1.0.0
)

require (
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/sirupsen/logrus v1.4.1 // indirect
golang.org/x/sys v0.5.0 // indirect
)
5 changes: 0 additions & 5 deletions tests/tools/vendor/github.com/cpuguy83/go-md2man/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions tests/tools/vendor/github.com/cpuguy83/go-md2man/go.sum

This file was deleted.

1 change: 0 additions & 1 deletion tests/tools/vendor/github.com/hashicorp/go-version/go.mod

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion tests/tools/vendor/github.com/russross/blackfriday/go.mod

This file was deleted.

10 changes: 0 additions & 10 deletions tests/tools/vendor/github.com/sirupsen/logrus/go.mod

This file was deleted.

13 changes: 0 additions & 13 deletions tests/tools/vendor/github.com/sirupsen/logrus/go.sum

This file was deleted.

8 changes: 0 additions & 8 deletions tests/tools/vendor/github.com/vbatts/git-validation/go.mod

This file was deleted.

15 changes: 0 additions & 15 deletions tests/tools/vendor/github.com/vbatts/git-validation/go.sum

This file was deleted.

7 changes: 7 additions & 0 deletions tests/tools/vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# github.com/cpuguy83/go-md2man v1.0.10
## explicit; go 1.12
github.com/cpuguy83/go-md2man
github.com/cpuguy83/go-md2man/md2man
# github.com/hashicorp/go-version v1.2.0
## explicit
github.com/hashicorp/go-version
# github.com/konsorten/go-windows-terminal-sequences v1.0.1
## explicit
github.com/konsorten/go-windows-terminal-sequences
# github.com/russross/blackfriday v1.5.2
## explicit
github.com/russross/blackfriday
# github.com/sirupsen/logrus v1.4.1
## explicit
github.com/sirupsen/logrus
# github.com/vbatts/git-validation v1.0.0
## explicit; go 1.12
github.com/vbatts/git-validation
github.com/vbatts/git-validation/git
github.com/vbatts/git-validation/rules/danglingwhitespace
Expand All @@ -18,4 +24,5 @@ github.com/vbatts/git-validation/rules/messageregexp
github.com/vbatts/git-validation/rules/shortsubject
github.com/vbatts/git-validation/validate
# golang.org/x/sys v0.5.0
## explicit; go 1.17
golang.org/x/sys/unix