diff --git a/build/rules/check-composer.mk b/build/rules/check-composer.mk new file mode 100644 index 000000000000..decbed9b8cc7 --- /dev/null +++ b/build/rules/check-composer.mk @@ -0,0 +1,11 @@ +# Check that composer exists + +ifndef COMPOSER_CHECK_HAS_BEEN_DONE + COMPOSER_CHECK_HAS_BEEN_DONE=true + +COMPOSER_BIN := $(shell command -v composer 2> /dev/null) +ifndef COMPOSER_BIN + $(error composer is not available on your system, please install composer) +endif + +endif diff --git a/build/rules/check-npm.mk b/build/rules/check-npm.mk new file mode 100644 index 000000000000..f94bc615c13f --- /dev/null +++ b/build/rules/check-npm.mk @@ -0,0 +1,11 @@ +# Check that npm exists + +ifndef NPM_CHECK_HAS_BEEN_DONE + NPM_CHECK_HAS_BEEN_DONE=true + +NPM := $(shell command -v npm 2> /dev/null) +ifndef NPM + $(error npm is not available on your system, please install npm) +endif + +endif diff --git a/build/rules/clean.mk b/build/rules/clean.mk new file mode 100644 index 000000000000..26408abd31b5 --- /dev/null +++ b/build/rules/clean.mk @@ -0,0 +1,16 @@ +## +## Common clean rules +##-------------------------------------- + +ifndef CLEAN_HAS_BEEN_INCLUDED + CLEAN_HAS_BEEN_INCLUDED=true + +.PHONY: clean-deps +clean-deps: ## Clean all dependencies +clean-deps: $(clean_deps_rules) + +.PHONY: clean +clean: ## Clean all dependencies, build and dist +clean: clean-deps $(clean_dist_rules) $(clean_build_rules) + +endif diff --git a/build/rules/dist.mk b/build/rules/dist.mk new file mode 100644 index 000000000000..1f1c8ece5894 --- /dev/null +++ b/build/rules/dist.mk @@ -0,0 +1,90 @@ +## +## Distribution tarball +##-------------------------------------- + +# signing +PATH_TO_OCC=$(CURDIR)/occ +ifeq ("$(wildcard $(PATH_TO_OCC))","") + PATH_TO_OCC=$(CURDIR)/../../occ +endif +occ=$(PATH_TO_OCC) +private_key=$(HOME)/.owncloud/certificates/$(app_name).key +certificate=$(HOME)/.owncloud/certificates/$(app_name).crt +sign=$(occ) integrity:sign-app --privateKey="$(private_key)" --certificate="$(certificate)" +sign_skip_msg="Skipping signing, either no key and certificate found in $(private_key) and $(certificate) or occ can not be found at $(occ)" +ifneq (,$(wildcard $(private_key))) +ifneq (,$(wildcard $(certificate))) +ifneq (,$(wildcard $(occ))) + CAN_SIGN=true +endif +endif +endif + +# If the app_name has not been specified by the caller, +# then use the name of the directory that the main "make" is being run from. +ifndef app_name + app_name=$(notdir $(CURDIR)) +endif + +# If not specified by the caller, then select some common doc files to put in the tarball. +ifndef doc_files + doc_files=CHANGELOG.md README.md +ifneq ("$(wildcard LICENSE)","") + doc_files+=LICENSE +endif +ifneq ("$(wildcard LICENSE.md)","") + doc_files+=LICENSE.md +endif +ifneq ("$(wildcard CONTRIBUTING.md)","") + doc_files+=CONTRIBUTING.md +endif +endif + +# If not specified by the caller, then select a "standard" set of dirs to put in the tarball. +ifndef src_dirs + src_dirs=appinfo css img js l10n lib templates +endif + +all_src=$(src_dirs) $(extra_dirs) $(doc_files) $(extra_files) + +# Put the tarball and any other artifacts in a build dir by default +ifndef build_dir + build_dir=$(CURDIR)/build +endif + +# Put the tarball in a dist sub-dir of build_dir by default +ifndef dist_dir + dist_dir=$(build_dir)/dist +endif + +# +# dist +# +$(dist_dir)/$(app_name): $(composer_deps) $(bower_deps) $(nodejs_deps) + rm -Rf $@; mkdir -p $@ + cp -R $(all_src) $@ + +ifdef CAN_SIGN + $(sign) --path="$(dist_dir)/$(app_name)" +else + @echo $(sign_skip_msg) +endif + tar -czf $(dist_dir)/$(app_name).tar.gz -C $(dist_dir) $(app_name) + +.PHONY: dist +dist: ## Make the tarball for release distribution +dist: $(dist_dir)/$(app_name) + +clean_dist_rules+=clean-dist +clean_build_rules+=clean-build + +.PHONY: clean-dist +clean-dist: ## Clean the dist directory +clean-dist: + rm -Rf $(dist_dir) + +.PHONY: clean-build +clean-build: ## Clean the build directory +clean-build: + rm -Rf $(build_dir) + diff --git a/build/rules/help.mk b/build/rules/help.mk new file mode 100644 index 000000000000..378e302102ed --- /dev/null +++ b/build/rules/help.mk @@ -0,0 +1,8 @@ +# Define the help target and make it the default + +.DEFAULT_GOAL := help + +# start with displaying help +help: + @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | sed -e 's/ */ /' | column -t -s : + diff --git a/build/rules/test-acceptance.mk b/build/rules/test-acceptance.mk new file mode 100644 index 000000000000..a8ecca203f2a --- /dev/null +++ b/build/rules/test-acceptance.mk @@ -0,0 +1,50 @@ +## +## Acceptance Tests +##-------------------------------------- + +RELATIVE_PATH := $(dir $(lastword $(MAKEFILE_LIST))) +include $(RELATIVE_PATH)check-composer.mk + +acceptance_test_deps=vendor-bin/behat/vendor + +# bin file definitions +BEHAT_BIN=vendor-bin/behat/vendor/bin/behat +PHP_CODESNIFFER=vendor-bin/php_codesniffer/vendor/bin/phpcs + +.PHONY: test-acceptance-api +test-acceptance-api: ## Run API acceptance tests +test-acceptance-api: $(acceptance_test_deps) + BEHAT_BIN=$(BEHAT_BIN) ../../tests/acceptance/run.sh --remote --type api + +.PHONY: test-acceptance-cli +test-acceptance-cli: ## Run CLI acceptance tests +test-acceptance-cli: $(acceptance_test_deps) + BEHAT_BIN=$(BEHAT_BIN) ../../tests/acceptance/run.sh --remote --type cli + +.PHONY: test-acceptance-webui +test-acceptance-webui: ## Run webUI acceptance tests +test-acceptance-webui: $(acceptance_test_deps) + BEHAT_BIN=$(BEHAT_BIN) ../../tests/acceptance/run.sh --remote --type webui + +.PHONY: test-acceptance-style +test-acceptance-style: ## Run php_codesniffer and check acceptance test code-style +test-acceptance-style: vendor-bin/php_codesniffer/vendor + $(PHP_CODESNIFFER) --runtime-set ignore_warnings_on_exit --standard=phpcs.xml tests/acceptance + +# +# Dependency management +#-------------------------------------- + +include $(RELATIVE_PATH)vendor-bin.mk + +vendor-bin/behat/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/behat/composer.lock + composer bin behat install --no-progress + +vendor-bin/behat/composer.lock: vendor-bin/behat/composer.json + @echo behat composer.lock is not up to date. + +vendor-bin/php_codesniffer/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/php_codesniffer/composer.lock + composer bin php_codesniffer install --no-progress + +vendor-bin/php_codesniffer/composer.lock: vendor-bin/php_codesniffer/composer.json + @echo php_codesniffer composer.lock is not up to date. diff --git a/build/rules/test-js.mk b/build/rules/test-js.mk new file mode 100644 index 000000000000..0e029ac615fb --- /dev/null +++ b/build/rules/test-js.mk @@ -0,0 +1,34 @@ +## +## JavaScript Tests +##-------------------------------------- + +# bin file definitions +NODE_PREFIX=$(shell pwd) +KARMA=$(NODE_PREFIX)/node_modules/.bin/karma + +nodejs_deps=node_modules + +.PHONY: test-js +test-js: ## Run JS test suites (single run) +test-js: $(KARMA) + $(KARMA) start tests/js/karma.config.js --single-run + +test-js-debug: ## Run JS test suites and watch for changes +test-js-debug: $(KARMA) + $(KARMA) start tests/js/karma.config.js + +$(KARMA): $(nodejs_deps) + +# +# Dependency management +#-------------------------------------- + +$(nodejs_deps): package.json yarn.lock + yarn install + touch $@ + +clean_deps_rules+=clean-js-deps + +.PHONY: clean-js-deps +clean-js-deps: + rm -Rf $(nodejs_deps) diff --git a/build/rules/test-php.mk b/build/rules/test-php.mk new file mode 100644 index 000000000000..018bcae0fcf0 --- /dev/null +++ b/build/rules/test-php.mk @@ -0,0 +1,71 @@ +## +## PHP Tests +##-------------------------------------- + +RELATIVE_PATH := $(dir $(lastword $(MAKEFILE_LIST))) +include $(RELATIVE_PATH)check-composer.mk + +# bin file definitions +PATH_TO_PHPUNIT=$(CURDIR)/lib/composer/bin/phpunit +ifeq ("$(wildcard $(PATH_TO_PHPUNIT))","") + PATH_TO_PHPUNIT=$(CURDIR)/../../lib/composer/bin/phpunit +endif +PHPUNIT=php -d zend.enable_gc=0 "$(PATH_TO_PHPUNIT)" +PHPUNITDBG=phpdbg -qrr -d memory_limit=4096M -d zend.enable_gc=0 "$(PATH_TO_PHPUNIT)" +PHP_CS_FIXER=php -d zend.enable_gc=0 vendor-bin/owncloud-codestyle/vendor/bin/php-cs-fixer +PHAN=php -d zend.enable_gc=0 vendor-bin/phan/vendor/bin/phan +PHPSTAN=php -d zend.enable_gc=0 vendor-bin/phpstan/vendor/bin/phpstan + +.PHONY: test-php-unit +test-php-unit: ## Run php unit tests +test-php-unit: + $(PHPUNIT) --configuration ./phpunit.xml --testsuite unit + +.PHONY: test-php-unit-dbg +test-php-unit-dbg: ## Run php unit tests using phpdbg +test-php-unit-dbg: + $(PHPUNITDBG) --configuration ./phpunit.xml --testsuite unit + +.PHONY: test-php-style +test-php-style: ## Run php-cs-fixer and check owncloud code-style +test-php-style: vendor-bin/owncloud-codestyle/vendor + $(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes --dry-run + +.PHONY: test-php-style-fix +test-php-style-fix: ## Run php-cs-fixer and fix code style issues +test-php-style-fix: vendor-bin/owncloud-codestyle/vendor + $(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes + +.PHONY: test-php-phan +test-php-phan: ## Run phan +test-php-phan: vendor-bin/phan/vendor + $(PHAN) --config-file .phan/config.php --require-config-exists + +.PHONY: test-php-phpstan +test-php-phpstan: ## Run phpstan +test-php-phpstan: vendor-bin/phpstan/vendor + $(PHPSTAN) analyse --memory-limit=4G --configuration=./phpstan.neon --no-progress --level=5 appinfo lib + +# +# Dependency management +#-------------------------------------- + +include $(RELATIVE_PATH)vendor-bin.mk + +vendor-bin/owncloud-codestyle/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/owncloud-codestyle/composer.lock + composer bin owncloud-codestyle install --no-progress + +vendor-bin/owncloud-codestyle/composer.lock: vendor-bin/owncloud-codestyle/composer.json + @echo owncloud-codestyle composer.lock is not up to date. + +vendor-bin/phan/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/phan/composer.lock + composer bin phan install --no-progress + +vendor-bin/phan/composer.lock: vendor-bin/phan/composer.json + @echo phan composer.lock is not up to date. + +vendor-bin/phpstan/vendor: vendor/bamarni/composer-bin-plugin vendor-bin/phpstan/composer.lock + composer bin phpstan install --no-progress + +vendor-bin/phpstan/composer.lock: vendor-bin/phpstan/composer.json + @echo phpstan composer.lock is not up to date. diff --git a/build/rules/vendor-bin.mk b/build/rules/vendor-bin.mk new file mode 100644 index 000000000000..df2dcb8e7f7a --- /dev/null +++ b/build/rules/vendor-bin.mk @@ -0,0 +1,25 @@ +# Dependencies for getting the vendor and vendor-bin directory happening + +ifndef VENDOR_BIN_HAS_BEEN_INCLUDED + VENDOR_BIN_HAS_BEEN_INCLUDED=true + +composer.lock: composer.json + @echo composer.lock is not up to date. + +vendor: composer.lock + composer install --no-dev + +vendor/bamarni/composer-bin-plugin: composer.lock + composer install + +clean_deps_rules+=clean-vendor clean-vendor-bin + +.PHONY: clean-vendor +clean-vendor: + rm -Rf vendor + +.PHONY: clean-vendor-bin +clean-vendor-bin: + rm -Rf vendor-bin/**/vendor vendor-bin/**/composer.lock + +endif