ó
ÓnäZc           @   sj   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d „  Z d „  Z	 d „  Z
 d „  Z d S(   sÅ  Xcode-ninja wrapper project file generator.

This updates the data structures passed to the Xcode gyp generator to build
with ninja instead. The Xcode project itself is transformed into a list of
executable targets, each with a build step to build with ninja, and a target
with every source and resource file.  This appears to sidestep some of the
major performance headaches experienced using complex projects and large number
of targets within Xcode.
iÿÿÿÿNc         C   s‘  t  j j |  ƒ \ } } | d } | d } | j rP t  j j | j | ƒ } n  y t  j | ƒ Wn+ t k
 rŽ } | j t j k r ‚  q n Xd d } xa |  | g D]S }	 t  j j t  j j	 |	 ƒ ƒ d d }
 t
 j j j d |
 ƒ }
 | d |
 7} q¦ W| d	 7} t  j j | d
 ƒ } y8 t | d ƒ # } | j ƒ  } | | k rMd SWd QXWn t k
 rgn Xt | d ƒ  } | j | ƒ Wd QXd S(   s8    Create a workspace to wrap main and sources gyp paths. s   .xcworkspacet   optionss'   <?xml version="1.0" encoding="UTF-8"?>
s   <Workspace version = "1.0">
i    s
   .xcodeprojs   group:s$     <FileRef location = %s></FileRef>
s   </Workspace>
s   contents.xcworkspacedatat   rNt   w(   t   ost   patht   splitextt   generator_outputt   joint   makedirst   OSErrort   errnot   EEXISTt   basenamet   xmlt   saxt   saxutilst	   quoteattrt   opent   readt   IOErrort   write(   t   main_gypt   sources_gypt   paramst   build_file_roott   build_file_extt   workspace_pathR    t   et   output_stringt   gyp_namet   namet   workspace_filet
   input_filet   input_stringt   output_file(    (    s3   /usr/lib/python2.7/dist-packages/gyp/xcode_ninja.pyt   _WriteWorkspace   s6    

	
&
c         C   sÝ  d& } d } | rd | d } t j j | j t j j j | ƒ ƒ } | j	 d i  ƒ j	 d d ƒ } n  |  j	 d ƒ } |  j	 d | ƒ } |  j	 d ƒ } i  } | | d <| | d <| rÁ | | d <n  |  j	 d ƒ | d <|  j	 d	 ƒ | d	 <i  | d
 <i  }	 | rd | |	 d <n  d
 |  k rÍx° |  d
 j
 ƒ  D]› }
 |  d
 |
 j	 d i  ƒ } d | k rrd |	 d <| d |	 d <n  x1 d d g D]# } | | k r| | |	 | <qqWi  | d
 |
 <|	 | d
 |
 d <q+Wn  |  j	 d d ƒ | d <|  j	 d d ƒ | d <|  j	 d d ƒ | d <|  j	 d d ƒ | d <|  j	 d d ƒ | d <|  d | d <| rÙi d | d 6g  d 6g  d 6d d t j d d  d! |	 d | g d" 6d | d# 6g | d$ <| d k rÙ| d$ d d" j d% | f ƒ qÙn  | S('   s-    Create fake target for xcode-ninja wrapper. i    R    t   generator_flagst   xcode_ninja_jobst   target_namet   product_namet   product_extensiont   toolsett   default_configurationt   configurationss-   %s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)t   CONFIGURATION_BUILD_DIRt   xcode_settingst   IPHONEOS_DEPLOYMENT_TARGETt   NOt   CODE_SIGNING_REQUIREDt   BUNDLE_LOADERt	   TEST_HOSTt
   mac_bundlet   mac_xctest_bundlet   ios_app_extensiont   ios_watchkit_extensiont   ios_watchkit_appt   types   Compile and copy %s via ninjat   action_namet   inputst   outputst   envs   PATH=%st   PATHt   ninjas   -Ct   actiont   messaget   actionss   -jN(   t   NoneR   R   R   t   toplevel_dirt   gypt	   generatorR>   t   ComputeOutputDirt   gett   iterkeyst   environt   extend(   t   old_specR   t   ninja_toplevelt   jobsR    R&   R'   R(   t   ninja_targett   new_xcode_settingst   configt   old_xcode_settingst   key(    (    s3   /usr/lib/python2.7/dist-packages/gyp/xcode_ninja.pyt   _TargetFromSpec8   sj    
!




%c         C   s¬   | j  d ƒ } |  d	 k	 r1 t j |  | ƒ r1 t St | j  d d ƒ ƒ d k s | j  d d ƒ d k r¨ | j  d d ƒ d k r¨ | d	 k	 r¤ t j | | ƒ s¤ t Sn  t St S(
   sp  Limit targets for Xcode wrapper.

  Xcode sometimes performs poorly with too many targets, so only include
  proper executable targets, with filters to customize.
  Arguments:
    target_extras: Regular expression to always add, matching any target.
    executable_target_pattern: Regular expression limiting executable targets.
    spec: Specifications for target.
  R&   R4   i    R8   t    t
   executableR(   t   bundleN(   RG   RB   t   ret   searcht   Truet   intt   False(   t   target_extrast   executable_target_patternt   specR&   (    (    s3   /usr/lib/python2.7/dist-packages/gyp/xcode_ninja.pyt   IsValidTargetForWrapperƒ   s    
c   $      C   s²  | d d } x3 | j  ƒ  D]% \ } } | | k r | d } q q W| j d i  ƒ } | j d d$ ƒ }	 |	 d$ k r t j j | ƒ \ }
 } |
 d | }	 n  g  } i  } i  } i  | |	 <g  | |	 d <g  | |	 d <| | j d	 i  ƒ | |	 d	 <| j d
 d$ ƒ } | j d d$ ƒ } xÜ |  D]Ô } | | } t | | | ƒ r| j d ƒ } d |	 | f } | j | ƒ t | | ƒ | | <xp | | j	 d ƒ d d D]P } | d | k r›i  } | d | d <| d | d <| |	 d j | ƒ q›q›WqqWd } t i | d 6d d 6d d 6d d 6d d 6d$ ƒ } i i | g d 6d 6| d <| j d t
 ƒ } g  } xM| j  ƒ  D]?\ } } t j j | ƒ } | j d g  ƒ | j d g  ƒ } | sá| j | j d g  ƒ | j d g  ƒ ƒ n  xU | j d g  ƒ D]A } | j | j d  g  ƒ ƒ | sô| j | j d! g  ƒ ƒ qôqôWg  | D] }  |  j d" ƒ s@|  ^ q@} t j j |	 ƒ }! | g  | D]* }  t j j t j j | |  ƒ |! ƒ ^ q}7} qoWt t | ƒ ƒ | d <t j j t j j |	 ƒ | d# ƒ }" d |" | f }# | j |# ƒ | | |# <i  } | d | d <| | d <d | d <i  | |" <g  | |" d <g  | |" d <| | j d	 i  ƒ | |" d	 <| |" d j | ƒ t |	 |" | ƒ | | | f S(%   sš  Initialize targets for the ninja wrapper.

  This sets up the necessary variables in the targets to generate Xcode projects
  that use ninja as an external builder.
  Arguments:
    target_list: List of target pairs: 'base/base.gyp:base'.
    target_dicts: Dict of target properties keyed on target pair.
    data: Dict of flattened build files keyed on gyp path.
    params: Dict of global options for gyp.
  t   build_filesi    t   _DEPTHR$   t   xcode_ninja_main_gyps   .ninjat   included_filest   targetsR-   t%   xcode_ninja_executable_target_patternt   xcode_ninja_target_patternR&   s   %s:%s#targett   :R)   t   sources_for_indexingt   targett   DefaultR*   t   0R3   RU   R8   t   include_dirsR+   t   xcode_ninja_list_excluded_filest   sourcest   mac_bundle_resourcest   sources_excludedt   mac_bundle_resources_excludedRA   R:   t   inputs_excludedt   $s   .gypN(   t	   iteritemsRG   RB   R   R   R   R_   t   appendRS   t   splitRY   t   dirnameRJ   t
   startswitht   relpathR   t   sortedt   setR#   ($   t   target_listt   target_dictst   dataR   t   orig_gypR   t   gyp_dictt   depthR$   R   R   R   t   new_target_listt   new_target_dictst   new_dataR]   R\   t   old_qualified_targetR^   R&   t   new_target_namet
   old_targett   new_data_targett   sources_target_namet   sources_targett   skip_excluded_filesRn   Ri   t   target_dictt   baset   filesR?   t   filet   relative_pathR   t   fully_qualified_target_name(    (    s3   /usr/lib/python2.7/dist-packages/gyp/xcode_ninja.pyt   CreateWrapperž   s’    

"#
	 (9%



(   t   __doc__R
   t   gyp.generator.ninjaRD   R   RW   t   xml.sax.saxutilsR   R#   RS   R_   R’   (    (    (    s3   /usr/lib/python2.7/dist-packages/gyp/xcode_ninja.pyt   <module>   s   	"	K	