1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:37:46 +00:00

Ports: Improve and refactor build_all.sh script

All the shellcheck errors are fixed, and output will how have coloured
logs with status symbol.

	1. # -> operation completed successfully
	2. ~ -> currently processing port
	3. * -> information
	4. ! -> warning
	5. x -> error in processing port

Now, you can use the failfast option to instantly exit the loop
whenever it reports an error while processing any port. Using realpath
of the ports directory to use `cd` operation only once and get rid of
pushd-popd pattern here.
This commit is contained in:
Gurkirat Singh 2023-08-07 22:19:51 +05:30 committed by Tim Schumacher
parent 54eab251f6
commit 294a778492

View file

@ -1,89 +1,112 @@
#!/usr/bin/env bash #!/usr/bin/env bash
clean=false some_failed='false'
verbose=false action='build'
verbose='false'
failfast='false'
case "$1" in for arg in "$@"; do
clean) case "$arg" in
clean=true clean*)
action="$arg"
;; ;;
verbose) verbose)
verbose=true verbose='true'
;; ;;
*) failfast)
;; failfast='true'
esac
case "$2" in
clean)
clean=true
;;
verbose)
verbose=true
;;
*)
;; ;;
esac esac
done
some_failed=false some_failed=false
built_ports="" processed_ports=()
for file in *; do log_success() {
if [ -d $file ]; then echo -e "\033[1;32m[#]\033[0m $1"
pushd $file > /dev/null }
port=$(basename $file)
port_built=0 log_warn() {
for built_port in $built_ports; do echo -e "\033[1;33m[!]\033[0m $1"
if [ "$built_port" = "$port" ]; then }
port_built=1
break log_info() {
echo -e "\033[1;36m[*]\033[0m $1"
}
log_process() {
echo -e "\033[1m[~]\033[0m $1"
}
log_error() {
echo -e "\033[1;31m[x]\033[0m $1"
}
do_build_port() {
log_process "Building $port_name"
if $verbose; then
./package.sh
else
./package.sh &> /dev/null
fi fi
done }
if [ $port_built -eq 1 ]; then
echo "Built $port." do_clean_port() {
popd > /dev/null log_process "Cleaning $port_name"
continue if $verbose; then
./package.sh "$1"
else
./package.sh "$1" &> /dev/null
fi fi
if ! [ -f package.sh ]; then }
echo "ERROR: Skipping $port because its package.sh script is missing."
popd > /dev/null ports_dir=$(realpath "$(dirname "${BASH_SOURCE[0]}")")
while IFS= read -r -d '' port_dir; do
port_name="$(basename "$port_dir")"
if [[ " ${processed_ports[*]} " == *" $port_name "* ]]; then
log_info "$port_name is already processed"
continue continue
fi fi
if [ "$clean" == true ]; then if ! cd "$port_dir"; then
if [ "$verbose" == true ]; then log_error "Can not change directory to '$port_name'"
./package.sh clean_all exit 1
else fi
./package.sh clean_all > /dev/null 2>&1
fi if [[ ! -x ./package.sh ]]; then
fi log_warn "$port_name does not have executable package.sh"
if [ "$verbose" == true ]; then continue
if ./package.sh; then fi
echo "Built ${port}."
else case "$action" in
echo "ERROR: Build of ${port} was not successful!" clean*)
some_failed=true if do_clean_port "$action"; then
popd > /dev/null log_success "Cleaned $port_name"
continue else
fi log_error "Failed cleaning $port_name"
else some_failed='true'
if ./package.sh > /dev/null 2>&1; then if $failfast; then
echo "Built ${port}." exit 1
else fi
echo "ERROR: Build of ${port} was not successful!" fi
some_failed=true ;;
popd > /dev/null build)
continue if do_build_port; then
fi log_success "Built $port_name"
fi else
log_error "Failed building $port_name"
built_ports="$built_ports $port $(./package.sh showproperty depends) " some_failed='true'
popd > /dev/null if $failfast; then
fi exit 1
done fi
fi
if [ "$some_failed" == false ]; then ;;
exit 0 esac
else
# shellcheck disable=SC2207
processed_ports+=("$port_name" $(./package.sh showproperty depends))
done < <(find "$ports_dir" -mindepth 1 -maxdepth 1 -type d -print0 | sort -z)
if $some_failed; then
exit 1 exit 1
fi fi