deploy_android.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import argparse
  9. import logging
  10. import os
  11. import pathlib
  12. import sys
  13. # Resolve the common python module
  14. ROOT_DEV_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
  15. if ROOT_DEV_PATH not in sys.path:
  16. sys.path.append(ROOT_DEV_PATH)
  17. from cmake.Tools import common
  18. from cmake.Tools.Platform.Android import android_deployment
  19. DEPLOY_TYPES = (android_deployment.AndroidDeployment.DEPLOY_APK_ONLY,
  20. android_deployment.AndroidDeployment.DEPLOY_ASSETS_ONLY,
  21. android_deployment.AndroidDeployment.DEPLOY_BOTH)
  22. def validate_android_deployment_arguments(build_dir_name):
  23. """
  24. Validate the minimal platform deployment arguments
  25. @param build_dir_name: The name of the build directory relative to the current working directory
  26. @param game_name: The name of the game project to deploy
  27. @return: Tuple of (resolved pathlib, game name, asset mode, asset_type, platform_settings object, Android SDK path, embedded_assets, is_unit_test (bool) )
  28. """
  29. build_dir = pathlib.Path(os.getcwd()) / build_dir_name
  30. if not build_dir.is_dir():
  31. raise common.LmbrCmdError(f"Invalid build directory {build_dir_name}")
  32. platform_settings = common.PlatformSettings(build_dir)
  33. if not platform_settings.projects:
  34. raise common.LmbrCmdError("Missing required platform settings object from build directory.")
  35. game_name = platform_settings.projects[0]
  36. android_sdk_path = getattr(platform_settings, 'android_sdk_path', None)
  37. if not android_sdk_path:
  38. raise common.LmbrCmdError(f"Android SDK Path {android_sdk_path} is missing in the platform settings for {build_dir_name}.")
  39. if not os.path.isdir(android_sdk_path):
  40. raise common.LmbrCmdError(f"Android SDK Path {android_sdk_path} in the platform settings for {build_dir_name} is not valid.")
  41. embedded_assets_str = getattr(platform_settings, 'embed_assets_in_apk', None)
  42. if not embedded_assets_str:
  43. raise common.LmbrCmdError(f"The emdedded assets flag 'embed_assets_in_apk' is missing in the platform settings for {build_dir_name}.")
  44. embedded_assets = embedded_assets_str.lower() in ('t', 'true', '1')
  45. is_unit_test_str = getattr(platform_settings, 'is_unit_test', 'False')
  46. is_unit_test = is_unit_test_str.lower() in ('t', 'true', '1')
  47. return build_dir, game_name, platform_settings.asset_deploy_mode, platform_settings.asset_deploy_type, android_sdk_path, embedded_assets, is_unit_test
  48. def main(args):
  49. parser = argparse.ArgumentParser()
  50. parser.add_argument('-b', '--build-dir',
  51. help='The relative build directory to deploy from.',
  52. required=True)
  53. parser.add_argument('-c', '--configuration',
  54. help='The build configuration from the build directory for the source deployment files',
  55. default='profile')
  56. parser.add_argument('--device-id-filter',
  57. help='Comma separated list of connected android device IDs to filter the deployment to. If not supplied, no filter will be applied and deployment will occur on all devices.',
  58. default='')
  59. parser.add_argument('-t', '--deployment-type',
  60. help=f'The deployment type ({"|".join(DEPLOY_TYPES)}) to execute.',
  61. choices=DEPLOY_TYPES,
  62. default=android_deployment.AndroidDeployment.DEPLOY_BOTH)
  63. parser.add_argument('--clean',
  64. help='Option to clean the target dev kit before deploying, ensuring a clean installation.',
  65. action='store_true')
  66. parser.add_argument('--debug',
  67. help='Option to enable debug messages',
  68. action='store_true')
  69. parser.add_argument('--kill-adb-server',
  70. help='Kills adb server at the end of deployment',
  71. action='store_true')
  72. parsed_args = parser.parse_args(args)
  73. # Prepare the logging
  74. logging.basicConfig(format='%(levelname)s: %(message)s',
  75. level=logging.DEBUG if parsed_args.debug else logging.INFO)
  76. build_dir, game_project, asset_mode, asset_type, android_sdk_path, embedded_assets, is_unit_test = validate_android_deployment_arguments(build_dir_name=parsed_args.build_dir)
  77. deployment = android_deployment.AndroidDeployment(dev_root=ROOT_DEV_PATH,
  78. build_dir=build_dir,
  79. configuration=parsed_args.configuration,
  80. game_name=game_project,
  81. asset_mode=asset_mode,
  82. asset_type=asset_type,
  83. embedded_assets=embedded_assets,
  84. android_device_filter=parsed_args.device_id_filter,
  85. clean_deploy=parsed_args.clean,
  86. android_sdk_path=android_sdk_path,
  87. deployment_type=parsed_args.deployment_type,
  88. is_unit_test=is_unit_test,
  89. kill_adb_server=parsed_args.kill_adb_server)
  90. deployment.execute()
  91. if __name__ == '__main__':
  92. try:
  93. main(sys.argv[1:])
  94. exit(0)
  95. except common.LmbrCmdError as err:
  96. print(str(err), file=sys.stderr)
  97. exit(err.code)