#!/bin/zsh zmodload zsh/stat setopt extendedglob dir=`dirname "$0"` PATH=$dir:$PATH if [ -z "`git --version`" ]; then echo 'This script needs git!' >&2 exit 1 fi git=git if hub --version 2> /dev/null > /dev/null; then case "$(hub --version)" in *hub\ version*) git=hub;; esac fi if ! ${git} diff --exit-code > /dev/null || ! ${git} diff --staged --exit-code > /dev/null ; then echo 'Your working directory contains local modifications!' >&2 exit 1 fi cd "`${git} rev-parse --show-toplevel`" if [ -n "`${git} ls-files --other --exclude-standard --exclude=build\*`" ]; then echo 'You have untracked files!' >&2 exit 1 fi branch=$1 # if ! ${git} rev-parse "$branch" > /dev/null 2>&1; then # echo "\"$branch\" is not a valid branch!" >&2 # exit 1 #fi trap 'echo "(aborting the merge now)" && ${git} merge --abort' EXIT echo ".. Test merging of the branch \"$branch\"..." ${git} merge --no-ff --no-commit "$branch" && ${git} status && ${git} diff --staged --summary if true; then # REMOVE echo '.. Testing permissions...' detect_wrong_permissions || exit 1 echo '.. Testing licenses...' detect_packages_licenses || exit 1 if ! ${git} diff --exit-code > /dev/null; then echo '=> There are modifications in licenses:' ${git} status --porcelain exit 1 fi fi # REMOVE if [ -d build ] && \ [ -f build/CMakeCache.txt ] && \ [ "$(grep -c -iE 'WITH_(demos|examples|tests):BOOL=(ON|TRUE|1)' build/CMakeCache.txt)" -eq "3" ]; then echo '.. Testing CMake configuration...' cmake_output=$(cmake build 2>&1) cmake_exit_code=$? if [ "$cmake_exit_code" -ne 0 ]; then echo 'CMake error:' printf '%s\n' "${cmake_output}" exit 1 else echo OK fi else echo '.. Skip the CMake test (please configure a build/ CMake binary directory,' echo 'with -DWITH_tests:BOOL=TRUE -DWITH_examples:BOOL=TRUE -DWITH_demos:BOOL=TRUE)' fi echo '.. List of new files (please check that it is the expected list:' new_files=( ${(f)"$(${git} status --porcelain | grep -E '^A')"} ) if [ ${#new_files[@]} -gt 0 ]; then string=${(F)new_files} echo $string else echo 'No new files.' fi #check cmake scripts of tests, examples are present echo '.. Checking if all CMakeLists.txt are present...' for i in `ls -d ^build*/examples/*/ ^build*/test/*/ ^build*/demo/^(icons|resources)/`; do if ! [ -f $i/CMakeLists.txt ]; then echo "Error: $i/CMakeLists.txt does not exist!" exit 1 fi done # check project in cmake scripts is correct echo '.. Checking if all CMakeLists.txt project names are correct...' project_name_tests=$(for i in ^build*/test/*/CMakeLists.txt; do pkg=$(echo $i | awk -F "/" '{print $3}'); egrep "${pkg}_Tests\s*\)" -L $i; done) project_name_examples=$(for i in ^build*/examples/*/CMakeLists.txt; do pkg=$(echo $i | awk -F "/" '{print $3}'); egrep "${pkg}_Examples\s*\)" -L $i; done) project_name_demo=$(for i in ^build*/demo/*/CMakeLists.txt; do pkg=$(echo $i | awk -F "/" '{print $3}'); egrep "${pkg}_Demo\s*\)" -L $i; done) if [ -n "${project_name_tests}" ]; then echo "CMakeLists with incorrect project name" echo ${project_name_tests} exit 1 fi if [ -n "${project_name_examples}" ]; then echo "CMakeLists with incorrect project name" echo ${project_name_examples} exit 1 fi if [ -n "${project_name_demo}" ]; then echo "CMakeLists with incorrect project name" echo ${project_name_demo} exit 1 fi #check header files without SPDX license identifier echo '.. Checking SPDX license identifier presence in header files...' file_without_SPDX_identifiers=$(for pkg in `find */package_info -name 'license.txt' | awk -F "/" '{print $1}'`; do if [ -e ${pkg}/include ]; then find ${pkg}/include -type f \( -name '*.h' -o -name '*.hpp' \) | xargs -r grep -L "SPDX-License-Identifier"; fi; done) if [ -n "${file_without_SPDX_identifiers}" ]; then echo "The following files do not have a SPDX license identifier:" echo ${file_without_SPDX_identifiers} exit 1 fi #check header files without $Id$ tags echo '.. Checking $Id$ tag presence in header files...' file_without_Id_tag=$(for pkg in `find */package_info -name 'license.txt' | awk -F "/" '{print $1}'`; do if [ -e ${pkg}/include ]; then find ${pkg}/include -type f \( -name '*.h' -o -name '*.hpp' \) | xargs -r grep -L '$Id\$'; fi; done) if [ -n "${file_without_Id_tag}" ]; then echo 'The following files do not have a $Id$ tag:' echo ${file_without_Id_tag} exit 1 fi #check header files without $URL$ tags echo '.. Checking $URL$ tag presence in header files...' file_without_URL_tag=$(for pkg in `find */package_info -name 'license.txt' | awk -F "/" '{print $1}'`; do if [ -e ${pkg}/include ]; then find ${pkg}/include -type f \( -name '*.h' -o -name '*.hpp' \) | xargs -r grep -L '$URL\$'; fi; done) if [ -n "${file_without_URL_tag}" ]; then echo 'The following files do not have a $URL$:' echo ${file_without_URL_tag} exit 1 fi #check GPL header files without license include directive echo '.. Checking include directives in GPL header files...' file_without_license_include=$(for pkg in `find */package_info -name 'license.txt' | awk -F "/" '{print $1}'`; do if [ -e ${pkg}/include ]; then find ${pkg}/include -type f -name '*.h' | xargs -r egrep -l "^#\s*define\s+CGAL_.*_H\s*$" | xargs -r egrep -l "SPDX-License-Identifier.*[ (]GPL" | xargs -r grep -L "#include /dev/null 2>&1 && gzip bundle || exit 1 size=$(zstat +size bundle.gz) echo "=> $size" exit 0