|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | +# capture failing exits in commands obscured behind a pipe |
| 4 | +set -o pipefail |
| 5 | + |
| 6 | +if [ -z "${NO_FORCE+x}" ]; then |
| 7 | + export FORCE="-f" |
| 8 | +else |
| 9 | + export FORCE="" |
| 10 | +fi |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +# trap any script errors and exit |
| 16 | +# trap "trapError" ERR |
| 17 | + |
| 18 | +trapError() { |
| 19 | + echo |
| 20 | + echo " ^ Received error building $formula_name ^" |
| 21 | + cat "formula_${ARCH}.log" |
| 22 | + if [ "$formula_name" == "boost" ]; then |
| 23 | + cat $APOTHECARY_PATH/build/boost/bootstrap.log |
| 24 | + fi |
| 25 | + if [ -f $APOTHECARY_PATH/build/$formula_name/config.log ]; then |
| 26 | + tail -n1000 $APOTHECARY_PATH/build/$formula_name/config.log |
| 27 | + fi |
| 28 | + exit 1 |
| 29 | +} |
| 30 | + |
| 31 | +if [ "$TRAVIS" = true -o "$GITHUB_ACTIONS" = true ] && [ "$TARGET" == "emscripten" ]; then |
| 32 | + run(){ |
| 33 | + echo "TARGET=\"emscripten\" $@" |
| 34 | + docker exec -i emscripten sh -c "TARGET=\"emscripten\" $@" |
| 35 | + } |
| 36 | + |
| 37 | + run_bg(){ |
| 38 | + trap "trapError" ERR |
| 39 | + |
| 40 | + #PATH=\"$DOCKER_HOME/bin:\$PATH\" |
| 41 | + echo "TARGET=\"emscripten\" $@" |
| 42 | + docker exec -i emscripten sh -c "TARGET=\"emscripten\" $@" >> "formula_${ARCH}.log" 2>&1 & |
| 43 | + apothecaryPID=$! |
| 44 | + echoDots $apothecaryPID |
| 45 | + wait $apothecaryPID |
| 46 | + |
| 47 | + echo "Tail of log for $formula_name" |
| 48 | + run "tail -n 100 formula_${ARCH}.log" |
| 49 | + } |
| 50 | + |
| 51 | + # DOCKER_HOME=$(docker exec -i emscripten echo '$HOME') |
| 52 | + # CCACHE_DOCKER=$(docker exec -i emscripten ccache -p | grep "cache_dir =" | sed "s/(default) cache_dir = \(.*\)/\1/") |
| 53 | + ROOT=$(docker exec -i emscripten pwd) |
| 54 | + LOCAL_ROOT=$(cd $(dirname "$0"); pwd -P)/.. |
| 55 | +else |
| 56 | + run(){ |
| 57 | + echo "$@" |
| 58 | + eval "$@" |
| 59 | + } |
| 60 | + |
| 61 | + run_bg(){ |
| 62 | + trap "trapError" ERR |
| 63 | + |
| 64 | + echo "$@" |
| 65 | + eval "$@" >> "formula_${ARCH}.log" 2>&1 & |
| 66 | + apothecaryPID=$! |
| 67 | + echoDots $apothecaryPID |
| 68 | + wait $apothecaryPID |
| 69 | + |
| 70 | + echo "Tail of log for $formula_name" |
| 71 | + run "tail -n 10 formula_${ARCH}.log" |
| 72 | + } |
| 73 | + |
| 74 | + ROOT=$(cd $(dirname "$0"); pwd -P)/.. |
| 75 | + LOCAL_ROOT=$ROOT |
| 76 | +fi |
| 77 | + |
| 78 | +APOTHECARY_PATH=$ROOT/apothecary |
| 79 | + |
| 80 | +if [ -z "${OUTPUT_FOLDER+x}" ]; then |
| 81 | + export OUTPUT_FOLDER="$ROOT/out" |
| 82 | +fi |
| 83 | +#OUTPUT_FOLDER=$ROOT/out |
| 84 | + |
| 85 | + |
| 86 | +# VERBOSE=true |
| 87 | + |
| 88 | +if [ -z $TARGET ] ; then |
| 89 | + echo "Environment variable TARGET not defined. Should be target os" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +echo "Running apothecary from $PWD" |
| 94 | +echo "Target: $TARGET" |
| 95 | +echo "Architecture: $ARCH" |
| 96 | +echo "Bundle: $BUNDLE" |
| 97 | +echo "Apothecary path: $APOTHECARY_PATH" |
| 98 | +echo "Output folder is: $OUTPUT_FOLDER" |
| 99 | + |
| 100 | +# Source the calculate_formulas.sh script to get the list of formulas |
| 101 | +source $LOCAL_ROOT/scripts/calculate_formulas.sh |
| 102 | + |
| 103 | +if [ -z "$FORMULAS" ]; then |
| 104 | + echo "No formulas to build" |
| 105 | + exit 0 |
| 106 | +fi |
| 107 | + |
| 108 | +# Define the base directory where the library folders are located |
| 109 | +LIBRARY_BASE_DIR="$LOCAL_ROOT/libraries" |
| 110 | + |
| 111 | +# Create an associative array to keep track of the libraries to keep |
| 112 | +declare -A KEEP_LIBRARIES |
| 113 | +for formula in "${FORMULAS[@]}"; do |
| 114 | + formula_name="${formula%.*}" |
| 115 | + KEEP_LIBRARIES[$formula_name]=1 |
| 116 | +done |
| 117 | + |
| 118 | +# Iterate over the folders in the library base directory |
| 119 | +for library_dir in "$OUTPUT_FOLDER"/*; do |
| 120 | + library_name=$(basename "$library_dir") |
| 121 | + |
| 122 | + # Check if the library name is not in the keep list |
| 123 | + if [ -z "${KEEP_LIBRARIES[$library_name]}" ]; then |
| 124 | + echo "Deleting library folder: $library_dir" |
| 125 | + rm -rf "$library_dir" |
| 126 | + else |
| 127 | + echo "Keeping library folder: $library_dir" |
| 128 | + fi |
| 129 | +done |
| 130 | + |
| 131 | + |
| 132 | +echo "" |
| 133 | +echo "" |
0 commit comments