
    "Kb(,                     J    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 )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                            |           \  }}|dz   }|d         }|j        r%t           j                            |j        |          }	 t          j        |           n-# t          $ r }|j        t          j        k    r Y d}~nd}~ww xY wd}| |fD ]v}	t           j                            t           j        	                    |	                    d         dz   }
t          j        j                            d|
z             }
|d|
z  z  }w|d	z  }t           j                            |d
          }	 t          |d          5 }|                                }||k    r	 ddd           dS 	 ddd           n# 1 swxY w Y   n# t           $ r Y nw xY wt          |d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )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   &(g&6&6x&@&@#?N"^3.9' LW\\'":NKKNK	   w%, 2-[) D Dh7BG,,X6677:\ID7%%ho66D<tCCMM##-7<<0JKK.		nc	"	" j__&&l		&	&       	&               
 	 	 	D	 NC   %Km$$$% % % % % % % % % % % % % % % % % %sf   A2 2
B<BBF F.F <F FF FF 
F! F!4GGGc           	         d}d}|ry|d         }t           j                            |j        t          j        j                            |                    }|                    di                               dd          }|                     d          }|                     d|          }|                     d          }i }||d<   ||d<   |r||d<   |                     d	          |d	<   |                     d
          |d
<   i |d<   i }	|rd|z  |	d<   d| v r| d         	                                D ]h}
| d         |
                             di           }d|v rd|	d<   |d         |	d<   dD ]}||v r||         |	|<   i |d         |
<   |	|d         |
         d<   i|                     dd          |d<   |                     dd          |d<   |                     dd          |d<   |                     dd          |d<   |                     dd          |d<   | d         |d<   |r`d|z  g g ddt           j
        d         z  dd|	d         |gd|z  dg|d <   |dk    r)|d          d         d!                             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   sA    .	
$ HYG
W)](99&AA	C 	C  ::',,001CQGGD]+++nk::,ll#677, +,}!-,~ :(9L$%$LL33,y*2,,7N*O*O,&'#%,   I7.H 01 !!+,1133  !"6*../?DD 	%);	;	;6:23;< 	78/ < <#$$$$6s$;
S
!/1l#$V,
 #$V,-=>>  (||L!<<,|&.ll3F&J&J,"#&.ll3F&J&J,"#ll+Q// '(%-\\2Da%H%H,!"!&),v @ 7D

bj(
(


6
7

 3[@ L  axx9a *114,???	    c                 N   |                     d          }| t          j        | |          rdS t          |                     dd                    dk    s4|                     dd          dk    r5|                     d	d          d
k    r|t          j        ||          sdS dS dS )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,   NTr:   r   r>    
executabler.   bundleF)rL   researchint)target_extrasexecutable_target_patternspecr,   s       r'   IsValidTargetForWrapperrd      s     ''+29]K#H#H4 
$((&
*
*++q00xx|++xx#R((H44 !,Y0+>> u4	rY   c                   !" |d         d         }|                                 D ]\  }}||k    r|d         }|                    di           }|                    dd          }	|	*t          j                            |          \  }
}|
dz   |z   }	g }i }i }i ||	<   g ||	         d<   g ||	         d	<   ||                             d
i           ||	         d
<   |                    dd          }|                    dd          }| D ]}||         }t          |||          r|                    d          }|	d|d}|                    |           t          ||          ||<   ||                    d          d                  d	         D ]G}|d         |k    r9i }|d         |d<   |d         |d<   ||	         d	                             |           Hd}t          |dddddd          }dd|gii|d<   |                    dd           }g }|                                 D ]>\  }}t          j        	                    |          !|                    dg           |                    dg           z   }|s@|
                    |                    dg           |                    dg           z              |                    dg           D ]V}|
                    |                    d g                      |s)|
                    |                    d!g                      Wd" |D             }t          j        	                    |	          "|!"fd#|D             z  }@t          t          |                    |d<   t          j                            t          j        	                    |	          |d$z             }|d|d} |                    |            ||| <   i }|d         |d<   ||d<   d|d<   i ||<   g ||         d	<   g ||         d<   ||                             d
i           ||         d
<   ||         d	                             |           t          |	||           |||fS )%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_excludedc                 <    g | ]}|                     d           |S )$)
startswith).0files     r'   
<listcomp>z!CreateWrapper.<locals>.<listcomp>  s)    AAAtDOOC,@,@AdAAArY   c                     g | ]@}t           j                            t           j                            |                    AS  )r   r   relpathr   )r|   r}   baserelative_paths     r'   r~   z!CreateWrapper.<locals>.<listcomp>  sI     ( ( ( dD!9!9=II ( ( (rY   z.gyp)itemsrL   r   r   r	   rd   appendrX   splitdirnamerO   sortedsetr   r(   )#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filesrE   r   fully_qualified_target_namer   r   s#                                    @@r'   CreateWrapperr      se    M"1%( JJLL ! !h8x e JJ0"55/  !7>>((*(8(8(B(B%_n)N:H /( (8)+(8%&"$(8Y
8n)2.. 8%& A4HH 
 "%%&BDII-) @ @,-D}.GNN @HH]++k*2((KKK@o_--- +:$*G*G' 177<<Q?@K @ @*m$33/+5m+D/-
('1)'</)
$
8
Y
'
.
.
?
?
? /")(	 
  . '0>U91N%P.!" 

?
F
FF  ')//11 ( (fk7??6""DOOIr**OO2B778E  Ill;??#5r::??#BBGGH I I I //)R00 8 8ll6::h++,,,  8VZZ 1266777 BAuAAAE GOOH--M ( ( ( ( ( %( ( ( (GG %S\\22. 	gll27??8,,.AF.JKK  $%8%8%89  45552@.//#1-#@/- #/('/)(;%'(;	",.(;()
8n)2.. ;()
;	"))/::: (K000
+X	66rY   )__doc__r   gyp.generator.ninjarI   r   r^   xml.sax.saxutilsr   r(   rX   rd   r   r   rY   r'   <module>r      s   
       				 				     %  %  %DI I IV  6C7 C7 C7 C7 C7rY   