-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
137 lines (113 loc) · 4.33 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
APP_EXECUTABLE=$(shell swift build $(SWIFT_BUILD_FLAGS) --show-bin-path)/$(APP_NAME_LOWERCASE)
APP_NAME=Finch
APP_NAME_LOWERCASE=$(shell echo '$(APP_NAME)' | tr '[:upper:]' '[:lower:]')
APP_TMP=/tmp/$(APP_NAME).dst
BIN_DIR=$(INSTALL_DIR)/bin
BINARIES_DIR=/usr/local/bin
BUILD=swift build
BUILD_NUMBER_FILE=./Sources/$(APP_NAME)/App/BuildNumber.swift
CONFIG_TEMPLATE=template.config.yml
CONFIRM=./Scripts/prompt_confirmation
CP=cp
CURRENT_BRANCH=$(shell git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
DISTRIBUTION_PLIST=$(APP_TMP)/Distribution.plist
DOCS=docs
INSTALL_DIR=$(HOME)/.$(APP_NAME_LOWERCASE)
INTERNAL_PACKAGE=$(APP_NAME)App.pkg
JAZZY=bundle exec jazzy --module-version $(VERSION_STRING)
LN=ln -fs
MKDIR=mkdir -p
ORG_IDENTIFIER=org.$(APP_NAME_LOWERCASE).$(APP_NAME_LOWERCASE)
OUTPUT_PACKAGE=$(APP_NAME).pkg
PIPEFAIL=set -o pipefail
SWIFT_BUILD_FLAGS=--configuration release
TEST=FINCH_TESTS=1 swift test
UNAME=$(shell uname)
VERSION_FILE=./Sources/$(APP_NAME)/App/Version.swift
VERSION_STRING=$(shell cat $(VERSION_FILE) | grep appVersion | sed -n -e 's/^.*(//p' | tr -d ") " | tr "," ".")
# RM_SAFELY · `rm -rf` ensuring first and only parameter is non-null, contains more than whitespace, non-root if resolving absolutely.
RM_SAFELY := bash -c '[[ ! $${1:?} =~ "^[[:space:]]+\$$" ]] && [[ $${1:A} != "/" ]] && [[ $${\#} == "1" ]] && set -o noglob && rm -rf $${1:A}' --
.PHONY: all build build_with_disable_sandbox config_template install lint linuxmain package prefix_install project publish symlink test update_build_number update_version
all: install
build: update_build_number
$(BUILD) $(SWIFT_BUILD_FLAGS)
build_with_disable_sandbox: update_build_number
$(BUILD) --disable-sandbox $(SWIFT_BUILD_FLAGS)
config_template:
@echo "\nAdding config template to $(INSTALL_DIR)/$(CONFIG_TEMPLATE)"
$(MKDIR) $(INSTALL_DIR)
$(CP) Resources/$(CONFIG_TEMPLATE) $(INSTALL_DIR)/
docs: project
$(JAZZY) --config .jazzy/FinchApp.yml -o $(DOCS)/FinchApp
$(JAZZY) --config .jazzy/FinchCore.yml -o $(DOCS)/FinchCore
install: build symlink config_template
install -d $(BIN_DIR)
install $(APP_EXECUTABLE) $(BIN_DIR)/
lint:
mint run swiftlint swiftlint --strict
linuxmain:
$(TEST) --generate-linuxmain
package: build
$(MKDIR) $(APP_TMP)
$(CP) $(APP_EXECUTABLE) $(APP_TMP)
pkgbuild \
--identifier $(ORG_IDENTIFIER) \
--install-location $(BINARIES_DIR) \
--root $(APP_TMP) \
--version $(VERSION_STRING) \
$(INTERNAL_PACKAGE)
productbuild \
--synthesize \
--package $(INTERNAL_PACKAGE) \
$(DISTRIBUTION_PLIST)
productbuild \
--distribution $(DISTRIBUTION_PLIST) \
--package-path $(INTERNAL_PACKAGE) \
$(OUTPUT_PACKAGE)
@$(RM_SAFELY) $(APP_TMP)
@$(RM_SAFELY) $(INTERNAL_PACKAGE)
prefix_install:
@NO_UPDATE_BUILD_NUMBER=1 $(MAKE) build_with_disable_sandbox
install -d "$(PREFIX)/bin"
install "$(APP_EXECUTABLE)" "$(PREFIX)/bin/"
@$(MAKE) config_template
publish: test
$(eval NEW_VERSION:=$(filter-out $@, $(MAKECMDGOALS)))
@$(CONFIRM) "Warning: This will create and push a tag for '$(NEW_VERSION)' \
based off the current state of the current branch: $(CURRENT_BRANCH)."
@NEW_VERSION=$(NEW_VERSION) $(MAKE) update_version
git add $(VERSION_FILE)
git commit --allow-empty -m "[version] Publish version $(NEW_VERSION)"
@$(MAKE) update_build_number
cat $(BUILD_NUMBER_FILE)
git add -f $(BUILD_NUMBER_FILE)
git commit --amend --no-edit
git tag $(NEW_VERSION)
git push origin $(NEW_VERSION)
git reset origin/$(CURRENT_BRANCH)
symlink: build
@echo "\nSymlinking $(APP_NAME)"
$(LN) $(BIN_DIR)/$(APP_NAME_LOWERCASE) $(BINARIES_DIR)
test: update_build_number
@$(RM_SAFELY) ./.build/debug/$(APP_NAME)PackageTests.xctest
ifeq ($(UNAME), Darwin)
$(PIPEFAIL) && $(TEST) 2>&1 | xcpretty -r junit --output build/reports/test/junit.xml
else
$(TEST)
endif
update_build_number:
ifndef NO_UPDATE_BUILD_NUMBER
@echo "let appBuildNumber: Int = $(shell git rev-list @ --count)" > $(BUILD_NUMBER_FILE)
endif
update_version:
ifdef NEW_VERSION
$(eval VERSION_COMPONENTS:=$(subst ., ,$(NEW_VERSION)))
$(eval MAJOR:=$(word 1,$(VERSION_COMPONENTS)))
$(eval MINOR:=$(word 2,$(VERSION_COMPONENTS)))
$(eval PATCH:=$(word 3,$(VERSION_COMPONENTS)))
@echo "import Version\n\nlet appVersion: Version = .init(major: $(MAJOR), minor: $(MINOR), patch: $(PATCH))" > $(VERSION_FILE)
endif
project:
FINCH_TESTS=1 swift package generate-xcodeproj --enable-code-coverage
%:
@: