-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
281 lines (238 loc) · 7.82 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright (c) 2016, Samantha Marshall (http://pewpewthespells.com)
# All rights reserved.
#
# https://github.com/samdmarshall/nslocalizer
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# 3. Neither the name of Samantha Marshall nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
# Variables
# path to installation record that gets written when performing:
# - make build2
# - make build3
INSTALLED_FILES_RECORD := ./installed_files.txt
# names of the executables that are used as a part of this project
PYTHON3_CMD := python3
TOX_CMD := tox
COVERAGE_CMD := coverage
DANGER_CMD := danger
GEM_CMD := gem
FIND_CMD := find
RM_CMD := rm
WHICH_CMD := which
XARGS_CMD := xargs
PRINTF_CMD := printf
TOUCH_CMD := touch
CP_CMD := cp
CAT_CMD := cat
PIP_CMD := pip
PIP3_CMD := pip3
CCTREPORTER_CMD := codeclimate-test-reporter
UNAME_CMD := uname
EXIT_CMD := exit
TPUT_CMD := tput
TR_CMD := tr
PYLINT_CMD := pylint
BREW_CMD := brew
PYENV_CMD := pyenv
TOX_PYENV := tox-pyenv
PYOBJC_CORE := pyobjc-core
PYOBJC_COCOA := pyobjc-framework-Cocoa
# invoke the specific executable command
PYTHON3 = $(shell command -v $(PYTHON3_CMD) 2> /dev/null)
TOX = $(shell command -v $(TOX_CMD) 2> /dev/null)
COVERAGE = $(shell command -v $(COVERAGE_CMD) 2> /dev/null)
DANGER = $(shell command -v $(DANGER_CMD) 2> /dev/null)
GEM = $(shell command -v $(GEM_CMD) 2> /dev/null)
FIND = $(shell command -v $(FIND_CMD) 2> /dev/null)
RM = $(shell command -v $(RM_CMD) 2> /dev/null)
WHICH = $(shell command -v $(WHICH_CMD) 2> /dev/null)
XARGS = $(shell command -v $(XARGS_CMD) 2> /dev/null)
PRINTF = $(shell command -v $(PRINTF_CMD) 2> /dev/null)
TOUCH = $(shell command -v $(TOUCH_CMD) 2> /dev/null)
CP = $(shell command -v $(CP_CMD) 2> /dev/null)
CAT = $(shell command -v $(CAT_CMD) 2> /dev/null)
PIP = $(shell command -v $(PIP_CMD) 2> /dev/null)
PIP3 = $(shell command -v $(PIP3_CMD) 2> /dev/null)
CCTREPORTER = $(shell command -v $(CCTREPORTER_CMD) 2> /dev/null)
UNAME = $(shell command -v $(UNAME_CMD) 2> /dev/null)
EXIT = $(shell command -v $(EXIT_CMD) 2> /dev/null)
TPUT = $(shell command -v $(TPUT_CMD) 2> /dev/null)
TR = $(shell command -v $(TR_CMD) 2> /dev/null)
PYLINT = $(shell command -v $(PYLINT_CMD) 2> /dev/null)
BREW = $(shell command -v $(BREW_CMD) 2> /dev/null)
PYENV = $(shell command -v $(PYENV_CMD) 2> /dev/null)
SYSTEM := $(shell $(UNAME) -s)
ifeq ($(SYSTEM),Darwin)
USER_FLAG := --user
else
USER_FLAG :=
endif
TERM_COLUMNS := `$(TPUT) cols`
DISPLAY_SEPARATOR := $(PRINTF) "%*.s\n" $(TERM_COLUMNS) " " | $(TR) ' ' '='
# Targets
# ---
checkfor = @$(PRINTF) "Checking for $1..."; \
if [ -z `$(WHICH) $1` ]; then \
$(PRINTF) " no\n"; \
$(EXIT) 1;\
else \
$(PRINTF) " yes\n"; \
fi
check:
$(call checkfor,$(WHICH_CMD))
$(call checkfor,$(CAT_CMD))
$(call checkfor,$(CP_CMD))
$(call checkfor,$(TPUT_CMD))
$(call checkfor,$(TR_CMD))
$(call checkfor,$(PRINTF_CMD))
$(call checkfor,$(TOUCH_CMD))
$(call checkfor,$(FIND_CMD))
$(call checkfor,$(XARGS_CMD))
$(call checkfor,$(RM_CMD))
$(call checkfor,$(BREW_CMD))
$(call checkfor,$(PYTHON3_CMD))
$(call checkfor,$(PIP3_CMD))
$(call checkfor,$(TOX_CMD))
$(call checkfor,$(COVERAGE_CMD))
$(call checkfor,$(PYLINT_CMD))
$(call checkfor,$(PYENV_CMD))
$(call checkfor,$(GEM_CMD))
$(call checkfor,$(DANGER_CMD))
@$(DISPLAY_SEPARATOR)
# ---
pipinstall = @$(PIP) install $1 $(USER_FLAG)
pipthreeinstall = @$(PIP3_CMD) install $1
geminstall = @$(GEM) install $1
brewinstall = @$(BREW) install $1
pyenv_exec = @$(PYENV_CMD) $1 $2
install-deps:
$(call brewinstall,$(PYENV_CMD))
$(call brewinstall,$(PYTHON3_CMD))
$(call checkfor,$(PIP3_CMD))
$(call pipthreeinstall,-r requirements.txt)
@$(DISPLAY_SEPARATOR)
$(call checkfor,$(GEM_CMD))
$(call geminstall,$(DANGER_CMD))
@$(DISPLAY_SEPARATOR)
$(call pyenv_exec, install, 3.5.1)
@$(DISPLAY_SEPARATOR)
# ---
# this is for installing any tools that we don't already have
install-tools: check
@$(PRINTF) "Installing git hooks..."
@$(PYTHON2) ./tools/hooks-config.py
@$(PRINTF) " done!\n"
@$(DISPLAY_SEPARATOR)
# ---
removeall = $(RM) -rRf
cleanlocation = @$(FIND) $1 $2 -print0 | $(XARGS) -0 $(removeall)
clean: check
@$(PRINTF) "Removing existing installation... "
@$(TOUCH) $(INSTALLED_FILES_RECORD)
@$(CAT) $(INSTALLED_FILES_RECORD) | $(XARGS) $(removeall)
@$(removeall) ./nslocalizer.egg-info
@$(removeall) ./build
@$(removeall) ./dist
@$(removeall) ./.tox
@$(removeall) .coverage
@$(removeall) ./htmlcov
@$(removeall) ./.eggs
$(call cleanlocation, ., -name ".DS_Store")
$(call cleanlocation, ., -name "*.pyc")
$(call cleanlocation, ., -name "__pycache__" -type d)
$(call cleanlocation, ., -name "*_output.plist")
@$(PRINTF) "done!\n"
@$(DISPLAY_SEPARATOR)
# ---
build: clean
$(PYTHON3) ./setup.py install --record $(INSTALLED_FILES_RECORD)
@$(DISPLAY_SEPARATOR)
# ---
test: clean
$(TOX)
@$(DISPLAY_SEPARATOR)
# ---
upload_artifacts = @$(PRINTF) "Checking for path to upload artifacts..." ; \
if [ -d $1 ] ; then \
$(PRINTF) "uploading.\n" ; \
$(CP) -r ./htmlcov $1 ; \
$(CP) lint_output.txt $1 ; \
else \
$(PRINTF) "skipping.\n" ; \
fi
run_cctreporter = @$(PRINTF) "Checking CI branch to upload coverage results... " ; \
if [ "$(CIRCLE_BRANCH)" = "develop" ]; then \
$(PRINTF) "OK.\n"; \
$(CCTREPORTER) --token $(value CIRCLECI_CODECLIMATE_TOKEN) ; \
else \
$(PRINTF) "skipping.\n"; \
fi
checktest = @$(PRINTF) "Checking that coverage data exists... " ; \
if [ -e ./.coverage ] ; then \
$(PRINTF) "ok!\n" ; \
else \
$(PRINTF) "not found!\n" ; \
$(PRINTF) "Please run 'make test' before running 'make report'\n" ; \
exit 1 ; \
fi \
report: check
@$(call checktest)
$(COVERAGE) report
@$(DISPLAY_SEPARATOR)
@$(PRINTF) "Generating html report... "
@$(COVERAGE) html
@$(PRINTF) "done!\n"
@$(PRINTF) "Generated html report is located at: ./htmlcov/index.html\n"
ifdef CIRCLE_ARTIFACTS
@$(DISPLAY_SEPARATOR)
$(call upload_artifacts,$(CIRCLE_ARTIFACTS))
endif
@$(DISPLAY_SEPARATOR)
$(call run_cctreporter)
@$(DISPLAY_SEPARATOR)
# ---
danger: check
@$(PRINTF) "Running danger "
ifdef CIRCLECI_DANGER_GITHUB_API_TOKEN
@$(PRINTF) "(PR)... \n"
@export DANGER_GITHUB_API_TOKEN=$(value CIRCLECI_DANGER_GITHUB_API_TOKEN)
@$(DANGER) --verbose
else
@$(PRINTF) "(local)... \n"
@$(DANGER) local --verbose
endif
@$(DISPLAY_SEPARATOR)
# ---
ci: test lint report danger
# ---
lint: check
@$(TOUCH) lint_output.txt
@$(PRINTF) "Running linter... "
@$(PYLINT) --rcfile=pylintrc ./nslocalizer > lint_output.txt || :
@$(PRINTF) " done!\n"
@$(PRINTF) "Generated linter report: lint_output.txt\n"
@$(DISPLAY_SEPARATOR)
# ---
.PHONY: danger lint ci report test build clean install-tools install-deps check