-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
182 lines (152 loc) · 6.54 KB
/
Makefile
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
PREFIX ?= /usr/local
AGE ?= age
SCDOC=$(shell command -v scdoc)
export SOURCE_DATE_EPOCH=1715696361
ifneq ($(V),1)
AT=@
endif
ifeq ($(RELEASE),1)
SWIFT_BUILD_FLAGS=-c release --disable-sandbox $(SWIFT_EXTRA_BUILD_FLAGS)
endif
SWIFT_TEST_FLAGS := --parallel
ifeq ($(COVERAGE),1)
SWIFT_TEST_FLAGS := $(SWIFT_TEST_FLAGS) --enable-code-coverage
endif
# E.g. Tests.RecipientV1Tests/testRecipient
ifneq ($(TEST_FILTER),)
SWIFT_TEST_FLAGS := $(SWIFT_TEST_FLAGS) --filter $(TEST_FILTER)
endif
ifeq ($(OS),Windows_NT)
UNAME_S=Windows
else
UNAME_S=$(shell uname -s)
endif
VERSION ?= $(shell cat Sources/CLI.swift | grep '^let version' | sed -e "s/.*\"v\\(.*\\)\".*/\\1/")
BUILD_DIR ?= $(shell swift build $(SWIFT_BUILD_FLAGS) --show-bin-path)
COMMIT_SHA=$(shell git rev-parse HEAD)
PACKAGE_ARCHS = arm64-apple-macosx x86_64-apple-macosx
PACKAGE_LINUX_ARCHS = aarch64 x86_64
APK_PACKAGE_VERSION=r0
ECHO = echo
ifneq ($(UNAME_S),Darwin)
ECHO = /usr/bin/echo -e
endif
ifneq ($(SCDOC),)
MAN_TARGET := man
endif
.PHONY: all
all: $(BUILD_DIR)/age-plugin-p256tag $(MAN_TARGET)
swift build $(SWIFT_BUILD_FLAGS)
.PHONY: package
ifeq ($(UNAME_S),Darwin)
package:
for arch in $(PACKAGE_ARCHS); do swift build -c release --triple $$arch; done
lipo -create -output .build/age-plugin-se $(foreach arch, $(PACKAGE_ARCHS), \
$(shell swift build -c release --triple $(arch) --show-bin-path)/age-plugin-se)
cd .build && ditto -c -k age-plugin-se age-plugin-se-v$(VERSION)-macos.zip
package-linux:
set -e; for arch in $(PACKAGE_LINUX_ARCHS); do \
package=age-plugin-se-v$(VERSION)-$$arch-linux; \
make RELEASE=1 PREFIX=/usr DESTDIR=.build/$$package SWIFT_EXTRA_BUILD_FLAGS="--swift-sdk $$arch-swift-linux-musl" all install; \
tar czf .build/$$package.tgz -C .build $$package; \
go run Scripts/alpine/dir2apk.go --arch=$$arch --version=$(VERSION)-$(APK_PACKAGE_VERSION) --commit=$(COMMIT_SHA) --key=Scripts/alpine/[email protected] --out=.build .build/$$package; \
done
else
package:
swift build -c release --static-swift-stdlib
tar czf .build/age-plugin-se-v$(VERSION)-$(shell uname -m)-linux.tgz -C $(shell swift build -c release --show-bin-path) age-plugin-se
endif
.PHONY: test
test:
swift test $(SWIFT_TEST_FLAGS)
ifeq ($(COVERAGE),1)
swift ./Scripts/ProcessCoverage.swift $$(swift test --show-codecov-path) .build/coverage.json .build/coverage.html .build/coverage.svg
endif
.PHONY: test-loop
test-loop: test
reflex -r '\.swift$$' $(MAKE) test
# Need to explicitly list source dirs instead of `.`, because swift-format doesn't ignore
# hidden dirs. Should be fixed 'soon'? (https://github.com/apple/swift-format/pull/644)
.PHONY: lint
lint:
swift-format lint --recursive --strict Package.swift Sources Scripts Tests
.PHONY: install
install: install-doc
install -d $(DESTDIR)$(PREFIX)/bin
install $(BUILD_DIR)/age-plugin-se $(DESTDIR)$(PREFIX)/bin
.PHONY: install-doc
install-doc:
install -d $(DESTDIR)$(PREFIX)/share/licenses/age-plugin-se
install LICENSE.txt $(DESTDIR)$(PREFIX)/share/licenses/age-plugin-se
ifneq ($(SCDOC),)
install -d $(DESTDIR)$(PREFIX)/share/man/man1
install .build/age-plugin-se.1 $(DESTDIR)$(PREFIX)/share/man/man1
endif
man: .build/age-plugin-se.1
.build/age-plugin-se.1: Documentation/age-plugin-se.1.scd
mkdir -p .build
cat $< | sed "s/@VERSION@/$(VERSION)/g" | scdoc > [email protected]
mv [email protected] $@
$(BUILD_DIR)/age-plugin-p256tag:
mkdir -p $(BUILD_DIR)
ln -sf age-plugin-se $@
.PHONY: smoke-test
smoke-test:
$(AT)PATH="$(BUILD_DIR):$$PATH" && \
$(ECHO) '\xf0\x9f\x94\x91 Generating key...' && \
recipient=`age-plugin-se keygen $(TEST_KEYGEN_FLAGS) --access-control=any-biometry -o key.txt | sed -e "s/Public key: //"` && \
$(ECHO) '\xf0\x9f\x94\x92 Encrypting...' && \
($(ECHO) '\xe2\x9c\x85 \x53\x75\x63\x63\x65\x73\x73' | $(AGE) --encrypt --recipient $$recipient -o secret.txt.age) && \
$(ECHO) '\xf0\x9f\x94\x93 Decrypting...' && \
$(AGE) --decrypt -i key.txt secret.txt.age && \
rm -f key.txt secret.txt.age
.PHONY: smoke-test-noninteractive
smoke-test-noninteractive:
$(AT)PATH="$(BUILD_DIR):$$PATH" && \
$(ECHO) '\xf0\x9f\x94\x91 Generating key...' && \
recipient=`age-plugin-se keygen $(TEST_KEYGEN_FLAGS) --access-control=none -o key.txt | sed -e "s/Public key: //"` && \
$(ECHO) '\xf0\x9f\x94\x92 Encrypting...' && \
($(ECHO) '\xe2\x9c\x85 \x53\x75\x63\x63\x65\x73\x73' | $(AGE) --encrypt --recipient $$recipient -o secret.txt.age) && \
$(ECHO) '\xf0\x9f\x94\x93 Decrypting...' && \
$(AGE) --decrypt -i key.txt secret.txt.age && \
rm -f key.txt secret.txt.age
.PHONY: smoke-test-encrypt
smoke-test-encrypt:
$(AT)PATH="$(BUILD_DIR):$$PATH" && \
$(ECHO) '\xf0\x9f\x94\x92 Encrypting...' && \
($(ECHO) "test" | $(AGE) --encrypt $(TEST_KEYGEN_FLAGS) --recipient age1se1qgg72x2qfk9wg3wh0qg9u0v7l5dkq4jx69fv80p6wdus3ftg6flwg5dz2dp -o secret.txt.age) && \
$(ECHO) '\xe2\x9c\x85 \x53\x75\x63\x63\x65\x73\x73' && \
rm -f secret.txt.age
INTEROP_PLUGIN=yubikey
.PHONY: piv-p256-decrypt-interop-test
piv-p256-decrypt-interop-test:
$(AT)PATH="$(BUILD_DIR):$$PATH" && \
$(ECHO) '\xf0\x9f\x94\x91 Generating key...' && \
recipient=`age-plugin-se keygen --access-control=none -o key.txt | sed -e "s/Public key: //"` && \
interop_recipient=`./Scripts/ConvertBech32HRP.swift $$recipient age1$(INTEROP_PLUGIN)` && \
$(ECHO) '\xf0\x9f\x94\x92 Encrypting to '$$interop_recipient'...' && \
($(ECHO) '\xe2\x9c\x85 \x53\x75\x63\x63\x65\x73\x73' | $(AGE) --encrypt --recipient $$interop_recipient -o secret.txt.age) && \
$(ECHO) '\xf0\x9f\x94\x93 Decrypting...' && \
$(AGE) --decrypt -i key.txt secret.txt.age && \
rm -f key.txt secret.txt.age
.PHONY: gen-manual-tests
gen-manual-tests:
-rm -rf gen-manual-tests
mkdir -p manual-tests
PATH="$(BUILD_DIR):$$PATH" && set -e && \
for control in none passcode current-biometry any-biometry current-biometry-and-passcode any-biometry-and-passcode any-biometry-or-passcode; do \
recipient=`age-plugin-se keygen $(TEST_KEYGEN_FLAGS) --access-control=$$control -o manual-tests/key.$$control.txt | sed -e "s/Public key: //"`;\
($(ECHO) '\xe2\x9c\x85 \x53\x75\x63\x63\x65\x73\x73' | $(AGE) --encrypt --recipient $$recipient -o manual-tests/secret.txt.$$control.age); \
done
.PHONY: run-manual-tests
run-manual-tests:
$(AT)PATH="$(BUILD_DIR):$$PATH" && set -e && \
for control in none passcode any-biometry current-biometry-and-passcode any-biometry-and-passcode any-biometry-or-passcode; do \
$(ECHO) "\\xf0\\x9f\\x94\\x93 Decrypting '$$control'..." && \
$(AGE) --decrypt -i manual-tests/key.$$control.txt manual-tests/secret.txt.$$control.age; \
$(ECHO) "\n-----\n"; \
done
.PHONY: clean
clean:
-rm -rf .build manual-tests
.IGNORE: .build/age-plugin-se.1