
    "Kb(,                     H    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y)a  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.
    Nc                    t         j                  j                  |       \  }}|dz   }|d   }|j                  r*t         j                  j	                  |j                  |      }	 t        j
                  |       d}| |fD ]x  }	t         j                  j                  t         j                  j                  |	            d   dz   }
t        j                  j                  j                  d|
z         }
|d|
z  z  }z |d	z  }t         j                  j	                  |d
      }	 t        |d      5 }|j                         }||k(  r
	 ddd       y	 ddd       t        |d      5 }|j#                  |       ddd       y# t        $ r)}|j                  t        j                  k7  r Y d}~0d}~ww xY w# 1 sw Y   exY w# t         $ r Y sw xY w# 1 sw Y   yxY w)z8 Create a workspace to wrap main and sources gyp paths. z.xcworkspaceoptionsNzC<?xml version="1.0" encoding="UTF-8"?>
<Workspace version = "1.0">
r   z
.xcodeprojzgroup:z$  <FileRef location = %s></FileRef>
z</Workspace>
zcontents.xcworkspacedatarw)ospathsplitextgenerator_outputjoinmakedirsOSErrorerrnoEEXISTbasenamexmlsaxsaxutils	quoteattropenreadIOErrorwrite)main_gypsources_gypparamsbuild_file_rootbuild_file_extworkspace_pathr   eoutput_stringgyp_namenameworkspace_file
input_fileinput_stringoutput_files                  1/usr/lib/python3/dist-packages/gyp/xcode_ninja.py_WriteWorkspacer(      s   &(gg&6&6x&@#?N"^3.9'WW\\'":":NKNKK2-[) Dh77BGG,,X67:\ID77%%ho6D<tCCMD ##-77<<0JK.		nc	" j__&l		& 	& NC  %Km$% %- 
 ww%,,   
 		% %sT   $E<  F= ,F1F= F= !G<	F.F))F.1F:6F= =	G	G	Gc           	      `   d}d}|rx|d   }t         j                  j                  |j                  t        j
                  j                  j                  |            }|j                  di       j                  dd      }| j                  d      }| j                  d|      }| j                  d      }i }||d<   ||d<   |r||d<   | j                  d	      |d	<   | j                  d
      |d
<   i |d<   i }	|rd|z  |	d<   d| v rh| d   j                         D ]R  }
| d   |
   j                  di       }d|v rd|	d<   |d   |	d<   dD ]  }||v s||   |	|<    i |d   |
<   |	|d   |
   d<   T | j                  dd      |d<   | j                  dd      |d<   | j                  dd      |d<   | j                  dd      |d<   | j                  dd      |d<   | d   |d<   |rPd|z  g g ddt         j                  d   z  dd|	d   |gd|z  dg|d <   |dkD  r|d    d   d!   j                  d"|f       |S )#z- Create fake target for xcode-ninja wrapper. Nr   r   generator_flagsxcode_ninja_jobstarget_nameproduct_nameproduct_extensiontoolsetdefault_configurationconfigurationsz-%s/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)CONFIGURATION_BUILD_DIRxcode_settingsIPHONEOS_DEPLOYMENT_TARGETNOCODE_SIGNING_REQUIRED)BUNDLE_LOADER	TEST_HOST
mac_bundlemac_xctest_bundleios_app_extensionios_watchkit_extensionios_watchkit_apptypezCompile and copy %s via ninjaenvzPATH=%sPATHninjaz-C)action_nameinputsoutputsactionmessageactionsrE   z-j)r   r   r   toplevel_dirgyp	generatorrA   ComputeOutputDirgetkeysenvironextend)old_specr   ninja_topleveljobsr   r,   r-   r.   ninja_targetnew_xcode_settingsconfigold_xcode_settingskeys                r'   _TargetFromSpecrX   8   s    .	
$YG
W))]]((99&A	C  ::',001CQGD]++nk:,ll#67, +,}!-,~(9L$%$LL3,y*2,,7N*O,&'#%,  7.H 01 !+,113 !"6*../?D 	%);	;6:23;< 	78/ <#$$$6s$;
S
!< 02l#$V,
 #$V,-=>  (||L!<,|&.ll3F&J,"#&.ll3F&J,"#ll+Q/ '(%-\\2Da%H,!"!&),v 7D

bjj(
(


6
7

 3[@L  ax9a *114,?	    c                    |j                  d      }| t        j                  | |      ryt        |j                  dd            dk7  s*|j                  dd      dk(  r/|j                  dd      d	k7  r|t        j                  ||      sy
yy
)ap  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,   Tr:   r   r>    
executabler.   bundleF)rL   researchint)target_extrasexecutable_target_patternspecr,   s       r'   IsValidTargetForWrapperrd      s     '+299]K#H 
$((&
*+q0xx|+xx#R(H4 !,YY0+>	rY   c                 0   |d   d   }|j                         D ]  \  }}||k(  s|d   } |j                  di       }|j                  dd      }	|	*t        j                  j	                  |      \  }
}|
dz   |z   }	g }i }i }i ||	<   g ||	   d<   g ||	   d	<   ||   j                  d
i       ||	   d
<   |j                  dd      }|j                  dd      }| D ]  }||   }t        |||      s|j                  d      }|	d|d}|j                  |       t        ||      ||<   ||j                  d      d      d	   D ]4  }|d   |k(  si }|d   |d<   |d   |d<   ||	   d	   j                  |       6  d}t        |dddddd      }ddgii|d<   |j                  dd       }g }|j                         D ]k  \  }}t        j                  j                  |      }|j                  dg       |j                  dg       z   }|s4|j                  |j                  dg       |j                  dg       z          |j                  dg       D ]G  }|j                  |j                  d g              |r'|j                  |j                  d!g              I |D  cg c]  } | j                  d"      r|  }} t        j                  j                  |	      }!||D  cg c]@  } t        j                  j                  t        j                  j                  ||       |!      B c} z  }n t        t        |            |d<   t        j                  j                  t        j                  j                  |	      |d#z         }"|"d|d}#|j                  |#       |||#<   i }|d   |d<   ||d<   d|d<   i ||"<   g ||"   d	<   g ||"   d<   ||   j                  d
i       ||"   d
<   ||"   d	   j                  |       t!        |	|"|       |||fS c c} w c c} w )$a  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.
  build_filesr   _DEPTHr*   xcode_ninja_main_gypNz.ninjaincluded_filestargetsr3   %xcode_ninja_executable_target_patternxcode_ninja_target_patternr,   :z#targetr/   sources_for_indexingtargetDefault0r\   )r,   r/   r0   r9   r>   include_dirsr1   xcode_ninja_list_excluded_filesTsourcesmac_bundle_resourcessources_excludedmac_bundle_resources_excludedrG   rC   inputs_excluded$z.gyp)itemsrL   r   r   r	   rd   appendrX   splitdirnamerO   
startswithrelpathr   sortedsetr(   )$target_listtarget_dictsdatar   orig_gypr!   gyp_dictdepthr*   r   r   r   new_target_listnew_target_dictsnew_datarb   ra   old_qualified_targetrc   r,   new_target_name
old_targetnew_data_targetsources_target_namesources_targetskip_excluded_filesrt   ro   target_dictbasefilesrE   filerelative_pathr   fully_qualified_target_names$                                       r'   CreateWrapperr      s    M"1%( JJL !h8x e! JJ0"5/  !7>((*(8(8(B%_n)N:H /( (8)+(8%&"$(8Y
8n)2. 8%& A4H 
 "%%&BDI-) @,-D}.GNHH]+k*2K@o_- +:$*G' 177<Q?@K @*m$3/+5m+D/-
('1)'</)
$
8
Y
'
.
.
?@@( /")(	
 . '0>U91N%P.!" 

?
FF  ')//1 (fk77??6"DOOIr*OO2B78E ll;??#5r:??#BBGH I //)R0 8ll6::h+, VZZ 1267	8  %AtDOOC,@dAEA GGOOH-M %( dD!9=I ( (G+(0 %S\2. 	ggll277??8,.AF.JK  $%89  452@.//#1-#@/- #/('/)(;%'(;	",.(;()
8n)2. ;()
;	"))/: (K0
+X	66? B(s   P5PAP)__doc__r   gyp.generator.ninjarI   r   r^   xml.sax.saxutilsr   r(   rX   rd   r    rY   r'   <module>r      s3   
   	 	  %DIV6C7rY   