Jenkins: Continuing build speed optimizations

This commit is contained in:
richardg867
2022-07-24 13:31:58 -03:00
committed by GitHub
parent d62ef9b19f
commit 63ade10a56

View File

@@ -107,6 +107,19 @@ make_tar() {
return $? return $?
} }
cache_dir="$HOME/86box-build-cache"
[ ! -d "$cache_dir" ] && mkdir -p "$cache_dir"
check_buildtag() {
[ -z "$BUILD_TAG" -o "$BUILD_TAG" != "$(cat "$cache_dir/buildtag.$1" 2> /dev/null)" ]
return $?
}
save_buildtag() {
local contents="$BUILD_TAG"
[ -n "$2" ] && local contents="$2"
echo "$contents" > "$cache_dir/buildtag.$1"
return $?
}
# Set common variables. # Set common variables.
project=86Box project=86Box
cwd=$(pwd) cwd=$(pwd)
@@ -220,8 +233,6 @@ esac
# Perform platform-specific setup. # Perform platform-specific setup.
strip_binary=strip strip_binary=strip
cache_dir="$HOME/86box-build-cache"
[ ! -d "$cache_dir" ] && mkdir -p "$cache_dir"
if is_windows if is_windows
then then
# Switch into the correct MSYSTEM if required. # Switch into the correct MSYSTEM if required.
@@ -248,26 +259,34 @@ then
# Install dependencies only if we're in a new build and/or architecture. # Install dependencies only if we're in a new build and/or architecture.
freetype_dll="$cache_dir/freetype.$MSYSTEM.dll" freetype_dll="$cache_dir/freetype.$MSYSTEM.dll"
buildtag_file="$cache_dir/buildtag.$MSYSTEM" if check_buildtag "$MSYSTEM"
if [ -z "$BUILD_TAG" -o "$(cat "$buildtag_file" 2> /dev/null)" != "$BUILD_TAG" ]
then then
# Update keyring, as the package signing keys sometimes change. # Update databases and keyring only if we're in a new build.
if check_buildtag pacmansync
then
# Update keyring as well, since the package signing keys sometimes change.
echo [-] Updating package databases and keyring echo [-] Updating package databases and keyring
yes | pacman -Sy --needed msys2-keyring yes | pacman -Sy --needed msys2-keyring
# Save build tag to skip pacman sync/keyring later.
save_buildtag pacmansync
else
echo [-] Not updating package databases and keyring again
fi
# Query installed packages. # Query installed packages.
pacman -Qe > pacman.txt pacman -Qe > "$cache_dir/pacman.txt"
# Download the specified versions of architecture-specific dependencies. # Download the specified versions of architecture-specific dependencies.
echo -n [-] Downloading dependencies: echo -n [-] Downloading dependencies:
pkg_dir="/var/cache/pacman/pkg" pkg_dir="/var/cache/pacman/pkg"
repo_base="https://repo.msys2.org/mingw/$(echo $MSYSTEM | tr '[:upper:]' '[:lower:]')" repo_base="https://repo.msys2.org/mingw/$(echo $MSYSTEM | tr '[:upper:]' '[:lower:]')"
cat .ci/dependencies_msys.txt | tr -d '\r' > deps.txt cat .ci/dependencies_msys.txt | tr -d '\r' > "$cache_dir/deps.txt"
pkgs="" pkgs=""
while IFS=" " read pkg version while IFS=" " read pkg version
do do
prefixed_pkg="$MINGW_PACKAGE_PREFIX-$pkg" prefixed_pkg="$MINGW_PACKAGE_PREFIX-$pkg"
installed_version=$(grep -E "^$prefixed_pkg " pacman.txt | cut -d " " -f 2) installed_version=$(grep -E "^$prefixed_pkg " "$cache_dir/pacman.txt" | cut -d " " -f 2)
if [ "$installed_version" != "$version" ] # installed_version will be empty if not installed if [ "$installed_version" != "$version" ] # installed_version will be empty if not installed
then then
echo -n " [$pkg" echo -n " [$pkg"
@@ -310,7 +329,7 @@ then
fi fi
echo -n "]" echo -n "]"
fi fi
done < deps.txt done < "$cache_dir/deps.txt"
[ -z "$pkgs" ] && echo -n ' none required' [ -z "$pkgs" ] && echo -n ' none required'
echo echo
@@ -331,7 +350,7 @@ then
popd popd
# Query installed packages again. # Query installed packages again.
pacman -Qe > pacman.txt pacman -Qe > "$cache_dir/pacman.txt"
fi fi
# Install the latest versions for any missing packages (if the specified version couldn't be installed). # Install the latest versions for any missing packages (if the specified version couldn't be installed).
@@ -339,9 +358,9 @@ then
while IFS=" " read pkg version while IFS=" " read pkg version
do do
prefixed_pkg="$MINGW_PACKAGE_PREFIX-$pkg" prefixed_pkg="$MINGW_PACKAGE_PREFIX-$pkg"
grep -qE "^$prefixed_pkg " pacman.txt || pkgs="$pkgs $prefixed_pkg" grep -qE "^$prefixed_pkg " "$cache_dir/pacman.txt" || pkgs="$pkgs $prefixed_pkg"
done < deps.txt done < "$cache_dir/deps.txt"
rm -f pacman.txt deps.txt rm -f "$cache_dir/pacman.txt" "$cache_dir/deps.txt"
yes | pacman -S --needed $pkgs yes | pacman -S --needed $pkgs
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
@@ -357,7 +376,7 @@ then
# Save build tag to skip this later. Doing it here (once everything is # Save build tag to skip this later. Doing it here (once everything is
# in place) is important to avoid potential issues with retried builds. # in place) is important to avoid potential issues with retried builds.
echo "$BUILD_TAG" > "$buildtag_file" save_buildtag "$MSYSTEM"
else else
echo [-] Not installing dependencies again echo [-] Not installing dependencies again
fi fi
@@ -408,18 +427,18 @@ then
echo [-] Merging app bundles [$merge_src] and [$arch_universal] into [$merge_dest] echo [-] Merging app bundles [$merge_src] and [$arch_universal] into [$merge_dest]
# Merge directory structures. # Merge directory structures.
(cd "archive_tmp_universal/$merge_src.app" && find . -type d && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type d && cd ../..) | sort > universal_listing.txt (cd "archive_tmp_universal/$merge_src.app" && find . -type d && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type d && cd ../..) | sort > "$cache_dir/universal_listing.txt"
cat universal_listing.txt | uniq | while IFS= read line cat "$cache_dir/universal_listing.txt" | uniq | while IFS= read line
do do
echo "> Directory: $line" echo "> Directory: $line"
mkdir -p "archive_tmp_universal/$merge_dest.app/$line" mkdir -p "archive_tmp_universal/$merge_dest.app/$line"
done done
# Create merged file listing. # Create merged file listing.
(cd "archive_tmp_universal/$merge_src.app" && find . -type f && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type f && cd ../..) | sort > universal_listing.txt (cd "archive_tmp_universal/$merge_src.app" && find . -type f && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type f && cd ../..) | sort > "$cache_dir/universal_listing.txt"
# Copy files that only exist on one bundle. # Copy files that only exist on one bundle.
cat universal_listing.txt | uniq -u | while IFS= read line cat "$cache_dir/universal_listing.txt" | uniq -u | while IFS= read line
do do
if [ -e "archive_tmp_universal/$merge_src.app/$line" ] if [ -e "archive_tmp_universal/$merge_src.app/$line" ]
then then
@@ -432,7 +451,7 @@ then
done done
# Copy or lipo files that exist on both bundles. # Copy or lipo files that exist on both bundles.
cat universal_listing.txt | uniq -d | while IFS= read line cat "$cache_dir/universal_listing.txt" | uniq -d | while IFS= read line
do do
if cmp -s "archive_tmp_universal/$merge_src.app/$line" "archive_tmp_universal/$arch_universal.app/$line" if cmp -s "archive_tmp_universal/$merge_src.app/$line" "archive_tmp_universal/$arch_universal.app/$line"
then then
@@ -448,8 +467,8 @@ then
done done
# Merge symlinks. # Merge symlinks.
(cd "archive_tmp_universal/$merge_src.app" && find . -type l && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type l && cd ../..) | sort > universal_listing.txt (cd "archive_tmp_universal/$merge_src.app" && find . -type l && cd "../../archive_tmp_universal/$arch_universal.app" && find . -type l && cd ../..) | sort > "$cache_dir/universal_listing.txt"
cat universal_listing.txt | uniq | while IFS= read line cat "$cache_dir/universal_listing.txt" | uniq | while IFS= read line
do do
# Get symlink destinations. # Get symlink destinations.
other_link_dest= other_link_dest=
@@ -544,8 +563,7 @@ then
export PATH="$macports/bin:$macports/sbin:$macports/libexec/qt5/bin:$PATH" export PATH="$macports/bin:$macports/sbin:$macports/libexec/qt5/bin:$PATH"
# Install dependencies only if we're in a new build and/or architecture. # Install dependencies only if we're in a new build and/or architecture.
buildtag_file="$cache_dir/buildtag.$(arch)" if check_buildtag "$(arch)"
if [ -z "$BUILD_TAG" -o "$(cat "$buildtag_file" 2> /dev/null)" != "$BUILD_TAG" ]
then then
# Install dependencies. # Install dependencies.
echo [-] Installing dependencies through MacPorts echo [-] Installing dependencies through MacPorts
@@ -554,7 +572,7 @@ then
# Save build tag to skip this later. Doing it here (once everything is # Save build tag to skip this later. Doing it here (once everything is
# in place) is important to avoid potential issues with retried builds. # in place) is important to avoid potential issues with retried builds.
echo "$BUILD_TAG" > "$buildtag_file" save_buildtag "$(arch)"
else else
echo [-] Not installing dependencies again echo [-] Not installing dependencies again
@@ -572,7 +590,6 @@ else
esac esac
# Establish general dependencies. # Establish general dependencies.
buildtag_aptupdate_file="$cache_dir/buildtag.aptupdate"
pkgs="cmake ninja-build pkg-config git wget p7zip-full wayland-protocols tar gzip file appstream" pkgs="cmake ninja-build pkg-config git wget p7zip-full wayland-protocols tar gzip file appstream"
if [ "$(dpkg --print-architecture)" = "$arch_deb" ] if [ "$(dpkg --print-architecture)" = "$arch_deb" ]
then then
@@ -584,7 +601,7 @@ else
sudo dpkg --add-architecture "$arch_deb" sudo dpkg --add-architecture "$arch_deb"
# Force an apt-get update. # Force an apt-get update.
rm -f "$buildtag_aptupdate_file" save_buildtag aptupdate "arch_$arch_deb"
fi fi
pkgs="$pkgs crossbuild-essential-$arch_deb" pkgs="$pkgs crossbuild-essential-$arch_deb"
@@ -645,25 +662,24 @@ EOF
strip_binary="$arch_triplet-strip" strip_binary="$arch_triplet-strip"
# Install dependencies only if we're in a new build and/or architecture. # Install dependencies only if we're in a new build and/or architecture.
buildtag_file="$cache_dir/buildtag.$arch_deb" if check_buildtag "$arch_deb"
if [ -z "$BUILD_TAG" -o "$(cat "$buildtag_file" 2> /dev/null)" != "$BUILD_TAG" ]
then then
# Install or update dependencies. # Install or update dependencies.
echo [-] Installing dependencies through apt echo [-] Installing dependencies through apt
if [ -z "$BUILD_TAG" -o "$(cat "$buildtag_aptupdate_file" 2> /dev/null)" != "$BUILD_TAG" ] if check_buildtag aptupdate
then then
sudo apt-get update sudo apt-get update
# Save build tag to skip apt-get update later, unless a new architecture # Save build tag to skip apt-get update later, unless a new architecture
# is added to dpkg, in which case, this saved tag file gets removed. # is added to dpkg, in which case, this saved tag file gets replaced.
echo "$BUILD_TAG" > "$buildtag_aptupdate_file" save_buildtag aptupdate
fi fi
DEBIAN_FRONTEND=noninteractive sudo apt-get -y install $pkgs $libpkgs DEBIAN_FRONTEND=noninteractive sudo apt-get -y install $pkgs $libpkgs
sudo apt-get clean sudo apt-get clean
# Save build tag to skip this later. Doing it here (once everything is # Save build tag to skip this later. Doing it here (once everything is
# in place) is important to avoid potential issues with retried builds. # in place) is important to avoid potential issues with retried builds.
echo "$BUILD_TAG" > "$buildtag_file" save_buildtag "$arch_deb"
else else
echo [-] Not installing dependencies again echo [-] Not installing dependencies again
fi fi
@@ -724,8 +740,7 @@ fi
# Download Discord Game SDK from their CDN if we're in a new build. # Download Discord Game SDK from their CDN if we're in a new build.
discord_zip="$cache_dir/discord_game_sdk.zip" discord_zip="$cache_dir/discord_game_sdk.zip"
buildtag_file="$cache_dir/buildtag.any" if check_buildtag discord
if [ -z "$BUILD_TAG" -o "$(cat "$buildtag_file" 2> /dev/null)" != "$BUILD_TAG" ]
then then
# Download file. # Download file.
echo [-] Downloading Discord Game SDK echo [-] Downloading Discord Game SDK
@@ -738,7 +753,7 @@ then
else else
# Save build tag to skip this later. Doing it here (once everything is # Save build tag to skip this later. Doing it here (once everything is
# in place) is important to avoid potential issues with retried builds. # in place) is important to avoid potential issues with retried builds.
echo "$BUILD_TAG" > "$buildtag_file" save_buildtag discord
fi fi
else else
echo [-] Not downloading Discord Game SDK again echo [-] Not downloading Discord Game SDK again