-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (93 loc) · 5.02 KB
/
Copy pathMakefile
File metadata and controls
107 lines (93 loc) · 5.02 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
# Builds DoNotType.app from the SPM executable.
#
# There is no .xcodeproj on purpose: a pbxproj is unreviewable in a diff and merges badly, and
# everything it would provide here (bundle layout, plist, entitlements, signing) is a dozen lines
# of shell. Xcode can still open Package.swift directly for debugging.
CONFIG ?= release
APP := DoNotType
# The SPM product cannot also be called DoNotType -- the iOS project consumes this package and has
# a target by that name, and Xcode would resolve the collision by building the macOS executable
# for iOS. The binary is renamed back on the way into the bundle, which is what Info.plist's
# CFBundleExecutable expects.
PRODUCT := DoNotTypeMac
BUNDLE_ID := app.donottype
BUILD_DIR := .build/$(CONFIG)
APP_BUNDLE := .build/$(APP).app
CONTENTS := $(APP_BUNDLE)/Contents
# Falls back to ad-hoc signing. Note that ad-hoc means macOS forgets your Accessibility grant on
# every rebuild, because TCC keys permissions to the code signature.
SIGN_ID ?= $(shell security find-identity -v -p codesigning 2>/dev/null | \
grep "Developer ID Application" | head -1 | sed -E 's/.*"(.*)"/\1/')
CODESIGN_ID := $(if $(SIGN_ID),$(SIGN_ID),-)
.PHONY: all build app run test eval clean install install-cli cli sign-info
all: app
build:
swift build -c $(CONFIG)
test:
swift test
eval:
swift run -c $(CONFIG) dnt-eval suite eval/nearmiss
cli:
swift build -c $(CONFIG) --product dnt
@echo "built $(BUILD_DIR)/dnt — try: $(BUILD_DIR)/dnt doctor"
# Symlinked rather than copied, so a rebuild does not leave a stale binary on the PATH claiming to
# be the current one. Points at the bundle when the app is installed, since that copy is signed and
# ships prompt/ beside it.
install-cli: install
@mkdir -p /usr/local/bin
@ln -sf "/Applications/$(APP).app/Contents/MacOS/dnt" /usr/local/bin/dnt
@echo "linked /usr/local/bin/dnt -> /Applications/$(APP).app/Contents/MacOS/dnt"
app: build
@rm -rf "$(APP_BUNDLE)"
@mkdir -p "$(CONTENTS)/MacOS" "$(CONTENTS)/Resources"
@cp "$(BUILD_DIR)/$(PRODUCT)" "$(CONTENTS)/MacOS/$(APP)"
@# The CLI ships inside the bundle so a release carries it, and so an installed `dnt` finds
@# prompt/ one directory up in Resources without needing a checkout.
@cp "$(BUILD_DIR)/dnt" "$(CONTENTS)/MacOS/dnt"
@cp Resources/Info.plist "$(CONTENTS)/Info.plist"
@# Build metadata is stamped into the bundled plist only, never the repo copy: the checkout
@# stays diff-stable, and a build that skips this step (e.g. `swift run`) reports "dev"
@# instead of a commit it may no longer match.
@/usr/libexec/PlistBuddy -c "Add :DNTBuildCommit string $$(git rev-parse --short HEAD 2>/dev/null || echo dev)" "$(CONTENTS)/Info.plist"
@/usr/libexec/PlistBuddy -c "Add :DNTBuildTimestamp string $$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$(CONTENTS)/Info.plist"
@# SwiftPM keeps target resources in a sibling bundle. Bundle.module looks for that bundle in
@# Contents/Resources once the executable is wrapped as an app, so it must cross that boundary
@# with the binary. This carries the local Silero model and its licence notice.
@cp -R "$(BUILD_DIR)/DoNotType_DoNotTypeCore.bundle" "$(CONTENTS)/Resources/"
@# The contract ships inside the bundle so the app does not depend on the source tree. The
@# directory layout is preserved, because a part is found by its path under prompt/.
@cp -R prompt "$(CONTENTS)/Resources/prompt"
@# Binary distributions carry the same MIT grant as the source checkout. Keep the repository's
@# canonical file as the source so the bundle cannot grow a stale second license text.
@cp LICENSE "$(CONTENTS)/Resources/LICENSE.txt"
@# The third-party credits the licence refers to, shipped from the same canonical file so the
@# bundle cannot grow a stale second copy. The About tab reads both out of the bundle.
@cp THIRD-PARTY-NOTICES.txt "$(CONTENTS)/Resources/THIRD-PARTY-NOTICES.txt"
@# Both rendered from Resources/Icon/DoNotType.svg; see Resources/Icon/make-icons.sh.
@cp Resources/AppIcon.icns "$(CONTENTS)/Resources/AppIcon.icns"
@cp Resources/MenuBar/*.png "$(CONTENTS)/Resources/"
@# Any translations that exist. SwiftUI looks a literal up by its English text, so a .lproj
@# dropped in here is the whole mechanism — see docs/LOCALIZATION.md.
@[ -d Resources/Localizations ] && cp -R Resources/Localizations/*.lproj "$(CONTENTS)/Resources/" 2>/dev/null || true
@printf 'APPL????' > "$(CONTENTS)/PkgInfo"
@if [ "$(CODESIGN_ID)" = "-" ]; then \
codesign --force --deep --sign - "$(APP_BUNDLE)"; \
else \
codesign --force --deep --options runtime \
--entitlements Resources/$(APP).entitlements \
--sign "$(CODESIGN_ID)" "$(APP_BUNDLE)"; \
fi
@echo "built $(APP_BUNDLE) (signed with: $(CODESIGN_ID))"
run: app
@pkill -x $(APP) 2>/dev/null || true
@open "$(APP_BUNDLE)"
install: app
@rm -rf "/Applications/$(APP).app"
@cp -R "$(APP_BUNDLE)" /Applications/
@echo "installed to /Applications/$(APP).app"
sign-info:
@echo "identity: $(CODESIGN_ID)"
@codesign -dv --entitlements - "$(APP_BUNDLE)" 2>&1 | head -20
clean:
swift package clean
@rm -rf "$(APP_BUNDLE)"