Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PoC] [stable10] Provide common make files #34661

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build/rules/check-composer.mk
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions build/rules/check-npm.mk
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions build/rules/clean.mk
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions build/rules/dist.mk
Original file line number Diff line number Diff line change
@@ -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)

8 changes: 8 additions & 0 deletions build/rules/help.mk
Original file line number Diff line number Diff line change
@@ -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 :

50 changes: 50 additions & 0 deletions build/rules/test-acceptance.mk
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions build/rules/test-js.mk
Original file line number Diff line number Diff line change
@@ -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)
71 changes: 71 additions & 0 deletions build/rules/test-php.mk
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions build/rules/vendor-bin.mk
Original file line number Diff line number Diff line change
@@ -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