import subprocess, os
from py2app.decorators import converts

@converts(suffix=".xib")
def convert_xib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    if dry_run:
        return

    p = subprocess.Popen(['ibtool', '--compile', destination, source])
    xit = p.wait()
    if xit != 0:
        raise RuntimeError("ibtool failed, code %d"%(xit,))


@converts(suffix=".nib")
def convert_nib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    if dry_run:
        return

    p = subprocess.Popen(['ibtool', '--compile', destination, source])
    xit = p.wait()
    if xit != 0:
        raise RuntimeError("ibtool failed, code %d"%(xit,))


from __future__ import print_function
import subprocess, os
from py2app.decorators import converts

gTool = None
def _get_ibtool():
    global gTool
    if gTool is None:
        if os.path.exists('/usr/bin/xcrun'):
            gTool = subprocess.check_output(['/usr/bin/xcrun', '-find', 'ibtool'])[:-1]
        else:
            gTool = 'ibtool'

    print (gTool)
    return gTool

@converts(suffix=".xib")
def convert_xib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    print("compile %s -> %s"%(source, destination))
    if dry_run:
        return

    subprocess.check_call([_get_ibtool(), '--compile', destination, source])

@converts(suffix=".nib")
def convert_nib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"
    print("compile %s -> %s"%(source, destination))

    if dry_run:
        return

    subprocess.check_call([_get_ibtool, '--compile', destination, source])

Simplify nib compiler and support recent Xcode versions by using xcrun
Simplify nib compiler and support recent Xcode versions by using xcrun

+ from __future__ import print_function
  import subprocess, os
  from py2app.decorators import converts
+ 
+ gTool = None
+ def _get_ibtool():
+     global gTool
+     if gTool is None:
+         if os.path.exists('/usr/bin/xcrun'):
+             gTool = subprocess.check_output(['/usr/bin/xcrun', '-find', 'ibtool'])[:-1]
+         else:
+             gTool = 'ibtool'
+ 
+     print (gTool)
+     return gTool
  
  @converts(suffix=".xib")
  def convert_xib(source, destination, dry_run=0):
      destination = destination[:-4] + ".nib"
  
+     print("compile %s -> %s"%(source, destination))
      if dry_run:
          return
  
-     p = subprocess.Popen(['ibtool', '--compile', destination, source])
+     subprocess.check_call([_get_ibtool(), '--compile', destination, source])
-     xit = p.wait()
-     if xit != 0:
-         raise RuntimeError("ibtool failed, code %d"%(xit,))
- 
  
  @converts(suffix=".nib")
  def convert_nib(source, destination, dry_run=0):
      destination = destination[:-4] + ".nib"
+     print("compile %s -> %s"%(source, destination))
  
      if dry_run:
          return
  
-     p = subprocess.Popen(['ibtool', '--compile', destination, source])
+     subprocess.check_call([_get_ibtool, '--compile', destination, source])
-     xit = p.wait()
-     if xit != 0:
-         raise RuntimeError("ibtool failed, code %d"%(xit,))
  
- 
Simplify nib compiler and support recent Xcode versions by using xcrun
## Code Before:
import subprocess, os
from py2app.decorators import converts

@converts(suffix=".xib")
def convert_xib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    if dry_run:
        return

    p = subprocess.Popen(['ibtool', '--compile', destination, source])
    xit = p.wait()
    if xit != 0:
        raise RuntimeError("ibtool failed, code %d"%(xit,))


@converts(suffix=".nib")
def convert_nib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    if dry_run:
        return

    p = subprocess.Popen(['ibtool', '--compile', destination, source])
    xit = p.wait()
    if xit != 0:
        raise RuntimeError("ibtool failed, code %d"%(xit,))


## Instruction:
Simplify nib compiler and support recent Xcode versions by using xcrun
## Code After:
from __future__ import print_function
import subprocess, os
from py2app.decorators import converts

gTool = None
def _get_ibtool():
    global gTool
    if gTool is None:
        if os.path.exists('/usr/bin/xcrun'):
            gTool = subprocess.check_output(['/usr/bin/xcrun', '-find', 'ibtool'])[:-1]
        else:
            gTool = 'ibtool'

    print (gTool)
    return gTool

@converts(suffix=".xib")
def convert_xib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"

    print("compile %s -> %s"%(source, destination))
    if dry_run:
        return

    subprocess.check_call([_get_ibtool(), '--compile', destination, source])

@converts(suffix=".nib")
def convert_nib(source, destination, dry_run=0):
    destination = destination[:-4] + ".nib"
    print("compile %s -> %s"%(source, destination))

    if dry_run:
        return

    subprocess.check_call([_get_ibtool, '--compile', destination, source])
