From 1d1af807e4f26f3bed5946751d9692553a78ea05 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 15 Mar 2023 09:24:52 -0500 Subject: [PATCH] ci: Respect FDO_CI_CONCURRENT. Avoid oversubscribing shared runners. --- .gitlab-ci.yml | 112 ++++++++++++++++------------------ .gitlab-ci/ci-cmake-build.sh | 10 +++ .gitlab-ci/ci-gradle-build.sh | 13 ++++ .gitlab-ci/ci.template | 15 ++--- .gitlab-ci/prebuild.sh | 22 +++++++ 5 files changed, 103 insertions(+), 69 deletions(-) create mode 100755 .gitlab-ci/ci-cmake-build.sh create mode 100755 .gitlab-ci/ci-gradle-build.sh create mode 100755 .gitlab-ci/prebuild.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 45297a2ba..00a6eba85 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ # SPDX-License-Identifier: CC0-1.0 -# SPDX-FileCopyrightText: 2018-2022 Collabora, Ltd. and the Monado contributors +# SPDX-FileCopyrightText: 2018-2023 Collabora, Ltd. and the Monado contributors ###################################### # GENERATED - DO NOT EDIT # @@ -85,7 +85,7 @@ debian:bullseye:container_prep: - .gitlab-ci/**/* variables: FDO_DISTRIBUTION_PACKAGES: 'build-essential ca-certificates clang-format cmake codespell curl debhelper devscripts doxygen dput-ng gettext-base git glslang-tools graphviz libavcodec-dev libbluetooth-dev libbsd-dev libcjson-dev libdbus-1-dev libegl1-mesa-dev libeigen3-dev libgl1-mesa-dev libglvnd-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libhidapi-dev libopencv-dev libsdl2-dev libsystemd-dev libudev-dev libusb-1.0-0-dev libuvc-dev libv4l-dev libvulkan-dev libwayland-dev libx11-dev libx11-xcb-dev libxcb-randr0-dev libxrandr-dev libxxf86vm-dev ninja-build pandoc patch pkg-config python3 python3-click python3-pip unzip wget' - FDO_DISTRIBUTION_EXEC: 'bash .gitlab-ci/i386_and_proclamation_container_prep.sh' + FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/i386_and_proclamation_container_prep.sh' # Make Debian bullseye-ndk image debian:bullseye-ndk:container_prep: @@ -98,7 +98,7 @@ debian:bullseye-ndk:container_prep: - .gitlab-ci/**/* variables: FDO_DISTRIBUTION_PACKAGES: 'ca-certificates cmake default-jdk-headless git glslang-tools libeigen3-dev meson ninja-build pkg-config python3 unzip wget' - FDO_DISTRIBUTION_EXEC: 'bash .gitlab-ci/android_container_prep.sh' + FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/android_container_prep.sh' # Make Ubuntu focal image ubuntu:focal:container_prep: @@ -135,7 +135,7 @@ arch:rolling:container_prep: - .gitlab-ci/**/* variables: FDO_DISTRIBUTION_PACKAGES: 'base-devel bc bluez-libs boost check clang cmake diffutils doxygen eigen ffmpeg fmt gcc git glew glfw-x11 glslang glu graphviz gtest gtk3 hidapi libbsd libusb libxrandr mesa meson ninja opencv patch pipewire-jack pkgconfig python-attrs python-setuptools python3 qt5-base v4l-utils vulkan-headers vulkan-icd-loader wayland wget wireplumber' - FDO_DISTRIBUTION_EXEC: 'bash .gitlab-ci/install-arch-additional-deps.sh' + FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/install-arch-additional-deps.sh' ### # Container usage base jobs @@ -285,10 +285,9 @@ debian:cmake: - popd script: - - rm -rf build - - cmake -GNinja -B build -S . - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh - cd build && ctest --output-on-failure artifacts: paths: @@ -299,10 +298,9 @@ debian:cmake-no-opencv: extends: - .monado.image.debian:bullseye script: - - rm -rf build - - cmake -GNinja -B build -S . -DBUILD_DOC=OFF -DXRT_HAVE_OPENCV=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DBUILD_DOC=OFF -DXRT_HAVE_OPENCV=OFF - cd build && ctest --output-on-failure debian:cmake-no-sdl2: @@ -310,10 +308,9 @@ debian:cmake-no-sdl2: extends: - .monado.image.debian:bullseye script: - - rm -rf build - - cmake -GNinja -B build -S . -DBUILD_DOC=OFF -DXRT_HAVE_SDL2=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DBUILD_DOC=OFF -DXRT_HAVE_SDL2=OFF - cd build && ctest --output-on-failure debian:cmake-no-service: @@ -321,10 +318,9 @@ debian:cmake-no-service: extends: - .monado.image.debian:bullseye script: - - rm -rf build - - cmake -GNinja -B build -S . -DBUILD_DOC=OFF -DXRT_FEATURE_SERVICE=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DBUILD_DOC=OFF -DXRT_FEATURE_SERVICE=OFF - cd build && ctest --output-on-failure debian:cmake:32bit: @@ -332,10 +328,9 @@ debian:cmake:32bit: extends: - .monado.image.debian:bullseye script: - - rm -rf build - - cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE=.gitlab-ci/i386.cmake -DXRT_HAVE_OPENCV=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DCMAKE_TOOLCHAIN_FILE=.gitlab-ci/i386.cmake -DXRT_HAVE_OPENCV=OFF - cd build && ctest --output-on-failure ndk:armeabi-v7a: @@ -343,20 +338,18 @@ ndk:armeabi-v7a: extends: - .monado.image.debian:bullseye-ndk script: - - rm -rf build - - cmake -GNinja -B build -S . -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=26 -DBUILD_DOC=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake -DEigen3_DIR=/usr/lib/cmake/eigen3/ -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3 - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DANDROID_ABI=armeabi-v7a -DANDROID_PLATFORM=26 -DBUILD_DOC=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake -DEigen3_DIR=/usr/lib/cmake/eigen3/ -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3 ndk:arm64-v8a: stage: build extends: - .monado.image.debian:bullseye-ndk script: - - rm -rf build - - cmake -GNinja -B build -S . -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=26 -DBUILD_DOC=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake -DEigen3_DIR=/usr/lib/cmake/eigen3/ -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3 - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=26 -DBUILD_DOC=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/android-ndk/build/cmake/android.toolchain.cmake -DEigen3_DIR=/usr/lib/cmake/eigen3/ -DEIGEN3_INCLUDE_DIR=/usr/include/eigen3 android:outOfProcessDebug: stage: build @@ -374,9 +367,9 @@ android:outOfProcessDebug: - .gradlehome/caches script: - - cp .gitlab-ci/local.properties . - - ./gradlew clean - - ./gradlew assembleOutOfProcessDebug + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-gradle-build.sh assembleOutOfProcessDebug artifacts: paths: - src/xrt/targets/openxr_android/build/outputs/apk/outOfProcess @@ -397,9 +390,9 @@ android:inProcessDebug: - .gradlehome/caches script: - - cp .gitlab-ci/local.properties . - - ./gradlew clean - - ./gradlew assembleInProcessDebug + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-gradle-build.sh assembleInProcessDebug artifacts: paths: - src/xrt/targets/openxr_android/build/outputs/apk/inProcess @@ -420,9 +413,9 @@ android:outOfProcessRelease: - .gradlehome/caches script: - - cp .gitlab-ci/local.properties . - - ./gradlew clean - - ./gradlew assembleOutOfProcessRelease + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-gradle-build.sh assembleOutOfProcessRelease artifacts: paths: - src/xrt/targets/openxr_android/build/outputs/apk/outOfProcess @@ -443,9 +436,9 @@ android:inProcessRelease: - .gradlehome/caches script: - - cp .gitlab-ci/local.properties . - - ./gradlew clean - - ./gradlew assembleInProcessRelease + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-gradle-build.sh assembleInProcessRelease artifacts: paths: - src/xrt/targets/openxr_android/build/outputs/apk/inProcess @@ -455,10 +448,9 @@ ubuntu:focal:cmake: extends: - .monado.image.ubuntu:focal script: - - rm -rf build - - cmake -GNinja -B build -S . -DBUILD_DOC=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DBUILD_DOC=OFF - cd build && ctest --output-on-failure ubuntu:jammy:cmake: @@ -466,10 +458,9 @@ ubuntu:jammy:cmake: extends: - .monado.image.ubuntu:jammy script: - - rm -rf build - - cmake -GNinja -B build -S . -DBUILD_DOC=OFF - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DBUILD_DOC=OFF - cd build && ctest --output-on-failure arch:cmake: @@ -477,10 +468,9 @@ arch:cmake: extends: - .monado.image.arch:rolling script: - - rm -rf build - - cmake -GNinja -B build -S . - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh - cd build && ctest --output-on-failure arch:cmake:clang: @@ -488,10 +478,9 @@ arch:cmake:clang: extends: - .monado.image.arch:rolling script: - - rm -rf build - - cmake -GNinja -B build -S . -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + + - .gitlab-ci/prebuild.sh + - .gitlab-ci/ci-cmake-build.sh -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ - cd build && ctest --output-on-failure # Windows build @@ -534,6 +523,7 @@ debian:bullseye:package: - git config --global user.name Monado CI - git config --global user.email ryan.pavlik@collabora.com script: + - .gitlab-ci/prebuild.sh # Prep the source tree - git clean -dfx # Call this script to build binary and source packages. @@ -560,6 +550,7 @@ ubuntu:focal:package: - git config --global user.name Monado CI - git config --global user.email ryan.pavlik@collabora.com script: + - .gitlab-ci/prebuild.sh # Prep the source tree - git clean -dfx # Call this script to build binary and source packages. @@ -586,6 +577,7 @@ ubuntu:jammy:package: - git config --global user.name Monado CI - git config --global user.email ryan.pavlik@collabora.com script: + - .gitlab-ci/prebuild.sh # Prep the source tree - git clean -dfx # Call this script to build binary and source packages. diff --git a/.gitlab-ci/ci-cmake-build.sh b/.gitlab-ci/ci-cmake-build.sh new file mode 100755 index 000000000..b56b2e74a --- /dev/null +++ b/.gitlab-ci/ci-cmake-build.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2018-2022 Collabora, Ltd. and the Monado contributors +set -e +set -x + +rm -rf build +cmake -GNinja -B build -S . "$@" +echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt +ninja -C build diff --git a/.gitlab-ci/ci-gradle-build.sh b/.gitlab-ci/ci-gradle-build.sh new file mode 100755 index 000000000..035b9fdb7 --- /dev/null +++ b/.gitlab-ci/ci-gradle-build.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: CC0-1.0 +# SPDX-FileCopyrightText: 2018-2022 Collabora, Ltd. and the Monado contributors +set -e + +MAX_WORKERS="${FDO_CI_CONCURRENT:-4}" + +export GRADLE_ARGS="-Porg.gradle.daemon=false " + +set -x +cp .gitlab-ci/local.properties . +./gradlew clean +./gradlew --max-workers "$MAX_WORKERS" "$@" diff --git a/.gitlab-ci/ci.template b/.gitlab-ci/ci.template index 0684a2528..383f56612 100644 --- a/.gitlab-ci/ci.template +++ b/.gitlab-ci/ci.template @@ -1,5 +1,5 @@ # SPDX-License-Identifier: CC0-1.0 -# SPDX-FileCopyrightText: 2018-2022 Collabora, Ltd. and the Monado contributors +# SPDX-FileCopyrightText: 2018-2023 Collabora, Ltd. and the Monado contributors {# ignore the warning, this is actually the template to edit. #} ###################################### @@ -80,7 +80,7 @@ stages: {# Needed to be a mapping so it could be "merged" #} FDO_DISTRIBUTION_PACKAGES: '{{image.packages | sort | join(" ")}}' {% if "script" in image %} - FDO_DISTRIBUTION_EXEC: 'bash .gitlab-ci/{{image["script"]}}' + FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/{{image["script"]}}' {% endif %} {% endfor -%} {%- endfor %} @@ -166,20 +166,16 @@ reuse: script: + - .gitlab-ci/prebuild.sh {#- regular or NDK cmake builds -#} {%- if "cmake" in job.name or "ndk" in job.name %} - - rm -rf build - - cmake -GNinja -B build -S . {{- make_cmake_args(job.cmake_defines) }} - - echo "Build Options:"; grep "^XRT_" build/CMakeCache.txt - - ninja -C build + - .gitlab-ci/ci-cmake-build.sh {{- make_cmake_args(job.cmake_defines) }} {#- gradle builds -#} {%- elif "android" in job.name %} - - cp .gitlab-ci/local.properties . - - ./gradlew clean - - ./gradlew {{ job.target }} + - .gitlab-ci/ci-gradle-build.sh {{ job.target }} {%- else %} @@ -247,6 +243,7 @@ windows: - git config --global user.name {{packaging.name}} - git config --global user.email {{packaging.email}} script: + - .gitlab-ci/prebuild.sh # Prep the source tree - git clean -dfx # Call this script to build binary and source packages. diff --git a/.gitlab-ci/prebuild.sh b/.gitlab-ci/prebuild.sh new file mode 100755 index 000000000..2d77b5ee3 --- /dev/null +++ b/.gitlab-ci/prebuild.sh @@ -0,0 +1,22 @@ +#!/bin/sh +# Copyright 2020-2023, Mesa contributors +# Copyright 2020, Collabora, Ltd. +# SPDX-License-Identifier: MIT + +# From https://gitlab.freedesktop.org/mesa/mesa/-/blob/999b956ebc4c26fa0c407369e630c687ece02209/.gitlab-ci/container/container_pre_build.sh + +set -e + +# Make a wrapper script for ninja to always include the -j flags +# to avoid oversubscribing/DOS'ing the shared runners +{ + echo '#!/bin/sh -x' + # shellcheck disable=SC2016 + echo '/usr/bin/ninja -j${FDO_CI_CONCURRENT:-4} "$@"' +} > /usr/local/bin/ninja +chmod +x /usr/local/bin/ninja + + +# Set MAKEFLAGS so that all make invocations in container builds include the +# flags (doesn't apply to non-container builds, but we don't run make there) +export MAKEFLAGS="-j${FDO_CI_CONCURRENT:-4}"