def handle_invocation()

in Utilities/build-script-helper.py [0:0]


def handle_invocation(args):
  swiftpm_args = get_swiftpm_options(args)
  toolchain_bin = os.path.join(args.toolchain, 'bin')
  swift_exec = os.path.join(toolchain_bin, 'swift')
  swiftc_exec = os.path.join(toolchain_bin, 'swiftc')

  # Platform-specific targets for which we must build swift-driver
  if args.cross_compile_hosts:
    targets = args.cross_compile_hosts
  elif platform.system() == 'Darwin':
    targets = [get_build_target(swiftc_exec, args) + macos_deployment_target]
  else:
    targets = [get_build_target(swiftc_exec, args)]

  env = os.environ
  # Use local dependencies (i.e. checked out next to swift-driver).
  if not args.no_local_deps:
    env['SWIFTCI_USE_LOCAL_DEPS'] = "1"

  if args.ninja_bin:
    env['NINJA_BIN'] = args.ninja_bin

  if args.sysroot:
    env['SDKROOT'] = args.sysroot

  env['SWIFT_EXEC'] = '%sc' % (swift_exec)

  if args.action == 'build':
    if args.cross_compile_hosts and not re.match('-macosx', args.cross_compile_hosts[0]):
      swiftpm('build', swift_exec, swiftpm_args, env)
    else:
      build_using_cmake(args, toolchain_bin, args.build_path, targets)

  elif args.action == 'clean':
    print('Cleaning ' + args.build_path)
    shutil.rmtree(args.build_path, ignore_errors=True)
  elif args.action == 'test':
    for tool in driver_toolchain_tools:
        tool_path = os.path.join(toolchain_bin, tool)
        if os.path.exists(tool_path):
            env['SWIFT_DRIVER_' + tool.upper().replace('-','_') + '_EXEC'] = '%s' % (tool_path)
    test_args = swiftpm_args
    test_args += ['-Xswiftc', '-enable-testing']
    if should_test_parallel():
      test_args += ['--parallel']
    # The test suite consults these variables to control what tests get run
    env['SWIFT_DRIVER_ENABLE_INTEGRATION_TESTS'] = "1"
    if args.lit_test_dir:
      env['SWIFT_DRIVER_LIT_DIR'] = args.lit_test_dir
    swiftpm('test', swift_exec, test_args, env)
  elif args.action == 'install':
    if platform.system() == 'Darwin':
      build_using_cmake(args, toolchain_bin, args.build_path, targets)
      install(args, args.build_path, targets)
    else:
      bin_path = swiftpm_bin_path(swift_exec, swiftpm_args, env)
      swiftpm('build', swift_exec, swiftpm_args, env)
      non_darwin_install(args, bin_path)
  else:
    assert False, 'unknown action \'{}\''.format(args.action)