input:b0003v0627p0001e0001-e0,1,2,3,4,k110,111,112,r8,B,a0,1,m4,lsfw
 ?÷     #!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Utility functions to perform Xcode-style build steps.

These functions are executed via gyp-mac-tool when using the Makefile generator.
"""

from __future__ import print_function

import fcntl
import fnmatch
import glob
import json
import os
import plistlib
import re
import shutil
import struct
import subprocess
import sys
import tempfile


def main(args):
  executor = MacTool()
  exit_code = executor.Dispatch(args)
  if exit_code is not None:
    sys.exit(exit_code)


class MacTool(object):
  """This class performs all the Mac tooling steps. The methods can either be
  executed directly, or dispatched from an argument list."""

  def Dispatch(self, args):
    """Dispatches a string command to a method."""
    if len(args) < 1:
      raise Exception("Not enough arguments")

    method = "Exec%s" % self._CommandifyName(args[0])
    return getattr(self, method)(*args[1:])

  def _CommandifyName(self, name_string):
    """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
    return name_string.title().replace('-', '')

  def ExecCopyBundleResource(self, source, dest, convert_to_binary):
    """Copies a resource file to the bundle/Resources directory, performing any
    necessary compilation on each resource."""
    convert_to_binary = convert_to_binary == 'True'
    extension = os.path.splitext(source)[1].lower()
    if os.path.isdir(source):
      # Copy tree.
      # TODO(thakis): This copies file attributes like mtime, while the
      # single-file branch below doesn't. This should probably be changed to
      # be consistent with the single-file branch.
      if os.path.exists(dest):
        shutil.rmtree(dest)
      shutil.copytree(source, dest)
    elif extension == '.xib':
      return self._CopyXIBFile(source, dest)
    elif extension == '.storyboard':
      return self._CopyXIBFile(source, dest)
    elif extension == '.strings' and not convert_to_binary:
      self._CopyStringsFile(source, dest)
    else:
      if os.path.exists(dest):
        os.unlink(dest)
      shutil.copy(source, dest)

    if convert_to_binary and extension in ('.plist', '.strings'):
      self._ConvertToBinary(dest)

  def _CopyXIBFile(self, source, dest):
    """Compiles a XIB file with ibtool into a binary plist in the bundle."""

    # ibtool sometimes crashes with relative paths. See crbug.com/314728.
    base = os.path.dirname(os.path.realpath(__file__))
    if os.path.relpath(source):
      source = os.path.join(base, source)
    if os.path.relpath(dest):
      dest = os.path.join(base, dest)

    args = ['xcrun', 'ibtool', '--errors', '--warnings', '--notices']

    if os.environ['XCODE_VERSION_ACTUAL'] > '0700':
      args.extend(['--auto-activate-custom-fonts'])
      if 'IPHONEOS_DEPLOYMENT_TARGET' in os.environ:
        args.extend([
            '--target-device', 'iphone', '--target-device', 'ipad',
            '--minimum-deployment-target',
            os.environ['IPHONEOS_DEPLOYMENT_TARGET'],
        ])
      else:
        args.extend([
            '--target-device', 'mac',
            '--minimum-deployment-target',
            os.environ['MACOSX_DEPLOYMENT_TARGET'],
        ])

    args.extend(['--output-format', 'human-readable-text', '--compile', dest,
        source])

    ibtool_section_re = re.compile(r'/\*.*\*/')
    ibtool_re = re.compile(r'.*note:.*is clipping its content')
    try:
      stdout = subprocess.check_output(args)
    except subprocess.CalledProcessError as e:
      print(e.output)
      raise
    current_section_header = None
    for line in stdout.splitlines():
      line_decoded = line.decode('utf-8')
      if ibtool_section_re.match(line_decoded):
        current_section_header = line_decoded
      elif not ibtool_re.match(line_decoded):
        if current_section_header:
          print(current_section_header)
          current_sect