#!/bin/sh REPOROOT="$(git rev-parse --show-toplevel)" SCRIPTPATH="$(dirname $(readlink -f "$0"))" cd "$SCRIPTPATH" makefile=" all: service/.copyts service/.copyts: src/* bash do.sh cleansrc src service/src touch service/.copyts " shopt -s expand_aliases alias pushd="pushd &>/dev/null" alias popd="popd &>/dev/null" if [ "$1" == "compose" ]; then # ensure built service files are up to date make --file <(echo "$makefile") # forward commands to compose pushd service docker-compose ${@:2} popd elif [ "$1" == "cleansrc" ]; then if [ $# -lt 3 ]; then echo "USAGE: do.sh cleansrc " exit 0 fi # copy files src="$2" dst="$3" [ -e "$dst" ] && rm -rf "$dst" mkdir -p "$dst" cp -r "$src"/{*.c,*.h,Makefile,msgs} "$dst" # strip comments find "$dst" | while read path; do if [ -f "$path" ]; then if [ ! -z $(echo "$path" | grep '.[hc]$') ]; then sed -i -e 's/^\s*\/\*.*\*\/\s*$//g' "$path" # remove /* */ style comments sed -i -e 's/\s*\/\*.*\*\/\s*/ /g' "$path" # remove /* */ style comments sed -i -e 's/\/\/.*//g' "$path" # remove // style comments sed -i -e ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "$path" # collapse multiple newlines sed -i -e 's/fprintf(\s*stderr\s*,\s*/printf(/g' "$path" # replace fprintf stderr elif [ "$(basename "$path")" == "Makefile" ]; then sed -i -e 's/\s*#.*//g' "$path" # remove # style comments sed -i -e ':a;N;$!ba;s/\n\{3,\}/\n\n/g' "$path" # collapse multiple newlines fi fi done # apply patches if requested if [ ! -z "$PATCHED" ]; then pushd "$dst" git apply "$REPOROOT/src/patches/"*.diff popd fi elif [ "$1" == "test" ]; then SRCDIR="$PWD/src" DATADIR="$PWD/service/data" bash "tests/test.sh" ${@:2} elif [ "$1" == "make" ]; then make -C src else echo "USAGE: do.sh (compose|test|cleansrc) [args..]" echo "EXAMPLES:" echo " do.sh compose up --build # setup src and start the container" echo " do.sh test stl-upload test.stl # test the upload of STL files" echo " do.sh make # build local binary in src" echo " do.sh cleansrc # post-process source files for release" echo " # if \$PATCHED is set, patches are applied" fi