gradle_windows.cmd 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. @ECHO OFF
  2. REM
  3. REM Copyright (c) Contributors to the Open 3D Engine Project.
  4. REM For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. REM
  6. REM SPDX-License-Identifier: Apache-2.0 OR MIT
  7. REM
  8. REM
  9. SETLOCAL EnableDelayedExpansion
  10. IF NOT EXIST "%LY_3RDPARTY_PATH%" (
  11. ECHO [ci_build] LY_3RDPARTY_PATH is invalid or not set
  12. GOTO :error
  13. )
  14. IF NOT EXIST "%GRADLE_BUILD_HOME%" (
  15. REM This is the default for developers
  16. SET GRADLE_BUILD_HOME=C:\Gradle\gradle-7.0
  17. )
  18. IF NOT EXIST "%GRADLE_BUILD_HOME%" (
  19. ECHO [ci_build] FAIL: GRADLE_BUILD_HOME=%GRADLE_BUILD_HOME%
  20. GOTO :error
  21. )
  22. IF NOT "%ANDROID_GRADLE_PLUGIN%" == "" (
  23. set ANDROID_GRADLE_PLUGIN_OPTION=--gradle-plugin-version=%ANDROID_GRADLE_PLUGIN%
  24. )
  25. IF NOT EXIST %OUTPUT_DIRECTORY% (
  26. mkdir %OUTPUT_DIRECTORY%
  27. ) ELSE (
  28. ECHO Clearing and reseting existing build folder
  29. DEL /S /F /Q %OUTPUT_DIRECTORY%
  30. RMDIR /S /Q %OUTPUT_DIRECTORY%
  31. mkdir %OUTPUT_DIRECTORY%
  32. )
  33. REM Jenkins does not defined TMP
  34. IF "%TMP%"=="" (
  35. IF "%WORKSPACE%"=="" (
  36. SET TMP=%APPDATA%\Local\Temp
  37. SET TEMP=%APPDATA%\Local\Temp
  38. ) ELSE (
  39. SET TMP=%WORKSPACE%\Temp
  40. SET TEMP=%WORKSPACE%\Temp
  41. REM This folder may not be created in the workspace
  42. IF NOT EXIST "!TMP!" (
  43. MKDIR "!TMP!"
  44. )
  45. )
  46. )
  47. REM Create a minimal project for the native build process
  48. IF EXIST "%TMP%\o3de_gradle_ar" (
  49. DEL /S /F /Q "%TMP%\o3de_gradle_ar"
  50. RMDIR /S /Q "%TMP%\o3de_gradle_ar"
  51. )
  52. ECHO Creating a minimal project for the native build process
  53. ECHO %PYTHON% scripts\o3de.py create-project -pp "%TMP%\o3de_gradle_ar" -pn GradleTest -tn MinimalProject
  54. CALL %PYTHON% scripts\o3de.py create-project -pp "%TMP%\o3de_gradle_ar" -pn GradleTest -tn MinimalProject
  55. REM Optionally sign the APK if we are generating an APK
  56. SET GENERATE_SIGNED_APK=false
  57. IF "%SIGN_APK%"=="true" (
  58. IF "%GRADLE_BUILD_CMD%"=="assemble" (
  59. SET GENERATE_SIGNED_APK=true
  60. )
  61. )
  62. SET PYTHON=python\python.cmd
  63. REM Regardless of whether or not we generate a signing key, apparently we must set variables outside of
  64. REM an IF clause otherwise it will not work.
  65. REM First look for the JDK HOME in the environment variable
  66. IF EXIST "%JDK_HOME%" (
  67. ECHO JDK Home found in Environment: !JDK_HOME!
  68. GOTO JDK_FOUND
  69. )
  70. REM Next, look in the registry
  71. FOR /F "skip=2 tokens=1,2*" %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\1.8" /v "JavaHome" 2^>nul') DO (
  72. SET JDK_REG_VALUE=%%C
  73. )
  74. IF EXIST "%JDK_REG_VALUE%" (
  75. SET JDK_HOME=!JDK_REG_VALUE!
  76. ECHO JDK Home found in registry: !JDK_HOME!
  77. GOTO JDK_FOUND
  78. )
  79. ECHO Unable to locate JDK_HOME
  80. GOTO error
  81. :JDK_FOUND
  82. SET JDK_BIN=%JDK_HOME%\bin
  83. IF NOT EXIST "%JDK_BIN%" (
  84. ECHO The environment variable JDK_HOME is not set to a valid JDK 1.8 folder %JDK_BIN%
  85. ECHO Make sure the variable is set to your local JDK 1.8 installation
  86. GOTO error
  87. )
  88. SET KEYTOOL_PATH=%JDK_BIN%\keytool.exe
  89. IF NOT EXIST "%KEYTOOL_PATH%" (
  90. ECHO The environment variable JDK_HOME is not set to a valid JDK 1.8 folder. Cannot find keytool at %JDK_BIN%\keytool.exe
  91. ECHO Make sure the variable is set to your local JDK 1.8 installation
  92. GOTO error
  93. )
  94. SET CI_ANDROID_KEYSTORE_FILE=ly-android-dev.keystore
  95. SET CI_ANDROID_KEYSTORE_ALIAS=ly-android
  96. SET CI_ANDROID_KEYSTORE_PASSWORD=lumberyard
  97. SET CI_ANDROID_KEYSTORE_DN=cn=LY Developer, ou=Lumberyard, o=Amazon, c=US
  98. SET CI_KEYSTORE_VALIDITY_DAYS=10000
  99. SET CI_KEYSTORE_CERT_DN=cn=LY Developer, ou=Lumberyard, o=Amazon, c=US
  100. REM Clear out any existing keystore file since the password/alias may have changed
  101. SET CI_ANDROID_KEYSTORE_FILE_ABS=%cd%\%OUTPUT_DIRECTORY%\%CI_ANDROID_KEYSTORE_FILE%
  102. IF "%GENERATE_SIGNED_APK%"=="true" (
  103. REM Prepare a temporary keystore just for this unit test session
  104. REM Generate the keystore file if needed
  105. IF NOT EXIST "%CI_ANDROID_KEYSTORE_FILE_ABS%" (
  106. ECHO [ci_build] Generating keystore file %CI_ANDROID_KEYSTORE_FILE%
  107. ECHO [ci_build] "%KEYTOOL_PATH%" -genkeypair -v -keystore %CI_ANDROID_KEYSTORE_FILE_ABS% -storepass %CI_ANDROID_KEYSTORE_PASSWORD% -alias %CI_ANDROID_KEYSTORE_ALIAS% -keypass %CI_ANDROID_KEYSTORE_PASSWORD% -keyalg RSA -keysize 2048 -validity %CI_KEYSTORE_VALIDITY_DAYS% -dname "%CI_KEYSTORE_CERT_DN%"
  108. CALL "%KEYTOOL_PATH%" -genkeypair -v -keystore %CI_ANDROID_KEYSTORE_FILE_ABS% -storepass %CI_ANDROID_KEYSTORE_PASSWORD% -alias %CI_ANDROID_KEYSTORE_ALIAS% -keypass %CI_ANDROID_KEYSTORE_PASSWORD% -keyalg RSA -keysize 2048 -validity %CI_KEYSTORE_VALIDITY_DAYS% -dname "%CI_KEYSTORE_CERT_DN%" 2> nul
  109. IF errorlevel 1 (
  110. ECHO Unable to generate keystore file "%CI_ANDROID_KEYSTORE_FILE_ABS%"
  111. GOTO error
  112. )
  113. ) ELSE (
  114. ECHO Using keystore file at %CI_ANDROID_KEYSTORE_FILE_ABS%
  115. )
  116. ECHO [ci_build] %PYTHON% cmake\Tools\Platform\Android\generate_android_project.py --engine-root=. --build-dir=%OUTPUT_DIRECTORY% -g "%TMP%\o3de_gradle_ar" --gradle-install-path=%GRADLE_BUILD_HOME% --third-party-path=%LY_3RDPARTY_PATH% --enable-unity-build --android-sdk-path=%ANDROID_HOME% %ANDROID_GRADLE_PLUGIN_OPTION% --signconfig-store-file %CI_ANDROID_KEYSTORE_FILE_ABS% --signconfig-store-password %CI_ANDROID_KEYSTORE_PASSWORD% --signconfig-key-alias %CI_ANDROID_KEYSTORE_ALIAS% --signconfig-key-password %CI_ANDROID_KEYSTORE_PASSWORD% %ADDITIONAL_GENERATE_ARGS% --overwrite-existing
  117. CALL %PYTHON% cmake\Tools\Platform\Android\generate_android_project.py --engine-root=. --build-dir=%OUTPUT_DIRECTORY% -g "%TMP%\o3de_gradle_ar" --gradle-install-path=%GRADLE_BUILD_HOME% --third-party-path=%LY_3RDPARTY_PATH% --enable-unity-build --android-sdk-path=%ANDROID_HOME% %ANDROID_GRADLE_PLUGIN_OPTION% --signconfig-store-file %CI_ANDROID_KEYSTORE_FILE_ABS% --signconfig-store-password %CI_ANDROID_KEYSTORE_PASSWORD% --signconfig-key-alias %CI_ANDROID_KEYSTORE_ALIAS% --signconfig-key-password %CI_ANDROID_KEYSTORE_PASSWORD% %ADDITIONAL_GENERATE_ARGS% --overwrite-existing
  118. ) ELSE (
  119. ECHO [ci_build] %PYTHON% cmake\Tools\Platform\Android\generate_android_project.py --engine-root=. --build-dir=%OUTPUT_DIRECTORY% -g "%TMP%\o3de_gradle_ar" %GRADLE_OVERRIDE_OPTION% --third-party-path=%LY_3RDPARTY_PATH% --enable-unity-build %ANDROID_GRADLE_PLUGIN_OPTION% --android-sdk-path=%ANDROID_HOME% %ADDITIONAL_GENERATE_ARGS% --overwrite-existing
  120. CALL %PYTHON% cmake\Tools\Platform\Android\generate_android_project.py --engine-root=. --build-dir=%OUTPUT_DIRECTORY% -g "%TMP%\o3de_gradle_ar" --gradle-install-path=%GRADLE_BUILD_HOME% --third-party-path=%LY_3RDPARTY_PATH% --enable-unity-build %ANDROID_GRADLE_PLUGIN_OPTION% --android-sdk-path=%ANDROID_HOME% %ADDITIONAL_GENERATE_ARGS% --overwrite-existing
  121. )
  122. SET CMAKE_BUILD_PARALLEL_LEVEL=!NUMBER_OF_PROCESSORS!
  123. REM Validate the android project generation
  124. IF %ERRORLEVEL%==0 GOTO generate_project_success
  125. ECHO Error Generating Android Project
  126. goto error
  127. :generate_project_success
  128. REM Run the gradle build from the output directory
  129. PUSHD %OUTPUT_DIRECTORY%
  130. REM Stop any running or orphaned gradle daemon
  131. ECHO [ci_build] gradlew --stop
  132. CALL gradlew --stop
  133. ECHO [ci_build] gradlew --info --no-daemon %GRADLE_BUILD_CMD%%CONFIGURATION%
  134. CALL gradlew --info --no-daemon %GRADLE_BUILD_CMD%%CONFIGURATION%
  135. IF %ERRORLEVEL%==0 GOTO gradle_build_success
  136. REM Do another build with the debug flag to try to get the failure reasons
  137. GOTO error
  138. ECHO Error building gradle. Rebuilding with debug information
  139. ECHO [ci_build] gradlew --debug --full-stacktrace --no-daemon %GRADLE_BUILD_CMD%%CONFIGURATION%
  140. CALL gradlew --debug --full-stacktrace --no-daemon %GRADLE_BUILD_CMD%%CONFIGURATION%
  141. ECHO [ci_build] gradlew --stop
  142. CALL gradlew --stop
  143. POPD
  144. GOTO error
  145. :gradle_build_success
  146. ECHO [ci_build] gradlew --stop
  147. CALL gradlew --stop
  148. POPD
  149. EXIT /b 0
  150. :popd_error
  151. POPD
  152. :error
  153. EXIT /b 1