Compare commits

...

3 Commits

1 changed files with 70 additions and 57 deletions

127
build.sh
View File

@ -67,6 +67,14 @@ process_arguments() {
-r|--release) -r|--release)
RELEASE=1 RELEASE=1
shift shift
if [ -z "$1" ]; then
print_usage
exit 1
fi
if [ ${1:0:1} == "-" ]; then
print_usage
exit 1
fi
VERSION_STR=$1 VERSION_STR=$1
;; ;;
*) *)
@ -85,7 +93,7 @@ COLOR_RESET="\033[0;m"
## -- cross platform helpers ## -- cross platform helpers
if [ "`echo -n`" = "-n" ]; then if [ "`echo -n`" == "-n" ]; then
n=""; c="\c" n=""; c="\c"
else else
n="-n"; c="" n="-n"; c=""
@ -109,8 +117,8 @@ check_zip() {
# check for zip # check for zip
STATUS=0 STATUS=0
command -v zip >/dev/null 2>&1 || STATUS=1 command -v zip >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "zip found" echo "zip found"
fi fi
return 0 return 0
@ -126,7 +134,7 @@ check_version_number() {
# loop condition - test format of $VERSION_STR: # loop condition - test format of $VERSION_STR:
echo "$VERSION_STR" | egrep -q "v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)?" && break; echo "$VERSION_STR" | egrep -q "v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)?" && break;
# loop test # loop test
if [ "$BATCHMODE" = 0 ]; then if [ "$BATCHMODE" == 0 ]; then
echo "${RED}Your version '$VERSION_STR' has not the correct format!${COLOR_RESET}" echo "${RED}Your version '$VERSION_STR' has not the correct format!${COLOR_RESET}"
echo $n "Please specify as Semantic Versioning ( e.g. v1.0.0 ): $c" echo $n "Please specify as Semantic Versioning ( e.g. v1.0.0 ): $c"
read VERSION_STR read VERSION_STR
@ -144,8 +152,8 @@ check_versionhistory() {
# check if $VERSION is present in doc/versionhistory.tex # check if $VERSION is present in doc/versionhistory.tex
STATUS=0 STATUS=0
grep -qs "vhEntry{$VERSION_NUM" doc/versionhistory.tex || STATUS=1 grep -qs "vhEntry{$VERSION_NUM" doc/versionhistory.tex || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM is present in versionhistory.tex." echo "Version $VERSION_NUM is present in versionhistory.tex."
fi fi
return 0 return 0
@ -160,8 +168,8 @@ check_changelog() {
# check if $VERSION is present in CHANGELOG.md # check if $VERSION is present in CHANGELOG.md
STATUS=0 STATUS=0
grep -qs "Version \[$VERSION_NUM\]" CHANGELOG.md || STATUS=1 grep -qs "Version \[$VERSION_NUM\]" CHANGELOG.md || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM is present in CHANGELOG.md." echo "Version $VERSION_NUM is present in CHANGELOG.md."
fi fi
return 0 return 0
@ -179,10 +187,10 @@ check_date() {
DATEISO_1=$(echo $LINE_1 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])') DATEISO_1=$(echo $LINE_1 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
DATEISO_2=$(echo $LINE_2 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])') DATEISO_2=$(echo $LINE_2 | egrep -o '[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])')
if [ $DATEISO_1 = $DATEISO_2 ]; then if [ $DATEISO_1 == $DATEISO_2 ]; then
# DATE=$(date "+%Y-%m-%d") # DATE=$(date "+%Y-%m-%d")
DATE="$DATEISO_1" DATE="$DATEISO_1"
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "The date $DATE was extracted from versionhistory.tex and CHANGELOG.md." echo "The date $DATE was extracted from versionhistory.tex and CHANGELOG.md."
fi fi
return 0 return 0
@ -198,8 +206,8 @@ check_url1() {
STATUS=0 STATUS=0
LINE=$(grep "\[$VERSION_NUM\]: https://" CHANGELOG.md) LINE=$(grep "\[$VERSION_NUM\]: https://" CHANGELOG.md)
echo $LINE | grep -qs "...$VERSION_STR" || STATUS=1 echo $LINE | grep -qs "...$VERSION_STR" || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Version $VERSION_NUM URL is present in CHANGELOG.md." echo "Version $VERSION_NUM URL is present in CHANGELOG.md."
fi fi
return 0 return 0
@ -215,8 +223,8 @@ check_url2() {
STATUS=0 STATUS=0
LINE=$(grep "\[Unreleased\]: https://" CHANGELOG.md) LINE=$(grep "\[Unreleased\]: https://" CHANGELOG.md)
echo $LINE | grep -qs "/$VERSION_STR..." || STATUS=1 echo $LINE | grep -qs "/$VERSION_STR..." || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "The URL for [Unreleased] was also updated in CHANGELOG.md! Thx!" echo "The URL for [Unreleased] was also updated in CHANGELOG.md! Thx!"
fi fi
return 0 return 0
@ -243,7 +251,7 @@ check_url2() {
} }
create_release() { create_release() {
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to create a release for the version $VERSION_NUM?" echo "Do you wish to create a release for the version $VERSION_NUM?"
echo $n "(y/n) $c" echo $n "(y/n) $c"
@ -260,7 +268,7 @@ create_release() {
## create backup-file und update VERSIONDATE in tikz-trackschematic.sty ## create backup-file und update VERSIONDATE in tikz-trackschematic.sty
sed -i".backup" -e"s/%\[VERSIONDATE/\[$DATE $VERSION_STR/g" src/tikz-trackschematic.sty sed -i".backup" -e"s/%\[VERSIONDATE/\[$DATE $VERSION_STR/g" src/tikz-trackschematic.sty
sedi "/%%\[SCRIPT\]/d" src/tikz-trackschematic.sty sedi "/%%\[SCRIPT\]/d" src/tikz-trackschematic.sty
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "Updated version in src/tikz-trackschematic.sty" echo "Updated version in src/tikz-trackschematic.sty"
fi fi
@ -287,7 +295,7 @@ create_release() {
mkdir $TMP/tikz-trackschematic-snippets mkdir $TMP/tikz-trackschematic-snippets
cp -R doc/examples/* $TMP/tikz-trackschematic-examples/ cp -R doc/examples/* $TMP/tikz-trackschematic-examples/
cp -R doc/snippets/* $TMP/tikz-trackschematic-snippets/ cp -R doc/snippets/* $TMP/tikz-trackschematic-snippets/
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "copied documentation" echo "copied documentation"
fi fi
@ -299,12 +307,12 @@ create_release() {
cp $SRC $TMP/ cp $SRC $TMP/
fi fi
done done
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "copied src-files" echo "copied src-files"
fi fi
# zip package # zip package
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
zip -r $RELEASE.zip $TMP/* zip -r $RELEASE.zip $TMP/*
echo "compressed the release in $RELEASE.zip" echo "compressed the release in $RELEASE.zip"
else else
@ -316,13 +324,13 @@ create_release() {
rm -rf $TMP rm -rf $TMP
# undo changes to tikz-trackschematic.sty by sed # undo changes to tikz-trackschematic.sty by sed
mv src/tikz-trackschematic.sty.backup src/tikz-trackschematic.sty mv src/tikz-trackschematic.sty.backup src/tikz-trackschematic.sty
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "clean up done!" echo "clean up done!"
fi fi
} }
create_release_notes() { create_release_notes() {
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to create a release notes for the version $VERSION_NUM?" echo "Do you wish to create a release notes for the version $VERSION_NUM?"
echo $n "(y/n) $c" echo $n "(y/n) $c"
@ -357,22 +365,22 @@ check_sudo() {
# checks if sudo is available # checks if sudo is available
rootrun="" rootrun=""
# If we are root, we do note require sudo # If we are root, we do note require sudo
if [ "$EUID" = 0 ]; then if [ "$EUID" == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "you are root" echo "you are root"
fi fi
return 0 return 0
fi fi
if sudo -v >/dev/null 2>&1; then if sudo -v >/dev/null 2>&1; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "sudo ok" echo "sudo ok"
fi fi
rootrun="sudo" rootrun="sudo"
else else
echo "sudo failed" echo "sudo failed"
# Check if user is root (might be unnecessary) # Check if user is root (might be unnecessary)
if ! [ $(id -u) = 0 ]; then if ! [ $(id -u) == 0 ]; then
echo "This script must be run as root" 1>&2 echo "This script must be run as root" 1>&2
exit 1 exit 1
fi fi
@ -384,8 +392,8 @@ check_texlive() {
STATUS=0 STATUS=0
command -v kpsewhich >/dev/null 2>&1 || STATUS=1 command -v kpsewhich >/dev/null 2>&1 || STATUS=1
command -v mktexlsr >/dev/null 2>&1 || STATUS=1 command -v mktexlsr >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "kpsewhich and mktexlsr found" echo "kpsewhich and mktexlsr found"
fi fi
TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL) TEXMFLOCAL=$(kpsewhich --var-value TEXMFLOCAL)
@ -401,8 +409,8 @@ check_pdflatex() {
# check for pdflatex # check for pdflatex
STATUS=0 STATUS=0
command -v pdflatex >/dev/null 2>&1 || STATUS=1 command -v pdflatex >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "pdflatex found" echo "pdflatex found"
fi fi
return 0 return 0
@ -420,8 +428,8 @@ check_trackschematic() {
DEVDIR="tex/latex/local/tikz-trackschematic-dev" DEVDIR="tex/latex/local/tikz-trackschematic-dev"
ls $TEXMFLOCAL/$DEVDIR/tikz-trackschematic-dev.sty >> /dev/null 2>&1 || STATUS=1 ls $TEXMFLOCAL/$DEVDIR/tikz-trackschematic-dev.sty >> /dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "tikz-trackschematic-dev found" echo "tikz-trackschematic-dev found"
fi fi
return 0 return 0
@ -436,8 +444,8 @@ check_imagemagick() {
# check for ImageMagick/compare # check for ImageMagick/compare
STATUS=0 STATUS=0
command -v compare >/dev/null 2>&1 || STATUS=1 command -v compare >/dev/null 2>&1 || STATUS=1
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "compare found" echo "compare found"
fi fi
return 0 return 0
@ -459,7 +467,7 @@ run_test_cases() {
# Start with an empty List: # Start with an empty List:
FAILED="" FAILED=""
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "===========" echo "==========="
echo "Comparison of the expected appearance with the freshly created." echo "Comparison of the expected appearance with the freshly created."
echo "-----------" echo "-----------"
@ -471,32 +479,37 @@ run_test_cases() {
NAME=${FILE%.*} # remove extension NAME=${FILE%.*} # remove extension
ADD_TO_LIST=0 ADD_TO_LIST=0
# #
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "$NAME test:" echo "$NAME test:"
fi fi
# #
# #
## TeX build ## TeX build
# #
exit_code_pdflatex=0 EXIT_CODE=0
pdflatex -output-directory=.tex -interaction=batchmode -halt-on-error ${NAME}.tex >> /dev/null 2>&1 || exit_code_pdflatex=1 /usr/bin/time -p -o .tex/${NAME}.time \
pdflatex -output-directory=.tex -interaction=batchmode -halt-on-error ${NAME}.tex >> /dev/null 2>&1 || EXIT_CODE=1
#
TIME=$(awk "NR==2" .tex/${NAME}.time | cut -d " " -f2)
# understanding TeX statistics: # understanding TeX statistics:
# -> https://tex.stackexchange.com/questions/26208/components-of-latexs-memory-usage # -> https://tex.stackexchange.com/questions/26208/components-of-latexs-memory-usage
# TOP=$(grep -n "Here is how much of TeX's memory you used:" .tex/${NAME}.log | cut -d: -f1) # TOP=$(grep -n "Here is how much of TeX's memory you used:" .tex/${NAME}.log | cut -d: -f1)
# BOTTOM=$(($(grep -n "stack positions out of" .tex/${NAME}.log | cut -d: -f1) + 1)) # BOTTOM=$(($(grep -n "stack positions out of" .tex/${NAME}.log | cut -d: -f1) + 1))
# awk "NR>$TOP&&NR<$BOTTOM" .tex/${NAME}.log > .tex/${NAME}.statistics.log # awk "NR>$TOP&&NR<$BOTTOM" .tex/${NAME}.log > .tex/${NAME}.statistics.log
memory_usage=$(grep "words of memory out of" .tex/${NAME}.log | cut -d " " -f2) MEMORY_USAGE=$(grep "words of memory out of" .tex/${NAME}.log | cut -d " " -f2)
memory_usage=$(($memory_usage/1000)) MEMORY_USAGE=$(($MEMORY_USAGE/1000))
if [ $exit_code_pdflatex = 0 ]; then if [ $EXIT_CODE == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo $n " - ${GREEN}build succesful${COLOR_RESET}: $c" echo $n " - ${GREEN}build succesful${COLOR_RESET}: $c"
echo "${memory_usage}k of memory used." echo $n "in ${TIME}s $c"
echo $n "and with $c"
echo "${MEMORY_USAGE}k of memory used."
# cat .tex/${NAME}.statistics.log # cat .tex/${NAME}.statistics.log
fi fi
else else
STATUS=1 STATUS=1
ADD_TO_LIST=1 ADD_TO_LIST=1
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${RED}build failed${COLOR_RESET}." echo " - ${RED}build failed${COLOR_RESET}."
fi fi
fi fi
@ -518,19 +531,19 @@ run_test_cases() {
# #
EXIT_CODE=0 EXIT_CODE=0
compare -metric RMSE -colorspace RGB .tex/${NAME}.pdf ${NAME}_expected.pdf NULL: >> /dev/null 2>&1 || EXIT_CODE=1 compare -metric RMSE -colorspace RGB .tex/${NAME}.pdf ${NAME}_expected.pdf NULL: >> /dev/null 2>&1 || EXIT_CODE=1
if [ $EXIT_CODE = 0 ]; then if [ $EXIT_CODE == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${GREEN}comparison succesful${COLOR_RESET}." echo " - ${GREEN}comparison succesful${COLOR_RESET}."
fi fi
else else
STATUS=1 STATUS=1
ADD_TO_LIST=1 ADD_TO_LIST=1
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo " - ${RED}comparison failed${COLOR_RESET}." echo " - ${RED}comparison failed${COLOR_RESET}."
fi fi
fi fi
## if a test failed add to list ## if a test failed add to list
if [ $ADD_TO_LIST = 1 ]; then if [ $ADD_TO_LIST == 1 ]; then
if [ -z "$FAILED" ]; then if [ -z "$FAILED" ]; then
# first item # first item
FAILED="$NAME" FAILED="$NAME"
@ -540,14 +553,14 @@ run_test_cases() {
fi fi
done done
if [ $STATUS = 0 ]; then if [ $STATUS == 0 ]; then
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "-----------" echo "-----------"
echo "${GREEN}All tests passed!${COLOR_RESET}" echo "${GREEN}All tests passed!${COLOR_RESET}"
fi fi
exit 0 exit 0
else else
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "-----------" echo "-----------"
echo "${RED}The following tests failed: ${FAILED}!${COLOR_RESET}" echo "${RED}The following tests failed: ${FAILED}!${COLOR_RESET}"
else else
@ -561,7 +574,7 @@ link_dev_files() {
# destination folder inside the TeX Live installation # destination folder inside the TeX Live installation
DEVDIR="tex/latex/local/tikz-trackschematic-dev" DEVDIR="tex/latex/local/tikz-trackschematic-dev"
PROJECTDIR=$(pwd -P) PROJECTDIR=$(pwd -P)
if [ $BATCHMODE = 0 ]; then if [ $BATCHMODE == 0 ]; then
echo "" echo ""
echo "Do you wish to link this package from" echo "Do you wish to link this package from"
echo "$PROJECTDIR/src to" echo "$PROJECTDIR/src to"
@ -590,7 +603,7 @@ link_dev_files() {
POSTFIX=${NAME#*.} POSTFIX=${NAME#*.}
EXT=${SRC##*.} EXT=${SRC##*.}
if [ "$PREFIX" = "$POSTFIX" ]; then if [ "$PREFIX" == "$POSTFIX" ]; then
DST="$PREFIX-dev.$EXT" DST="$PREFIX-dev.$EXT"
else else
DST="$PREFIX-dev.$POSTFIX.$EXT" DST="$PREFIX-dev.$POSTFIX.$EXT"
@ -598,14 +611,14 @@ link_dev_files() {
$rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/$DST $rootrun ln -sfn $PROJECTDIR/$SRC $TEXMFLOCAL/$DEVDIR/$DST
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
echo "linked '$DST'" echo "linked '$DST'"
fi fi
done done
# update TeX Live installation # update TeX Live installation
TEXlsr=`which mktexlsr` TEXlsr=`which mktexlsr`
if [ $VERBOSE = 1 ]; then if [ $VERBOSE == 1 ]; then
$rootrun $TEXlsr $rootrun $TEXlsr
else else
$rootrun $TEXlsr --quiet $rootrun $TEXlsr --quiet
@ -617,7 +630,7 @@ link_dev_files() {
process_arguments $@ process_arguments $@
## do what is requested ## do what is requested
if [ $INSTALL = 1 ]; then if [ $INSTALL == 1 ]; then
## ##
check_path check_path
check_texlive check_texlive
@ -628,7 +641,7 @@ if [ $INSTALL = 1 ]; then
fi fi
if [ $TESTING = 1 ]; then if [ $TESTING == 1 ]; then
## ##
check_path check_path
check_pdflatex check_pdflatex
@ -644,7 +657,7 @@ if [ $TESTING = 1 ]; then
fi fi
if [ $RELEASE = 1 ]; then if [ $RELEASE == 1 ]; then
#### ####
# This script produces a .zip-file in accordance to the requirements for CTAN. # This script produces a .zip-file in accordance to the requirements for CTAN.
# For more information see https://ctan.org/help/upload-pkg. # For more information see https://ctan.org/help/upload-pkg.