forked from intel/PerfSpect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (142 loc) · 5.6 KB
/
Makefile
File metadata and controls
164 lines (142 loc) · 5.6 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
#!make
#
# Copyright (C) 2021-2025 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
COMMIT_ID := $(shell git rev-parse --short=8 HEAD)
COMMIT_DATE := $(shell git show -s --format=%cd --date=short HEAD)
COMMIT_TIME := $(shell git show -s --format=%cd --date=format:'%H:%M:%S' HEAD)
VERSION_FILE := ./version.txt
VERSION_NUMBER := $(shell cat ${VERSION_FILE})
VERSION := $(VERSION_NUMBER)_$(COMMIT_DATE)_$(COMMIT_ID)
default: perfspect
GOFLAGS_COMMON=-trimpath -mod=readonly -ldflags="-X perfspect/cmd.gVersion=$(VERSION) -s -w"
GO=CGO_ENABLED=0 GOOS=linux go
# Build the perfspect binary
.PHONY: perfspect
perfspect:
GOARCH=amd64 $(GO) build $(GOFLAGS_COMMON) -gcflags="all=-spectre=all -N -l" -asmflags="all=-spectre=all" -o $@
# Build the perfspect binary for AARCH64
.PHONY: perfspect-aarch64
perfspect-aarch64:
GOARCH=arm64 $(GO) build $(GOFLAGS_COMMON) -o $@
# Copy prebuilt tools to script resources
.PHONY: resources
resources:
mkdir -p internal/script/resources
ifneq ("$(wildcard /prebuilt/tools)","") # /prebuilt/tools is a directory in the container
@echo "Copying prebuilt tools from /prebuilt/tools to script resources"
cp -r /prebuilt/tools/* internal/script/resources/
else # copy dev system tools to script resources
ifneq ("$(wildcard tools/bin)","")
@echo "Copying dev system tools from tools/bin to script resources"
cp -r tools/bin/* internal/script/resources/
else # no prebuilt tools found
@echo "No prebuilt tools found in /prebuilt/tools or tools/bin"
endif
endif
# Build the distribution package
.PHONY: dist
dist: resources check perfspect perfspect-aarch64
rm -rf dist/perfspect
mkdir -p dist/perfspect/tools/x86_64
mkdir -p dist/perfspect/tools/aarch64
cp LICENSE dist/perfspect/
cp THIRD_PARTY_PROGRAMS dist/perfspect/
cp NOTICE dist/perfspect/
cp targets.yaml dist/perfspect/
cp perfspect dist/perfspect/
cd dist && tar -czf perfspect.tgz perfspect
cd dist && md5sum perfspect.tgz > perfspect.tgz.md5.txt
# for aarch64 dist, overwrite perfspect binary
cp perfspect-aarch64 dist/perfspect/perfspect
cd dist && tar -czf perfspect-aarch64.tgz perfspect
cd dist && md5sum perfspect-aarch64.tgz > perfspect-aarch64.tgz.md5.txt
rm -rf dist/perfspect
echo '{"version": "$(VERSION_NUMBER)", "date": "$(COMMIT_DATE)", "time": "$(COMMIT_TIME)", "commit": "$(COMMIT_ID)" }' | jq '.' > dist/manifest.json
ifneq ("$(wildcard /prebuilt)","") # /prebuilt is a directory in the container
cp -r /prebuilt/oss_source* dist/
endif
# Run package-level unit tests
.PHONY: test
test:
@echo "Running unit tests..."
go test -v ./...
cd tools/stackcollapse-perf && go test -v ./...
.PHONY: update-deps
update-deps:
@echo "Updating Go dependencies..."
go get -u ./...
go mod tidy
# Check code formatting
.PHONY: check_format
check_format:
@echo "Running gofmt to check for code formatting issues..."
@test -z "$(shell gofmt -l -s ./)" || { echo "[WARN] Formatting issues detected. Resolve with 'make format'"; exit 1; }
@echo "gofmt detected no issues"
# Format code
.PHONY: format
format:
@echo "Running gofmt to format code..."
gofmt -l -w -s ./
.PHONY: check_vet
check_vet:
@echo "Running go vet to check for suspicious constructs..."
@test -z "$(shell go vet ./...)" || { echo "[WARN] go vet detected issues"; exit 1; }
@echo "go vet detected no issues"
.PHONY: check_static
check_static:
@echo "Running staticcheck to check for bugs..."
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
.PHONY: check_license
check_license:
@echo "Confirming source files have license headers..."
@for f in `find . -type f ! -path './perfspect_202*' ! -path './tools/bin/*' ! -path './tools/bin-aarch64/*' ! -path './internal/script/resources/*' ! -path './scripts/.venv/*' ! -path './test/output/*' ! -path './debug_out/*' ! -path './tools/perf-archive/*' ! -path './tools/avx-turbo/*' \( -name "*.go" -o -name "*.s" -o -name "*.html" -o -name "Makefile" -o -name "*.sh" -o -name "*.Dockerfile" -o -name "*.py" \)`; do \
if ! grep -E 'SPDX-License-Identifier: BSD-3-Clause' "$$f" >/dev/null; then echo "Error: license not found: $$f"; fail=1; fi; \
done; if [ -n "$$fail" ]; then exit 1; fi
.PHONY: check_lint
check_lint:
@echo "Running golangci-lint to check for style issues..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run
.PHONY: check_vuln
check_vuln:
@echo "Running govulncheck to check for vulnerabilities..."
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
.PHONY: check_sec
check_sec:
@echo "Running gosec to check for security issues..."
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec ./...
.PHONY: check_semgrep
check_semgrep:
@echo "Running semgrep to check for security issues..."
@echo "Please install semgrep from https://semgrep.dev/docs/getting-started/installation/ if not already installed."
@echo "Running semgrep..."
semgrep scan
.PHONY: check_modernize
check_modernize:
@echo "Running go-modernize to check for modernization opportunities..."
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test ./...
.PHONY: modernize
modernize:
@echo "Running go-modernize to apply modernization opportunities..."
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
.PHONY: check
check: check_format check_vet check_static check_license check_lint check_vuln check_modernize
.PHONY: sweep
sweep:
rm -rf perfspect_2025-*
rm -rf debug_out/*
rm -rf test/output
rm -f __debug_bin*.log
rm -f perfspect.log
.PHONY: clean
clean: sweep
@echo "Cleaning up..."
rm -f perfspect
rm -f perfspect-aarch64
sudo rm -rf dist
rm -rf internal/script/resources