Rac@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZdZdefdYZedkre jee jdndS( sUtility functions to perform Xcode-style build steps. These functions are executed via gyp-mac-tool when using the Makefile generator. i(tprint_functionNcCs8t}|j|}|dk r4tj|ndS(N(tMacTooltDispatchtNonetsystexit(targstexecutort exit_code((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytmains  RcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(sThis class performs all the Mac tooling steps. The methods can either be executed directly, or dispatched from an argument list.cCsOt|dkr!tdnd|j|d}t|||dS(s(Dispatches a string command to a method.isNot enough argumentssExec%si(tlent Exceptiont_CommandifyNametgetattr(tselfRtmethod((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyR&scCs|jjddS(s<Transforms a tool name like copy-info-plist to CopyInfoPlistt-t(ttitletreplace(Rt name_string((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyR .scCstjj|dj}tjj|rctjj|rPtj|ntj||nj|dkr|j ||S|dkr|j ||S|dkr|j |||ntj ||dS(stCopies a resource file to the bundle/Resources directory, performing any necessary compilation on each resource.is.xibs .storyboards.stringsN( tostpathtsplitexttlowertisdirtexiststshutiltrmtreetcopytreet _CopyXIBFilet_CopyStringsFiletcopy(Rtsourcetdesttconvert_to_binaryt extension((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytExecCopyBundleResource2s   c CsFtjjtjjt}tjj|rHtjj||}ntjj|rrtjj||}ndddddddd||g }tjd }tjd }t j |d t j }d }xj|j D]_} |j| r| }q|j| s|r(tj j|d }ntj j| qqW|jS( sBCompiles a XIB file with ibtool into a binary plist in the bundle.txcruntibtools--errorss --warningss --noticess--output-formatshuman-readable-texts --compiles/\*.*\*/s .*note:.*is clipping its contenttstdoutN(RRtdirnametrealpatht__file__trelpathtjointretcompilet subprocesstPopentPIPERR(tmatchRtwritet returncode( RR!R"tbaseRtibtool_section_ret ibtool_ret ibtoolouttcurrent_section_headertline((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRGs(  cCs&tjddddd||gdS(NR&tplutils-converttbinary1s-o(R0t check_call(RR"((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyt_ConvertToBinaryasc Cs|j|pd}ddl}t|dj}|jd|t|}|jd|dd\}} | rydSt|d} | j|j |j d| j |dkr|j |ndS( sFCopies a .strings file using iconv to reconvert the input into UTF-16.sUTF-8iNtrbitwbsUTF-16tTrue( t_DetectInputEncodingtCoreFoundationtopentreadt CFDataCreateRR tCFPropertyListCreateFromXMLDataR4tdecodetencodetcloseR?( RR!R"R#t input_codeRDtstdt_terrortfp((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRes   cCst|d}y|jd}Wntk r@|jdSX|j|jdr^dS|jdrqdS|jdrdSdSdS( sReads 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.R@issUTF-16sssUTF-8N(RERFR RKRt startswith(Rt file_nameRQtheader((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRC|s   c Gst|d}|j}|jtj|}|rft|jtj|dj}ntj |}t j d}xt j D]} | jdrqnd| } t j | } tj|| | }d| } |jdt j | } tj|| | }d| } |jdt j | } tj|| | }qW|jd }xNtt|D]:} || jjd rkd|| ${icSs |dk S(N(R(tx((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytRtwRBN(RERFRKtplistlibtreadPlistFromStringtdicttitemstjsontloadstwritePlistToStringR.R/RtenvironRRtstringRtsubtsplittrangeR tstripRR-tfilterR4t _WritePkgInfoR?( RR!R"R#tkeystfdtlinestplisttIDENT_REtkeytevartevalueti((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytExecCopyInfoPlists@  ,         cCstj|}|sdS|d}|dkr3dS|jdd}t|dkr`d }ntjjtjj|d}t|d }|j d ||f|j dS( s@This writes the PkgInfo file from the data stored in Info.plist.NtCFBundlePackageTypetAPPLtCFBundleSignatures????it?tPkgInfoRXs%s%ss????( RYt readPlisttgetR RRR-R)RER4RK(Rt info_plistRkt package_typetsignature_codeR"RQ((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRgs   !cGsFtj|tjtjBtjBd}tj|tjtj |S(s5Emulates the most basic behavior of Linux's flock(1).i( RREtO_RDONLYtO_NOCTTYtO_CREATtfcntltflocktLOCK_EXR0tcall(Rtlockfiletcmd_listRi((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyt ExecFlocks&c Gs3tjd}tjddd}tjj}d|d( RRhtinputst command_linetis_iphone_targettplatformRmtvaluetarg_nametv((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytExecCompileXcassets&s@             cGsJi}x-|D]%}|j|}|j||q Wtj||dS(s6Merge multiple .plist files into a single .plist file.N(t_LoadPlistMaybeBinaryt _MergePlistRYt writePlist(RtoutputRt merged_plistRRk((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytExecMergeInfoPlistZs  c Cs|j|}|j||j\}}|j|||}tjddd|d|d|tjjtj dtj dg dS( sCode sign a bundle. This function tries to code sign an iOS bundle, following the same algorithm as Xcode: 1. copy ResourceRules.plist from the user or the SDK into the bundle, 2. pick the provisioning profile that best match the bundle identifier, and copy it into the bundle as embedded.mobileprovision, 3. copy Entitlements.plist from user or SDK next to the bundle, 4. code sign the bundle. tcodesigns--forces--signs--resource-ruless--entitlementstTARGET_BUILD_DIRtFULL_PRODUCT_NAMEN( t_InstallResourceRulest_InstallProvisioningProfilet_GetCFBundleIdentifiert_InstallEntitlementsR0R>RRR-R`( RRmtresource_rulest entitlementst provisioningtresource_rules_patht substitutionst overridestentitlements_path((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pytExecCodeSignBundlebs    cCse|}tjjtjdtjdd}|sQtjjtjdd}ntj|||S(s$Installs ResourceRules.plist from user or SDK into the bundle. Args: resource_rules: string, optional, path to the ResourceRules.plist file to use, default to "${SDKROOT}/ResourceRules.plist" Returns: Path to the copy of ResourceRules.plist into the bundle. tBUILT_PRODUCTS_DIRRsResourceRules.plisttSDKROOT(RRR-R`Rtcopy2(RRt source_patht target_path((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRys      cCsu|j||\}}}tjjtjdtjdd}tj|||j||d}||dfS(sInstalls 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. RRsembedded.mobileprovisionRt Entitlements(t_FindProvisioningProfileRRR-R`RRt_GetSubstitutions(Rtprofiletbundle_identifierRtprovisioning_datatteam_idRR((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRs     c Cstjjtjdddd}tjj|s[td|dtjtjdnd}|rtjj||d}tjj |r|g}qn|st j tjj|d }ni}x|D]}|j |}|j d ij d d }xR|j d gD]>} d| |f} tj| |r||| f||tnameR(RRttemp((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRs cCsx~|jD]p\}}t|trs|j|i}t|trf|j|||||(Rt plist_pathR((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRs cCsi|d6|d6S(sFConstructs 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. tCFBundleIdentifiertAppIdentifierPrefix((RRtapp_identifier_prefix((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRs cCs:tjjtjdtjd}|j|}|dS(sExtracts CFBundleIdentifier value from Info.plist in the bundle. Returns: Value of CFBundleIdentifier in the Info.plist located in the bundle. RtINFOPLIST_PATHR(RRR-R`R(Rtinfo_plist_pathtinfo_plist_data((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRs   cCs|}tjjtjdtjdd}|sRtjjtjdd}ntj|||j|}|j||}|rx.|D]#}||kr||||^s (RRR\RRRR[(RRRRmRR((RRRsj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyRKs #(t__name__t __module__t__doc__RR R%RR?RRCRqRgRRRRRRRRRRRRRRRRR(((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyR"s6        9      4     5    "t__main__i(R t __future__RRRRR]RRYR.RRaR0RRR tobjectRR Rtargv(((sj/opt/alt/alt-nodejs8/root/usr/lib/node_modules/npm/node_modules.bundled/node-gyp/gyp/pylib/gyp/mac_tool.pyt s&             A