o
    p.a6j  ã                   @   sÀ   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ZddlZddlZdd„ ZG dd„ deƒZdd	„ Zd
d„ Zedkr^e eejdd… ƒ¡ dS dS )zˆUtility functions to perform Xcode-style build steps.

These functions are executed via gyp-mac-tool when using the Makefile generator.
é    )Úprint_functionNc                 C   s*   t ƒ }| | ¡}|d urt |¡ d S d S ©N)ÚMacToolÚDispatchÚsysÚexit)ÚargsZexecutorZ	exit_code© r	   ú./usr/lib/python3/dist-packages/gyp/mac_tool.pyÚmain   s
   
ÿr   c                   @   sð   e Zd Z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$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:S );r   z‚This class performs all the Mac tooling steps. The methods can either be
  executed directly, or dispatched from an argument list.c                 C   s<   t |ƒdk r
tdƒ‚d|  |d ¡ }t| |ƒ|dd… Ž S )z(Dispatches a string command to a method.é   zNot enough argumentszExec%sr   N)ÚlenÚ	ExceptionÚ_CommandifyNameÚgetattr)Úselfr   Úmethodr	   r	   r
   r   &   s   zMacTool.Dispatchc                 C   s   |  ¡  dd¡S )z<Transforms a tool name like copy-info-plist to CopyInfoPlistú-Ú )ÚtitleÚreplace)r   Zname_stringr	   r	   r
   r   .   s   zMacTool._CommandifyNamec                 C   sÒ   |dk}t j |¡d  ¡ }t j |¡r&t j |¡rt |¡ t ||¡ n2|dkr0|  	||¡S |dkr:|  	||¡S |dkrG|sG|  
||¡ nt j |¡rRt  |¡ t ||¡ |re|dv rg|  |¡ dS dS dS )ztCopies a resource file to the bundle/Resources directory, performing any
    necessary compilation on each resource.ÚTruer   z.xibz.storyboardú.strings)z.plistr   N)ÚosÚpathÚsplitextÚlowerÚisdirÚexistsÚshutilÚrmtreeÚcopytreeÚ_CopyXIBFileÚ_CopyStringsFileÚunlinkÚcopyÚ_ConvertToBinary)r   ÚsourceÚdestÚconvert_to_binaryÚ	extensionr	   r	   r
   ÚExecCopyBundleResource2   s$   

ÿzMacTool.ExecCopyBundleResourcec              
   C   sZ  t j t j t¡¡}t j |¡rt j ||¡}t j |¡r$t j ||¡}g d¢}t jd dkrU| dg¡ dt jv rI| ddddd	t jd g¡ n| dd
d	t jd g¡ | ddd||g¡ t	 
d¡}t	 
d¡}zt |¡}W n tjyƒ } zt|jƒ ‚ d}~ww d}	| ¡ D ] }
|
 d¡}| |¡r™|}	qŠ| |¡sª|	r¦t|	ƒ d}	t|ƒ qŠdS )zBCompiles a XIB file with ibtool into a binary plist in the bundle.)ÚxcrunZibtoolú--errorsú
--warningsú	--noticesZXCODE_VERSION_ACTUALZ0700z--auto-activate-custom-fontsÚIPHONEOS_DEPLOYMENT_TARGETú--target-deviceÚiphoneÚipadú--minimum-deployment-targetÚmacÚMACOSX_DEPLOYMENT_TARGETú--output-formatúhuman-readable-textú	--compilez/\*.*\*/z .*note:.*is clipping its contentNúutf-8r   )r   r   ÚdirnameÚrealpathÚ__file__ÚrelpathÚjoinÚenvironÚextendÚreÚcompileÚ
subprocessZcheck_outputZCalledProcessErrorÚprintÚoutputÚ
splitlinesÚdecodeÚmatch)r   r'   r(   Úbaser   Zibtool_section_reZ	ibtool_reÚstdoutÚeZcurrent_section_headerÚlineÚline_decodedr	   r	   r
   r"   M   sV   
ýýÿ


€þ


€zMacTool._CopyXIBFilec              	   C   s   t  ddddd||g¡ d S )Nr,   Úplutilú-convertZbinary1ú-o)rD   Ú
check_call)r   r(   r	   r	   r
   r&   ~   s   
ÿzMacTool._ConvertToBinaryc           
      C   s~   |   |¡pd}ddl}t|dƒ ¡ }| d|t|ƒ¡}| d|dd¡\}}|r)dS t|dƒ}	|	 | |¡ 	d¡¡ |	 
¡  dS )zFCopies a .strings file using iconv to reconvert the input into UTF-16.úUTF-8r   NÚrbÚwbúUTF-16)Ú_DetectInputEncodingÚCoreFoundationÚopenÚreadZCFDataCreater   ZCFPropertyListCreateFromXMLDataÚwriterH   ÚencodeÚclose)
r   r'   r(   Z
input_coderX   ÚsÚdÚ_ÚerrorÚfpr	   r	   r
   r#   ‚   s   
zMacTool._CopyStringsFilec                 C   sd   t |dƒ}z| d¡}W n
   | ¡  Y dS | ¡  | d¡r"dS | d¡r)dS | d¡r0dS dS )	zReads the first few bytes from file_name and tries to guess the text
    encoding. Returns None as a guess if it can't detect it.rT   é   Ns   þÿrV   s   ÿþs   ï»¿rS   )rY   rZ   r]   Ú
startswith)r   Ú	file_namerb   Úheaderr	   r	   r
   rW   –   s   



zMacTool._DetectInputEncodingc                 G   sh  t |dƒ}| ¡ }| ¡  t |¡}|r| t |d ¡¡ t |¡}t	 
d¡}tjD ]=}	|	 d¡r3q+d|	 }
tj|	 }| |
|¡}d|	 }
| dtj|	 ¡}| |
|¡}d|	 }
| dtj|	 ¡}| |
|¡}q+| d	¡}tt|ƒƒD ]}||  ¡  d
¡r‰d||< d||d < qtd	 tdd„ |ƒ¡}t |dƒ}| |¡ | ¡  |  |¡ |dkr²|  |¡ dS dS )zCCopies the |source| Info.plist to the destination directory |dest|.Úrr   z[_/\s]r`   z${%s}z${%s:identifier}z${%s:rfc1034identifier}r   Ú
z
<string>${Nr   c                 S   s   | d uS r   r	   ©Úxr	   r	   r
   Ú<lambda>Ô   ó    z+MacTool.ExecCopyInfoPlist.<locals>.<lambda>Úwr   )rY   rZ   r]   ÚplistlibZreadPlistFromStringÚupdateÚjsonÚloadsZwritePlistToStringrB   rC   r   r@   rd   r   ÚsubÚsplitÚranger   Ústripr?   Úfilterr[   Ú_WritePkgInfor&   )r   r'   r(   r)   ÚkeysÚfdÚlinesÚplistZIDENT_REÚkeyZevarZevalueÚir	   r	   r
   ÚExecCopyInfoPlist©   sD   







€


ÿzMacTool.ExecCopyInfoPlistc                 C   s€   t  |¡}|s	dS |d }|dkrdS | dd¡}t|ƒdkr!d}tj tj |¡d¡}t|dƒ}| 	d	||f ¡ | 
¡  dS )
z@This writes the PkgInfo file from the data stored in Info.plist.NZCFBundlePackageTypeZAPPLZCFBundleSignaturez????é   ZPkgInform   z%s%s)rn   Ú	readPlistÚgetr   r   r   r?   r;   rY   r[   r]   )r   Z
info_plistr{   Zpackage_typeZsignature_coder(   rb   r	   r	   r
   rw   â   s   

zMacTool._WritePkgInfoc                 G   s4   t  |t jt jB t jB d¡}t |tj¡ t 	|¡S )z5Emulates the most basic behavior of Linux's flock(1).i¶  )
r   rY   ÚO_RDONLYÚO_NOCTTYÚO_CREATÚfcntlZflockZLOCK_EXrD   Úcall)r   ZlockfileÚcmd_listry   r	   r	   r
   Ú	ExecFlockù   s   
zMacTool.ExecFlockc                 G   sÚ   t  d¡}t  d¡}tj ¡ }d|d< tj|tj|d}| ¡ \}}| 	¡ D ]}| 
d¡}	| |	¡s>| |	¡s>t|	tjd q&|jsjtt|ƒd ƒD ]}
||
 d	kri||
d   d
¡rit ||
d  d¡  |jS qJ|jS )zQCalls libtool and filters out '/path/to/libtool: file: foo.o has no
    symbols'.z?^.*libtool: (?:for architecture: \S* )?file: .* has no symbols$zƒ^.*libtool: warning for library: .* the table of contents is empty \(no object file members in the library define global symbols\)$Ú1ZZERO_AR_DATE)ÚstderrÚenvr:   ©Úfiler   rQ   z.aN)rB   rC   r   r@   r%   rD   ÚPopenÚPIPEZcommunicaterG   rH   rI   rE   r   rŠ   Ú
returncodert   r   ÚendswithÚutime)r   r‡   Z
libtool_reZlibtool_re5r‹   Z
libtooloutr`   ÚerrrM   rN   r}   r	   r	   r
   ÚExecFilterLibtool   s*   
ÿ

€€ zMacTool.ExecFilterLibtoolc                 C   sp   t j |¡ d¡d }t j |d¡}t j |¡st  |¡ d||f }tt j |d¡dƒ}| |¡ | 	¡  d S )NÚ.r   ZModuleszUframework module %s {
  umbrella header "%s.h"

  export *
  module * { export * }
}
zmodule.modulemaprm   )
r   r   Úbasenamers   r?   r   ÚmkdirrY   r[   r]   )r   Ú	frameworkÚbinaryZmodule_pathZmodule_templateZmodule_filer	   r	   r
   ÚExecPackageIosFramework  s   
û
zMacTool.ExecPackageIosFrameworkc                 C   s¦   t j |¡ d¡d }d}d}d}t j t j ||||¡¡s dS t  ¡ }t  |¡ |  |t j ||¡¡ |  t j |||¡|¡ |  t j |||¡|¡ t  |¡ dS )zeTakes a path to Something.framework and the Current version of that and
    sets up all the symlinks.r•   r   ZCurrentZ	ResourcesZVersionsN)	r   r   r–   rs   r   r?   ÚgetcwdÚchdirÚ_Relink)r   r˜   Úversionr™   ZCURRENTZ	RESOURCESÚVERSIONSÚpwdr	   r	   r
   ÚExecPackageFramework/  s   
zMacTool.ExecPackageFrameworkc                 C   s&   t j |¡rt  |¡ t  ||¡ dS )zZCreates a symlink to |dest| named |link|. If |link| already exists,
    it is overwritten.N)r   r   ÚlexistsÚremoveÚsymlink)r   r(   Úlinkr	   r	   r
   r   L  s   
zMacTool._Relinkc                 G   sf   t j |¡ d¡d }tt jj|ƒ}i }|D ]}t j |¡}|||< ||t j ||¡< qt||ƒ d S )Nr•   r   )r   r   r–   rs   ÚmapÚabspathr?   Ú	WriteHmap)r   Úoutr˜   Zall_headersZframework_nameÚfilelistrf   Úfilenamer	   r	   r
   Ú ExecCompileIosFrameworkHeaderMapS  s   z(MacTool.ExecCompileIosFrameworkHeaderMapc              
   G   sP   t j |d¡}t j |¡st  |¡ |D ]}t |t j |t j |¡¡¡ qd S )NZHeaders)r   r   r?   r   Úmakedirsr   r%   r–   )r   r˜   Zcopy_headersZheader_pathrf   r	   r	   r
   ÚExecCopyIosFrameworkHeaders]  s   
 ÿz#MacTool.ExecCopyIosFrameworkHeadersc           
      G   sB  g d¢}dt jv }|r5t jd  d¡d }|dvrd}| d|d	d
d	ddt jd dt j t jd ¡g
¡ n| ddd	ddt jd dt j t jd ¡g¡ |rt |¡}| ¡ D ]8\}}d| }t	|t
ƒrl|rk| |¡ qWt	|tƒrƒ|D ]}	| |¡ | t|	ƒ¡ qsqW| |¡ | t|ƒ¡ qW| tt jj|ƒ¡ t |¡ dS )a¤  Compiles multiple .xcassets files into a single .car file.

    This invokes 'actool' to compile all the inputs .xcassets files. The
    |keys| arguments is a json-encoded dictionary of extra arguments to
    pass to 'actool' when the asset catalogs contains an application icon
    or a launch image.

    Note that 'actool' does not create the Assets.car file if the asset
    catalogs does not contains imageset.
    )r,   Zactoolr7   r8   z--compress-pngsr/   r.   r-   r0   ZCONFIGURATIONr   éÿÿÿÿ)ZiphoneosÚiphonesimulatorr°   z
--platformr1   r2   r3   r4   r9   ÚCONTENTS_FOLDER_PATHZmacosxr5   r6   Z!UNLOCALIZED_RESOURCES_FOLDER_PATHz--N)r   r@   rs   rA   r   r§   rp   rq   ÚitemsÚ
isinstanceÚboolÚappendÚlistÚstrr¦   rD   rR   )
r   rx   ÚinputsZcommand_lineZis_iphone_targetÚplatformr|   ÚvalueZarg_nameÚvr	   r	   r
   ÚExecCompileXcassetsd  sF   

ü
ü


€

þ
zMacTool.ExecCompileXcassetsc                 G   s4   i }|D ]}|   |¡}|  ||¡ qt ||¡ dS )z6Merge multiple .plist files into a single .plist file.N)Ú_LoadPlistMaybeBinaryÚ_MergePlistrn   Ú
writePlist)r   rF   r¸   Úmerged_plistr   r{   r	   r	   r
   ÚExecMergeInfoPlist˜  s
   
zMacTool.ExecMergeInfoPlistc           
      C   sp   |   ||  ¡ ¡\}}|  |||¡}ddd|g}	|dkr#|	 ddg¡ n|	 d|g¡ |	 d|g¡ t |	¡ d	S )
am  Code sign a bundle.

    This function tries to code sign an iOS bundle, following the same
    algorithm as Xcode:
      1. pick the provisioning profile that best match the bundle identifier,
         and copy it into the bundle as embedded.mobileprovision,
      2. copy Entitlements.plist from user or SDK next to the bundle,
      3. code sign the bundle.
    Zcodesignz--forcez--signr   z--deepz+--preserve-metadata=identifier,entitlementsz--entitlementsz--timestamp=noneN)Ú_InstallProvisioningProfileÚ_GetCFBundleIdentifierÚ_InstallEntitlementsrA   rD   rR   )
r   r|   ÚentitlementsZprovisioningr   ZpreserveÚsubstitutionsÚ	overridesZentitlements_pathr   r	   r	   r
   ÚExecCodeSignBundle   s   
ÿÿzMacTool.ExecCodeSignBundlec                 C   sV   |   ||¡\}}}tj tjd tjd d¡}t ||¡ |  ||d ¡}||d fS )aÊ  Installs embedded.mobileprovision into the bundle.

    Args:
      profile: string, optional, short name of the .mobileprovision file
        to use, if empty or the file is missing, the best file installed
        will be used
      bundle_identifier: string, value of CFBundleIdentifier from Info.plist

    Returns:
      A tuple containing two dictionary: variables substitutions and values
      to overrides when generating the entitlements file.
    ÚBUILT_PRODUCTS_DIRr±   zembedded.mobileprovisionr•   ÚEntitlements)Ú_FindProvisioningProfiler   r   r?   r@   r   Úcopy2Ú_GetSubstitutions)r   ÚprofileÚbundle_identifierÚsource_pathZprovisioning_dataZteam_idÚtarget_pathrÆ   r	   r	   r
   rÂ   ·  s   
ÿýz#MacTool._InstallProvisioningProfilec                 C   s   t j t jd ddd¡}t j |¡s td| tjd t d¡ d}|r6t j ||d	 ¡}t j 	|¡r6|g}|sBt
 
t j |d
¡¡}i }|D ]-}|  |¡}| di ¡ dd¡}| dg ¡D ]}	d|	|f }
t |
|¡rr|||	f||< q]qF|s„td| tjd t d¡ t|dd„ d}|| S )a/  Finds the .mobileprovision file to use for signing the bundle.

    Checks all the installed provisioning profiles (or if the user specified
    the PROVISIONING_PROFILE variable, only consult it) and select the most
    specific that correspond to the bundle identifier.

    Args:
      profile: string, optional, short name of the .mobileprovision file
        to use, if empty or the file is missing, the best file installed
        will be used
      bundle_identifier: string, value of CFBundleIdentifier from Info.plist

    Returns:
      A tuple of the path to the selected provisioning profile, the data of
      the embedded plist in the provisioning profile and the team identifier
      to use for code signing.

    Raises:
      SystemExit: if no .mobileprovision can be used to sign the bundle.
    ÚHOMEÚLibraryZMobileDevicezProvisioning Profilesz&cannot find mobile provisioning for %srŒ   r   Nz.mobileprovisionz*.mobileprovisionrÊ   zapplication-identifierr   ZTeamIdentifierz%s.%sc                 S   s   t | ƒS r   ©r   )r»   r	   r	   r
   rk     rl   z2MacTool._FindProvisioningProfile.<locals>.<lambda>©r|   )r   r   r?   r@   r   rE   r   rŠ   r   r   ÚglobÚ_LoadProvisioningProfiler   ÚfnmatchÚmax)r   rÎ   rÏ   Zprofiles_dirZprovisioning_profilesÚprofile_pathZvalid_provisioning_profilesZprofile_dataZapp_id_patternZteam_identifierZapp_idZselected_keyr	   r	   r
   rË   Î  sR   ÿþ
ÿ
ÿÿÿ€ýþ
z MacTool._FindProvisioningProfilec              
   C   sR   t  ¡ }t dddd|d|jg¡ |  |j¡W  d  ƒ S 1 s"w   Y  dS )zãExtracts the plist embedded in a provisioning profile.

    Args:
      profile_path: string, path to the .mobileprovision file

    Returns:
      Content of the plist embedded in the provisioning profile as a dictionary.
    ZsecurityZcmsz-Dz-irQ   N)ÚtempfileÚNamedTemporaryFilerD   rR   Únamer½   )r   rÚ   Útempr	   r	   r
   r×     s   
	ÿ
$ýz MacTool._LoadProvisioningProfilec                 C   s^   |  ¡ D ](\}}t|tƒr(| |i ¡}t|tƒr#|  ||¡ |||< q|||< q|||< qdS )z"Merge |plist| into |merged_plist|.N)r²   r³   Údictr   r¾   )r   rÀ   r{   r|   rº   Zmerged_valuer	   r	   r
   r¾     s   




÷zMacTool._MergePlistc                 C   sp   zt  |¡W S    Y t ¡ }t ||j¡ t ddd|jg¡ t  |j¡W  d  ƒ S 1 s1w   Y  dS )a}  Loads into a memory a plist possibly encoded in binary format.

    This is a wrapper around plistlib.readPlist that tries to convert the
    plist to the XML format if it can't be parsed (assuming that it is in
    the binary format).

    Args:
      plist_path: string, path to a plist file, in XML or binary format

    Returns:
      Content of the plist as a dictionary.
    rO   rP   Zxml1N)	rn   r€   rÛ   rÜ   r   rÌ   rÝ   rD   rR   )r   Z
plist_pathrÞ   r	   r	   r
   r½   "  s   

$ýzMacTool._LoadPlistMaybeBinaryc                 C   s
   ||dœS )aF  Constructs a dictionary of variable substitutions for Entitlements.plist.

    Args:
      bundle_identifier: string, value of CFBundleIdentifier from Info.plist
      app_identifier_prefix: string, value for AppIdentifierPrefix

    Returns:
      Dictionary of substitutions to apply when generating Entitlements.plist.
    )ÚCFBundleIdentifierZAppIdentifierPrefixr	   )r   rÏ   Zapp_identifier_prefixr	   r	   r
   rÍ   ;  s   þzMacTool._GetSubstitutionsc                 C   s,   t j t jd t jd ¡}|  |¡}|d S )zžExtracts CFBundleIdentifier value from Info.plist in the bundle.

    Returns:
      Value of CFBundleIdentifier in the Info.plist located in the bundle.
    ZTARGET_BUILD_DIRZINFOPLIST_PATHrà   )r   r   r?   r@   r½   )r   Zinfo_plist_pathZinfo_plist_datar	   r	   r
   rÃ   J  s   þ
zMacTool._GetCFBundleIdentifierc                 C   sŽ   |}t j t jd t jd d ¡}|st j t jd d¡}t ||¡ |  |¡}|  ||¡}|r?|D ]}||vr>|| ||< q2t 	||¡ |S )a[  Generates and install the ${BundleName}.xcent entitlements file.

    Expands variables "$(variable)" pattern in the source entitlements file,
    add extra entitlements defined in the .mobileprovision file and the copy
    the generated plist to "${BundlePath}.xcent".

    Args:
      entitlements: string, optional, path to the Entitlements.plist template
        to use, defaults to "${SDKROOT}/Entitlements.plist"
      substitutions: dictionary, variable substitutions
      overrides: dictionary, values to add to the entitlements

    Returns:
      Path to the generated entitlements file.
    rÉ   ZPRODUCT_NAMEz.xcentZSDKROOTzEntitlements.plist)
r   r   r?   r@   r   rÌ   r½   Ú_ExpandVariablesrn   r¿   )r   rÅ   rÆ   rÇ   rÐ   rÑ   Údatar|   r	   r	   r
   rÄ   V  s(   þþ
€zMacTool._InstallEntitlementsc                    sr   t ˆ tƒrˆ ¡ D ]\}}ˆ  d| |¡‰ q	ˆ S t ˆ tƒr'‡‡fdd„ˆ D ƒS t ˆ tƒr7‡ ‡‡fdd„ˆ D ƒS ˆ S )az  Expands variables "$(variable)" in data.

    Args:
      data: object, can be either string, list or dictionary
      substitutions: dictionary, variable substitutions to perform

    Returns:
      Copy of data where each references to "$(variable)" has been replaced
      by the corresponding value found in substitutions, or left intact if
      the key was not found.
    z$(%s)c                    s   g | ]}ˆ   |ˆ¡‘qS r	   ©rá   )Ú.0r»   )r   rÆ   r	   r
   Ú
<listcomp>‰  s    z,MacTool._ExpandVariables.<locals>.<listcomp>c                    s   i | ]}|ˆ  ˆ | ˆ¡“qS r	   rã   )rä   Úk©râ   r   rÆ   r	   r
   Ú
<dictcomp>‹  s    z,MacTool._ExpandVariables.<locals>.<dictcomp>)r³   r·   r²   r   r¶   rß   )r   râ   rÆ   r|   rº   r	   rç   r
   rá   x  s   


zMacTool._ExpandVariablesN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r+   r"   r&   r#   rW   r~   rw   rˆ   r”   rš   r¡   r   r¬   r®   r¼   rÁ   rÈ   rÂ   rË   r×   r¾   r½   rÍ   rÃ   rÄ   rá   r	   r	   r	   r
   r   "   s<    19
49"r   c                 C   s   d|   ¡  S )Né   )Ú
bit_lengthri   r	   r	   r
   ÚNextGreaterPowerOf2Ž  s   rï   c                 C   sV  d}d}d}t |ƒ}t|ƒ}dd|  }t t| ¡ dd„ dd ƒ}t| d	ƒ}	|	 t d
|||||||¡¡ dg| }
| ¡ D ]7\}}d}|D ]}|t| 	¡ ƒd 7 }qG|
||d @  durl|d }|
||d @  dus^||f|
||d @ < q?d}|
D ]F}|du r|	 t dddd¡¡ q{|\}}|}|t |ƒ d }|t t
j |¡t
j ƒ d }|t t
j |¡ƒ d }|	 t d|||¡¡ q{|	 t d¡¡ |
D ]\}|dur(|\}}|	 t dt |ƒ |¡¡ |	 t dd¡¡ t
j |¡t
j }|	 t dt |ƒ |¡¡ |	 t dd¡¡ t
j |¡}|	 t dt |ƒ |¡¡ |	 t dd¡¡ qÌdS )a  Generates a header map based on |filelist|.

  Per Mark Mentovai:
    A header map is structured essentially as a hash table, keyed by names used
    in #includes, and providing pathnames to the actual files.

  The implementation below and the comment above comes from inspecting:
    http://www.opensource.apple.com/source/distcc/distcc-2503/distcc_dist/include_server/headermap.py?txt
  while also looking at the implementation in clang in:
    https://llvm.org/svn/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp
  ipamhr   r   é   é   c                 S   s   t | d ƒS )Nr   rÔ   )Útr	   r	   r
   rk   £  s    zWriteHmap.<locals>.<lambda>rÕ   rU   z<LHHLLLLNé   z<LLLz<xz<%dsz<sú )r   rï   rÙ   r²   rY   r[   ÚstructZpackÚordr   r   r   r;   Úsepr–   )Zoutput_namerª   Úmagicrž   Z	_reservedÚcountZcapacityZstrings_offsetZmax_value_lengthr©   Zbucketsr   r   r|   ÚcZnext_offsetZbucketZ
key_offsetZprefix_offsetZsuffix_offsetrJ   r	   r	   r
   r¨   ‘  sX   
ÿ
ÿ
€ör¨   Ú__main__r   )rì   Z
__future__r   r…   rØ   rÖ   rp   r   rn   rB   r   rõ   rD   r   rÛ   r   Úobjectr   rï   r¨   ré   r   Úargvr	   r	   r	   r
   Ú<module>   s2       p?ÿ