def main()

in scripts/gha/build_testapps.py [0:0]


def main(argv):
  if len(argv) > 1:
    raise app.UsageError("Too many command-line arguments.")

  platforms = FLAGS.platforms
  testapps = FLAGS.testapps

  sdk_dir = _fix_path(FLAGS.packaged_sdk or FLAGS.repo_dir)
  root_output_dir = _fix_path(FLAGS.output_directory)
  repo_dir = _fix_path(FLAGS.repo_dir)

  update_pod_repo = FLAGS.update_pod_repo
  if FLAGS.add_timestamp:
    timestamp = datetime.datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
  else:
    timestamp = ""

  if FLAGS.short_output_paths:
    output_dir = os.path.join(root_output_dir, "ta")
  else:
    output_dir = os.path.join(root_output_dir, "testapps" + timestamp)

  config = config_reader.read_config()

  xcframework_dir = os.path.join(sdk_dir, "xcframeworks")
  xcframework_exist = os.path.isdir(xcframework_dir)
  if not xcframework_exist:
    if _IOS in platforms:
      _build_xcframework_from_repo(repo_dir, "ios", testapps, config)
    if _TVOS in platforms:
      _build_xcframework_from_repo(repo_dir, "tvos", testapps, config)

  if update_pod_repo and (_IOS in platforms or _TVOS in platforms):
    _run(["pod", "repo", "update"])

  cmake_flags = _get_desktop_compiler_flags(FLAGS.compiler, config.compilers)
  # VCPKG is used to install dependencies for the desktop SDK.
  # Building from source requires building the underlying SDK libraries,
  # so we need to use VCPKG as well.
  if _DESKTOP in platforms and not FLAGS.packaged_sdk:
    vcpkg_arch = FLAGS.arch
    installer = os.path.join(repo_dir, "scripts", "gha", "build_desktop.py")
    _run([sys.executable, installer, "--vcpkg_step_only", "--arch", vcpkg_arch])
    toolchain_file = os.path.join(
        repo_dir, "external", "vcpkg", "scripts", "buildsystems", "vcpkg.cmake")
    if utils.is_mac_os() and FLAGS.arch == "arm64":
      toolchain_file = os.path.join(
          repo_dir, "external", "vcpkg", "scripts", "buildsystems", "macos_arm64.cmake")
    if utils.is_linux_os() and FLAGS.arch == "x86":
      toolchain_file = os.path.join(
          repo_dir, "external", "vcpkg", "scripts", "buildsystems", "linux_32.cmake")

    cmake_flags.extend((
        "-DCMAKE_TOOLCHAIN_FILE=%s" % toolchain_file,
        "-DVCPKG_TARGET_TRIPLET=%s" % utils.get_vcpkg_triplet(arch=vcpkg_arch)
    ))

  if FLAGS.cmake_flag:
    cmake_flags.extend(FLAGS.cmake_flag)

  failures = []
  for testapp in testapps:
    api_config = config.get_api(testapp)
    if FLAGS.repo_dir and not FLAGS.packaged_sdk and api_config.internal_testapp_path:
      testapp_dirs = [api_config.internal_testapp_path]
    else:
      testapp_dirs = [api_config.testapp_path]
    for testapp_dir in testapp_dirs:
      logging.info("BEGIN building for %s: %s", testapp, testapp_dir)
      failures += _build(
          testapp=testapp,
          platforms=platforms,
          api_config=config.get_api(testapp),
          testapp_dir=testapp_dir,
          output_dir=output_dir,
          sdk_dir=sdk_dir,
          xcframework_exist=xcframework_exist,
          repo_dir=repo_dir,
          ios_sdk=FLAGS.ios_sdk,
          tvos_sdk=FLAGS.tvos_sdk,
          cmake_flags=cmake_flags,
          short_output_paths=FLAGS.short_output_paths)
      logging.info("END building for %s", testapp)
  
  _collect_integration_tests(testapps, root_output_dir, output_dir, FLAGS.artifact_name)

  _summarize_results(testapps, platforms, failures, root_output_dir, FLAGS.artifact_name)
  return 1 if failures else 0