| 1 | #!/bin/bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Extract information about unit dependencies, |
| 5 | # including implementation dependencies. |
| 6 | # Good script to keep track of dependencies between many CGE units. |
| 7 | # |
| 8 | # This can only check units it can compile. |
| 9 | # For now it assumes that it runs on a desktop Unix (like a Linux), |
| 10 | # so it omits stuff specific to Windows, Android, it also omits stuff |
| 11 | # that requires Lazarus LCL. |
| 12 | |
| 13 | CHECK_DIR=`pwd` |
| 14 | |
| 15 | # Enter CGE src dir. |
| 16 | cd "${CASTLE_ENGINE_PATH}"/src/ |
| 17 | |
| 18 | # Clean ppu/o files. |
| 19 | make clean -C ../ |
| 20 | |
| 21 | # Calculate temp file location. |
| 22 | # Work regardless if $HOME/tmp is created. |
| 23 | TMP_PAS_LIST="${CASTLE_ENGINE_PATH}/test-cge-units-dependencies_all_units.txt" |
| 24 | TMP_LOG="${CASTLE_ENGINE_PATH}/cge_check_units_dependencies.log" |
| 25 | |
| 26 | # clean previous log |
| 27 | rm -f "${TMP_LOG}" |
| 28 | echo "Logging compilation output to ${TMP_LOG}" |
| 29 | |
| 30 | echo "All units list in ${TMP_PAS_LIST}" |
| 31 | # Avoid |
| 32 | # - compatibility, to avoid https://bugs.freepascal.org/view.php?id=32192 |
| 33 | # - vampyre_imaginglib: |
| 34 | # To avoid considering DOM, XMLRead etc. (Vampyre has their copies) inside CGE. |
| 35 | # Also, some units inside may not compile without LCL. |
| 36 | # - lcl, indy as they depend on LCL, Indy and compilation with just `castle-engine simple-compile ...` may fail |
| 37 | # - deprecated_units, we don't track their dependencies |
| 38 | # - delphi, as they only compile with Delphi, as this check uses FPC later |
| 39 | find . \ |
| 40 | '(' -type d -iname android -prune ')' -or \ |
| 41 | '(' -type d -iname windows -prune ')' -or \ |
| 42 | '(' -type d -iname lcl -prune ')' -or \ |
| 43 | '(' -type d -iname delphi -prune ')' -or \ |
| 44 | '(' -type d -iname indy -prune ')' -or \ |
| 45 | '(' -type d -iname nodes_specification -prune ')' -or \ |
| 46 | '(' -type d -iname compatibility -prune ')' -or \ |
| 47 | '(' -type d -iname deprecated_units -prune ')' -or \ |
| 48 | '(' -type d -iname vampyre_imaginglib -prune ')' -or \ |
| 49 | '(' -type f -iname '*.pas' -print ')' > "${TMP_PAS_LIST}" |
| 50 | |
| 51 | SUCCESS='true' |
| 52 | |
| 53 | for F in `cat "${TMP_PAS_LIST}"`; do |
| 54 | echo "Checking dependencies of $F" |
| 55 | castle-engine simple-compile "$F" >> "${TMP_LOG}" |
| 56 | # Like `stringoper ChangeFileExt %F .ppu` |
| 57 | PPU="${F%.*}.ppu" |
| 58 | |
| 59 | # Strip directory name, |
| 60 | # and add castle-engine-output/compilation/<arch-cpu>/, |
| 61 | # because that's where "castle-engine simple-compile" places ppu now. |
| 62 | PPU="`basename \"${PPU}\"`" |
| 63 | PPU='castle-engine-output/compilation/'`fpc -iTP`-`fpc -iTO`"/${PPU}" |
| 64 | |
| 65 | DEPENDENCIES_TO_CHECK=`ppudump "$PPU" | grep 'Uses unit' | awk '{ print $3 }' | sort -u` |
| 66 | # echo 'Got dependencies:' |
| 67 | # echo "$DEPENDENCIES_TO_CHECK" |
| 68 | |
| 69 | set +e |
| 70 | "${CHECK_DIR}"/check_one_unit_dependencies "${TMP_PAS_LIST}" "$F" "$DEPENDENCIES_TO_CHECK" |
| 71 | if [ "$?" != 0 ]; then |
| 72 | echo 'check_units_dependencies.sh: Failure detected, we will continue but exit with non-zero status at the end' |
| 73 | SUCCESS='false' |
| 74 | fi |
| 75 | set +e |
| 76 | done |
| 77 | |
| 78 | if [ "${SUCCESS}" = 'false' ]; then |
| 79 | echo 'Finished, some errors detected, exiting with non-zero status. Consult the above log for details what failed.' |
| 80 | exit 1 |
| 81 | else |
| 82 | echo 'Finished, everything correct.' |
| 83 | fi |