diff --git a/CMakeLists.txt b/CMakeLists.txt index 16cade29..3dbe1e42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,11 @@ if(MSVC) endif() set(THIRDPARTY_DIRECTORY "${CMAKE_SOURCE_DIR}/third_party") set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install") +if(CMAKE_BUILD_TYPE STREQUAL "Release") + set(CMAKE_BUILD_TYPE_LOWERCASE "release") +elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_BUILD_TYPE_LOWERCASE "debug") +endif() if(ANDROID) add_subdirectory(third_party/freedreno) @@ -107,28 +112,23 @@ else() if(NOT CMAKE_HOST_WIN32) message(CHECK_START "Build gfxr for android") execute_process( - COMMAND ./gradlew assembleDebug - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android - ) - - execute_process( - COMMAND ./gradlew assembleRelease + COMMAND ./gradlew assemble${CMAKE_BUILD_TYPE} --console=verbose WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android + COMMAND_ERROR_IS_FATAL ANY ) + message(CHECK_PASS "successful") - file(ARCHIVE_EXTRACT - INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-debug.aar" - DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/layer" + message(CHECK_START "Move gfxr files") + file( + ARCHIVE_EXTRACT + INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-${CMAKE_BUILD_TYPE_LOWERCASE}.aar" + DESTINATION "${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/layer" ) - - file(ARCHIVE_EXTRACT - INPUT "${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/layer/build/outputs/aar/layer-release.aar" - DESTINATION "${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/layer" + file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/tools/replay) + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/${CMAKE_BUILD_TYPE_LOWERCASE}/. + DESTINATION ${CMAKE_SOURCE_DIR}/build_android/${CMAKE_BUILD_TYPE}/third_party/gfxreconstruct/android/tools/replay ) - - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Debug/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/debug) - - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release DESTINATION ${CMAKE_SOURCE_DIR}/build_android/Release/third_party/gfxreconstruct/android/tools/replay/build/outputs/apk/release) message(CHECK_PASS "successful") endif() endif() diff --git a/README.md b/README.md index f4d2cad5..d0fd1b02 100644 --- a/README.md +++ b/README.md @@ -90,15 +90,17 @@ Run the script On Linux, run: ``` -./scripts/build_android.sh +./scripts/build_android.sh Debug ``` And on Windows, Open Developer Command Prompt for VS 2022(or 2019) and run ``` -scripts\build_android.bat +scripts\build_android.bat Debug ``` -It will build both debug and release version of the libraries under `build_android` folder. It will also build gfxreconstruct binaries under `third_party/gfxreconstruct/android` and copy them to under `build_android`. +It will build the debug version of the libraries under `build_android` folder. To build release version, replace parameter with `Release`. To build both versions, do not pass a parameter. + +It will also trigger gradle to rebuild gfxreconstruct binaries under `third_party/gfxreconstruct/android/...` and copy them to under `build_android`. Troubleshooting tips: - Open the gradle project at `third_party/gfxreconstruct/android` in Android Studio and try making recommended changes to the project and building from there. @@ -106,6 +108,7 @@ Troubleshooting tips: - `third_party/gfxreconstruct/android/layer/build` - `third_party/gfxreconstruct/android/tools/replay/build` - `build_android` +- If incremental builds are slow, try building only one version (Debug or Release) and not both ### CLI Tool for capture and cleanup #### Capture with command line tool for Android applications diff --git a/scripts/build_android.bat b/scripts/build_android.bat index 627d81aa..ba94d785 100644 --- a/scripts/build_android.bat +++ b/scripts/build_android.bat @@ -13,14 +13,26 @@ :: limitations under the License. @echo off - +setlocal enabledelayedexpansion set PROJECT_ROOT=%~dp0\.. set BUILD_TYPE=Debug Release set SRC_DIR=%PROJECT_ROOT% set GFXR_ROOT_DIR=%PROJECT_ROOT%\\third_party\\gfxreconstruct\\android set startTime=%time% -(for %%b in (%BUILD_TYPE%) do ( +if "%~1"=="" goto parsingdone +if "%1"=="Debug" set BUILD_TYPE=%1 +if "%1"=="Release" set BUILD_TYPE=%1 +if not !BUILD_TYPE!==%1 ( + echo Invalid parameter passed for BUILD_TYPE: %1 + echo Valid options: 'Debug', 'Release' + echo To build all types, do not pass a parameter. + exit /b 1 +) +:parsingdone +echo Building all the following types: !BUILD_TYPE! + +(for %%b in (!BUILD_TYPE!) do ( setlocal enabledelayedexpansion echo. echo %%b : Building dive android layer @@ -51,19 +63,18 @@ set startTime=%time% )) pushd !GFXR_ROOT_DIR! -(for %%b in (%BUILD_TYPE%) do ( +(for %%b in (!BUILD_TYPE!) do ( setlocal enabledelayedexpansion echo. echo %%b : Building gfxr android layer set build=%%b echo GFXR_ROOT_DIR: !GFXR_ROOT_DIR! - call gradlew assemble!build! + call gradlew assemble!build! --console=verbose )) popd - -(for %%b in (%BUILD_TYPE%) do ( +(for %%b in (!BUILD_TYPE!) do ( setlocal enabledelayedexpansion if "%%b" == "Release" set build_lowercase=release if "%%b" == "Debug" set build_lowercase=debug @@ -78,14 +89,20 @@ popd echo Extracting gfxr android layer into build_android set GFXR_LAYER_SRC=!GFXR_ROOT_DIR!\\layer\\build\\outputs\\aar\\layer-!build_lowercase!.aar set GFXR_LAYER_DST=!GFXR_BUILD_DIR!\\layer - if not exist !GFXR_LAYER_DST! md !GFXR_LAYER_DST! + if exist !GFXR_LAYER_DST! rm -rf !GFXR_LAYER_DST! + if not !ERRORLEVEL!==0 exit /b 1 + md !GFXR_LAYER_DST! + if not !ERRORLEVEL!==0 exit /b 1 tar -xf !GFXR_LAYER_SRC! -C !GFXR_LAYER_DST! + if not !ERRORLEVEL!==0 exit /b 1 echo Copying gfxr android replay into build_android set GFXR_REPLAY_SRC=!GFXR_ROOT_DIR!\\tools\\replay\\build\\outputs\\apk\\!build_lowercase! set GFXR_REPLAY_DST=!GFXR_BUILD_DIR!\\tools\\replay - if not exist !GFXR_REPLAY_DST! md !GFXR_REPLAY_DST! - copy !GFXR_REPLAY_SRC! !GFXR_REPLAY_DST! + if exist !GFXR_REPLAY_DST! rm -rf !GFXR_REPLAY_DST! + if not !ERRORLEVEL!==0 exit /b 1 + xcopy /i !GFXR_REPLAY_SRC! !GFXR_REPLAY_DST! + if not !ERRORLEVEL!==0 exit /b 1 )) echo Start Time: %startTime% diff --git a/scripts/build_android.sh b/scripts/build_android.sh index 17059c76..9015bdb8 100755 --- a/scripts/build_android.sh +++ b/scripts/build_android.sh @@ -19,9 +19,22 @@ PROJECT_ROOT="${PROJECT_ROOT%/*}/.." readonly PROJECT_ROOT="$(readlink -f ${PROJECT_ROOT})" readonly BUILD_DIR_ROOT=${PROJECT_ROOT}/build_android readonly SRC_DIR=${PROJECT_ROOT} -readonly BUILD_TYPE=(Debug Release) +BUILD_TYPE=(Debug Release) +readonly START_TIME=`date +%r` -for build in "${BUILD_TYPE[@]}" +if [ $# -ne 0 ]; then + if [ "$1" = "Debug" ] || [ "$1" = "Release" ]; then + BUILD_TYPE=$1 + else + echo "Invalid parameter passed for BUILD_TYPE: $1" + echo "Valid options: 'Debug', 'Release'" + echo "To build all types, do not pass a parameter." + exit 1 + fi +fi +echo "Building all the following types: $BUILD_TYPE" + +for build in "${BUILD_TYPE}" do BUILD_DIR=${BUILD_DIR_ROOT}/${build} mkdir -p ${BUILD_DIR} @@ -50,4 +63,7 @@ do cmake --install . || exit 1 fi popd -done \ No newline at end of file +done + +echo "Start Time:" ${START_TIME} +echo "Finish Time:" `date +%r` \ No newline at end of file