clang_build_check.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. # The GitHub workflow's clang-build job (cmake.yml) on this machine: everything built with clang/clang++ in Debug and
  3. # Release. The job runs on Ubuntu 24.04 with clang 18, whose -Werror warnings differ from newer clang's (a private field
  4. # that is never read broke the job on 7bf52ed6 and passed with clang 22 here), so by default it builds inside an Ubuntu
  5. # 24.04 rootfs with the job's own apt packages, under proot like the portable release build. Run it with the other build
  6. # variants (DISABLE_KDE_FEATURES) of a release prep, before the smoke tests and the VM matrix.
  7. #
  8. # Usage:
  9. # tools/clang_build_check.sh --setup make the rootfs (a copy of distro-rootfs/ubuntu-24.04 with clang and the
  10. # packages of the clang-build job, taken from the workflow file), once
  11. # tools/clang_build_check.sh [--host] [Release] [Debug] default: the rootfs, both types, Release first
  12. # --host builds with the clang of this machine instead (build-clang-<type>)
  13. # Build trees: build-ci-<type> (rootfs) or build-clang-<type> (host), CEF comes from the main build tree (hard links), so
  14. # nothing is downloaded. Exit code 0 when every requested type built; the log of each is <tree>/build.log.
  15. # PROOT points at the proot binary (default: proot on PATH, else ~/.local/share/arch-proot/proot).
  16. set -u
  17. ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
  18. ROOTFS_DIR=${ROOTFS_DIR:-$HOME/.local/share/distro-rootfs}
  19. CI_ROOTFS=$ROOTFS_DIR/ubuntu-24.04-ci
  20. export PROOT=${PROOT:-$(command -v proot || echo "$HOME/.local/share/arch-proot/proot")}
  21. if [ "${1:-}" = --setup ]; then
  22. [ -d "$ROOTFS_DIR/ubuntu-24.04" ] || { echo "no $ROOTFS_DIR/ubuntu-24.04, tools/distro_rootfs.sh fetch ubuntu:24.04 it first"; exit 1; }
  23. [ -d "$CI_ROOTFS" ] || cp -a "$ROOTFS_DIR/ubuntu-24.04" "$CI_ROOTFS"
  24. packages=$(awk '/^ clang-build:/ { in_job = 1 } in_job && /apt-get -y install/ { sub(/.*apt-get -y install /, ""); print; exit }' \
  25. "$ROOT/.github/workflows/cmake.yml")
  26. [ -n "$packages" ] || { echo "cannot find the clang-build job's packages in cmake.yml"; exit 1; }
  27. "$ROOT/tools/distro_rootfs.sh" run "$CI_ROOTFS" bash -c \
  28. "export DEBIAN_FRONTEND=noninteractive; apt-get update >/dev/null && apt-get -y install clang cmake make git pkg-config ccache ca-certificates $packages && clang++ --version | head -1"
  29. exit $?
  30. fi
  31. host=0
  32. types=()
  33. for argument in "$@"; do
  34. case $argument in
  35. --host) host=1 ;;
  36. *) types+=("$argument") ;;
  37. esac
  38. done
  39. [ ${#types[@]} -gt 0 ] || types=(Release Debug)
  40. jobs=${JOBS:-$(nproc)}
  41. status=0
  42. if [ $host = 0 ] && [ ! -d "$CI_ROOTFS" ]; then
  43. echo "FAIL clang build: no $CI_ROOTFS, run tools/clang_build_check.sh --setup first (or --host)"; exit 1
  44. fi
  45. for type in "${types[@]}"; do
  46. if [ $host = 1 ]; then dir=$ROOT/build-clang-$type; else dir=$ROOT/build-ci-$type; fi
  47. mkdir -p "$dir"
  48. if [ ! -e "$dir/cef" ] && [ -d "$ROOT/build/cef" ]; then
  49. cp -al "$ROOT/build/cef" "$dir/cef" 2>/dev/null || cp -a "$ROOT/build/cef" "$dir/cef"
  50. fi
  51. if [ $host = 1 ]; then
  52. label="clang $type ($(clang++ --version | head -1))"
  53. cmake -S "$ROOT" -B "$dir" -DCMAKE_BUILD_TYPE="$type" -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ \
  54. > "$dir/configure.log" 2>&1 && cmake --build "$dir" --config "$type" -j "$jobs" > "$dir/build.log" 2>&1
  55. else
  56. label="clang $type (Ubuntu 24.04 rootfs, clang 18)"
  57. BINDS="-b $ROOT:/src -b $dir:/build" "$ROOT/tools/distro_rootfs.sh" run "$CI_ROOTFS" bash -c "
  58. cmake -S /src -B /build -DCMAKE_BUILD_TYPE=$type -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ \
  59. > /build/configure.log 2>&1 && cmake --build /build --config $type -j $jobs > /build/build.log 2>&1"
  60. fi
  61. if [ $? -eq 0 ]; then
  62. echo "PASS $label: built"
  63. else
  64. echo "FAIL $label: see $dir/configure.log and $dir/build.log"
  65. grep -m5 'error:' "$dir/build.log" 2>/dev/null | cut -c1-240
  66. status=1
  67. fi
  68. done
  69. exit $status