-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (127 loc) · 4.77 KB
/
Makefile
File metadata and controls
157 lines (127 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Copyright IBM Corp All Rights Reserved.
# Copyright London Stock Exchange Group All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# -------------------------------------------------------------
# Run `make help` to find the supported targets
# Disable implicit rules
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules
BUILD_DIR ?= bin
PKGNAME = github.com/hyperledger/fabric-x-common
GO_TAGS ?=
go_cmd ?= go
go_test ?= $(go_cmd) test -json -v -timeout 30m
project_dir := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
proto_flags ?=
fabric_protos_tag ?= $(shell go list -m -f '{{.Version}}' github.com/hyperledger/fabric-protos-go-apiv2)
ifneq ("$(wildcard /usr/include)","")
proto_flags += --proto_path="/usr/include"
endif
TOOLS_EXES = configtxgen configtxlator cryptogen
pkgmap.configtxgen := $(PKGNAME)/cmd/configtxgen
pkgmap.configtxlator := $(PKGNAME)/cmd/configtxlator
pkgmap.cryptogen := $(PKGNAME)/cmd/cryptogen
.DEFAULT_GOAL := help
MAKEFLAGS += --jobs=16
.PHONY: help
## List all commands with documentation
help:
@echo "Available commands:"
@awk '\
/^## / { h = substr($$0, 4); next } \
/^[a-zA-Z_-]+:/ && h { \
printf "\033[36m%-15s\033[0m %s\n", $$1, h; \
h = "" \
} \
' $(MAKEFILE_LIST)
.PHONY: tools
## Builds all tools
tools: $(TOOLS_EXES)
go_test_cmd=gotestsum --rerun-fails=0 --format dots -- -v -timeout 30m ./...
## Run all tests.
test: FORCE
@$(go_test_cmd) -race
# Runs test with coverage analysis.
test-cover: FORCE
@$(go_test_cmd) -coverprofile=coverage.profile -coverpkg=./...
@scripts/test-coverage-filter-files.sh
cover-report: FORCE
$(go_cmd) tool cover -html=coverage.profile
.PHONY: $(TOOLS_EXES)
## Builds a native binary
$(TOOLS_EXES): %: $(BUILD_DIR)/%
$(BUILD_DIR)/%: GO_LDFLAGS = $(METADATA_VAR:%=-X $(PKGNAME)/common/metadata.%)
$(BUILD_DIR)/%:
@echo "Building $@"
@mkdir -p $(@D)
@GOBIN=$(abspath $(@D)) go install -tags "$(GO_TAGS)" -ldflags "$(GO_LDFLAGS)" -buildvcs=false $(pkgmap.$(@F))
@touch $@
.PHONY: clean
## Cleans the build area
clean:
-@rm -rf $(BUILD_DIR)
## Run code linter
lint: lint-proto lint-asn1 FORCE
@echo "Running Go Linters..."
golangci-lint run --color=always --new-from-rev=main --timeout=4m
@echo "Running License Header Linters..."
scripts/license-lint.sh
## Run ASN.1 schema linter
lint-asn1: FORCE
@echo "Running ASN.1 schema linters..."
@asn1c -EP $(shell find ${project_dir}/api -name '*.asn')
# https://www.gnu.org/software/make/manual/html_node/Force-Targets.html
# If a rule has no prerequisites or recipe, and the target of the rule is a nonexistent file,
# then make imagines this target to have been updated whenever its rule is run.
# This implies that all targets depending on this one will always have their recipe run.
FORCE:
#########################
# Generate protos
#########################
BUILD_DIR := .build
PROTOS_REPO := https://github.com/hyperledger/fabric-protos.git
PROTOS_DIR := ${BUILD_DIR}/fabric-protos@${fabric_protos_tag}
# We depend on this specific file to ensure the repo is actually cloned
PROTOS_SENTINEL := ${PROTOS_DIR}/.git
## Build protobufs
proto: FORCE $(PROTOS_SENTINEL)
@echo "Generating protobufs: $(shell find ${project_dir}/api -name '*.proto' -print0 \
| xargs -0 -n 1 dirname | xargs -n 1 basename | sort -u)"
@protoc \
-I="${project_dir}" \
-I="${PROTOS_DIR}" \
--go_opt=Mmsp/msp_config.proto=github.com/hyperledger/fabric-protos-go-apiv2/msp \
--go-grpc_opt=Mmsp/msp_config.proto=github.com/hyperledger/fabric-protos-go-apiv2/msp \
--go_opt=Mcommon/common.proto=github.com/hyperledger/fabric-protos-go-apiv2/common \
--go_opt=Mcommon/ledger.proto=github.com/hyperledger/fabric-protos-go-apiv2/common \
--go-grpc_opt=Mcommon/common.proto=github.com/hyperledger/fabric-protos-go-apiv2/common \
--go-grpc_opt=Mcommon/ledger.proto=github.com/hyperledger/fabric-protos-go-apiv2/common \
--go-grpc_out=. \
--go-grpc_opt=paths=source_relative \
--go_out=paths=source_relative:. \
${proto_flags} \
${project_dir}/api/*/*.proto
## Run protobuf linter
lint-proto: FORCE $(PROTOS_SENTINEL)
@echo "Running protobuf linters..."
@api-linter \
-I="${project_dir}/api" \
-I="${PROTOS_DIR}" \
--config .apilinter.yaml \
--set-exit-status \
--output-format github \
$(shell find ${project_dir}/api -name '*.proto' | sed 's|${project_dir}/api/||')
$(PROTOS_SENTINEL):
@echo "Cloning fabric-protos..."
@mkdir -p ${BUILD_DIR}
@rm -rf ${PROTOS_DIR} # Ensure we start fresh if re-cloning
@git -c advice.detachedHead=false clone --branch ${fabric_protos_tag} \
--single-branch --depth 1 ${PROTOS_REPO} ${PROTOS_DIR}
## Generate testing mocks
mocks: FORCE
@COUNTERFEITER_NO_GENERATE_WARNING=true go generate ./...
## Clean build dependencies
clean-deps:
rm -rf ${PROTOS_DIR}