def main()

in tools/codesigningtool/codesigningtool.py [0:0]


def main(args):
  extra = []
  if args.extra:
    if args.extra[0] != "--":
      print(
          "ERROR: unknown argument given: %s (the only unknown arguments "
          "allowed are those following '--' and which go directly to "
          "codesign)" % args.extra[0], file=sys.stderr)
  extra = args.extra[1:]
  identity = args.identity
  if identity is None:
    identity = _find_codesign_identity(args.mobileprovision)
  elif identity != "-":
    matching_identities = _find_codesign_identities(identity)
    if matching_identities:
      identity = matching_identities[0]
    else:
      print(
          "ERROR: No signing identity found for '{}'".format(identity),
          file=sys.stderr)
      return -1
  # No identity was found, fail
  if identity is None:
    print("ERROR: Unable to find an identity on the system matching the "
          "ones in %s" % args.mobileprovision, file=sys.stderr)
    return 1
  # No targets to sign were provided, fail
  if not args.target_to_sign and not args.directory_to_sign:
    print("INTERNAL ERROR: No paths to sign were given to codesign. Should "
          "have one of --target_to_sign or --directory_to_sign")
    return 1
  all_paths_to_sign = _all_paths_to_sign(args.target_to_sign,
                                         args.directory_to_sign)
  if not all_paths_to_sign:
    # TODO(b/149874635): Cleanly error here rather than no-op when the failure
    # to find paths to sign is a valid error condition.
    return 0
  signed_path = args.signed_path
  if signed_path:
    all_paths_to_sign = _filter_paths_already_signed(all_paths_to_sign,
                                                     signed_path)

  for path_to_sign in all_paths_to_sign:
    _invoke_codesign(args.codesign, identity, args.entitlements, args.force,
                     args.disable_timestamp, path_to_sign, extra)