Skip to content

Commit

Permalink
chore(plugins): remove potentials warnings make build (#5238)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored Jun 8, 2020
1 parent ad593a9 commit b9b5453
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
21 changes: 11 additions & 10 deletions .build/go.mk
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion .build/plugin.mk
Original file line number Diff line number Diff line change
@@ -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%
Expand Down
3 changes: 2 additions & 1 deletion contrib/grpcplugins/action/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contrib/grpcplugins/action/plugin-clair/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

TARGET_NAME = plugin-clair
TARGET_OS_EXCLUDED = freebsd openbsd
TARGET_OS_EXCLUDED = freebsd openbsd windows

##### ^^^^^^ EDIT ABOVE ^^^^^^ #####

Expand Down

0 comments on commit b9b5453

Please sign in to comment.