From b36cebd867b8e7c8814aef1a4d3766ecb804a587 Mon Sep 17 00:00:00 2001 From: Balazs Nadasdi Date: Wed, 10 Aug 2022 14:36:38 +0200 Subject: [PATCH 1/2] fix: go build target with makefile With `go build` we can't specify more than one binaries to build. Go will not know what to do with them. It feels logical to assume it will build a binary with the same name as the package defined, but 1. You can specify `-o` flag and it can only be one. 2. You can have different modules with the same name like `cmd/mybin` and `extra/mybin`. To prevent polluting the root of the repo, I moved all binary under the `bin/` directory. --- .gitignore | 1 + Makefile | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9aaac31e4..609bc04cd 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ local /gen /cmds/test/generics /gen +bin/ diff --git a/Makefile b/Makefile index cef9b4fbf..0d3aeffb2 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,22 @@ SOURCES := $(shell go list -f '{{$$I:=.Dir}}{{range .GoFiles }}{{$$I}}/{{.}} {{e GOPATH := $(shell go env GOPATH) build: ${SOURCES} + mkdir -p bin go build -ldflags "-s -w \ -X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \ -X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \ -X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \ -X github.com/open-component-model/ocm/pkg/version.buildDate=$(shell date --rfc-3339=seconds | sed 's/ /T/')" \ - ./cmds/ocm ./cmds/helminstaller + -o bin/ocm \ + ./cmds/ocm + + go build -ldflags "-s -w \ + -X github.com/open-component-model/ocm/pkg/version.gitVersion=$(EFFECTIVE_VERSION) \ + -X github.com/open-component-model/ocm/pkg/version.gitTreeState=$(GIT_TREE_STATE) \ + -X github.com/open-component-model/ocm/pkg/version.gitCommit=$(COMMIT) \ + -X github.com/open-component-model/ocm/pkg/version.buildDate=$(shell date --rfc-3339=seconds | sed 's/ /T/')" \ + -o bin/helminstaller \ + ./cmds/helminstaller .PHONY: install-requirements install-requirements: From e537c42fac35103bdd92d2d4ddeeb8096a5b7ba3 Mon Sep 17 00:00:00 2001 From: Balazs Nadasdi Date: Wed, 10 Aug 2022 14:46:02 +0200 Subject: [PATCH 2/2] remove extra force-test definition --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index 0d3aeffb2..342aecd5b 100644 --- a/Makefile +++ b/Makefile @@ -51,10 +51,6 @@ check: force-test: @go test --count=1 $(REPO_ROOT)/cmds/ocm $(REPO_ROOT)/cmds/helminstaller $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/... -.PHONY: force-test -force-test: - @go test --count=1 $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/pkg/... - .PHONY: test test: @echo "> Test"