-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
310 lines (261 loc) · 8.8 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# This file is licensed under the Affero General Public License version 3 or
# later. See the COPYING file.
SRCDIR = .
ABSSRCDIR = $(CURDIR)
#
# try to parse the info.xml if we can, only then fall-back to the directory name
#
APP_INFO = $(SRCDIR)/appinfo/info.xml
XPATH = $(shell which xpath 2> /dev/null)
ifneq ($(XPATH),)
APP_NAME = $(shell $(XPATH) -q -e '/info/id/text()' $(APP_INFO))
else
$(warning The xpath binary could not be found, falling back to using the CWD as app-name)
APP_NAME = $(notdir $(CURDIR))
endif
BUILDDIR = ./build
ABSBUILDDIR = $(CURDIR)/build
BUILD_TOOLS_DIR = $(BUILDDIR)/tools
DOWNLOADS_DIR = ./downloads
SILENT = @
# make these overridable from the command line
RSYNC = $(shell which rsync 2> /dev/null)
PHP = $(shell which php 2> /dev/null)
NPM = $(shell which npm 2> /dev/null)
WGET = $(shell which wget 2> /dev/null)
OPENSSL = $(shell which openssl 2> /dev/null)
COMPOSER_SYSTEM = $(shell which composer 2> /dev/null)
ifeq (, $(COMPOSER_SYSTEM))
COMPOSER = $(PHP) $(BUILD_TOOLS_DIR)/composer.phar
else
COMPOSER = $(COMPOSER_SYSTEM)
endif
COMPOSER_OPTIONS = --prefer-dist
ifeq ($(PHP),)
$(error PHP binary is needed, but could not be found and was not specified on the command-line)
endif
ifeq ($(NPM),)
$(error NPM binary is needed, but could not be found and was not specified on the command-line)
endif
ifeq ($(COMPOSER),)
$(error COMPOSER binary is needed, but could not be found and was not specified on the command-line)
endif
ifeq ($(WGET),)
$(error WGET binary is needed, but could not be found and was not specified on the command-line)
endif
MAKE_HELP_DIR = $(SRCDIR)/dev-scripts/MakeHelp
include $(MAKE_HELP_DIR)/MakeHelp.mk
APPSTORE_BUILD_DIR = $(BUILDDIR)/artifacts/appstore
APPSTORE_COMPRESSION = z
APPSTORE_PACKAGE_FILE := $(APPSTORE_BUILD_DIR)/$(APP_NAME).tar
ifeq ($(APPSTORE_COMPRESSION),z)
APPSTORE_PACKAGE_FILE := $(APPSTORE_PACKAGE_FILE).gz
else ifeq ($(APPSTORE_COMPRESSION),J)
APPSTORE_PACKAGE_FILE := $(APPSTORE_PACKAGE_FILE).xz
endif
APPSTORE_SIGN_DIR = $(APPSTORE_BUILD_DIR)/sign
BUILD_CERT_DIR = $(BUILD_TOOLS_DIR)/certificates
CERT_DIR = $(HOME)/.nextcloud/certificates
OCC = $(CURDIR)/../../occ
#@@ The default rule.
all: help
.PHONY: all
#@@ Build the distribution assets (minified, without debugging info)
build: dev-setup npm-build # test
.PHONY: build
#@@ Build the development assets (include debugging information)
dev: dev-setup npm-dev # test
.PHONY: dev
#@private
dev-setup: app-toolkit composer
.PHONY: dev-setup
#@private
composer.json: composer.json.in
cp composer.json.in composer.json
#@private
stamp.composer-core-versions: composer.lock
date > $@
#@private
composer.lock: DRY:=
#@private
composer.lock: composer.json composer.json.in
rm -f composer.lock
$(COMPOSER) install $(COMPOSER_OPTIONS)
env DRY=$(DRY) dev-scripts/tweak-composer-json.sh || {\
rm -f composer.lock;\
$(COMPOSER) install $(COMPOSER_OPTIONS);\
}
#@private
composer-download:
mkdir -p $(BUILD_TOOLS_DIR)
curl -sS https://getcomposer.org/installer | php
mv composer.phar $(BUILD_TOOLS_DIR)
.PHONY: comoser-download
#@@ Installs and updates the composer dependencies. If composer is not installed
#@@ a copy is fetched from the web
composer: stamp.composer-core-versions
$(COMPOSER) install $(COMPOSER_OPTIONS)
.PHONY: composer
#@@ Display the composer suggestions
composer-suggest:
@echo -e "\n*** Regular Composer Suggestions ***\n"
$(COMPOSER) suggest --all
.PHONY: composer-suggest
APP_TOOLKIT_DIR = $(ABSSRCDIR)/php-toolkit
APP_TOOLKIT_DEST = $(ABSSRCDIR)/lib/Toolkit
APP_TOOLKIT_NS = RoundCube
include $(APP_TOOLKIT_DIR)/tools/scopeme.mk
JS_FILES = $(shell find $(ABSSRCDIR)/src -name "*.js" -o -name "*.vue")
NPM_INIT_DEPS =\
Makefile package-lock.json package.json webpack.config.js .eslintrc.js
WEBPACK_DEPS =\
$(NPM_INIT_DEPS)\
$(JS_FILES)
WEBPACK_TARGETS = $(ABSSRCDIR)/js/asset-meta.json
#@private
package-lock.json: package.json webpack.config.js Makefile
{ [ -d package-lock.json ] && [ test -d node_modules ]; } || $(NPM) install
$(NPM) update
touch package-lock.json
BUILD_FLAVOUR_FILE = $(ABSSRCDIR)/build-flavour
PREV_BUILD_FLAVOUR = $(shell cat $(BUILD_FLAVOUR_FILE) 2> /dev/null || echo)
#@private
build-flavour-dev:
ifneq ($(PREV_BUILD_FLAVOUR), dev)
make clean
echo dev > $(BUILD_FLAVOUR_FILE)
endif
.PHONY: build-flavour-dev
#@private
build-flavour-build:
ifneq ($(PREV_BUILD_FLAVOUR), build)
make clean
echo build > $(BUILD_FLAVOUR_FILE)
endif
.PHONY: build-flavour-build
#@private
$(WEBPACK_TARGETS): $(WEBPACK_DEPS) $(BUILD_FLAVOUR_FILE)
make webpack-clean
$(NPM) run $(shell cat $(BUILD_FLAVOUR_FILE)) || rm -f $(WEBPACK_TARGETS)
#@private
npm-dev: build-flavour-dev $(WEBPACK_TARGETS)
.PHONY: npm-dev
#@private
npm-build: build-flavour-build $(WEBPACK_TARGETS)
.PHONY: npm-build
#@@ Linting
lint:
$(NPM) run lint
.PHONY: lint
#@@ Lint and fix (be careful!)
lint-fix:
$(NPM) run lint:fix
.PHONY: lint-fix
#@@ Style linting
stylelint:
$(NPM) run stylelint
.PHONY: stylelint
#@@ Style linting and apply fixes (be carful!)
stylelint-fix:
$(NPM) run stylelint:fix
.PHONY: stylelint-
#@@ Run phpcs on the PHP code
phpcs: composer
vendor/bin/phpcs -s --report=emacs --standard=$(SRCDIR)/.phpcs.xml lib/ appinfo/ templates/
#@@ Run phpcs on the PHP code, hiding mere warnings
phpcs-errors: composer
vendor/bin/phpcs -n --standard=$(SRCDIR)/.phpcs.xml lib/ appinfo/ templates/|grep FILE:|awk '{ print $$2; }'
#@@ Run phpmd on the PHP code
phpmd: composer
vendor/bin/phpmd lib/,appinfo/,templates/ text $(SRCDIR)/.phpmd.xml
# what has to be copied to the appstore archive
APPSTORE_FILES =\
appinfo\
css\
js\
img\
l10n\
templates\
lib\
vendor\
CHANGELOG.md\
COPYING\
README.md
# .htaccess is blacklisted by the app-store installer, so we have to remove it
APPSTORE_BLACKLISTED = foobar .git* .*keep .htaccess *~
#@private
appstore: COMPOSER_OPTIONS := $(COMPOSER_OPTIONS) --no-dev
#@@ Prepare appstore archive
appstore: clean dev-setup npm-build
mkdir -p $(APPSTORE_SIGN_DIR)/$(APP_NAME)
$(RSYNC) -a -L $(APPSTORE_BLACKLISTED:%=--exclude '%') $(APPSTORE_FILES) $(APPSTORE_SIGN_DIR)/$(APP_NAME)
mkdir -p $(BUILD_CERT_DIR)
$(SILENT)if [ -n "$$APP_PRIVATE_KEY" ]; then\
echo "$$APP_PRIVATE_KEY" > $(BUILD_CERT_DIR)/$(APP_NAME).key;\
elif [ -f "$(CERT_DIR)/$(APP_NAME).key" ]; then\
cp $(CERT_DIR)/$(APP_NAME).key $(BUILD_CERT_DIR)/$(APP_NAME).key;\
fi
$(SILENT)if [ -f $(BUILD_CERT_DIR)/$(APP_NAME).key ] && [ ! -f $(BUILD_CERT_DIR)/$(APP_NAME).crt ]; then\
curl -L -o $(BUILD_CERT_DIR)/$(APP_NAME).crt\
"https://github.com/nextcloud/app-certificate-requests/raw/master/$(APP_NAME)/$(APP_NAME).crt";\
$(OPENSSL) x509 -in $(BUILD_CERT_DIR)/$(APP_NAME).crt -noout -text > /dev/null 2>&1 || rm -f $(BUILD_CERT_DIR)/$(APP_NAME).crt;\
fi
$(SILENT)if [ -f $(BUILD_CERT_DIR)/$(APP_NAME).key ] && [ -f $(BUILD_CERT_DIR)/$(APP_NAME).crt ]; then\
echo "Signing app files ...";\
$(PHP) $(OCC) integrity:sign-app\
--privateKey=$(ABSSRCDIR)/$(BUILD_CERT_DIR)/$(APP_NAME).key\
--certificate=$(ABSSRCDIR)/$(BUILD_CERT_DIR)/$(APP_NAME).crt\
--path=$(ABSSRCDIR)/$(APPSTORE_SIGN_DIR)/$(APP_NAME);\
echo "... signing app files done";\
else\
echo 'Cannot sign app-files, certificate "$(BUILD_CERT_DIR)/$(APP_NAME).crt" or private key "$(BUILD_CERT_DIR)/$(APP_NAME).key" not available.' 1>&2;\
fi
tar -c$(APPSTORE_COMPRESSION)f $(APPSTORE_PACKAGE_FILE) -C $(APPSTORE_SIGN_DIR) $(APP_NAME)
$(SILENT)if [ -f $(BUILD_CERT_DIR)/$(APP_NAME).key ] && [ -f $(BUILD_CERT_DIR)/$(APP_NAME).crt ]; then\
echo "Signing package ...";\
$(OPENSSL) dgst -sha512 -sign $(CERT_DIR)/$(APP_NAME).key $(APPSTORE_PACKAGE_FILE) | openssl base64; \
else\
echo 'Cannot sign app-store package, certificate "$(BUILD_CERT_DIR)/$(APP_NAME).crt" or private key "$(BUILD_CERT_DIR)/$(APP_NAME).key" not available.' 1>&2;\
fi
.PHONY: appstore
#@@ Removes WebPack builds
webpack-clean:
rm -rf ./js/*
rm -rf ./css/*
.PHONY: webpack-clean
#@@ Removes build files
clean: ## Tidy up local environment
rm -rf $(BUILDDIR)
.PHONY: clean
#@@ Same as clean but also removes dependencies installed by composer, bower and npm
distclean: clean ## Clean even more, calls clean
rm -rf vendor*
rm -rf node_modules
rm -rf lib/Toolkit/*
.PHONY: distclean
#@@ Almost everything but downloads
mostlyclean: webpack-clean distclean
rm -f composer*.lock
rm -f composer.json
rm -f stamp.composer-core-versions
rm -f package-lock.json
rm -f *.html
rm -f stats.json
#@@ Really delete everything but the bare source files
realclean: mostlyclean downloadsclean
.PHONY: realclean
#@@ Remove non-npm non-composer downloads
downloadsclean:
rm -rf $(DOWNLOADS_DIR)
.PHONY: downloadsclean
#@@ Run the test-suite
test: unit-tests integration-tests
.PHONY: test
#@@ Run the unit tests
unit-tests:
./vendor/phpunit/phpunit/phpunit -c phpunit.xml
.PHONY: unit-tests
#@@ Run the integration tests
integration-tests:
./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml
.PHONY: integration-tests