diff --git a/.build/go.mk b/.build/go.mk index 987be8d765..8dc44b95a1 100644 --- a/.build/go.mk +++ b/.build/go.mk @@ -1,17 +1,18 @@ +SHELL := /bin/bash GO_BUILD = GOPRIVATE="${GO_PRIVATE}" CGO_ENABLED=0 go build -a -installsuffix cgo GO_LIST = env GO111MODULE=on GOPRIVATE="${GO_PRIVATE}" go list TEST_CMD = go test -v -timeout 600s -coverprofile=profile.coverprofile TEST_C_CMD = go test -c -coverprofile=profile.coverprofile TEST_RUN_ARGS = -test.v -test.timeout 600s -test.coverprofile=profile.coverprofile LDFLAGS = -ldflags "-X github.com/ovh/cds/sdk.VERSION=$(VERSION) -X github.com/ovh/cds/sdk.GOOS=$$GOOS -X github.com/ovh/cds/sdk.GOARCH=$$GOARCH -X github.com/ovh/cds/sdk.GITHASH=$(GITHASH) -X github.com/ovh/cds/sdk.BUILDTIME=$(BUILDTIME) -X github.com/ovh/cds/sdk.BINARY=$(TARGET_ENGINE) -X github.com/ovh/cds/sdk.DBMIGRATE=$(DBMIGRATE)" -CURRENT_PACKAGE = $(shell $(GO_LIST)) +CURRENT_PACKAGE = $(shell $(GO_LIST) 2>&1 | grep -v 'no Go files in') TARGET_DIST := ./dist TARGET_RESULTS := ./dist/test-results ENABLE_CROSS_COMPILATION := true ##### =====> Clean <===== ##### - +.PHONY: mk_go_clean mk_go_clean: # clean target directory @rm -rf $(TARGET_DIST) @rm -rf $(TARGET_RESULTS) @@ -27,14 +28,14 @@ mk_go_clean: # clean target directory ##### =====> Compile <===== ##### -IS_TEST := $(filter test,$(MAKECMDGOALS)) -TARGET_OS := $(filter-out $(TARGET_OS_EXCLUDED), $(if ${ENABLE_CROSS_COMPILATION},$(if ${OS},${OS}, $(if $(IS_TEST), $(shell go env GOOS), windows darwin linux openbsd freebsd)),$(shell go env GOOS))) -TARGET_ARCH := $(if ${ARCH},${ARCH}, $(if $(IS_TEST), $(shell go env GOARCH),amd64 arm 386 arm64 ppc64le)) +IS_TEST = $(filter test,$(MAKECMDGOALS)) +TARGET_OS = $(filter-out $(TARGET_OS_EXCLUDED), $(if ${ENABLE_CROSS_COMPILATION},$(if ${OS},${OS}, $(if $(IS_TEST), $(shell go env GOOS), windows darwin linux openbsd freebsd)),$(shell go env GOOS))) +TARGET_ARCH = $(if ${ARCH},${ARCH}, $(if $(IS_TEST), $(shell go env GOARCH),amd64 arm 386 arm64 ppc64le)) BINARIES = $(addprefix $(TARGET_DIST)/, $(addsuffix -$(OS)-$(ARCH)$(if $(IS_WINDOWS),.exe), $(notdir $(TARGET_NAME)))) -OSARCHVALID = $(shell go tool dist list | grep -v '^darwin/arm'|grep -v '^darwin/386'|grep -v '^windows/386'|grep -v '^windows/arm'|grep -v '^openbsd/arm*'|grep -v '^openbsd/386'|grep -v '^freebsd/arm*'|grep -v '^freebsd/386') +OSARCHVALID := $(shell go tool dist list | grep -v '^darwin/arm'|grep -v '^darwin/386'|grep -v '^windows/386'|grep -v '^windows/arm'|grep -v '^openbsd/arm*'|grep -v '^openbsd/386'|grep -v '^freebsd/arm*'|grep -v '^freebsd/386') IS_OS_ARCH_VALID = $(filter $(OS)/$(ARCH),$(OSARCHVALID)) CROSS_COMPILED_BINARIES = $(foreach OS, $(TARGET_OS), $(foreach ARCH, $(TARGET_ARCH), $(if $(IS_OS_ARCH_VALID), $(BINARIES)))) -GOFILES = $(call get_recursive_files, '.') +GOFILES := $(call get_recursive_files, '.') mk_go_build: $(info *** mk_go_build) @@ -48,10 +49,10 @@ $(CROSS_COMPILED_BINARIES): $(GOFILES) ##### =====> Compile Tests <===== ##### -PKGS = $(or $(PKG),$(shell $(GO_LIST) ./...)) -TESTPKGS = $(shell $(GO_LIST) -f \ +PKGS := $(or $(PKG),$(shell $(GO_LIST) ./...)) +TESTPKGS := $(shell $(GO_LIST) -f \ '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \ - $(PKGS)) + $(PKGS) 2>&1 | grep -v 'no Go files in' ) TESTPKGS_C_FILE = $(addsuffix /bin.test, $(subst $(CURRENT_PACKAGE),.,$(PKG))) TESTPKGS_C = $(foreach PKG, $(TESTPKGS), $(TESTPKGS_C_FILE)) diff --git a/.build/plugin.mk b/.build/plugin.mk index 67b230b93e..4972b66108 100644 --- a/.build/plugin.mk +++ b/.build/plugin.mk @@ -1,8 +1,10 @@ - +SHELL := /bin/bash BINARIES_CONF = $(addprefix $(TARGET_DIST)/, $(addsuffix -$(OS)-$(ARCH).yml, $(notdir $(TARGET_NAME)))) PLUGIN_CONF = $(addprefix $(TARGET_DIST)/, $(addsuffix .yml, $(notdir $(TARGET_NAME)))) CROSS_COMPILED_PLUGIN_CONF = $(foreach OS, $(TARGET_OS), $(foreach ARCH, $(TARGET_ARCH), $(if $(IS_OS_ARCH_VALID), $(BINARIES_CONF)))) +.PHONY: build clean test publish package + define PLUGIN_MANIFEST_BINARY os: %os% arch: %arch% diff --git a/contrib/grpcplugins/action/Makefile b/contrib/grpcplugins/action/Makefile index 815fe04b1b..5924c2b376 100644 --- a/contrib/grpcplugins/action/Makefile +++ b/contrib/grpcplugins/action/Makefile @@ -13,7 +13,8 @@ define get_plugin_name_from_conf $(strip $(patsubst dist/%.yml, %,$(shell echo $(1)))) endef -$(TARGET_PLUGINS): $(TARGET_DIST) +$(TARGET_PLUGINS): + @mkdir -p dist $(info building $(call get_plugin_name_from_conf,$@)) @P=$(call get_plugin_name_from_conf,$@); \ $(MAKE) build -C $$P diff --git a/contrib/grpcplugins/action/plugin-clair/Makefile b/contrib/grpcplugins/action/plugin-clair/Makefile index fe70950012..62799aaa20 100644 --- a/contrib/grpcplugins/action/plugin-clair/Makefile +++ b/contrib/grpcplugins/action/plugin-clair/Makefile @@ -1,6 +1,6 @@ TARGET_NAME = plugin-clair -TARGET_OS_EXCLUDED = freebsd openbsd +TARGET_OS_EXCLUDED = freebsd openbsd windows ##### ^^^^^^ EDIT ABOVE ^^^^^^ #####