Skip to content

Commit

Permalink
Build scripts refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cvet committed Dec 17, 2024
1 parent c2afc3c commit 5fdd521
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 94 deletions.
8 changes: 5 additions & 3 deletions BuildTools/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ setlocal

call %~dp0\setup-env.cmd

if not exist %FO_WORKSPACE% mkdir %FO_WORKSPACE%
if not exist %FO_OUTPUT% mkdir %FO_OUTPUT%
pushd %FO_WORKSPACE%

if [%1] == [win32] (
set BUILD_ARCH=Win32
) else if [%1] == [win64] (
Expand Down Expand Up @@ -52,9 +56,6 @@ if [%3] == [] (
set CONFIG=%3
)

if not exist %FO_WORKSPACE% mkdir %FO_WORKSPACE%
cd %FO_WORKSPACE%

set BUILD_DIR=build-%1-%2-%CONFIG%
if not exist %BUILD_DIR% mkdir %BUILD_DIR%
cd %BUILD_DIR%
Expand All @@ -73,4 +74,5 @@ if not [%BUILD_TOOLSET%] == [] (
cmake --build . --config %CONFIG% --parallel
if errorlevel 1 exit /b 1

popd
exit /b
50 changes: 26 additions & 24 deletions BuildTools/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

if [[ "$1" = "" || "$2" = "" ]]; then
if [[ -z $1 || -z $2 ]]; then
echo "Provide at least two arguments"
exit 1
fi
Expand All @@ -9,36 +9,38 @@ CUR_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
source $CUR_DIR/setup-env.sh
source $CUR_DIR/internal-tools.sh

mkdir -p $FO_WORKSPACE
mkdir -p $FO_OUTPUT
pushd $FO_WORKSPACE

if [[ "$2" = "client" ]]; then
if [[ $2 = "client" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=1 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "server" ]]; then
elif [[ $2 = "server" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=1 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "single" ]]; then
elif [[ $2 = "single" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=1 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "editor" ]]; then
elif [[ $2 = "editor" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=1 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "mapper" ]]; then
elif [[ $2 = "mapper" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=1 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "ascompiler" ]]; then
elif [[ $2 = "ascompiler" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=1 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "baker" ]]; then
elif [[ $2 = "baker" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=1 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "unit-tests" ]]; then
elif [[ $2 = "unit-tests" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=1 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "code-coverage" ]]; then
elif [[ $2 = "code-coverage" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=0 -DFO_BUILD_BAKER=0 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=1"
elif [[ "$2" = "toolset" ]]; then
elif [[ $2 = "toolset" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=0 -DFO_BUILD_SERVER=0 -DFO_BUILD_SINGLE=0 -DFO_BUILD_EDITOR=0 -DFO_BUILD_MAPPER=0 -DFO_BUILD_ASCOMPILER=1 -DFO_BUILD_BAKER=1 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
elif [[ "$2" = "full" ]]; then
elif [[ $2 = "full" ]]; then
BUILD_TARGET="-DFO_BUILD_CLIENT=1 -DFO_BUILD_SERVER=1 -DFO_BUILD_SINGLE=1 -DFO_BUILD_EDITOR=1 -DFO_BUILD_MAPPER=1 -DFO_BUILD_ASCOMPILER=1 -DFO_BUILD_BAKER=1 -DFO_UNIT_TESTS=0 -DFO_CODE_COVERAGE=0"
else
echo "Invalid second command arg"
exit 1
fi

if [[ "$3" = "" ]]; then
if [[ -z $3 ]]; then
CONFIG="Release"
else
CONFIG="$3"
Expand All @@ -49,41 +51,41 @@ BUILD_DIR="build-$1-$2-$CONFIG"
mkdir -p $BUILD_DIR
cd $BUILD_DIR

rm -rf READY
rm -rf "READY"

if [[ "$1" = "linux" ]]; then
if [[ $1 = "linux" ]]; then
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++

cmake -G "Unix Makefiles" -DFO_OUTPUT_PATH="$FO_OUTPUT" $BUILD_TARGET -DCMAKE_BUILD_TYPE=$CONFIG "$FO_PROJECT_ROOT"
cmake --build . --config $CONFIG --parallel

elif [[ "$1" = "web" ]]; then
elif [[ $1 = "web" ]]; then
source $FO_WORKSPACE/emsdk/emsdk_env.sh

cmake -G "Unix Makefiles" -C "$FO_ENGINE_ROOT/BuildTools/web.cache.cmake" -DFO_OUTPUT_PATH="$FO_OUTPUT" $BUILD_TARGET -DCMAKE_BUILD_TYPE=$CONFIG "$FO_PROJECT_ROOT"
cmake --build . --config $CONFIG --parallel

elif [[ "$1" = "android" || "$1" = "android-arm64" || "$1" = "android-x86" ]]; then
if [[ "$1" = "android" ]]; then
elif [[ $1 = "android" || $1 = "android-arm64" || $1 = "android-x86" ]]; then
if [[ $1 = "android" ]]; then
export ANDROID_ABI=armeabi-v7a
elif [[ "$1" = "android-arm64" ]]; then
elif [[ $1 = "android-arm64" ]]; then
export ANDROID_ABI=arm64-v8a
elif [[ "$1" = "android-x86" ]]; then
elif [[ $1 = "android-x86" ]]; then
export ANDROID_ABI=x86
fi

cmake -G "Unix Makefiles" -C "$FO_ENGINE_ROOT/BuildTools/android.cache.cmake" -DFO_OUTPUT_PATH="$FO_OUTPUT" $BUILD_TARGET -DCMAKE_BUILD_TYPE=$CONFIG "$FO_PROJECT_ROOT"
cmake --build . --config $CONFIG --parallel

elif [[ "$1" = "mac" || "$1" = "ios" ]]; then
if [[ -x "$(command -v cmake)" ]]; then
elif [[ $1 = "mac" || $1 = "ios" ]]; then
if [[ -x $(command -v cmake) ]]; then
CMAKE=cmake
else
CMAKE=/Applications/CMake.app/Contents/bin/cmake
fi

if [[ "$1" = "mac" ]]; then
if [[ $1 = "mac" ]]; then
$CMAKE -G "Xcode" -DFO_OUTPUT_PATH="$FO_OUTPUT" $BUILD_TARGET "$FO_PROJECT_ROOT"
$CMAKE --build . --config $CONFIG --parallel
else
Expand All @@ -96,5 +98,5 @@ else
exit 1
fi

touch READY
touch "READY"
popd
6 changes: 3 additions & 3 deletions BuildTools/internal-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function wait_jobs()

function verify_workspace_part()
{
if [[ ! -f "$1-version.txt" || `cat $1-version.txt` != "$2" ]]; then
if [[ ! -f "$1-version.txt" || `cat $1-version.txt` != $2 ]]; then
if [[ ! -z `check_arg check` ]]; then
echo "Workspace is not ready"
exit 10
exit 1
fi

workspace_job()
Expand All @@ -47,7 +47,7 @@ function check_arg()
{
for i in $PROGRAM_ARGS; do
for j in $@; do
if [[ "$i" = "$j" ]]; then
if [[ $i = $j ]]; then
echo "1"
return
fi
Expand Down
13 changes: 6 additions & 7 deletions BuildTools/prepare-mac-workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ CUR_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
source $CUR_DIR/setup-env.sh
source $CUR_DIR/internal-tools.sh

while true
do
while true; do
ready=1

if [[ -z "$(xcode-select -p)" ]]; then
if [[ -z $(xcode-select -p) ]]; then
echo "Please install Xcode from AppStore"
ready=0
fi

if [[ -x "$(command -v cmake)" ]]; then
if [[ -x $(command -v cmake) ]]; then
CMAKE=cmake
else
CMAKE=/Applications/CMake.app/Contents/bin/cmake
fi
if [[ -z "$CMAKE" ]]; then
if [[ -z $CMAKE ]]; then
echo "Please install CMake from https://cmake.org"
ready=0
fi

if [[ "$ready" = "1" ]]; then
if [[ $ready = "1" ]]; then
echo "Workspace is ready!"
exit 0
elif [[ ! -z `check_arg check` ]]; then
echo "Workspace is not ready"
exit 10
exit 1
fi

read -p "..."
Expand Down
8 changes: 5 additions & 3 deletions BuildTools/prepare-workspace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

if [[ "$1" = "" ]]; then
if [[ -z $1 ]]; then
echo "Provide at least one argument"
exit 1
fi
Expand All @@ -11,6 +11,8 @@ CUR_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
source $CUR_DIR/setup-env.sh
source $CUR_DIR/internal-tools.sh

mkdir -p $FO_WORKSPACE
mkdir -p $FO_OUTPUT
pushd $FO_WORKSPACE

# All packages:
Expand Down Expand Up @@ -141,10 +143,10 @@ function setup_dotnet()

function verify_workspace_part()
{
if [[ ! -f "$1-version.txt" || `cat $1-version.txt` != "$2" ]]; then
if [[ ! -f "$1-version.txt" || `cat $1-version.txt` != $2 ]]; then
if [[ ! -z `check_arg check` ]]; then
echo "Workspace is not ready"
exit 10
exit 1
fi

workspace_job()
Expand Down
10 changes: 4 additions & 6 deletions BuildTools/setup-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

echo "Setup environment"

[[ ! -z "$FO_PROJECT_ROOT" ]] || export FO_PROJECT_ROOT="$(pwd)"
[[ ! -z "$FO_ENGINE_ROOT" ]] || export FO_ENGINE_ROOT="$(cd $(dirname ${BASH_SOURCE[0]})/../ && pwd)"
[[ ! -z "$FO_WORKSPACE" ]] || export FO_WORKSPACE=$PWD/Workspace
[[ ! -z "$FO_OUTPUT" ]] || export FO_OUTPUT=$FO_WORKSPACE/output
[[ ! -z $FO_PROJECT_ROOT ]] || export FO_PROJECT_ROOT=$PWD
[[ ! -z $FO_ENGINE_ROOT ]] || export FO_ENGINE_ROOT=$(cd $(dirname ${BASH_SOURCE[0]})/../ && pwd)
[[ ! -z $FO_WORKSPACE ]] || export FO_WORKSPACE=$PWD/Workspace
[[ ! -z $FO_OUTPUT ]] || export FO_OUTPUT=$FO_WORKSPACE/output

export FO_PROJECT_ROOT=$(cd $FO_PROJECT_ROOT; pwd)
export FO_ENGINE_ROOT=$(cd $FO_ENGINE_ROOT; pwd)
export FO_WORKSPACE=$(mkdir -p $FO_WORKSPACE; cd $FO_WORKSPACE; pwd)
export FO_OUTPUT=$(mkdir -p $FO_OUTPUT; cd $FO_OUTPUT; pwd)
export EMSCRIPTEN_VERSION=$(head -n 1 "$FO_ENGINE_ROOT/ThirdParty/emscripten")
export ANDROID_NDK_VERSION=$(head -n 1 "$FO_ENGINE_ROOT/ThirdParty/android-ndk")
export ANDROID_SDK_VERSION=$(head -n 1 "$FO_ENGINE_ROOT/ThirdParty/android-sdk")
Expand Down
14 changes: 7 additions & 7 deletions BuildTools/setup-mono.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
CUR_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
source $CUR_DIR/setup-env.sh

if [[ "$#" -ne 3 ]]; then
if [[ $# -ne 3 ]]; then
echo "Usage: setup-mono.sh <os> <arch> <config>"
exit 1
fi

TRIPLET="$1.$2.$3"

# Clone dotnet repo
if [[ ! -f CLONED ]]; then
if [[ -d runtime ]]; then
if [[ ! -f "CLONED" ]]; then
if [[ -d "runtime" ]]; then
echo "Remove previous repository"
rm -rf "runtime"
fi
Expand All @@ -26,7 +26,7 @@ if [[ ! -f CLONED ]]; then
fi
fi

touch CLONED
touch "CLONED"

# Build some configuration
if [[ ! -f "BUILT_$TRIPLET" ]]; then
Expand All @@ -41,10 +41,10 @@ touch "BUILT_$TRIPLET"

# Copy built files
copy_runtime() {
if [[ -d "$1" ]]; then
if [[ -d $1 ]]; then
echo "Copy from $1 to $2"
mkdir -p "$2"
cp -rf "$1"/* "$2"
mkdir -p $2
cp -rf "$1/*" $2
else
echo "Files not found: $1"
exit 1
Expand Down
1 change: 1 addition & 0 deletions BuildTools/toolset.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

call %~dp0\setup-env.cmd

if not exist %FO_WORKSPACE% mkdir %FO_WORKSPACE%
pushd %FO_WORKSPACE%

cd build-win64-toolset
Expand Down
1 change: 1 addition & 0 deletions BuildTools/toolset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
CUR_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
source $CUR_DIR/setup-env.sh

mkdir -p $FO_WORKSPACE
pushd $FO_WORKSPACE

if [[ -d "emsdk" ]]; then
Expand Down
1 change: 1 addition & 0 deletions BuildTools/validate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ setlocal

call %~dp0\setup-env.cmd

if not exist %FO_WORKSPACE% mkdir %FO_WORKSPACE%
pushd %FO_WORKSPACE%

if [%1] == [win32-client] (
Expand Down
Loading

0 comments on commit 5fdd521

Please sign in to comment.