@@ -2,25 +2,64 @@ BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
2
2
BUILDDATE ?= $(shell date -u +% FT% T% z)
3
3
BUILDTS ?= $(shell date -u +% s)
4
4
REVISION ?= $(shell git rev-parse HEAD)
5
- VERSION_DEV : = 0.4.0 -dev$(shell date +% Y% m% d% H% M)
6
- VERSION : = 0.3.9
5
+ VERSION_DEV ? = 0.4.5 -dev$(shell date +% Y% m% d% H% M)
6
+ VERSION ? = 0.4.4
7
7
8
8
PROMETHEUS_TAG := github.com/prometheus/common/version
9
9
KVM_PKG_NAME := github.com/jetkvm/kvm
10
10
11
+ GO_BUILD_ARGS := -tags netgo
12
+ GO_RELEASE_BUILD_ARGS := -trimpath $(GO_BUILD_ARGS )
11
13
GO_LDFLAGS := \
12
14
-s -w \
13
15
-X $(PROMETHEUS_TAG ) .Branch=$(BRANCH ) \
14
16
-X $(PROMETHEUS_TAG ) .BuildDate=$(BUILDDATE ) \
15
17
-X $(PROMETHEUS_TAG ) .Revision=$(REVISION ) \
16
18
-X $(KVM_PKG_NAME ) .builtTimestamp=$(BUILDTS )
17
19
20
+ GO_CMD := GOOS=linux GOARCH=arm GOARM=7 go
21
+ BIN_DIR := $(shell pwd) /bin
22
+
23
+ TEST_DIRS := $(shell find . -name "* _test.go" -type f -exec dirname {} \; | sort -u)
24
+
18
25
hash_resource :
19
26
@shasum -a 256 resource/jetkvm_native | cut -d ' ' -f 1 > resource/jetkvm_native.sha256
20
27
21
28
build_dev : hash_resource
22
29
@echo " Building..."
23
- GOOS=linux GOARCH=arm GOARM=7 go build -ldflags=" $( GO_LDFLAGS) -X $( KVM_PKG_NAME) .builtAppVersion=$( VERSION_DEV) " -o bin/jetkvm_app cmd/main.go
30
+ $(GO_CMD ) build \
31
+ -ldflags=" $( GO_LDFLAGS) -X $( KVM_PKG_NAME) .builtAppVersion=$( VERSION_DEV) " \
32
+ $(GO_RELEASE_BUILD_ARGS ) \
33
+ -o $(BIN_DIR ) /jetkvm_app cmd/main.go
34
+
35
+ build_test2json :
36
+ $(GO_CMD ) build -o $(BIN_DIR ) /test2json cmd/test2json
37
+
38
+ build_gotestsum :
39
+ @echo " Building gotestsum..."
40
+ $(GO_CMD ) install gotest.tools/gotestsum@latest
41
+ cp $(shell $(GO_CMD ) env GOPATH) /bin/linux_arm/gotestsum $(BIN_DIR ) /gotestsum
42
+
43
+ build_dev_test : build_test2json build_gotestsum
44
+ # collect all directories that contain tests
45
+ @echo "Building tests for devices ..."
46
+ @rm -rf $(BIN_DIR)/tests && mkdir -p $(BIN_DIR)/tests
47
+
48
+ @cat resource/dev_test.sh > $(BIN_DIR)/tests/run_all_tests
49
+ @for test in $(TEST_DIRS); do \
50
+ test_pkg_name=$$(echo $$test | sed 's/^.\///g'); \
51
+ test_pkg_full_name=$(KVM_PKG_NAME)/$$(echo $$test | sed 's/^.\///g'); \
52
+ test_filename=$$(echo $$test_pkg_name | sed 's/\//__/g')_test; \
53
+ $(GO_CMD) test -v \
54
+ -ldflags="$(GO_LDFLAGS) -X $(KVM_PKG_NAME).builtAppVersion=$(VERSION_DEV)" \
55
+ $(GO_BUILD_ARGS) \
56
+ -c -o $(BIN_DIR)/tests/$$test_filename $$test; \
57
+ echo "runTest ./$$test_filename $$test_pkg_full_name" >> $(BIN_DIR)/tests/run_all_tests; \
58
+ done; \
59
+ chmod +x $(BIN_DIR)/tests/run_all_tests; \
60
+ cp $(BIN_DIR)/test2json $(BIN_DIR)/tests/ && chmod +x $(BIN_DIR)/tests/test2json; \
61
+ cp $(BIN_DIR)/gotestsum $(BIN_DIR)/tests/ && chmod +x $(BIN_DIR)/tests/gotestsum; \
62
+ tar czfv device-tests.tar.gz -C $(BIN_DIR)/tests .
24
63
25
64
frontend :
26
65
cd ui && npm ci && npm run build:device
@@ -33,7 +72,10 @@ dev_release: frontend build_dev
33
72
34
73
build_release : frontend hash_resource
35
74
@echo " Building release..."
36
- GOOS=linux GOARCH=arm GOARM=7 go build -ldflags=" $( GO_LDFLAGS) -X $( KVM_PKG_NAME) .builtAppVersion=$( VERSION) " -o bin/jetkvm_app cmd/main.go
75
+ $(GO_CMD ) build \
76
+ -ldflags=" $( GO_LDFLAGS) -X $( KVM_PKG_NAME) .builtAppVersion=$( VERSION) " \
77
+ $(GO_RELEASE_BUILD_ARGS ) \
78
+ -o bin/jetkvm_app cmd/main.go
37
79
38
80
release :
39
81
@if rclone lsf r2://jetkvm-update/app/$(VERSION ) / | grep -q " jetkvm_app" ; then \
0 commit comments