build_ios_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 os
  10. import pathlib
  11. import sys
  12. SCHEME_NAME = 'AzTestRunner'
  13. XCODE_PROJECT_NAME = 'O3DE'
  14. # Resolve the common python module
  15. ROOT_DEV_PATH = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
  16. if ROOT_DEV_PATH not in sys.path:
  17. sys.path.append(ROOT_DEV_PATH)
  18. from cmake.Tools import common
  19. def build_ios_test(build_dir, configuration, device_name):
  20. build_path = pathlib.Path(build_dir) if os.path.isabs(build_dir) else pathlib.Path(ROOT_DEV_PATH) / build_dir
  21. if not build_path.is_dir():
  22. raise common.LmbrCmdError(f"Invalid build directory '{str(build_path)}'")
  23. xcode_build = common.CommandLineExec('/usr/bin/xcodebuild')
  24. command_line_arguments = ['build-for-testing',
  25. '-project', f'{XCODE_PROJECT_NAME}.xcodeproj',
  26. '-scheme', SCHEME_NAME,
  27. '-configuration', configuration,
  28. '-allowProvisioningUpdates',
  29. '-allowProvisioningDeviceRegistration',
  30. '-destination', f'platform=iOS,name={device_name}']
  31. xcode_out = xcode_build.popen(command_line_arguments, cwd=build_path, shell=False)
  32. while xcode_out.poll() is None:
  33. print(xcode_out.stdout.readline())
  34. def main(args):
  35. parser = argparse.ArgumentParser(description="Launch a test module on a target iOS device.")
  36. parser.add_argument('-b', '--build-dir',
  37. help='The relative build directory to deploy from.',
  38. required=True)
  39. parser.add_argument('--device-name',
  40. help='The name of the iOS device on which to launch.',
  41. required=True)
  42. parser.add_argument('-c', '--configuration',
  43. help='The build configuration from the build directory for the source deployment files',
  44. default='profile')
  45. parsed_args = parser.parse_args(args)
  46. build_ios_test(build_dir=parsed_args.build_dir,
  47. device_name=parsed_args.device_name,
  48. configuration=parsed_args.configuration)
  49. return 0
  50. if __name__ == '__main__':
  51. try:
  52. result_code = main(sys.argv[1:])
  53. exit(result_code)
  54. except common.LmbrCmdError as err:
  55. logging.error(str(err))
  56. exit(err.code)