From 4db3e59a7d6e71ce7d4b66355f5484ca5ed58115 Mon Sep 17 00:00:00 2001 From: Ed Welch Date: Tue, 22 Feb 2022 02:39:10 -0500 Subject: [PATCH] Build: simplify make targets to just run every time (#5411) * run the make targets regardless of file timestamps and changes, just run them every time. Signed-off-by: Edward Welch * attempt #2 Signed-off-by: Edward Welch * don't need GO_FILES anymore Signed-off-by: Edward Welch * remove all the mod=vendor flags required as we transitioned through go versions 13/14/15 Signed-off-by: Edward Welch * changing drone deps because check-generated-files removes protos and I guess this all happens in the same place at the same time in drone. Signed-off-by: Edward Welch * fix rebase Signed-off-by: Edward Welch --- .drone/drone.jsonnet | 2 +- .drone/drone.yml | 3 +- Makefile | 81 +++++++++++++++++--------------------------- 3 files changed, 34 insertions(+), 52 deletions(-) diff --git a/.drone/drone.jsonnet b/.drone/drone.jsonnet index b1eacd46622c..f50f904ae480 100644 --- a/.drone/drone.jsonnet +++ b/.drone/drone.jsonnet @@ -353,7 +353,7 @@ local manifest(apps) = pipeline('manifest') { image: 'koalaman/shellcheck-alpine:stable', commands: ['apk add make bash && make lint-scripts'], }, - make('loki', container=false) { depends_on: ['clone'] }, + make('loki', container=false) { depends_on: ['clone', 'check-generated-files'] }, make('validate-example-configs', container=false) { depends_on: ['loki'] }, make('check-example-config-doc', container=false) { depends_on: ['clone'] }, ], diff --git a/.drone/drone.yml b/.drone/drone.yml index a580f1beadd6..32bc69ce2efa 100644 --- a/.drone/drone.yml +++ b/.drone/drone.yml @@ -77,6 +77,7 @@ steps: - make BUILD_IN_CONTAINER=false loki depends_on: - clone + - check-generated-files image: grafana/loki-build-image:0.20.0 name: loki - commands: @@ -1064,6 +1065,6 @@ kind: secret name: deploy_config --- kind: signature -hmac: ca18b0336abbfa2af076bcf301c13450ce1a8cdad68b0d7c4a5a3e6fbb6a3140 +hmac: 6d010031b5c18947ac4710106d06f119e77d715ddc687983227700254b27e6d8 ... diff --git a/Makefile b/Makefile index 9cec92a609eb..511322f76613 100644 --- a/Makefile +++ b/Makefile @@ -12,23 +12,6 @@ SHELL = /usr/bin/env bash -# Empty value = no -mod parameter is used. -# If not empty, GOMOD is passed to -mod= parameter. -# In Go 1.13, "readonly" and "vendor" are accepted. -# In Go 1.14, "readonly", "vendor" and "mod" values are accepted. -# If no value is specified, defaults to "vendor". -# -# Can be used from command line by using "GOMOD= make" (empty = no -mod parameter), or "GOMOD=vendor make" (default). - -GOMOD ?= vendor -ifeq ($(strip $(GOMOD)),) # Is empty? - MOD_FLAG= - GOLANGCI_ARG= -else - MOD_FLAG=-mod=$(GOMOD) - GOLANGCI_ARG=--modules-download-mode=$(GOMOD) -endif - GOTEST ?= go test ############# @@ -59,20 +42,16 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) # 'make: Entering directory '/src/loki' phase. DONT_FIND := -name tools -prune -o -name vendor -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o -# These are all the application files, they are included in the various binary rules as dependencies -# to make sure binaries are rebuilt if any source files change. -APP_GO_FILES := $(shell find . $(DONT_FIND) -name .y.go -prune -o -name .pb.go -prune -o -name cmd -prune -o -type f -name '*.go' -print) - # Build flags VPREFIX := github.com/grafana/loki/pkg/util/build GO_LDFLAGS := -X $(VPREFIX).Branch=$(GIT_BRANCH) -X $(VPREFIX).Version=$(IMAGE_TAG) -X $(VPREFIX).Revision=$(GIT_REVISION) -X $(VPREFIX).BuildUser=$(shell whoami)@$(shell hostname) -X $(VPREFIX).BuildDate=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") -GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG) -DYN_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG) +GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w $(GO_LDFLAGS)" -tags netgo +DYN_GO_FLAGS := -ldflags "-s -w $(GO_LDFLAGS)" -tags netgo # Per some websites I've seen to add `-gcflags "all=-N -l"`, the gcflags seem poorly if at all documented # the best I could dig up is -N disables optimizations and -l disables inlining which should make debugging match source better. # Also remove the -s and -w flags present in the normal build which strip the symbol table and the DWARF symbol table. -DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "-extldflags \"-static\" $(GO_LDFLAGS)" -tags netgo $(MOD_FLAG) -DYN_DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "$(GO_LDFLAGS)" -tags netgo $(MOD_FLAG) +DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "-extldflags \"-static\" $(GO_LDFLAGS)" -tags netgo +DYN_DEBUG_GO_FLAGS := -gcflags "all=-N -l" -ldflags "$(GO_LDFLAGS)" -tags netgo # Docker mount flag, ignored on native docker host. see (https://docs.docker.com/docker-for-mac/osxfs-caching/#delegated) MOUNT_FLAGS := :delegated @@ -148,47 +127,49 @@ check-generated-files: yacc ragel protos clients/pkg/promtail/server/ui/assets_v ########## # Logcli # ########## - -logcli: yacc ragel cmd/logcli/logcli +.PHONY: cmd/logcli/logcli +logcli: cmd/logcli/logcli logcli-image: $(SUDO) docker build -t $(IMAGE_PREFIX)/logcli:$(IMAGE_TAG) -f cmd/logcli/Dockerfile . -cmd/logcli/logcli: $(APP_GO_FILES) cmd/logcli/main.go - CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) +cmd/logcli/logcli: + CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./cmd/logcli $(NETGO_CHECK) ######## # Loki # ######## - +.PHONY: cmd/loki/loki cmd/loki/loki-debug loki: cmd/loki/loki loki-debug: cmd/loki/loki-debug -cmd/loki/loki: $(APP_GO_FILES) cmd/loki/main.go +cmd/loki/loki: CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) -cmd/loki/loki-debug: $(APP_GO_FILES) cmd/loki/main.go +cmd/loki/loki-debug: CGO_ENABLED=0 go build $(DEBUG_GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) ############### # Loki-Canary # ############### - +.PHONY: cmd/loki-canary/loki-canary loki-canary: cmd/loki-canary/loki-canary -cmd/loki-canary/loki-canary: $(APP_GO_FILES) cmd/loki-canary/main.go +cmd/loki-canary/loki-canary: CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) ################# # Loki-QueryTee # ################# +.PHONY: cmd/querytee/querytee +loki-querytee: cmd/querytee/querytee -loki-querytee: $(APP_GO_FILES) cmd/querytee/main.go - CGO_ENABLED=0 go build $(GO_FLAGS) -o ./cmd/querytee/$@ ./cmd/querytee/ +cmd/querytee/querytee: + CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) ############ @@ -209,9 +190,9 @@ PROMTAIL_GO_FLAGS = $(DYN_GO_FLAGS) PROMTAIL_DEBUG_GO_FLAGS = $(DYN_DEBUG_GO_FLAGS) endif endif - -promtail: yacc ragel clients/cmd/promtail/promtail -promtail-debug: yacc ragel clients/cmd/promtail/promtail-debug +.PHONY: clients/cmd/promtail/promtail clients/cmd/promtail/promtail-debug +promtail: clients/cmd/promtail/promtail +promtail-debug: clients/cmd/promtail/promtail-debug promtail-clean-assets: rm -rf clients/pkg/promtail/server/ui/assets_vfsdata.go @@ -219,23 +200,23 @@ promtail-clean-assets: # Rule to generate promtail static assets file $(PROMTAIL_GENERATED_FILE): $(PROMTAIL_UI_FILES) @echo ">> writing assets" - GOFLAGS="$(MOD_FLAG)" GOOS=$(shell go env GOHOSTOS) go generate -x -v ./clients/pkg/promtail/server/ui + GOOS=$(shell go env GOHOSTOS) go generate -x -v ./clients/pkg/promtail/server/ui -clients/cmd/promtail/promtail: $(APP_GO_FILES) $(PROMTAIL_GENERATED_FILE) clients/cmd/promtail/main.go +clients/cmd/promtail/promtail: CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) -clients/cmd/promtail/promtail-debug: $(APP_GO_FILES) clients/pkg/promtail/server/ui/assets_vfsdata.go clients/cmd/promtail/main.go +clients/cmd/promtail/promtail-debug: CGO_ENABLED=$(PROMTAIL_CGO) go build $(PROMTAIL_DEBUG_GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) ############### # Migrate # ############### - +.PHONY: cmd/migrate/migrate migrate: cmd/migrate/migrate -cmd/migrate/migrate: $(APP_GO_FILES) cmd/migrate/main.go +cmd/migrate/migrate: CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) @@ -268,7 +249,7 @@ publish: packages # To run this efficiently on your workstation, run this from the root dir: # docker run --rm --tty -i -v $(pwd)/.cache:/go/cache -v $(pwd)/.pkg:/go/pkg -v $(pwd):/src/loki grafana/loki-build-image:0.17.0 lint lint: - GO111MODULE=on GOGC=10 golangci-lint run -v $(GOLANGCI_ARG) + GO111MODULE=on GOGC=10 golangci-lint run -v faillint -paths "sync/atomic=go.uber.org/atomic" ./... ######## @@ -276,7 +257,7 @@ lint: ######## test: all - GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt $(MOD_FLAG) -p=4 ./... + GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt -p=4 ./... ######### # Clean # @@ -297,7 +278,7 @@ clean: rm -rf clients/cmd/fluent-bit/out_grafana_loki.h rm -rf clients/cmd/fluent-bit/out_grafana_loki.so rm -rf cmd/migrate/migrate - go clean $(MOD_FLAG) ./... + go clean ./... ######### # YACCs # @@ -399,7 +380,7 @@ docker-driver: docker-driver-clean $(build-rootfs) docker plugin create $(LOKI_DOCKER_DRIVER):main$(PLUGIN_ARCH) clients/cmd/docker-driver -clients/cmd/docker-driver/docker-driver: $(APP_GO_FILES) +clients/cmd/docker-driver/docker-driver: CGO_ENABLED=0 go build $(GO_FLAGS) -o $@ ./$(@D) $(NETGO_CHECK) @@ -571,8 +552,8 @@ endif ######## benchmark-store: - go run $(MOD_FLAG) ./pkg/storage/hack/main.go - $(GOTEST) $(MOD_FLAG) ./pkg/storage/ -bench=. -benchmem -memprofile memprofile.out -cpuprofile cpuprofile.out -trace trace.out + go run ./pkg/storage/hack/main.go + $(GOTEST) ./pkg/storage/ -bench=. -benchmem -memprofile memprofile.out -cpuprofile cpuprofile.out -trace trace.out # regenerate drone yaml drone: