o
    Äñbh ã                   @   sD  d Z ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlmZ dadad2dd„ZG dd„ deƒZd	d
„ ZG dd„ deƒZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z	d2dd „Zd!d"„ Zd#d$„ Z d%d&„ Z!	d2d'd(„Z"d3d*d+„Z#d,d-„ Z$d.d/„ Z%d0d1„ Z&dS )4z~
This module contains classes that help to emulate xcodebuild behavior on top of
other build systems, such as make and ninja.
é    )Úprint_functionN)ÚGypErrorc                 C   s   d| i}|r
||d< |S )zConstructs a dictionary with expansion for $(ARCHS_STANDARD) variable,
  and optionally for $(ARCHS_STANDARD_INCLUDING_64_BIT).ú$(ARCHS_STANDARD)ú"$(ARCHS_STANDARD_INCLUDING_64_BIT)© )ÚarchsÚarchs_including_64_bitÚmappingr   r   ú5/usr/lib/python3/dist-packages/gyp/xcode_emulation.pyÚXcodeArchsVariableMapping!   s   r   c                   @   s:   e Zd ZdZe d¡Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dS )ÚXcodeArchsDefaultzüA class to resolve ARCHS variable from xcode_settings, resolving Xcode
  macros and implementing filtering by VALID_ARCHS. The expansion of macros
  depends on the SDKROOT used ("macosx", "iphoneos", "iphonesimulator") and
  on the version of Xcode.
  z\$\([a-zA-Z_][a-zA-Z0-9_]*\)$c                 C   s   |f| _ |||dœ| _d S )N)ÚmacÚiosÚiossim)Ú_defaultÚ_archs)ÚselfÚdefaultr   ÚiphonesimulatorÚiphoneosr   r   r
   Ú__init__3   s   zXcodeArchsDefault.__init__c                 C   s6   |  ¡ }d|v r| jd S d|v r| jd S | jd S )zDReturns the dictionary of variable mapping depending on the SDKROOT.r   r   r   r   r   )Úlowerr   )r   Úsdkrootr   r   r
   Ú_VariableMapping7   s   


z"XcodeArchsDefault._VariableMappingc           	      C   s˜   |   |¡}g }|D ]@}| j |¡r@|}z|| }|D ]}||vr%| |¡ qW q	 ty? } ztd| ƒ W Y d}~q	d}~ww ||vrI| |¡ q	|S )z=Expands variables references in ARCHS, and remove duplicates.z,Warning: Ignoring unsupported variable "%s".N)r   Úvariable_patternÚmatchÚappendÚKeyErrorÚprint)	r   r   r   Úvariable_mappingÚexpanded_archsÚarchÚvariableÚvariable_expansionÚer   r   r
   Ú_ExpandArchsA   s(   

€þ€ÿ
€zXcodeArchsDefault._ExpandArchsc                 C   sB   |   |p| j|p	d¡}|rg }|D ]}||v r| |¡ q|}|S )zÀExpands variables references in ARCHS, and filter by VALID_ARCHS if it
    is defined (if not set, Xcode accept any value in ARCHS, otherwise, only
    values present in VALID_ARCHS are kept).Ú )r%   r   r   )r   r   Úvalid_archsr   r    Úfiltered_archsr!   r   r   r
   ÚActiveArchsS   s   
€zXcodeArchsDefault.ActiveArchsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚreÚcompiler   r   r   r%   r)   r   r   r   r
   r   )   s    

r   c                  C   s´   t rt S tƒ \} }| dk rtdtdgƒtdgƒtdgƒƒa t S | dk r>tdtdgdgƒtdgddgƒtddgg d	¢ƒƒa t S tdtdgdgƒtddgddgƒtg d	¢g d	¢ƒƒa t S )
aè  Returns the |XcodeArchsDefault| object to use to expand ARCHS for the
  installed version of Xcode. The default values used by Xcode for ARCHS
  and the expansion of the variables depends on the version of Xcode used.

  For all version anterior to Xcode 5.0 or posterior to Xcode 5.1 included
  uses $(ARCHS_STANDARD) if ARCHS is unset, while Xcode 5.0 to 5.0.2 uses
  $(ARCHS_STANDARD_INCLUDING_64_BIT). This variable was added to Xcode 5.0
  and deprecated with Xcode 5.1.

  For "macosx" SDKROOT, all version starting with Xcode 5.0 includes 64-bit
  architecture as part of $(ARCHS_STANDARD) and default to only building it.

  For "iphoneos" and "iphonesimulator" SDKROOT, 64-bit architectures are part
  of $(ARCHS_STANDARD_INCLUDING_64_BIT) from Xcode 5.0. From Xcode 5.1, they
  are also part of $(ARCHS_STANDARD).

  All thoses rules are coded in the construction of the |XcodeArchsDefault|
  object to use depending on the version of Xcode detected. The object is
  for performance reason.Ú0500r   Úi386Úarmv7Ú0510r   Úx86_64Úarmv7s)r2   r5   Úarm64)ÚXCODE_ARCHS_DEFAULT_CACHEÚXcodeVersionr   r   )Úxcode_versionÚ_r   r   r
   ÚGetXcodeArchsDefaulta   s@   
üðþüùþür;   c                   @   sŠ  e Zd ZdZi Zi Zi Zi Zi Zdd„ Z	dd„ Z
dd„ Zdd	„ Zd–dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Z d3d4„ Z!d5d6„ Z"d7d8„ Z#d9d:„ Z$d;d<„ Z%d=d>„ Z&d?d@„ Z'dAdB„ Z(dCdD„ Z)dEdF„ Z*dGdH„ Z+dIdJ„ Z,dKdL„ Z-dMdN„ Z.dOdP„ Z/dQdR„ Z0d–dSdT„Z1d–dUdV„Z2dWdX„ Z3dYdZ„ Z4d–d[d\„Z5d]d^„ Z6d_d`„ Z7dadb„ Z8dcdd„ Z9dedf„ Z:dgdh„ Z;didj„ Z<dkdl„ Z=dmdn„ Z>dodp„ Z?dqdr„ Z@d–dsdt„ZAdudv„ ZBdwdx„ ZCd–dydz„ZDd–d{d|„ZEd}d~„ ZFdd€„ ZG	d—d‚dƒ„ZHd„d…„ ZId†d‡„ ZJg dfdˆd‰„ZKd–dŠd‹„ZLd–dŒd„ZMdŽd„ ZNdd‘„ ZOd–d’d“„ZPd”d•„ ZQd
S )˜ÚXcodeSettingsz9A class that understands the gyp 'xcode_settings' object.c                 C   s‚   || _ d| _d | _d | _i | _|d }| ¡ D ]\}}| di ¡| j|< |  |¡ | j|  dd ¡r5d| _qd | _t	 
d¡| _d S )NFÚconfigurationsÚxcode_settingsÚIPHONEOS_DEPLOYMENT_TARGETTz^lib([^/]+)\.(a|dylib)$)ÚspecÚisIOSÚmac_toolchain_dirÚheader_map_pathr>   ÚitemsÚgetÚ_ConvertConditionalKeysÚ
confignamer.   r/   Ú
library_re)r   r@   ÚconfigsrG   Úconfigr   r   r
   r   £   s    
ÿ€zXcodeSettings.__init__c                 C   sl   | j | }dd„ |D ƒ}|D ]%}| d¡r(| d¡r'| d¡d }|| ||< ntdd |¡ƒ ||= qd	S )
zÖConverts or warns on conditional keys.  Xcode supports conditional keys,
    such as CODE_SIGN_IDENTITY[sdk=iphoneos*].  This is a partial implementation
    with some keys converted while the rest force a warning.c                 S   s   g | ]	}|  d ¡r|‘qS )ú])Úendswith©Ú.0Úkeyr   r   r
   Ú
<listcomp>Â   s    z9XcodeSettings._ConvertConditionalKeys.<locals>.<listcomp>z[sdk=iphoneos*]r   ú[r   z4Warning: Conditional keys not implemented, ignoring:ú N)r>   rL   Úsplitr   Újoin)r   rG   ÚsettingsÚconditional_keysrO   Únew_keyr   r   r
   rF   ½   s   


€ÿ÷z%XcodeSettings._ConvertConditionalKeysc                 C   s   | j sJ ‚| j| j  S ©N)rG   r>   ©r   r   r   r
   Ú	_SettingsÎ   s   
zXcodeSettings._Settingsc                 C   s   |   ¡  ||¡|kS rX   )rZ   rE   )r   Útest_keyÚcond_keyr   r   r   r
   Ú_TestÒ   s   zXcodeSettings._TestNc                 C   sH   ||   ¡ v r| |t|   ¡ | ƒ ¡ d S |r"| |t|ƒ ¡ d S d S rX   )rZ   r   Ústr)r   Úlstr[   Ú
format_strr   r   r   r
   Ú_AppendfÕ   s
   ÿzXcodeSettings._Appendfc                 C   s    ||   ¡ v rtd| ƒ d S d S )Nz/Warning: Ignoring not yet implemented key "%s".)rZ   r   )r   r[   r   r   r
   Ú_WarnUnimplementedÛ   s   ÿz XcodeSettings._WarnUnimplementedc                 C   s(   | j rdnd}| j|  d|¡}|dkS )NÚbinaryÚxmlÚINFOPLIST_OUTPUT_FORMAT)rA   r>   rE   )r   rG   r   Úformatr   r   r
   ÚIsBinaryOutputFormatß   s
   ÿz"XcodeSettings.IsBinaryOutputFormatc                 C   s   | j d dko|  ¡ o| jS )NÚtypeÚshared_library)r@   Ú	_IsBundlerA   rY   r   r   r
   ÚIsIosFrameworkå   s   ÿzXcodeSettings.IsIosFrameworkc                 C   s&   t | j dd¡ƒdkp|  ¡ p|  ¡ S )NÚ
mac_bundler   )Úintr@   rE   Ú	_IsXCTestÚ_IsXCUiTestrY   r   r   r
   rj   é   s   ÿzXcodeSettings._IsBundlec                 C   ó   t | j dd¡ƒdkS )NÚmac_xctest_bundler   ©rm   r@   rE   rY   r   r   r
   rn   í   ó   zXcodeSettings._IsXCTestc                 C   rp   )NÚmac_xcuitest_bundler   rr   rY   r   r   r
   ro   ð   rs   zXcodeSettings._IsXCUiTestc                 C   rp   )NÚios_app_extensionr   rr   rY   r   r   r
   Ú_IsIosAppExtensionó   rs   z XcodeSettings._IsIosAppExtensionc                 C   rp   )NÚios_watchkit_extensionr   rr   rY   r   r   r
   Ú_IsIosWatchKitExtensionö   rs   z%XcodeSettings._IsIosWatchKitExtensionc                 C   rp   )NÚios_watch_appr   rr   rY   r   r   r
   Ú_IsIosWatchAppù   rs   zXcodeSettings._IsIosWatchAppc                 C   s   |   ¡ sJ ‚| jdddS )zPReturns the framework version of the current target. Only valid for
    bundles.ÚFRAMEWORK_VERSIONÚA©r   )rj   ÚGetPerTargetSettingrY   r   r   r
   ÚGetFrameworkVersionü   s   z!XcodeSettings.GetFrameworkVersionc                 C   s¬   |   ¡ sJ ‚| jd dv r'dddœ| jd  }| jd|d}d| j d|¡ S | jd d	krH|  ¡ s6|  ¡ r?d| j dd
¡ S d| j dd¡ S J d| jd | jd f ƒ‚)z[Returns the bundle extension (.app, .framework, .plugin, etc).  Only
    valid for bundles.rh   ©Úloadable_moduleri   ÚbundleÚ	frameworkÚWRAPPER_EXTENSIONr}   Ú.Úproduct_extensionÚ
executableÚappexÚappFz*Don't know extension for '%s', target '%s'Útarget_name)rj   r@   r~   rE   rv   rx   )r   Údefault_wrapper_extensionÚwrapper_extensionr   r   r
   ÚGetWrapperExtension  s$   þýÿÿz!XcodeSettings.GetWrapperExtensionc                 C   s   | j  d| j d ¡S )zReturns PRODUCT_NAME.Úproduct_namerŠ   ©r@   rE   rY   r   r   r
   ÚGetProductName  s   zXcodeSettings.GetProductNamec                 C   ó   |   ¡ r|  ¡ S |  ¡ S )zReturns FULL_PRODUCT_NAME.)rj   ÚGetWrapperNameÚ_GetStandaloneBinaryPathrY   r   r   r
   ÚGetFullProductName  s   z XcodeSettings.GetFullProductNamec                 C   s   |   ¡ sJ ‚|  ¡ |  ¡  S )z`Returns the directory name of the bundle represented by this target.
    Only valid for bundles.)rj   r   r   rY   r   r   r
   r’   "  s   zXcodeSettings.GetWrapperNamec                 C   sR   | j r|  ¡ S |  ¡ sJ ‚| jd dkr tj |  ¡ d|  ¡ ¡S tj |  ¡ d¡S )zŒReturns the qualified path to the bundle's contents folder. E.g.
    Chromium.app/Contents or Foo.bundle/Versions/A. Only valid for bundles.rh   ri   ÚVersionsÚContents)rA   r’   rj   r@   ÚosÚpathrT   r   rY   r   r   r
   ÚGetBundleContentsFolderPath(  s   ÿz)XcodeSettings.GetBundleContentsFolderPathc                 C   s,   |   ¡ sJ ‚| jr|  ¡ S tj |  ¡ d¡S )z}Returns the qualified path to the bundle's resource folder. E.g.
    Chromium.app/Contents/Resources. Only valid for bundles.Ú	Resources)rj   rA   r™   r—   r˜   rT   rY   r   r   r
   ÚGetBundleResourceFolder5  s   z%XcodeSettings.GetBundleResourceFolderc                 C   sL   |   ¡ sJ ‚| jd dv s| jr|  ¡ S | jd dv r$tj |  ¡ d¡S dS )z|Returns the qualified path to the bundle's executables folder. E.g.
    Chromium.app/Contents/MacOS. Only valid for bundles.rh   ri   ©r‡   r   ÚMacOSN)rj   r@   rA   r™   r—   r˜   rT   rY   r   r   r
   ÚGetBundleExecutableFolderPath=  s   ÿz+XcodeSettings.GetBundleExecutableFolderPathc                 C   ó   |   ¡ sJ ‚tj |  ¡ d¡S )z‡Returns the qualified path to the bundle's Java resource folder.
    E.g. Chromium.app/Contents/Resources/Java. Only valid for bundles.ÚJava)rj   r—   r˜   rT   r›   rY   r   r   r
   ÚGetBundleJavaFolderPathF  ó   z%XcodeSettings.GetBundleJavaFolderPathc                 C   rŸ   )z€Returns the qualified path to the bundle's frameworks folder. E.g,
    Chromium.app/Contents/Frameworks. Only valid for bundles.Ú
Frameworks©rj   r—   r˜   rT   r™   rY   r   r   r
   ÚGetBundleFrameworksFolderPathL  r¢   z+XcodeSettings.GetBundleFrameworksFolderPathc                 C   rŸ   )z†Returns the qualified path to the bundle's frameworks folder. E.g,
    Chromium.app/Contents/SharedFrameworks. Only valid for bundles.ÚSharedFrameworksr¤   rY   r   r   r
   Ú#GetBundleSharedFrameworksFolderPathR  s   ÿz1XcodeSettings.GetBundleSharedFrameworksFolderPathc                 C   s4   |   ¡ sJ ‚| jd dkr|  ¡ S tj |  ¡ d¡S )z‡Returns the qualified path to the bundle's shared support folder. E.g,
    Chromium.app/Contents/SharedSupport. Only valid for bundles.rh   ri   ÚSharedSupport)rj   r@   r›   r—   r˜   rT   r™   rY   r   r   r
   Ú GetBundleSharedSupportFolderPathY  s   ÿz.XcodeSettings.GetBundleSharedSupportFolderPathc                 C   rŸ   )zzReturns the qualified path to the bundle's plugins folder. E.g,
    Chromium.app/Contents/PlugIns. Only valid for bundles.ÚPlugInsr¤   rY   r   r   r
   ÚGetBundlePlugInsFolderPathc  r¢   z(XcodeSettings.GetBundlePlugInsFolderPathc                 C   rŸ   )zƒReturns the qualified path to the bundle's XPC services folder. E.g,
    Chromium.app/Contents/XPCServices. Only valid for bundles.ÚXPCServicesr¤   rY   r   r   r
   ÚGetBundleXPCServicesFolderPathi  r¢   z,XcodeSettings.GetBundleXPCServicesFolderPathc                 C   sH   |   ¡ sJ ‚| jd dv s|  ¡ rtj |  ¡ d¡S tj |  ¡ dd¡S )zyReturns the qualified path to the bundle's plist file. E.g.
    Chromium.app/Contents/Info.plist. Only valid for bundles.rh   rœ   z
Info.plistrš   )rj   r@   rk   r—   r˜   rT   r™   rY   r   r   r
   ÚGetBundlePlistPatho  s   ÿÿz XcodeSettings.GetBundlePlistPathc                 C   sÎ   |   ¡ r|  ¡ sJ d| jd  ƒ‚dS |  ¡ r&|  ¡ s$J d| jd  ƒ‚dS |  ¡ r9|  ¡ s7J d| jd  ƒ‚dS |  ¡ rL|  ¡ sJJ d| jd  ƒ‚d	S |  ¡ r[d
dddœ| jd  S dddddœ| jd  S )z(Returns the PRODUCT_TYPE of this target.z6ios_app_extension flag requires mac_bundle (target %s)rŠ   z$com.apple.product-type.app-extensionz;ios_watchkit_extension flag requires mac_bundle (target %s)z)com.apple.product-type.watchkit-extensionz2ios_watch_app flag requires mac_bundle (target %s)z+com.apple.product-type.application.watchappz8mac_xcuitest_bundle flag requires mac_bundle (target %s)z(com.apple.product-type.bundle.ui-testingz"com.apple.product-type.applicationzcom.apple.product-type.bundlez com.apple.product-type.framework)r‡   r   ri   rh   zcom.apple.product-type.toolz&com.apple.product-type.library.dynamicz%com.apple.product-type.library.static)r‡   r   ri   Ústatic_library)rv   rj   r@   rx   rz   ro   rY   r   r   r
   ÚGetProductTypez  sD   ÿÿÿÿýüüûzXcodeSettings.GetProductTypec                 C   s2   |   ¡ s| jd dkrdS dddddœ| jd  S )	z'Returns the MACH_O_TYPE of this target.rh   r‡   r&   Ú
mh_executeÚ	staticlibÚmh_dylibÚ	mh_bundle©r‡   r¯   ri   r   )rj   r@   rY   r   r   r
   ÚGetMachOTypeš  s   üûzXcodeSettings.GetMachOTypec                 C   s"   |   ¡ sJ ‚tj |  ¡ |  ¡ ¡S )zReturns the name of the bundle binary of by this target.
    E.g. Chromium.app/Contents/MacOS/Chromium. Only valid for bundles.)rj   r—   r˜   rT   rž   ÚGetExecutableNamerY   r   r   r
   Ú_GetBundleBinaryPath¦  s   ÿz"XcodeSettings._GetBundleBinaryPathc                 C   s0   d| j v rd| j d  S dddddœ| j d  S )	Nr†   r…   r&   z.aú.dylibz.sorµ   rh   )r@   rY   r   r   r
   Ú_GetStandaloneExecutableSuffix­  s   
üûz,XcodeSettings._GetStandaloneExecutableSuffixc                 C   s"   | j  ddddddœ| j d  ¡S )NÚproduct_prefixr&   Úlibrµ   rh   r   rY   r   r   r
   Ú_GetStandaloneExecutablePrefix·  s   úùz,XcodeSettings._GetStandaloneExecutablePrefixc                 C   s¶   |   ¡ rJ ‚| jd dv sJ d| jd  ƒ‚| jd }| jd dkr1|dd… dkr0|dd… }n| jd d	v rF|dd… dkrF|dd… }|  ¡ }| j d
|¡}|  ¡ }|| | S )zwReturns the name of the non-bundle binary represented by this target.
    E.g. hello_world. Only valid for non-bundles.rh   )r‡   ri   r¯   r   zUnexpected type %srŠ   r¯   Né   r¼   r€   rŽ   )rj   r@   r½   rE   rº   )r   ÚtargetÚtarget_prefixÚ
target_extr   r   r
   r“   Á  s    þ
€z&XcodeSettings._GetStandaloneBinaryPathc                 C   s$   |   ¡ r| j d| jd ¡S |  ¡ S )zXReturns the executable name of the bundle represented by this target.
    E.g. Chromium.rŽ   rŠ   )rj   r@   rE   r“   rY   r   r   r
   r·   Õ  s   zXcodeSettings.GetExecutableNamec                 C   r‘   )zReturns the qualified path to the primary executable of the bundle
    represented by this target. E.g. Chromium.app/Contents/MacOS/Chromium.)rj   r¸   r“   rY   r   r   r
   ÚGetExecutablePathÝ  s   zXcodeSettings.GetExecutablePathc                 C   s0   | j | }tƒ }| | d¡| d¡| d¡¡S )z:Returns the architectures this target should be built for.ÚARCHSÚVALID_ARCHSÚSDKROOT)r>   r;   r)   rE   )r   rG   Úconfig_settingsÚxcode_archs_defaultr   r   r
   ÚGetActiveArchså  s   
ýzXcodeSettings.GetActiveArchsc                 C   s    z	t dd||gƒW S    Y d S )NÚxcrunz--sdk)ÚGetStdoutQuiet)r   ÚsdkÚinfoitemr   r   r
   Ú_GetSdkVersionInfoItemî  s   z$XcodeSettings._GetSdkVersionInfoItemc                 C   s   |d u r| j }| jd|ddS )NrÅ   r&   r}   )rG   ÚGetPerConfigSetting)r   rG   r   r   r
   Ú_SdkRootø  s   zXcodeSettings._SdkRootc                 C   s4   |   |¡}|tjvr|  |d¡}|tj|< tj| S )Nz--show-sdk-platform-path)rÏ   r<   Ú_platform_path_cacherÍ   )r   rG   Úsdk_rootÚplatform_pathr   r   r
   Ú_XcodePlatformPathý  s   

ÿ

z XcodeSettings._XcodePlatformPathc                 C   s"   |   |¡}| d¡r|S |  |¡S )Nú/)rÏ   Ú
startswithÚ_XcodeSdkPath)r   rG   rÑ   r   r   r
   Ú_SdkPath  s   


zXcodeSettings._SdkPathc                 C   s8   |t jvr|  |d¡}|t j|< |r|t j|< t j| S )Nz--show-sdk-path)r<   Ú_sdk_path_cacherÍ   Ú_sdk_root_cache)r   rÑ   Úsdk_pathr   r   r
   rÖ     s   



zXcodeSettings._XcodeSdkPathc                 C   s`   |   |dd¡ d|  ¡ v r.tj |  ¡ ¡}| ¡  d¡r%|   |dd¡ d S |   |dd¡ d S d S )NÚMACOSX_DEPLOYMENT_TARGETz-mmacosx-version-min=%sr?   r   z-mios-simulator-version-min=%sz-miphoneos-version-min=%s)ra   rZ   r—   r˜   Úbasenamer×   r   rÕ   )r   r_   Úsdk_path_basenamer   r   r
   Ú_AppendPlatformVersionMinFlags  s   ÿÿùz,XcodeSettings._AppendPlatformVersionMinFlagsc                 C   s®  || _ g }|  ¡ }d|  ¡ v r|r| d| ¡ | jr#| d| j ¡ | jddddr0| d¡ | jd	dddr=| d
¡ | jddddrJ| d¡ d|  ¡ v r^|  ¡ d dkr]| d¡ n	 | jddddrl| d¡ | j|dddd | jddddr§|  ¡  dd¡}|dkr| d¡ n|dkr—tdƒ‚|dkr¡| d¡ ntd| ƒ‚|  ¡  d¡dkr¶| d¡ n|  ¡  d¡dkrÄ| d¡ | jddddrÑ| d ¡ | jd!dddrÞ| d"¡ | jd#dddrë| d$¡ | jd%dddrø| d&¡ |  	|¡ | jd'dddr|  
d'¡ |  
d(¡ |  
d)¡ |  
d*¡ |  
d+¡ |d,ur(|g}n| j s.J ‚|  | j ¡}t|ƒd-krC|  
d.¡ d/g}| d0|d1  ¡ |d1 d2v r‹| jd3dddra| d4¡ | jd5dddro| d6¡ | jd7dddr}| d8¡ | jd9dddr‹| d:¡ ||  ¡  d;g ¡7 }|  ¡ r«|  |¡}|r«| d<| d= ¡ |r±|}nd>}| jd? | j  }	|	 d@g ¡}
|
D ]}| d<| dA|¡ ¡ qÃd,| _ |S )BzMReturns flags that need to be added to .c, .cc, .m, and .mm
    compilations.rÅ   z-isysroot %sz-I%sÚCLANG_WARN_CONSTANT_CONVERSIONÚYESÚNOr}   z-Wconstant-conversionÚGCC_CHAR_IS_UNSIGNED_CHARz-funsigned-charÚGCC_CW_ASM_SYNTAXz-fasm-blocksÚGCC_DYNAMIC_NO_PICz-mdynamic-no-picÚGCC_ENABLE_PASCAL_STRINGSz-mpascal-stringsÚGCC_OPTIMIZATION_LEVELz-O%sÚsÚGCC_GENERATE_DEBUGGING_SYMBOLSÚDEBUG_INFORMATION_FORMATÚdwarfz	-gdwarf-2Ústabsz(stabs debug format is not supported yet.údwarf-with-dsymzUnknown debug format %sÚGCC_STRICT_ALIASINGz-fstrict-aliasingz-fno-strict-aliasingÚGCC_SYMBOLS_PRIVATE_EXTERNz-fvisibility=hiddenÚGCC_TREAT_WARNINGS_AS_ERRORSz-WerrorÚGCC_WARN_ABOUT_MISSING_NEWLINEz-Wnewline-eofÚLLVM_LTOz-fltoÚCOPY_PHASE_STRIPÚGCC_DEBUGGING_SYMBOLSÚGCC_ENABLE_OBJC_EXCEPTIONSÚMACH_O_TYPEÚPRODUCT_TYPENé   rÃ   r1   ú-arch r   )r1   r4   ÚGCC_ENABLE_SSE3_EXTENSIONSz-msse3Ú)GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONSz-mssse3ÚGCC_ENABLE_SSE41_EXTENSIONSz-msse4.1ÚGCC_ENABLE_SSE42_EXTENSIONSz-msse4.2ÚWARNING_CFLAGSú-Fú/Developer/Library/Frameworks/r&   r=   Úmac_framework_dirsú
$(SDKROOT))rG   r×   rZ   r   rC   r]   ra   rE   ÚNotImplementedErrorrÞ   rb   rÈ   Úlenrn   rÓ   r@   Úreplace)r   rG   r!   ÚcflagsrÑ   Ú
dbg_formatr   Úplatform_rootÚframework_rootrJ   Úframework_dirsÚ	directoryr   r   r
   Ú	GetCflags  s¤   



€














ÿ




zXcodeSettings.GetCflagsc                 C   sV   || _ g }|  ¡  dd¡dkr| d¡ n|  |dd¡ ||  ¡  dg ¡7 }d| _ |S )z?Returns flags that need to be added to .c, and .m compilations.ÚGCC_C_LANGUAGE_STANDARDr&   Úansiz-ansiú-std=%sÚOTHER_CFLAGSN)rG   rZ   rE   r   ra   )r   rG   Úcflags_cr   r   r
   Ú
GetCflagsC›  s   zXcodeSettings.GetCflagsCc                 C   s  || _ g }|  ¡  d¡}|r| d| ¡ |  |dd¡ | jddddr)| d	¡ | jd
dddr6| d¡ | jddddrC| d¡ | jddddrP| d¡ | jddddr]| d¡ g }|  ¡  ddg¡D ]}|dv rpd}|dv r||  ¡  dg ¡7 }qh| |¡ qh||7 }d| _ |S )zAReturns flags that need to be added to .cc, and .mm compilations.ÚCLANG_CXX_LANGUAGE_STANDARDr  ÚCLANG_CXX_LIBRARYú
-stdlib=%sÚGCC_ENABLE_CPP_RTTIrá   rà   r}   z	-fno-rttiÚGCC_ENABLE_CPP_EXCEPTIONSz-fno-exceptionsÚGCC_INLINES_ARE_PRIVATE_EXTERNz-fvisibility-inlines-hiddenÚGCC_THREADSAFE_STATICSz-fno-threadsafe-staticsÚ%GCC_WARN_ABOUT_INVALID_OFFSETOF_MACROz-Wno-invalid-offsetofÚOTHER_CPLUSPLUSFLAGSú$(inherited))z
$inheritedr  z${inherited}ú$OTHER_CFLAGS)r  z$(OTHER_CFLAGS)z${OTHER_CFLAGS}r  N)rG   rZ   rE   r   ra   r]   )r   rG   Ú	cflags_ccÚclang_cxx_language_standardÚother_ccflagsÚflagr   r   r
   ÚGetCflagsCC§  s8   ÿ




zXcodeSettings.GetCflagsCCc                 C   s@   |   ¡  dd¡}|dkr| d¡ d S |dkr| d¡ d S d S )NÚGCC_ENABLE_OBJC_GCÚunsupportedÚ	supportedz	-fobjc-gcÚrequiredz-fobjc-gc-only)rZ   rE   r   )r   ÚflagsÚ	gc_policyr   r   r
   Ú$_AddObjectiveCGarbageCollectionFlagsÐ  s   ÿz2XcodeSettings._AddObjectiveCGarbageCollectionFlagsc                 C   s<   | j ddddr| d¡ | j ddddr| d¡ d S d S )NÚCLANG_ENABLE_OBJC_ARCrà   rá   r}   z
-fobjc-arcÚCLANG_ENABLE_OBJC_WEAKz-fobjc-weak©r]   r   ©r   r&  r   r   r
   Ú_AddObjectiveCARCFlags×  s
   
ÿz$XcodeSettings._AddObjectiveCARCFlagsc                 C   s"   | j ddddr| d¡ d S d S )NÚ*CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESISrà   rá   r}   z!-Wobjc-missing-property-synthesisr+  r,  r   r   r
   Ú+_AddObjectiveCMissingPropertySynthesisFlagsÝ  s
   ÿþz9XcodeSettings._AddObjectiveCMissingPropertySynthesisFlagsc                 C   s2   || _ g }|  |¡ |  |¡ |  |¡ d| _ |S )z7Returns flags that need to be added to .m compilations.N)rG   r(  r-  r/  )r   rG   Úcflags_objcr   r   r
   ÚGetCflagsObjCâ  s   


zXcodeSettings.GetCflagsObjCc                 C   sL   || _ g }|  |¡ |  |¡ |  |¡ | jddddr!| d¡ d| _ |S )z8Returns flags that need to be added to .mm compilations.ÚGCC_OBJC_CALL_CXX_CDTORSrà   rá   r}   z-fobjc-call-cxx-cdtorsN)rG   r(  r-  r/  r]   r   )r   rG   Úcflags_objccr   r   r
   ÚGetCflagsObjCCì  s   



zXcodeSettings.GetCflagsObjCCc                 C   sF   | j d dkr| j d dks|  ¡ rdS | jd|  ¡ rdndd}|S )	z/Return DYLIB_INSTALL_NAME_BASE for this target.rh   ri   r   NÚDYLIB_INSTALL_NAME_BASEz/Library/Frameworksz/usr/local/libr}   )r@   rj   r~   )r   Úinstall_baser   r   r
   ÚGetInstallNameBaseø  s   þz XcodeSettings.GetInstallNameBasec                 C   sJ   d|v r#d|}}|  d¡r| dd¡\}}tj |¡}tj ||¡}|S )z(Do :standardizepath processing for path.rÔ   r&   ú@r÷   )rÕ   rS   r—   r˜   ÚnormpathrT   )r   r˜   ÚprefixÚrestr   r   r
   Ú_StandardizePath  s   

zXcodeSettings._StandardizePathc                 C   sÐ   | j d dkr| j d dks|  ¡ rdS d}| jd|d}d|v rf|d	|fv s2J d
| j d |f ƒ‚| d|  |  ¡ ¡¡}|  ¡ rR| d|  ¡ ¡}| d|  ¡ ¡}nd|vsXJ ‚d|vs^J ‚| d|  ¡ ¡}|S )z-Return LD_DYLIB_INSTALL_NAME for this target.rh   ri   r   Nz=$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)ÚLD_DYLIB_INSTALL_NAMEr}   ú$zJ$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(WRAPPER_NAME)/$(PRODUCT_NAME)z\Variables in LD_DYLIB_INSTALL_NAME are not generally supported yet in target '%s' (got '%s')rŠ   z*$(DYLIB_INSTALL_NAME_BASE:standardizepath)z$(WRAPPER_NAME)z$(PRODUCT_NAME)z$(EXECUTABLE_PATH))	r@   rj   r~   r  r<  r7  r’   r   rÂ   )r   Údefault_install_nameÚinstall_namer   r   r
   ÚGetInstallName  sB   ÿÿÿþþþÿÿÿzXcodeSettings.GetInstallNamec           	      C   s¬   d}d}d|gd|gd|gd|||gg}|D ],}t  dd |¡ ¡}| |¡}|rB|d	| d
¡… || d
¡ƒ || d
¡d	…  }q| d¡rTd||tdƒd	… ƒ }|S )zuChecks if ldflag contains a filename and if so remaps it from
    gyp-directory-relative to build-directory-relative.z(\S+)z\S+z-exported_symbols_listz-unexported_symbols_listz-reexported_symbols_listz-sectcreatez	(?:-Wl,)?z[ ,]Nr÷   ú-L)	r.   r/   rT   r   ÚstartÚgroupÚendrÕ   r  )	r   ÚldflagÚgyp_to_build_pathÚLINKER_FILEÚWORDÚlinker_flagsÚflag_patternÚregexÚmr   r   r
   Ú_MapLinkerFlagFilename5  s$   
ü
ÿ€
z$XcodeSettings._MapLinkerFlagFilenamec                 C   s¾  || _ g }|  ¡  dg ¡D ]}| |  ||¡¡ q| jddddr&| d¡ | jddddr3| d¡ |  |d	d
¡ |  |dd¡ |  |¡ d|  ¡ v rY|  ¡ rY| d|  ¡  ¡ |  ¡  dg ¡D ]}| d||ƒ ¡ qad|  ¡ v r€| d||  ¡ d ƒ ¡ |durˆ|g}n| j sJ ‚|  	| j ¡}t
|ƒdkr¡|  d¡ dg}| d|d  ¡ | d|dkr³|nd ¡ |  ¡ }	|	rÏ| jd dkrÏ| d|	 dd¡ ¡ |  ¡  d g ¡D ]	}
| d!|
 ¡ q×|  ¡ }|séd"}| jd# | j  }| d$g ¡}|D ]}| d%| d&|¡ ¡ qù|  ¡ r%|  |¡}|r%|r%| d%| d' ¡ | d(¡ |  ¡ p-|  ¡ }|rS|rStƒ d d)k rI| d*¡ | |d+ ¡ n| d,¡ | d-¡ |  |d.d/¡ d| _ |S )0a±  Returns flags that need to be passed to the linker.

    Args:
        configname: The name of the configuration to get ld flags for.
        product_dir: The directory where products such static and dynamic
            libraries are placed. This is added to the library search path.
        gyp_to_build_path: A function that converts paths relative to the
            current gyp file to paths relative to the build direcotry.
    ÚOTHER_LDFLAGSÚDEAD_CODE_STRIPPINGrà   rá   r}   z-Wl,-dead_stripÚ
PREBINDINGz-Wl,-prebindÚDYLIB_COMPATIBILITY_VERSIONz-compatibility_version %sÚDYLIB_CURRENT_VERSIONz-current_version %srÅ   z
-isysroot ÚLIBRARY_SEARCH_PATHSrB  Ú
ORDER_FILEz-Wl,-order_file -Wl,Nr÷   rÃ   r1   rø   r   r…   z./rh   r   z-install_name rR   z\ ÚLD_RUNPATH_SEARCH_PATHSz-Wl,-rpath,r&   r=   r   rþ   r  rÿ   z-framework XCTestÚ0900z	-lpkstartz?/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKitz-e _NSExtensionMainz-fapplication-extensionr  r  )rG   rZ   rE   r   rN  r]   ra   rÞ   r×   rÈ   r  rb   rA  r@   r  rn   rÓ   rv   rx   r8   )r   rG   Úproduct_dirrG  r!   ÚldflagsrF  Úlibrary_pathr   r@  ÚrpathrÑ   rJ   r	  r
  r  Úis_extensionr   r   r
   Ú
GetLdflagsQ  s~   


ÿÿ

ÿÿ





ÿ

zXcodeSettings.GetLdflagsc                 C   s4   || _ g }|  ¡  dg ¡D ]}| |¡ qd| _ |S )z‘Returns flags that need to be passed to the static linker.

    Args:
        configname: The name of the configuration to get ld flags for.
    rO  N)rG   rZ   rE   r   )r   rG   ÚlibtoolflagsÚlibtoolflagr   r   r
   ÚGetLibtoolflags²  s   zXcodeSettings.GetLibtoolflagsc                 C   sl   d}i }t | j ¡ ƒD ](}|rt| j| ƒ}d}q| j|  ¡ D ]\}}||vr)q || |kr2||= q q|S )z~Gets a list of all the per-target settings. This will only fetch keys
    whose values are the same across all configurations.TF)Úsortedr>   ÚkeysÚdictrD   )r   Ú
first_passÚresultrG   rO   Úvaluer   r   r
   ÚGetPerTargetSettingsÂ  s   €üz"XcodeSettings.GetPerTargetSettingsc                 C   s(   || j v r| j |  ||¡S |  ||¡S rX   )r>   rE   r~   )r   ÚsettingrG   r   r   r   r
   rÎ   Ó  s   
z!XcodeSettings.GetPerConfigSettingc                 C   st   d}d}t | j ¡ ƒD ]&}|r| j|  |d¡}d}q|| j|  |d¡ks1J d|| jd f ƒ‚q|du r8|S |S )zTries to get xcode_settings.setting from spec. Assumes that the setting
       has the same value in all configurations and throws otherwise.TNFzHExpected per-target setting for '%s', got per-config setting (target %s)rŠ   )ra  r>   rb  rE   r@   )r   rh  r   Úis_first_passre  rG   r   r   r
   r~   Ù  s   ÿÿz!XcodeSettings.GetPerTargetSettingc           	      C   sÜ   || _ g }| jddddri| jddddrid}| jd dks"|  ¡ r)|  ¡ r)d	}n	| jd d
kr2d}|  ¡  d|¡}ddddœ| }|  ¡  dd¡}|rT|dt|ƒ 7 }|s`| d| jd  ¡ | d||f ¡ d| _ |S )z¶Returns a list of shell commands that contain the shell commands
    neccessary to strip this target's binary. These should be run as postbuilds
    before the actual postbuilds run.ÚDEPLOYMENT_POSTPROCESSINGrà   rá   r}   ÚSTRIP_INSTALLED_PRODUCTÚ	debuggingrh   r   ú
non-globalr‡   ÚallÚSTRIP_STYLEr&   z-xz-S)rn  rm  rl  Ú
STRIPFLAGSrR   zecho STRIP\(%s\)rŠ   zstrip %s %sN)	rG   r]   r@   rv   rj   rZ   rE   Ú_NormalizeEnvVarReferencesr   )	r   rG   Úoutput_binaryÚquietre  Údefault_strip_styleÚstrip_styleÚstrip_flagsÚexplicit_strip_flagsr   r   r
   Ú_GetStripPostbuildsê  s6   ÿÿýüz!XcodeSettings._GetStripPostbuildsc                 C   sp   || _ g }| jddddr3| jddddr3| jd dkr3|s(| d	| jd
  ¡ | d||d f ¡ d| _ |S )zÃReturns a list of shell commands that contain the shell commands
    neccessary to massage this target's debug information. These should be run
    as postbuilds before the actual postbuilds run.rè   rà   r}   ré   rì   rê   rh   r¯   zecho DSYMUTIL\(%s\)rŠ   zdsymutil %s -o %sz.dSYMN)rG   r]   r@   r   )r   rG   Úoutputrr  rs  re  r   r   r
   Ú_GetDebugInfoPostbuilds  s   ÿÿz%XcodeSettings._GetDebugInfoPostbuildsFc                 C   s   |   ||||¡|  |||¡ S )zˆReturns a list of shell commands that contain the shell commands
    to run as postbuilds for this target, before the actual postbuilds.)rz  rx  )r   rG   ry  rr  rs  r   r   r
   Ú_GetTargetPostbuilds   s   ÿÿz"XcodeSettings._GetTargetPostbuildsc                 C   s,  | j r| jd dks|  ¡ s|  ¡ sg S g }|  ¡ }| j| }|  ¡ rEtj d|¡}tj 	| 
d¡¡}tj |d|¡}| d||f g¡ |  |¡}	|	sN|S dg}
t|
ƒt| j|  ¡ ƒ@ }
|
rktdd	 t|
ƒ¡ ƒ |  ¡ rôtj 	| 
d¡¡}tj |d
¡}|  |¡}ddg}|D ]9}tj ||¡}tj |tj |¡¡}| d||f g¡ | dtj dd¡|	| 
dd¡| 
dd¡|df g¡ qŠtj |d¡}tj ||¡|g}|D ]}| dtj dd¡|	| 
dd¡| 
dd¡|df g¡ qÖ| dtj dd¡|	| 
dd¡| 
dd¡tj d|¡df g¡ |S )z›Return a shell command to codesign the iOS output binary so it can
    be deployed to a device.  This should be run as the very last step of the
    build.rh   r‡   z${BUILT_PRODUCTS_DIR}Ú	TEST_HOSTrª   zditto %s %sÚOTHER_CODE_SIGN_FLAGSz9Warning: Some codesign keys not implemented, ignoring: %sz, r£   z@Developer/Library/PrivateFrameworks/IDEBundleInjection.frameworkz-Developer/Library/Frameworks/XCTest.frameworkz*%s code-sign-bundle "%s" "%s" "%s" "%s" %sz${TARGET_BUILD_DIR}zgyp-mac-toolÚCODE_SIGN_ENTITLEMENTSr&   ÚPROVISIONING_PROFILETF)rA   r@   rn   rk   r”   r>   r—   r˜   rT   ÚdirnamerE   ÚextendÚ_GetIOSCodeSignIdentityKeyÚsetrb  r   ra  rÓ   rÜ   )r   rG   rr  Ú
postbuildsrŽ   rU   ÚsourceÚ	test_hostÚxctest_destinationrO   ÚunimplÚframeworks_dirr  Ú
frameworksrƒ   ÚdestinationÚ
plugin_dirÚtargetsr¿   r   r   r
   Ú_GetIOSPostbuilds)  sl   ÿ

ÿ
ÿÿ
ý
ý


üzXcodeSettings._GetIOSPostbuildsc                 C   s”   |  d¡}|s	d S |tjvrCt g d¢¡}| ¡ D ])}| d¡}||v rB| ¡ d }tj}||vs=||| ks=J d| ƒ‚|tj|< qtj  |d¡S )NÚCODE_SIGN_IDENTITY)Úsecurityzfind-identityz-pÚcodesigningz-vúutf-8r÷   z2Multiple codesigning fingerprints for identity: %sr&   )rE   r<   Ú_codesigning_key_cacheÚ
subprocessÚcheck_outputÚ
splitlinesÚdecoderS   )r   rU   Úidentityry  ÚlineÚline_decodedÚfingerprintÚcacher   r   r
   r‚  l  s$   

ÿ
ÿ
€z(XcodeSettings._GetIOSCodeSignIdentityKeyc                 C   s4   |dusJ ‚|   ||||¡}|  ||¡}|| | S )zSReturns a list of shell commands that should run before and after
    |postbuilds|.N)r{  rŽ  )r   rG   ry  rr  r„  rs  ÚpreÚpostr   r   r
   ÚAddImplicitPostbuilds}  s   z#XcodeSettings.AddImplicitPostbuildsc           	      C   s´   |  d¡rdtj tj |¡¡d  }n| j |¡}|r$d| d¡ }n|}|  |¡}|s/d}| 	d|¡}| 
d¡rXtj |¡\}}|dkrXtj |¡sX|d	 }tj |¡rX|}|S )
Nz
.frameworkz-framework r   z-lr÷   r&   r  r¹   z.tbd)rL   r—   r˜   ÚsplitextrÜ   rH   r   rD  r×   r  rÕ   Úexists)	r   ÚlibraryÚconfig_nameÚlrM  rÑ   rÜ   ÚextÚtbd_libraryr   r   r
   Ú_AdjustLibrary†  s"   



zXcodeSettings._AdjustLibraryc                    s   ‡ ‡fdd„|D ƒ}|S )zTransforms entries like 'Cocoa.framework' in libraries into entries like
    '-framework Cocoa', 'libcrypto.dylib' into '-lcrypto', etc.
    c                    s   g | ]}ˆ  |ˆ ¡‘qS r   )r§  )rN   r¢  ©r£  r   r   r
   rP   ©  s    ÿz1XcodeSettings.AdjustLibraries.<locals>.<listcomp>r   )r   Ú	librariesr£  r   r¨  r
   ÚAdjustLibraries¥  s   ÿzXcodeSettings.AdjustLibrariesc                 C   s   t ddgƒS )NÚsw_versz-buildVersion)Ú	GetStdoutrY   r   r   r
   Ú_BuildMachineOSBuild­  s   z"XcodeSettings._BuildMachineOSBuildc                 C   s&   | j |  dd¡}dd„ | d¡D ƒS )NÚTARGETED_DEVICE_FAMILYÚ1c                 S   s   g | ]}t |ƒ‘qS r   )rm   )rN   Úxr   r   r
   rP   ²  s    z7XcodeSettings._XcodeIOSDeviceFamily.<locals>.<listcomp>ú,)r>   rE   rS   )r   rG   Úfamilyr   r   r
   Ú_XcodeIOSDeviceFamily°  s   z#XcodeSettings._XcodeIOSDeviceFamilyc           	      C   sL  |t jvr“i }|  ¡ |d< tƒ \}}||d< ||d< | j|  d¡}|dur*||d< |  |¡}|s5|  ¡ }|  |d¡}||p?d |d	< |d
krP|  |d¡|d< n|dkrY||d< n|d |d< | j	rŽ| j|  d¡|d< ||d< ||d< | 
d¡r…dg|d< |d |d< n	dg|d< d|d< |t j|< tt j| ƒ}| j	r¤|  |¡|d< |S )z@Returns a dictionary with extra items to insert into Info.plist.ÚBuildMachineOSBuildÚDTXcodeÚDTXcodeBuildÚGCC_VERSIONNÚ
DTCompilerz--show-sdk-versionr&   Ú	DTSDKNameÚ0720z--show-sdk-build-versionÚ
DTSDKBuildÚ0430r?   ÚMinimumOSVersionÚDTPlatformNameÚDTPlatformVersionr   ÚiPhoneOSÚCFBundleSupportedPlatformsÚDTPlatformBuildÚiPhoneSimulatorÚUIDeviceFamily)r<   Ú_plist_cacher­  r8   r>   rE   rÏ   Ú_DefaultSdkRootrÍ   rA   rL   rc  r³  )	r   rG   rœ  ÚxcodeÚxcode_buildÚcompilerrÑ   Úsdk_versionrD   r   r   r
   ÚGetExtraPlistItems´  sJ   



ÿ

ÿ



z XcodeSettings.GetExtraPlistItemsc           
      C   s¦   t ƒ \}}|dk rdS |  d¡}tj |¡}|r|S ztddgƒ}W n   Y dS | ¡ D ]#}| ¡ }t|ƒdkrP|d dkrP|d }|  |¡}	|	|krP|  S q-dS )	zûReturns the default SDKROOT to use.

    Prior to version 5.0.0, if SDKROOT was not explicitly set in the Xcode
    project, then the environment variable was empty. Starting with this
    version, Xcode uses the name of the newest SDK installed.
    r0   r&   Ú
xcodebuildz	-showsdksr¾   éþÿÿÿz-sdkéÿÿÿÿ)	r8   rÖ   r<   rÙ   rE   r¬  r–  rS   r  )
r   r9   rÈ  Údefault_sdk_pathÚdefault_sdk_rootÚall_sdksr™  rD   rÑ   rÚ   r   r   r
   rÆ  å  s(   


€zXcodeSettings._DefaultSdkRootrX   ©F)Rr*   r+   r,   r-   rØ   rÐ   rÙ   rÅ  r“  r   rF   rZ   r]   ra   rb   rg   rk   rj   rn   ro   rv   rx   rz   r   r   r   r”   r’   r™   r›   rž   r¡   r¥   r§   r©   r«   r­   r®   r°   r¶   r¸   rº   r½   r“   r·   rÂ   rÈ   rÍ   rÏ   rÓ   r×   rÖ   rÞ   r  r  r!  r(  r-  r/  r1  r4  r7  r<  rA  rN  r]  r`  rg  rÎ   r~   rx  rz  r{  rŽ  r‚  rŸ  r§  rª  r­  r³  rË  rÆ  r   r   r   r
   r<   ’   s¤    
	
 

	



|)
&
a

#
ÿ	C
ÿ
	

1r<   c                   @   sF   e Zd ZdZdd„ Zdd„ Zddd„Zd	d
„ Zddd„Zddd„Z	dS )ÚMacPrefixHeadera²  A class that helps with emulating Xcode's GCC_PREFIX_HEADER feature.

  This feature consists of several pieces:
  * If GCC_PREFIX_HEADER is present, all compilations in that project get an
    additional |-include path_to_prefix_header| cflag.
  * If GCC_PRECOMPILE_PREFIX_HEADER is present too, then the prefix header is
    instead compiled, and all other compilations in the project get an
    additional |-include path_to_compiled_header| instead.
    + Compiled prefix headers have the extension gch. There is one gch file for
      every language used in the project (c, cc, m, mm), since gch files for
      different languages aren't compatible.
    + gch files themselves are built with the target's normal cflags, but they
      obviously don't get the |-include| flag. Instead, they need a -x flag that
      describes their language.
    + All o files in the target need to depend on the gch file, to make sure
      it's built before any o file is built.

  This class helps with some of these tasks, but it needs help from the build
  system for writing dependencies to the gch files, for writing build commands
  for the gch files, and for figuring out the location of the gch files.
  c                 C   sr   d| _ d| _|r| d¡| _ |jddddk| _i | _| j r7| jr/dD ]}|| j |ƒ| j|< q#|| j ƒ| _ dS dS )a  If xcode_settings is None, all methods on this class are no-ops.

    Args:
        gyp_path_to_build_path: A function that takes a gyp-relative path,
            and returns a path relative to the build directory.
        gyp_path_to_build_output: A function that takes a gyp-relative path and
            a language code ('c', 'cc', 'm', or 'mm'), and that returns a path
            to where the output of precompiling that path for that language
            should be placed (without the trailing '.gch').
    NFÚGCC_PREFIX_HEADERÚGCC_PRECOMPILE_PREFIX_HEADERrá   r}   )ÚcÚccrM  Úmm)ÚheaderÚcompile_headersr~   Úcompiled_headers)r   r>   Úgyp_path_to_build_pathÚgyp_path_to_build_outputÚlangr   r   r
   r     s$   ÿÿÿûzMacPrefixHeader.__init__c                 C   s(   | j sJ ‚| j| }|r|d| 7 }|S )Nr…   )rÚ  rÛ  )r   rÞ  r!   Úhr   r   r
   Ú_CompiledHeader4  s
   

zMacPrefixHeader._CompiledHeaderNc                 C   s4   | j r|| jv rd|  ||¡ S | jrd| j S dS )zAGets the cflags to include the prefix header for language |lang|.z-include %sr&   )rÚ  rÛ  rà  rÙ  ©r   rÞ  r!   r   r   r
   Ú
GetInclude;  s
   
zMacPrefixHeader.GetIncludec                 C   s   | j sJ ‚|  ||¡d S )zFReturns the actual file name of the prefix header for language |lang|.z.gch)rÚ  rà  rá  r   r   r
   Ú_GchD  s   
zMacPrefixHeader._Gchc           	   	   C   sr   | j r| jsg S g }t||ƒD ]'\}}tj |¡d }dddddddœ |d¡}|r6| |||  ||¡f¡ q|S )a  Given a list of source files and the corresponding object files, returns
    a list of (source, object, gch) tuples, where |gch| is the build-directory
    relative path to the gch file each object file depends on.  |compilable[i]|
    has to be the source file belonging to |objs[i]|.r÷   rÖ  r×  rM  rØ  )z.cz.cppz.ccz.cxxz.mz.mmN)	rÙ  rÚ  Úzipr—   r˜   r   rE   r   rã  )	r   ÚsourcesÚobjsr!   re  r…  Úobjr¥  rÞ  r   r   r
   ÚGetObjDependenciesI  s    üû€z"MacPrefixHeader.GetObjDependenciesc                 C   sd   | j r| jsg S |  d|¡dd| j f|  d|¡dd| j f|  d|¡dd| j f|  d|¡dd| j fgS )	z‚Returns [(path_to_gch, language_flag, language, header)].
    |path_to_gch| and |header| are relative to the build directory.
    rÖ  z-x c-headerr×  z-x c++-headerrM  z-x objective-c-headerrØ  z-x objective-c++-header)rÙ  rÚ  rã  )r   r!   r   r   r
   ÚGetPchBuildCommands^  s   üz#MacPrefixHeader.GetPchBuildCommandsrX   )
r*   r+   r,   r-   r   rà  râ  rã  rè  ré  r   r   r   r
   rÓ    s    
	
rÓ  c                  C   sÄ   t rt S ztddgƒ ¡ } t| ƒdk rtdƒ‚W n   tƒ }|r,t d|¡ ¡ d }ntdƒ‚|dg} Y | d }| d	 }| 	¡ d	  
d
d¡}|ddt|ƒ    d¡}|r\| 	¡ d	 }||fa t S )z@Returns a tuple of version and build version of installed Xcode.rÌ  z-versioné   z&xcodebuild returned unexpected resultsz(\d+\.\d+\.?\d*)r   z!No Xcode or CLT version detected!r&   rÎ  r…   Ú0r¾   é   )ÚXCODE_VERSION_CACHErÊ   r–  r  r   Ú
CLTVersionr.   r   ÚgroupsrS   r  Úzfill)Úversion_listÚversionÚbuildr   r   r
   r8   l  s*   ÿ
r8   c                  C   s\   d} d}d}t  d¡}|| |fD ]}ztdd|gƒ}t  ||¡ ¡ d W   S    Y qdS )	z7Returns the version of command-line tools from pkgutil.z"com.apple.pkg.DeveloperToolsCLILeozcom.apple.pkg.DeveloperToolsCLIz!com.apple.pkg.CLTools_Executableszversion: (?P<version>.+)z/usr/sbin/pkgutilz
--pkg-inforò  N)r.   r/   r¬  ÚsearchÚ	groupdict)ÚSTANDALONE_PKG_IDÚFROM_XCODE_PKG_IDÚMAVERICKS_PKG_IDrL  rO   ry  r   r   r
   rî  –  s   	
ûrî  c                 C   sJ   t j| t jt jd}| ¡ d }|jdkr td|j| d f ƒ‚| d¡S )z£Returns the content of standard output returned by invoking |cmdlist|.
  Ignores the stderr.
  Raises |GypError| if the command return with a non-zero return code.)ÚstdoutÚstderrr   úError %d running %sÚ
)r”  ÚPopenÚPIPEÚcommunicateÚ
returncoder   Úrstrip©ÚcmdlistÚjobÚoutr   r   r
   rÊ   ¬  s   
ÿ

rÊ   c                 C   s\   t j| t jd}| ¡ d }|jdkr&tj |d ¡ td|j| d f ƒ‚| 	d¡ 
d¡S )zReturns the content of standard output returned by invoking |cmdlist|.
  Raises |GypError| if the command return with a non-zero return code.)rù  r   ó   
rû  r’  )r”  rý  rþ  rÿ  r   Úsysrú  Úwriter   r  r—  r  r   r   r
   r¬  ¸  s   
r¬  c                 C   sH   |   di ¡}|d  ¡ D ]}d|v r!| ¡ }| |d ¡ ||d< qdS )zÕMerges the global xcode_settings dictionary into each configuration of the
  target represented by spec. For keys that are both in the global and the local
  xcode_settings dict, the local key gets precendence.
  r>   r=   N)rE   ÚvaluesÚcopyÚupdate)Úglobal_dictr@   Úglobal_xcode_settingsrJ   Únew_settingsr   r   r
   ÚMergeGlobalXcodeSettingsToSpecÃ  s   €ür  c                 C   sh   t | dd¡ƒdkp!t | dd¡ƒdkp!t | dd¡ƒdko!| dk}|r2|d dks2J d|d	  ƒ‚|S )
zêReturns if |spec| should be treated as a bundle.

  Bundles are directories with a certain subdirectory structure, instead of
  just a single file. Bundle rules do not produce a binary but also package
  resources into that directory.rq   r   rt   rl   r   rh   Únonez6mac_bundle targets cannot have type none (target "%s")rŠ   )rm   rE   )Úflavorr@   Úis_mac_bundler   r   r
   ÚIsMacBundleÓ  s   ÿþÿÿr  c                 c   sÎ    t j | | ¡ ¡}|D ]X}|}d|vsJ d| ƒ‚t j |¡}t j |d ¡}|d  d¡r8t j ||d ¡}t j ||d ¡}| d¡rPt j |¡d d }| d¡r_t j |¡d d	 }||fV  qd
S )av  Yields (output, resource) pairs for every resource in |resources|.
  Only call this for mac bundle targets.

  Args:
      product_dir: Path to the directory containing the output bundle,
          relative to the build directory.
      xcode_settings: The XcodeSettings of the current target.
      resources: A list of bundle resources, relative to the build directory.
  rR   z/Spaces in resource filenames not supported (%s)r   r÷   z.lprojz.xibz.nibz.storyboardz.storyboardcN)r—   r˜   rT   r›   rS   rL   r   )rX  r>   Ú	resourcesÚdestÚresry  Ú	res_partsÚlproj_partsr   r   r
   ÚGetMacBundleResourcesä  s(   €
ÿ
ÿ

çr  c                 C   sˆ   |  d¡}|sddg i fS d|vsJ d| ƒ‚||ƒ}|j ddddkr/t |j d	d
d¡}ng }tj | | ¡ ¡}| ¡ }||||fS )a)  Returns (info_plist, dest_plist, defines, extra_env), where:
  * |info_plist| is the source plist path, relative to the
    build directory,
  * |dest_plist| is the destination plist path, relative to the
    build directory,
  * |defines| is a list of preprocessor defines (empty if the plist
    shouldn't be preprocessed,
  * |extra_env| is a dict of env variables that should be exported when
    invoking |mac_tool copy-info-plist|.

  Only call this for mac bundle targets.

  Args:
      product_dir: Path to the directory containing the output bundle,
          relative to the build directory.
      xcode_settings: The XcodeSettings of the current target.
      gyp_to_build_path: A function that converts paths relative to the
          current gyp file to paths relative to the build direcotry.
  ÚINFOPLIST_FILENrR   z1Spaces in Info.plist filenames not supported (%s)ÚINFOPLIST_PREPROCESSrá   r}   rà   Ú"INFOPLIST_PREPROCESSOR_DEFINITIONSr&   )r~   ÚshlexrS   r—   r˜   rT   r®   rg  )rX  r>   rÜ  Ú
info_plistÚdefinesÚ
dest_plistÚ	extra_envr   r   r
   ÚGetMacInfoPlist  s&   

ÿÿÿ
ÿr"  c              
   C   s(  | si S | j }||||  ¡ |d|dtƒ d dœ	}|  d|¡r&|  |¡|d< nd|d< | jr2| j|d< |d d	v rZ|  ¡ |d
< |  ¡ |d< |  ¡ |d< |  	¡ }|rT||d< |  
¡ |d< |  ¡ r¯tj |tj |  ¡  ¡|d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ |d< |  ¡ }|r¹||d< |  ¡ }	|	rÃ|	|d< tƒ d dkrå| d¡så|  |¡}
|
sÛ|  d¡}
|
du rád}
|
|d< |sêi }n|D ]}t || t!ƒsþd || ¡||< qì| "|¡ |D ]}t#|| ƒ||< q|S ) aŒ  Return the environment variables that Xcode would set. See
  http://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW153
  for a full list.

  Args:
      xcode_settings: An XcodeSettings object. If this is None, this function
          returns an empty dict.
      built_products_dir: Absolute path to the built products dir.
      srcroot: Absolute path to the source root.
      configuration: The build configuration name.
      additional_settings: An optional dict with more values to add to the
          result.
  z
${SRCROOT}z	${TMPDIR}r   )	ÚBUILT_FRAMEWORKS_DIRÚBUILT_PRODUCTS_DIRÚCONFIGURATIONÚPRODUCT_NAMEÚSRCROOTÚSOURCE_ROOTÚTARGET_BUILD_DIRÚTEMP_DIRÚXCODE_VERSION_ACTUALrÅ   r&   ÚDEVELOPER_DIRrh   rµ   ÚEXECUTABLE_NAMEÚEXECUTABLE_PATHÚFULL_PRODUCT_NAMErõ   rö   r#  ÚCONTENTS_FOLDER_PATHÚEXECUTABLE_FOLDER_PATHÚ!UNLOCALIZED_RESOURCES_FOLDER_PATHÚJAVA_FOLDER_PATHÚFRAMEWORKS_FOLDER_PATHÚSHARED_FRAMEWORKS_FOLDER_PATHÚSHARED_SUPPORT_FOLDER_PATHÚPLUGINS_FOLDER_PATHÚXPCSERVICES_FOLDER_PATHÚINFOPLIST_PATHÚWRAPPER_NAMEr=  r5  r0   NrR   )$r@   r   r8   rÎ   r×   rB   r·   rÂ   r”   r¶   r°   rj   r—   r˜   rT   Úsepr¥   r™   rž   r›   r¡   r§   r©   r«   r­   r®   r’   rA  r7  rE   rÏ   rÖ   Ú
isinstancer^   r  rq  )r>   Úbuilt_products_dirÚsrcrootÚconfigurationÚadditional_settingsr@   ÚenvÚmach_o_typer@  Úinstall_name_baserÑ   Úkr   r   r
   Ú_GetXcodeEnv;  sŽ   ô
ÿÿÿÿÿÿÿÿÿ

€
rE  c                 C   sX   t  dd| ¡} t  d| ¡}|D ]}|\}}d|vsJ d| ƒ‚|  |d| d ¡} q| S )zTakes a string containing variable references in the form ${FOO}, $(FOO),
  or $FOO, and returns a string with all variable references in the form ${FOO}.
  z\$([a-zA-Z_][a-zA-Z0-9_]*)z${\1}z(\$\(([a-zA-Z0-9\-_]+)\))ú$(z#$($(FOO)) variables not supported: ú${ú})r.   ÚsubÚfindallr  )r^   Úmatchesr   Ú
to_replacer"   r   r   r
   rq  §  s   rq  c                 C   sN   t |ƒD ] \}}|  d| d |¡} |  d| d |¡} |  d| |¡} q| S )a  Expands ${VARIABLES}, $(VARIABLES), and $VARIABLES in string per the
  expansions list. If the variable expands to something that references
  another variable, this variable is expanded as well if it's in env --
  until no variables present in env are left.rG  rH  rF  ú)r>  )Úreversedr  )ÚstringÚ
expansionsrD  Úvr   r   r
   ÚExpandEnvVars¸  s
   rR  c              
      sh   t  d¡‰‡ ‡fdd„}ztj ˆ  ¡ |¡}| ¡  |W S  tjjy3 } z	tdt	|j
ƒ ƒ‚d}~ww )a  Takes a dict |env| whose values are strings that can refer to other keys,
  for example env['foo'] = '$(bar) and $(baz)'. Returns a list L of all keys of
  env such that key2 is after key1 in L if env[key2] refers to env[key1].

  Throws an Exception in case of dependency cycles.
  z\$\{([a-zA-Z0-9\-_]+)\}c                    sB   t ‡ fdd„ˆ ˆ |  ¡D ƒƒ}|D ]}d|vsJ d| ƒ‚q|S )Nc                    s   g | ]}|ˆ v r|‘qS r   r   )rN   rQ  ©rA  r   r
   rP   Õ  ó    zD_TopologicallySortedEnvVarKeys.<locals>.GetEdges.<locals>.<listcomp>rG  z Nested variables not supported: )rƒ  rJ  )ÚnoderK  Údependee©rA  rL  r   r
   ÚGetEdgesÏ  s    z0_TopologicallySortedEnvVarKeys.<locals>.GetEdgesz6Xcode environment variables are cyclically dependent: N)r.   r/   ÚgypÚcommonÚTopologicallySortedrb  ÚreverseÚ
CycleErrorr   r^   Únodes)rA  rX  Úorderr$   r   rW  r
   Ú_TopologicallySortedEnvVarKeysÄ  s   

ÿ€ÿr`  c                    s&   t | ||||ƒ‰ ‡ fdd„tˆ ƒD ƒS )Nc                    s   g | ]}|ˆ | f‘qS r   r   rM   rS  r   r
   rP   ê  rT  z%GetSortedXcodeEnv.<locals>.<listcomp>)rE  r`  )r>   r=  r>  r?  r@  r   rS  r
   ÚGetSortedXcodeEnvæ  s   
ÿra  Fc                 C   sN   g }|   dg ¡D ]}|s| d| d |d f ¡ | tj |d ¡¡ q|S )z_Returns the list of postbuilds explicitly defined on |spec|, in a form
  executable by a shell.r„  zecho POSTBUILD\(%s\) %srŠ   Úpostbuild_nameÚaction)rE   r   rY  rZ  ÚEncodePOSIXShellList)r@   rs  r„  Ú	postbuildr   r   r
   ÚGetSpecPostbuildCommandsí  s   ÿrf  c                 C   s>   |   ¡ D ]}|d   ¡ D ]}| di ¡ d¡r  dS qqdS )zVReturns true if any target contains the iOS specific key
  IPHONEOS_DEPLOYMENT_TARGET.r=   r>   r?   TF)r	  rE   )r  Útarget_dictrJ   r   r   r
   Ú_HasIOSTargetù  s   ÿÿrh  c                 C   sz   |   ¡ D ]6}|d }|d }t|ƒ ¡ D ]%\}}t |¡}|||d < |||d < |dkr9d|d d< d	|d d< qq| S )
z–Clone all targets and append -iphoneos to the name. Configure these targets
  to build for iOS devices and use correct architectures for those builds.Útoolsetr=   z	-iphoneosz-iphonesimulatorr¿   r   r>   rÅ   r   )r	  rc  rD   r
  Údeepcopy)r  rg  ri  rI   r£  Úsimulator_config_dictÚiphoneos_config_dictr   r   r
   Ú_AddIOSDeviceConfigurations  s   
€úrm  c                 C   s   t | ƒrt| ƒS | S )zkIf |target_dicts| contains any iOS targets, automatically create -iphoneos
  targets for iOS device builds.)rh  rm  )Útarget_dictsr   r   r
   Ú&CloneConfigurationForDeviceAndEmulator  s   ro  rX   rÒ  )'r-   Ú
__future__r   r
  Ú
gyp.commonrY  r—   Úos.pathr.   r  r”  r  Útempfiler   rí  r7   r   Úobjectr   r;   r<   rÓ  r8   rî  rÊ   r¬  r  r  r  r"  rE  rq  rR  r`  ra  rf  rh  rm  ro  r   r   r   r
   Ú<module>   s\   
81        xj*(0
ÿl#
ÿ

