From 8e2f89575093cfb8ab7227b8709036465c36e3e3 Mon Sep 17 00:00:00 2001 From: Mike Beaton Date: Wed, 18 Dec 2024 21:40:29 +0000 Subject: [PATCH] BUILD TEST ONLY --- build_duet.tool | 2 +- build_oc.tool | 2 +- efibuild.sh | 563 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 565 insertions(+), 2 deletions(-) create mode 100755 efibuild.sh diff --git a/build_duet.tool b/build_duet.tool index e3cc2c3b072..fdf5b1f98b2 100755 --- a/build_duet.tool +++ b/build_duet.tool @@ -198,5 +198,5 @@ else export SELFPKG export NO_ARCHIVES - src=$(curl -LfsS https://raw.githubusercontent.com/acidanthera/ocbuild/master/efibuild.sh) && eval "$src" || exit 1 + . ./efibuild.sh || exit 1 fi diff --git a/build_oc.tool b/build_oc.tool index 14f0be50978..6d3d67b33c9 100755 --- a/build_oc.tool +++ b/build_oc.tool @@ -395,7 +395,7 @@ export SELFPKG export NO_ARCHIVES export DISCARD_SUBMODULES -src=$(curl -LfsS https://raw.githubusercontent.com/acidanthera/ocbuild/master/efibuild.sh) && eval "$src" || exit 1 +. ./efibuild.sh || exit 1 cd Utilities/ocvalidate || exit 1 ocv_tool="" diff --git a/efibuild.sh b/efibuild.sh new file mode 100755 index 00000000000..0752ebcca9a --- /dev/null +++ b/efibuild.sh @@ -0,0 +1,563 @@ +#!/bin/bash + +unset WORKSPACE +unset PACKAGES_PATH + +BUILDDIR=$(pwd) + +if [ "$NEW_BUILDSYSTEM" = "" ]; then + NEW_BUILDSYSTEM=0 +fi + +if [ "$OFFLINE_MODE" = "" ]; then + OFFLINE_MODE=0 +fi + +is_array() +{ + # Detects if argument is an array, returns 1 on success, 0 otherwise + [ -z "$1" ] && echo 0 + if [ -n "$BASH" ]; then + declare -p "${1}" 2> /dev/null | grep 'declare \-a' >/dev/null && echo 1 + fi + echo 0 +} + +prompt() { + echo "$1" + if [ "$FORCE_INSTALL" != "1" ]; then + read -rp "Enter [Y]es to continue: " v + if [ "$v" != "Y" ] && [ "$v" != "y" ]; then + exit 1 + fi + fi +} + +setcommitauthor() { + git config user.name ocbuild + git config user.email ocbuild@acidanthera.local + git config commit.gpgsign false +} + +updaterepo() { + if [ ! -d "$2" ]; then + git clone "$1" -b "$3" --depth=1 "$2" || exit 1 + fi + pushd "$2" >/dev/null || exit 1 + git pull --rebase --autostash + if [ "$2" != "UDK" ] && [ "$(unamer)" != "Windows" ]; then + sym=$(find . -not -type d -not -path "./coreboot/*" -not -path "./UDK/*" -exec file "{}" ";" | grep CRLF) + if [ "${sym}" != "" ]; then + echo "Repository $1 named $2 contains CRLF line endings" + echo "$sym" + exit 1 + fi + fi + if [ "$2" = "UDK" ] && [ "$DISCARD_SUBMODULES" != "" ] && [ ! -f submodules.ready ]; then + setcommitauthor + for module_to_discard in "${DISCARD_SUBMODULES[@]}" ; do + git rm "${module_to_discard}" + done + git commit -m "Discarded submodules" + touch submodules.ready + fi + git submodule update --init --recommend-shallow || exit 1 + popd >/dev/null || exit 1 +} + +abortbuild() { + echo "Build failed!" + tail -120 build.log + exit 1 +} + +pingme() { + local timeout=200 # in 30s + local count=0 + local cmd_pid=$1 + shift + + while [ $count -lt $timeout ]; do + count=$(( count + 1 )) + printf "." + sleep 30 + done + + ## ShellCheck Exception(s) + ## https://github.com/koalaman/shellcheck/wiki/SC2028 + ## https://github.com/koalaman/shellcheck/wiki/SC2145 + # shellcheck disable=SC2028,SC2145 + echo "\n\033[31;1mTimeout reached. Terminating $@.\033[0m" + kill -9 "${cmd_pid}" +} + +buildme() { + local cmd_pid + local mon_pid + local result + + build "$@" &>build.log & + cmd_pid=$! + + pingme $! build "$@" & + mon_pid=$! + + ## ShellCheck Exception(s) + ## https://github.com/koalaman/shellcheck/wiki/SC2069 + # shellcheck disable=SC2069 + { wait $cmd_pid 2>/dev/null; result=$?; ps -p$mon_pid 2>&1>/dev/null && kill $mon_pid; } || return 1 + return $result +} + +symlink() { + if [ "$(unamer)" = "Windows" ]; then + # This requires extra permissions. + # cmd <<< "mklink /D \"$2\" \"${1//\//\\}\"" > /dev/null + rm -rf "$2" + mkdir -p "$2" || exit 1 + for i in "$1"/* ; do + if [ "$(echo "${i}" | grep "$(basename "$(pwd)")")" != "" ]; then + continue + fi + cp -r "$i" "$2" || exit 1 + done + elif [ ! -d "$2" ]; then + ln -s "$1" "$2" || exit 1 + fi +} + +unamer() { + NAME="$(uname)" + + if [ "$(echo "${NAME}" | grep MINGW)" != "" ] || [ "$(echo "${NAME}" | grep MSYS)" != "" ]; then + echo "Windows" + else + echo "${NAME}" + fi +} + +echo "Building on $(unamer)" + +if [ "$(unamer)" = "Windows" ]; then + cmd <<< 'chcp 437' + export PYTHON_COMMAND="python" +fi + +if [ "${SELFPKG}" = "" ]; then + echo "You are required to set SELFPKG variable!" + exit 1 +fi + +if [ "${SELFPKG_DIR}" = "" ]; then + SELFPKG_DIR="${SELFPKG}" +fi + +if [ "${BUILDDIR}" != "$(printf "%s\n" "${BUILDDIR}")" ] ; then + echo "EDK2 build system may still fail to support directories with spaces!" + exit 1 +fi + +if [ "$(which git)" = "" ]; then + echo "Missing git, please install it!" + exit 1 +fi + +if [ "$(which zip)" = "" ]; then + echo "Missing zip, please install it!" + exit 1 +fi + +if [ "$(unamer)" = "Darwin" ]; then + if [ "$(which clang)" = "" ] || [ "$(clang -v 2>&1 | grep "no developer")" != "" ] || [ "$(git -v 2>&1 | grep "no developer")" != "" ]; then + echo "Missing Xcode tools, please install them!" + exit 1 + fi +fi + +# On Windows nasm and python may not be in PATH. +if [ "$(unamer)" = "Windows" ]; then + export PATH="/c/Python38:$PATH:/c/Program Files/NASM:/c/tools/ASL" +fi + +if [ "$(nasm -v)" = "" ] || [ "$(nasm -v | grep Apple)" != "" ]; then + echo "Missing or incompatible nasm!" + echo "Download the latest nasm from http://www.nasm.us/pub/nasm/releasebuilds" + echo "Current PATH: $PATH -- $(which nasm)" + # On Darwin we can install prebuilt nasm. On Linux let users handle it. + if [ "$(unamer)" = "Darwin" ]; then + prompt "Install last tested version automatically?" + else + exit 1 + fi + pushd /tmp >/dev/null || exit 1 + rm -rf nasm-mac64.zip + curl -OL "https://github.com/acidanthera/ocbuild/raw/master/external/nasm-mac64.zip" || exit 1 + nasmzip=$(cat nasm-mac64.zip) + rm -rf nasm-* + curl -OL "https://github.com/acidanthera/ocbuild/raw/master/external/${nasmzip}" || exit 1 + unzip -q "${nasmzip}" nasm*/nasm nasm*/ndisasm || exit 1 + sudo mkdir -p /usr/local/bin || exit 1 + sudo mv nasm*/nasm /usr/local/bin/ || exit 1 + sudo mv nasm*/ndisasm /usr/local/bin/ || exit 1 + rm -rf "${nasmzip}" nasm-* + popd >/dev/null || exit 1 +fi + +if [ "$(iasl -v)" = "" ]; then + echo "Missing iasl!" + echo "Download the latest iasl from https://acpica.org/downloads" + # On Darwin we can install prebuilt iasl. On Linux let users handle it. + if [ "$(unamer)" = "Darwin" ]; then + prompt "Install last tested version automatically?" + else + exit 1 + fi + pushd /tmp >/dev/null || exit 1 + rm -rf iasl-macosx.zip + curl -OL "https://github.com/acidanthera/ocbuild/raw/master/external/iasl-macosx.zip" || exit 1 + iaslzip=$(cat iasl-macosx.zip) + rm -rf iasl + curl -OL "https://github.com/acidanthera/ocbuild/raw/master/external/${iaslzip}" || exit 1 + unzip -q "${iaslzip}" iasl || exit 1 + sudo mkdir -p /usr/local/bin || exit 1 + sudo mv iasl /usr/local/bin/ || exit 1 + rm -rf "${iaslzip}" iasl + popd >/dev/null || exit 1 +fi + +# On Darwin we need mtoc. Only for XCODE5, but do not care for now. +if [ "$(unamer)" = "Darwin" ]; then + valid_mtoc=false +else + valid_mtoc=true +fi + +MTOC_LATEST_VERSION="1.0.3" + +if [ "$(which mtoc)" != "" ]; then + mtoc_version=$(mtoc --version) + if [ "${mtoc_version}" = "${MTOC_LATEST_VERSION}" ]; then + valid_mtoc=true + elif [ "${IGNORE_MTOC_VERSION}" = "1" ]; then + echo "Forcing the use of UNKNOWN mtoc version due to IGNORE_MTOC_VERSION=1" + valid_mtoc=true + else + echo "Found incompatible mtoc installed to $(which mtoc)!" + echo "Expected version: ${MTOC_LATEST_VERSION}" + echo "Found version: ${mtoc_version}" + echo "Hint: Reinstall this mtoc or use IGNORE_MTOC_VERSION=1 at your own risk." + fi +fi + +if ! $valid_mtoc; then + echo "Missing or incompatible mtoc!" + echo "To build mtoc follow: https://github.com/acidanthera/ocmtoc" + prompt "Install prebuilt mtoc automatically?" + pushd /tmp >/dev/null || exit 1 + rm -f mtoc ocmtoc-${MTOC_LATEST_VERSION}-RELEASE.zip + curl -OL "https://github.com/acidanthera/ocmtoc/releases/download/${MTOC_LATEST_VERSION}/ocmtoc-${MTOC_LATEST_VERSION}-RELEASE.zip" || exit 1 + unzip -q "ocmtoc-${MTOC_LATEST_VERSION}-RELEASE.zip" mtoc || exit 1 + sudo mkdir -p /usr/local/bin || exit 1 + sudo rm -f /usr/local/bin/mtoc /usr/local/bin/mtoc.NEW || exit 1 + sudo cp mtoc /usr/local/bin/mtoc || exit 1 + popd >/dev/null || exit 1 + + mtoc_version=$(mtoc --version) + if [ "${mtoc_version}" != "${MTOC_LATEST_VERSION}" ]; then + echo "Failed to install a compatible version of mtoc!" + echo "Expected version: ${MTOC_LATEST_VERSION}" + echo "Found version: ${mtoc_version}" + exit 1 + fi +fi + +if [ "$RELPKG" = "" ]; then + RELPKG="$SELFPKG" +fi + +if [ -n "$ARCHS" ] && [ "$(is_array ARCHS)" = "0" ]; then + IFS=', ' read -r -a ARCHS <<< "$ARCHS" +fi + +if [ -n "$ARCHS_EXT" ] && [ "$(is_array ARCHS_EXT)" = "0" ]; then + IFS=', ' read -r -a ARCHS_EXT <<< "$ARCHS_EXT" +fi + +if [ -n "$TOOLCHAINS" ] && [ "$(is_array TOOLCHAINS)" = "0" ]; then + IFS=', ' read -r -a TOOLCHAINS <<< "$TOOLCHAINS" +fi + +if [ -n "$TARGETS" ] && [ "$(is_array TARGETS)" = "0" ]; then + IFS=', ' read -r -a TARGETS <<< "$TARGETS" +fi + +if [ -n "$RTARGETS" ] && [ "$(is_array RTARGETS)" = "0" ]; then + IFS=', ' read -r -a RTARGETS <<< "$RTARGETS" +fi + +if [ -n "$BUILD_ARGUMENTS" ] && [ "$(is_array BUILD_ARGUMENTS)" = "0" ]; then + IFS=', ' read -r -a BUILD_ARGUMENTS <<< "$BUILD_ARGUMENTS" +fi + +if [ "${ARCHS[*]}" = "" ]; then + ARCHS=('X64') +fi + +if [ "${TOOLCHAINS[*]}" = "" ]; then + if [ "$(unamer)" = "Darwin" ]; then + TOOLCHAINS=('XCODE5') + elif [ "$(unamer)" = "Windows" ]; then + TOOLCHAINS=('VS2019') + else + TOOLCHAINS=('CLANGPDB' 'GCC') + fi +fi + +if [ "${TARGETS[*]}" = "" ]; then + TARGETS=('DEBUG' 'RELEASE' 'NOOPT') +elif [ "${RTARGETS[*]}" = "" ]; then + RTARGETS=("${TARGETS[@]}") +fi + +if [ "${RTARGETS[*]}" = "" ]; then + RTARGETS=('DEBUG' 'RELEASE') +fi + +if [ "${BUILD_ARGUMENTS[*]}" = "" ]; then + BUILD_ARGUMENTS=() +fi + +if [ -z "${SKIP_TESTS}" ]; then + SKIP_TESTS=0 +fi +if [ -z "${SKIP_BUILD}" ]; then + SKIP_BUILD=0 +fi +if [ -z "${SKIP_PACKAGE}" ]; then + SKIP_PACKAGE=0 +fi + +MODE="" + +while true; do + if [ "$1" == "--skip-tests" ]; then + SKIP_TESTS=1 + shift + elif [ "$1" == "--skip-build" ]; then + SKIP_BUILD=1 + shift + elif [ "$1" == "--skip-package" ]; then + SKIP_PACKAGE=1 + shift + elif [ "$1" == "--build-extra" ]; then + shift + BUILD_STRING="$1" + # shellcheck disable=SC2206 + BUILD_ARGUMENTS+=($BUILD_STRING ) + shift + else + break + fi +done + +if [ "$1" != "" ]; then + MODE="$1" + shift +fi + +echo "Primary toolchain ${TOOLCHAINS[0]} and arch ${ARCHS[0]}" + +if [ ! -d "Binaries" ]; then + mkdir Binaries || exit 1 +fi + +if [ "$NEW_BUILDSYSTEM" != "1" ]; then + if [ ! -f UDK/UDK.ready ]; then + rm -rf UDK + + if [ "$(unamer)" != "Windows" ]; then + sym=$(find . -not -type d -not -path "./coreboot/*" -exec file "{}" ";" | grep CRLF) + if [ "${sym}" != "" ]; then + echo "Error: the following files in the repository have CRLF line endings:" + echo "$sym" + exit 1 + fi + fi + fi +fi + +if [ "$NEW_BUILDSYSTEM" != "1" ]; then + if [ "$OFFLINE_MODE" != "1" ]; then + updaterepo "https://github.com/acidanthera/audk" UDK static-ip || exit 1 + else + echo "Working in offline mode. Skip UDK update" + fi +fi +cd UDK || exit 1 +HASH=$(git rev-parse '@{upstream}') + +if [ "$DISCARD_PACKAGES" != "" ]; then + for package_to_discard in "${DISCARD_PACKAGES[@]}" ; do + if [ -d "${package_to_discard}" ]; then + rm -rf "${package_to_discard}" + fi + done +fi + +if [ "$NEW_BUILDSYSTEM" != "1" ]; then + if [ -d ../Patches ]; then + if [ ! -f patches.ready ]; then + setcommitauthor + for i in ../Patches/* ; do + git apply --ignore-whitespace "$i" || exit 1 + git add . + git commit -m "Applied patch $i" || exit 1 + done + touch patches.ready + fi + fi +fi + +deps="${#DEPNAMES[@]}" +for (( i=0; i