Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
226 lines (182 loc) · 8.52 KB
/
Copy pathMakefile
File metadata and controls
226 lines (182 loc) · 8.52 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
NAME = suseconnect-ng
VERSION = $(shell bash -c "cat build/packaging/suseconnect-ng.spec | sed -n 's/^Version:\s*\(.*\)/\1/p'")
DIST = $(NAME)-$(VERSION)
PWD = $(shell pwd)
INTERACTIVE ?= $(shell if [ -t 0 ]; then echo true; else echo false; fi)
GO = go
OUT = -o out/
# coverage testing enabled by default
COVERAGE ?= true
COVERAGE_BIN ?= false
COVERAGE_LIB ?= false
GOFLAGS = -v -mod=vendor
BINFLAGS = -buildmode=pie
SOFLAGS = -buildmode=c-shared
GOCONTAINER = registry.suse.com/bci/golang:1.26-openssl
RUSTCONTAINER = registry.suse.com/bci/rust:1.95
CRM = docker run --rm $(if $(filter true,$(strip $(INTERACTIVE))),-it) --privileged
ENVFILE = .env
WORKDIR = /usr/src/connect-ng
MOUNT = -v $(PWD):$(WORKDIR)
AGAMA_SOURCES = $(PWD)/testdata/agama_srcs
AGAMA_REPO = https://github.com/agama-project/agama
AGAMA_MOUNT = -v $(AGAMA_SOURCES):/usr/src/agama
COVERAGE_DIR = $(PWD)/coverage
COVERAGE_MERGED = $(COVERAGE_DIR)/merged
COVERAGE_UNIT = $(COVERAGE_DIR)/unit
COVERAGE_FEATURE = $(COVERAGE_DIR)/feature
# NOTE: If adding additional coverage groups to be aggregated into the
# merged coverage results, remember to include the in the comma separated
# list of directories in the -i=... argument to go tool covdata merge in
# this routine.
define go-tool-covdata-merge
@if $(if $(filter true,$(strip $(COVERAGE))),true,false); then \
mkdir -p $(COVERAGE_MERGED); \
$(GO) tool covdata merge -i=$(COVERAGE_UNIT),$(COVERAGE_FEATURE) -o $(COVERAGE_MERGED); \
fi
endef
define go-tool-covdata-report
@if [ -z "$(strip $(1))" ]; then \
echo "ERROR: no go tool covdata action specified."; \
exit 1; \
fi
@if [ -z "$(strip $(2))" ]; then \
echo "ERROR: no test type target directory specified."; \
exit 1; \
fi
@if $(if $(filter true,$(strip $(COVERAGE))),true,false); then \
mkdir -p $(2); \
$(GO) tool covdata $(1) -i=$(strip $(2)); \
fi
endef
define cover-test-flags
$(if $(filter true,$(strip $(COVERAGE))),-cover -args -test.gocoverdir=$(COVERAGE_UNIT))
endef
define cover-bin-flags
$(if $(filter true,$(strip $(COVERAGE))),$(if $(filter true,$(strip $(COVERAGE_BIN))),-cover))
endef
define cover-lib-flags
$(if $(filter true,$(strip $(COVERAGE))),$(if $(filter true,$(strip $(COVERAGE_LIB))),-cover))
endef
.PHONY: all build build-arm build-ppc64le build-rpm build-s390 check-format
.PHONY: ci-env clean dist feature-tests out show-version test test-yast vendor vet
.PHONY: coverage coverage-check-enabled coverage-dirs coverage-func coverage-percent
.PHONY: agama-sources agama-tests bci-build go-env rust-env run-tests coverage-clean
.PHONY: fix-ownership real-clean unit-test-coverage feature-tests-coverage
all: clean build test
run-tests: coverage-clean check-format test build-rpm feature-tests test-yast agama-tests
$(call go-tool-covdata-merge)
$(call go-tool-covdata-report,percent,$(COVERAGE_MERGED))
$(call go-tool-covdata-report,func,$(COVERAGE_MERGED))
dist: clean internal/connect/version.txt vendor
@mkdir -p $(DIST)/build/packaging
@cp -r internal $(DIST)/
@cp -r pkg $(DIST)/
@cp -r third_party $(DIST)/
@cp -r cmd $(DIST)/
@cp -r docs $(DIST)/
@cp go.mod $(DIST)/
@cp go.sum $(DIST)/
@cp LICENSE README.md $(DIST)/
@cp build/packaging/suseconnect-keepalive* $(DIST)/build/packaging
@cp build/packaging/suse-uptime-tracker* $(DIST)/build/packaging
@cp -r build/packaging/suseconnect-ng* $(DIST)/
@tar cfvj vendor.tar.xz vendor
@tar cfvj $(DIST).tar.xz $(DIST)/
@rm -r $(DIST)/
vendor: go.mod go.sum
@$(GO) mod download
@$(GO) mod verify
@$(GO) mod vendor
out:
mkdir -p out
internal/connect/version.txt: build/packaging/suseconnect-ng.spec
@echo -n "$(VERSION)" > $@ && echo Setting $@ to $(VERSION)
show-version: internal/connect/version.txt
@cat internal/connect/version.txt
vet: internal/connect/version.txt
$(GO) vet ./...
build: clean out internal/connect/version.txt
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/suseconnect
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/zypper-migration
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/zypper-search-packages
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/suse-uptime-tracker
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/public-api-demo
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/validate-offline-certificate
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/offline-register-api
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/suseconnect-mcp
$(GO) build $(GOFLAGS) $(BINFLAGS) $(call cover-bin-flags) $(OUT) github.com/SUSE/connect-ng/cmd/subscription-info-demo
$(GO) build $(GOFLAGS) $(SOFLAGS) $(call cover-lib-flags) $(OUT)/libsuseconnect.so github.com/SUSE/connect-ng/third_party/libsuseconnect
bci-build:
$(CRM) $(MOUNT) -w $(WORKDIR) $(GOCONTAINER) bash -c 'git config --global --add safe.directory $(WORKDIR); make vendor build'
# This "arm" means ARM64v8 little endian, the one being delivered currently on
# OBS.
build-arm: clean out internal/connect/version.txt
GOOS=linux GOARCH=arm64 $(GO) build $(GOFLAGS) $(OUT) github.com/SUSE/connect-ng/cmd/suseconnect
build-s390: clean out internal/connect/version.txt
GOOS=linux GOARCH=s390x $(GO) build $(GOFLAGS) $(OUT) github.com/SUSE/connect-ng/cmd/suseconnect
build-ppc64le: clean out internal/connect/version.txt
GOOS=linux GOARCH=ppc64le $(GO) build $(GOFLAGS) $(OUT) github.com/SUSE/connect-ng/cmd/suseconnect
coverage-dirs:
@mkdir -p $(COVERAGE_UNIT) ${COVERAGE_FEATURE} ${COVERAGE_YAST} ${COVERAGE_AGAMA} ${COVERAGE_MERGED}
coverage-check-enabled:
@if [ -z "$(filter true,$(strip $(COVERAGE)))" ]; then \
echo "WARNING: Coverage generation and collection not enabled."; \
echo "To enable it either add COVERAGE=true on the make command line arguments or set COVERAGE=true in the environment."; \
exit 1; \
fi
coverage-func: coverage-check-enabled coverage-dirs
$(call go-tool-covdata-merge)
$(call go-tool-covdata-report,func,$(COVERAGE_MERGED))
coverage-percent: coverage-check-enabled coverage-dirs
$(call go-tool-covdata-merge)
$(call go-tool-covdata-report,percent,$(COVERAGE_MERGED))
coverage: coverage-func
test: internal/connect/version.txt coverage-dirs
$(GO) test ./internal/* ./cmd/suseconnect ./cmd/suseconnect-mcp ./pkg/* ./third_party/libsuseconnect $(call cover-test-flags)
$(call go-tool-covdata-report,func,$(COVERAGE_UNIT))
unit-test-coverage: coverage-dirs
$(call go-tool-covdata-report,percent,$(COVERAGE_UNIT))
$(call go-tool-covdata-report,func,$(COVERAGE_UNIT))
ci-env go-env:
$(CRM) $(MOUNT) --env-file $(ENVFILE) -w $(WORKDIR) $(GOCONTAINER) bash
agama-sources:
@if [ ! -d $(AGAMA_SOURCES) ]; then \
echo "Cloning $(AGAMA_REPO) under $(AGAMA_SOURCES) ..."; \
git clone $(AGAMA_REPO) $(AGAMA_SOURCES); \
fi
agama-tests: agama-sources bci-build
$(CRM) $(MOUNT) $(AGAMA_MOUNT) --env-file $(ENVFILE) -w $(WORKDIR) $(RUSTCONTAINER) bash -c 'build/ci/run-agama-rust-tests'
$(MAKE) fix-ownership
rust-env: agama-sources
$(CRM) $(MOUNT) $(AGAMA_MOUNT) --env-file $(ENVFILE) -w $(WORKDIR) $(RUSTCONTAINER) bash
check-format:
@test -z $(shell gofmt -l internal/* cmd/* pkg/* | tee /dev/stderr)
build-rpm:
$(CRM) $(MOUNT) -w $(WORKDIR) $(GOCONTAINER) bash -c 'build/ci/build-rpm'
feature-tests: coverage-dirs
$(CRM) $(MOUNT) --env-file $(ENVFILE) -w $(WORKDIR) $(GOCONTAINER) bash -c 'git config --global --add safe.directory $(WORKDIR); make vendor build COVERAGE_BIN=true && build/ci/run-feature-tests'
$(MAKE) fix-ownership
$(call go-tool-covdata-report,percent,$(COVERAGE_FEATURE))
$(call go-tool-covdata-report,func,$(COVERAGE_FEATURE))
feature-tests-coverage: coverage-dirs
$(call go-tool-covdata-report,percent,$(COVERAGE_FEATURE))
$(call go-tool-covdata-report,func,$(COVERAGE_FEATURE))
test-yast:
docker build -t go-connect-test-yast -f third_party/Dockerfile.yast . && docker run -t go-connect-test-yast
coverage-clean:
@rm -rf $(COVERAGE_DIR)
real-clean: clean coverage-clean
@rm -f internal/connect/version.txt
@rm -rf vendor/
@rm -rf out/
clean:
$(GO) clean
@rm -rf $(DIST)/
@rm -f vendor.tar.xz
@rm -f $(DIST).tar.xz
fix-ownership:
@for o in artifacts coverage internal/connect/version.txt out testdata/agama_srcs vendor; do \
[ -e $${o} ] || continue; \
sudo chown -R $$(id -u):$$(id -g) $${o}; \
done