NXc@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z e a e ae dZdefdYZdZdefd YZd efd YZd Zd ZdZdZdZdZdZe dZdZdZdZe dZ e!dZ"dZ#dZ$dZ%dS(s~ This module contains classes that help to emulate xcodebuild behavior on top of other build systems, such as make and ninja. iN(tGypErrorcCs$i|d6}|r ||de?d7Z@d8ZAd9ZBge?d:ZCdAd;ZDdAd<ZEd=ZFd>ZGdAd?ZHd@ZIRS(Bs9A class that understands the gyp 'xcode_settings' object.cCs||_t|_i|_|d}xe|jD]W\}}|jdi|j|<|j||j|jddr2t|_q2q2Wd|_ t j d|_ dS(Ntconfigurationstxcode_settingstIPHONEOS_DEPLOYMENT_TARGETs^lib([^/]+)\.(a|dylib)$( tspectFalsetisIOSR5t iteritemstgett_ConvertConditionalKeystNonetTruet confignameR%R&t library_re(R R7tconfigsR?tconfig((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRs       cCs|j|}g|D]}|jdr|^q}xl|D]d}|jdr|jdr|jdd}|||||jst|jr%|jStjj|jdS(s}Returns the qualified path to the bundle's resource folder. E.g. Chromium.app/Contents/Resources. Only valid for bundles.t Resources(R_RMR9RRRRH(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetBundleResourceFolder)s  cCs^|jst|jddkr>tjj|jdStjj|jddSdS(syReturns the qualified path to the bundle's plist file. E.g. Chromium.app/Contents/Info.plist. Only valid for bundles.RkRsRls Info.plistRN(s executablesloadable_module(R_RMR7RRRHR(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetBundlePlistPath1s cCs|jr3|js/td|jddS|jrf|jsbtd|jddS|jr|jstd|jddS|jridd 6d d 6d d 6|jdSidd 6dd 6dd 6dd6|jdSdS(s(Returns the PRODUCT_TYPE of this target.s6ios_app_extension flag requires mac_bundle (target %s)Rvs$com.apple.product-type.app-extensions;ios_watchkit_extension flag requires mac_bundle (target %s)s)com.apple.product-type.watchkit-extensions2ios_watch_app flag requires mac_bundle (target %s)s+com.apple.product-type.application.watchapps"com.apple.product-type.applicationRsscom.apple.product-type.bundleRls com.apple.product-type.frameworkRmRkscom.apple.product-type.tools&com.apple.product-type.library.dynamics%com.apple.product-type.library.statictstatic_libraryN(RbR_RMR7RdRf(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetProductType;s0     cCsO|j r$|jddkr$dSidd6dd6dd6d d 6|jdS( s'Returns the MACH_O_TYPE of this target.RkRsRt mh_executet staticlibRtmh_dylibRmt mh_bundleRl(R_R7(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetMachOTypeWs cCs|jst|jddks.|jr=|j}n1|jddkrntjj|jd}ntjj||jS(sReturns the name of the bundle binary of by this target. E.g. Chromium.app/Contents/MacOS/Chromium. Only valid for bundles.RkRmRsRltMacOS(s executablesloadable_module( R_RMR7R9RRRRHtGetExecutableName(R R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetBundleBinaryPathcs cCsId|jkrd|jdSidd6dd6dd6d d 6|jd S( NRrRqRRss.aRs.dylibRms.soRlRk(R7(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStandaloneExecutableSuffixmscCs:|jjdidd6dd6dd6dd6|jdS( Ntproduct_prefixRRstlibRRmRlRk(R7R;(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStandaloneExecutablePrefixws cCs|j st|jdd ks=td|jd|jd}|jddkr}|d d kr|d}qn3|jdd kr|d d kr|d}qn|j}|jjd |}|j}|||S( swReturns the name of the non-bundle binary represented by this target. E.g. hello_world. Only valid for non-bundles.RkRsRmRRlsUnexpected type %sRviRRz(s executablesshared_librarysstatic_librarysloadable_module(sloadable_modulesshared_library(R_RMR7RR;R(R ttargett target_prefixt target_ext((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyR}s     cCs4|jr&|jjd|jdS|jSdS(sXReturns the executable name of the bundle represented by this target. E.g. Chromium.RzRvN(R_R7R;R}(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRs cCs$|jr|jS|jSdS(ssReturns the directory name of the bundle represented by this target. E.g. Chromium.app/Contents/MacOS/Chromium.N(R_RR}(R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetExecutablePaths  cCsD|j|}t}|j|jd|jd|jdS(s:Returns the architectures this target should be built for.tARCHSt VALID_ARCHStSDKROOT(R5R2R!R;(R R?tconfig_settingstxcode_archs_default((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetActiveArchss     cCs(ytdd||gSWnnXdS(Ntxcruns--sdk(t GetStdout(R tsdktinfoitem((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetSdkVersionInfoItemscCs.|dkr|j}n|jd|ddS(NRR R(R=R?tGetPerConfigSetting(R R?((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_SdkRoots  cCsK|j|}|tjkr@|j|d}|tj|g} x+| D]#} |jd:| jd?|qWd@|_|S(BsMReturns flags that need to be added to .c, .cc, .m, and .mm compilations.Rs -isysroot %stCLANG_WARN_CONSTANT_CONVERSIONtYESR tNOs-Wconstant-conversiontGCC_CHAR_IS_UNSIGNED_CHARs-funsigned-chartGCC_CW_ASM_SYNTAXs -fasm-blockstGCC_DYNAMIC_NO_PICs-mdynamic-no-pictGCC_ENABLE_PASCAL_STRINGSs-mpascal-stringstGCC_OPTIMIZATION_LEVELs-O%ststGCC_GENERATE_DEBUGGING_SYMBOLStDEBUG_INFORMATION_FORMATtdwarfs -gdwarf-2tstabss(stabs debug format is not supported yet.sdwarf-with-dsymsUnknown debug format %stGCC_STRICT_ALIASINGs-fstrict-aliasings-fno-strict-aliasingtGCC_SYMBOLS_PRIVATE_EXTERNs-fvisibility=hiddentGCC_TREAT_WARNINGS_AS_ERRORSs-WerrortGCC_WARN_ABOUT_MISSING_NEWLINEs -Wnewline-eoftLLVM_LTOs-fltotCOPY_PHASE_STRIPtGCC_DEBUGGING_SYMBOLStGCC_ENABLE_OBJC_EXCEPTIONSt MACH_O_TYPEt PRODUCT_TYPEiRR(s-arch iR+tGCC_ENABLE_SSE3_EXTENSIONSs-msse3t)GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONSs-mssse3tGCC_ENABLE_SSE41_EXTENSIONSs-msse4.1tGCC_ENABLE_SSE42_EXTENSIONSs-msse4.2tWARNING_CFLAGSs-Fs/Developer/Library/Frameworks/RR4tmac_framework_dirss $(SDKROOT)N(si386sx86_64(R?RRNRRQRUR;tNotImplementedErrorRRVR=RMRtlenRR^R7treplace( R R?RtcflagsRt dbg_formatRt platform_roottframework_rootRBtframework_dirst directory((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagss                 ! cCsy||_g}|jjdddkr=|jdn|j|dd||jjdg7}d|_|S(s?Returns flags that need to be added to .c, and .m compilations.tGCC_C_LANGUAGE_STANDARDRtansis-ansis-std=%st OTHER_CFLAGSN(R?RNR;RRUR=(R R?tcflags_c((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsCWs  cCs||_g}|jjd}|r>|jd|n|j|dd|jddddry|jd n|jd dddr|jd n|jd dddr|jd n|jddddr|jdn|jddddr|jdng}xp|jjddgD]S}|dkrVd}n|dkr||jjdg7}q;|j|q;W||7}d|_|S(sAReturns flags that need to be added to .cc, and .mm compilations.tCLANG_CXX_LANGUAGE_STANDARDs-std=%stCLANG_CXX_LIBRARYs -stdlib=%stGCC_ENABLE_CPP_RTTIRR Rs -fno-rttitGCC_ENABLE_CPP_EXCEPTIONSs-fno-exceptionstGCC_INLINES_ARE_PRIVATE_EXTERNs-fvisibility-inlines-hiddentGCC_THREADSAFE_STATICSs-fno-threadsafe-staticst%GCC_WARN_ABOUT_INVALID_OFFSETOF_MACROs-Wno-invalid-offsetoftOTHER_CPLUSPLUSFLAGSs $(inherited)s $inheriteds ${inherited}s $OTHER_CFLAGSs$(OTHER_CFLAGS)s${OTHER_CFLAGS}R(s $inheriteds $(inherited)s ${inherited}(s $OTHER_CFLAGSs$(OTHER_CFLAGS)s${OTHER_CFLAGS}N(R?RNR;RRURQR=(R R?t cflags_cctclang_cxx_language_standardt other_ccflagstflag((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsCCcs6   "     cCsT|jjdd}|dkr4|jdn|dkrP|jdndS(NtGCC_ENABLE_OBJC_GCt unsupportedt supporteds -fobjc-gctrequireds-fobjc-gc-only(RNR;R(R tflagst gc_policy((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt$_AddObjectiveCGarbageCollectionFlagss   cCs,|jddddr(|jdndS(NtCLANG_ENABLE_OBJC_ARCRR Rs -fobjc-arc(RQR(R R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_AddObjectiveCARCFlagsscCs,|jddddr(|jdndS(Nt*CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESISRR Rs!-Wobjc-missing-property-synthesis(RQR(R R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt+_AddObjectiveCMissingPropertySynthesisFlagss cCsC||_g}|j||j||j|d|_|S(s7Returns flags that need to be added to .m compilations.N(R?RRRR=(R R?t cflags_objc((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsObjCs     cCsk||_g}|j||j||j||jddddr^|jdnd|_|S(s8Returns flags that need to be added to .mm compilations.tGCC_OBJC_CALL_CXX_CDTORSRR Rs-fobjc-call-cxx-cdtorsN(R?RRRRQRR=(R R?t cflags_objcc((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetCflagsObjCCs     cCsa|jddkr6|jddks2|jr6dS|jdd|jrTdnd}|S( s/Return DYLIB_INSTALL_NAME_BASE for this target.RkRmRltDYLIB_INSTALL_NAME_BASER s/Library/Frameworkss/usr/local/libN(R7R_R=Ri(R t install_base((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetInstallNameBasescCsqd|krmd|}}|jdrC|jdd\}}ntjj|}tjj||}n|S(s(Do :standardizepath processing for path.RRt@i(RRGRRtnormpathRH(R Rtprefixtrest((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_StandardizePaths  cCs/|jddkr6|jddks2|jr6dSd}|jdd|}d|kr+|d|fkstd |jd |f|jd |j|j}|jr|jd |j}|jd |j }n$d |kstd |kst|jd|j }n|S(s-Return LD_DYLIB_INSTALL_NAME for this target.RkRmRls=$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)tLD_DYLIB_INSTALL_NAMER t$sJ$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(WRAPPER_NAME)/$(PRODUCT_NAME)s\Variables in LD_DYLIB_INSTALL_NAME are not generally supported yet in target '%s' (got '%s')Rvs*$(DYLIB_INSTALL_NAME_BASE:standardizepath)s$(WRAPPER_NAME)s$(PRODUCT_NAME)s$(EXECUTABLE_PATH)N( R7R_R=RiRMRRRR|R{R(R tdefault_install_namet install_name((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetInstallNames0  c Csd}d}d|gd|gd|gd|||gg}xy|D]q}tjddj|}|j|}|rC||jd  ||jd ||jd }qCqCW|jd rd ||td }n|S( suChecks if ldflag contains a filename and if so remaps it from gyp-directory-relative to build-directory-relative.s(\S+)s\S+s-exported_symbols_lists-unexported_symbols_lists-reexported_symbols_lists -sectcreates (?:-Wl,)?s[ ,]is-L( R%R&RHRtstarttgrouptendRR( R tldflagtgyp_to_build_patht LINKER_FILEtWORDt linker_flagst flag_patterntregextm((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_MapLinkerFlagFilenames    #cCs||_g}x9|jjdgD]}|j|j||q(W|jddddrs|jdn|jddddr|jdn|j|d d |j|d d |j|d |jkr|jr|jd|jnx7|jjdgD]}|jd||qWd|jkrv|jd.||jdn|d/k r|g}n!|jst |j |j}t |dkr|j ddg}n|jd|d|jd||j} | rE|jddkrE|jd| jddnx1|jjdgD]} |jd| q^W|j} | sd } n|jd!|j} | jd"g} x+| D]#}|jd#|jd$| qW|j|}| r4|r4|jr4|jd#|d%|jd&n|jpI|j}| r|rtd'kr|jd(|j| d)n |jd*|jd+n|j|d,d-d/|_|S(0sReturns 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. t OTHER_LDFLAGStDEAD_CODE_STRIPPINGRR Rs-Wl,-dead_stript PREBINDINGs -Wl,-prebindtDYLIB_COMPATIBILITY_VERSIONs-compatibility_version %stDYLIB_CURRENT_VERSIONs-current_version %sRs -isysroot tLIBRARY_SEARCH_PATHSs-Lt ORDER_FILEs-Wl,-order_file s-Wl,iRR(s-arch iRkRls-install_name REs\ tLD_RUNPATH_SEARCH_PATHSs -Wl,-rpath,RR4Rs-Fs $(SDKROOT)s/Developer/Library/Frameworks/s-framework XCTestt0900s -lpkstarts?/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKits-e _NSExtensionMains-fapplication-extensionRs -stdlib=%ss-Wl,-order_file -Wl,N(R?RNR;RRRQRURRR=RMRRRVR R7RRR^RbRdR/(R R?t product_dirRRtldflagsRt library_pathRR trpathRRBRRRt is_extension((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetLdflags sr             !      cCsL||_g}x-|jjdgD]}|j|q(Wd|_|S(sReturns flags that need to be passed to the static linker. Args: configname: The name of the configuration to get ld flags for. RN(R?RNR;RR=(R R?t libtoolflagst libtoolflag((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetLibtoolflagsjs   cCst}i}xt|jjD]x}|rJt|j|}t}q"xM|j|jD]8\}}||kr|q^q^|||kr^||=q^q^Wq"W|S(s~Gets a list of all the per-target settings. This will only fetch keys whose values are the same across all configurations.(R>tsortedR5tkeystdictR8R:(R t first_passtresultR?RJtvalue((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetPerTargetSettingszs   cCs:||jkr&|j|j||S|j||SdS(N(R5R;Ri(R tsettingR?R ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRscCst}d}xt|jjD]j}|rP|j|j|d}t}q"||j|j|dks"td||jdfq"W|dkr|S|S(sTries to get xcode_settings.setting from spec. Assumes that the setting has the same value in all configurations and throws otherwise.sHExpected per-target setting for '%s', got per-config setting (target %s)RvN( R>R=R)R5R*R;R8RMR7(R R0R t is_first_passR-R?((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRis " c CsI||_g}|jddddr<|jddddr<d}|jddksd|jry|jryd }n|jdd krd }n|jjd |}id d 6dd 6dd6|}|jjdd }|r|dt|7}n|s"|jd|jdn|jd||fnd|_|S(sReturns 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.tDEPLOYMENT_POSTPROCESSINGRR RtSTRIP_INSTALLED_PRODUCTt debuggingRkRls non-globalRstallt STRIP_STYLERs-xs-St STRIPFLAGSREsecho STRIP\(%s\)Rvs strip %s %sN( R?RQR7RbR_RNR;t_NormalizeEnvVarReferencesRR=( R R?t output_binarytquietR-tdefault_strip_stylet strip_stylet strip_flagstexplicit_strip_flags((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStripPostbuildss0     cCs||_g}|jddddr|jddddr|jddkr|ss|jd |jd n|jd ||d fnd |_|S(sReturns 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.RRR Rsdwarf-with-dsymRRkRsecho DSYMUTIL\(%s\)Rvsdsymutil %s -o %ss.dSYMN(R?RQR7RR=(R R?toutputR9R:R-((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetDebugInfoPostbuildss  cCs)|j|||||j|||S(sReturns a list of shell commands that contain the shell commands to run as postbuilds for this target, before the actual postbuilds.(RAR?(R R?R@R9R:((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetTargetPostbuildsscCs|jo%|jddkp%|js,gS|j|}|j|}|sRgSdg}t|t|j|j@}|rddjt|GHndt j jdd||j d d |j d d fgS( sReturn 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.RkRstOTHER_CODE_SIGN_FLAGSs9Warning: Some codesign keys not implemented, ignoring: %ss, s"%s code-sign-bundle "%s" "%s" "%s"s${TARGET_BUILD_DIR}s gyp-mac-tooltCODE_SIGN_ENTITLEMENTSRtPROVISIONING_PROFILE( R9R7R^R5t_GetIOSCodeSignIdentityKeytsetR*RHR)RRR;(R R?R9RIRJtunimpl((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetIOSPostbuildss    #cCs|jd}|sdS|tjkrtjdddddg}xx|jD]g}||krS|jd}tj}||ks|||kstd||tj|sc Cs|tjkri}|j|d.+)s/usr/sbin/pkgutils --pkg-infoRN(R%R&Rtsearcht groupdict(tSTANDALONE_PKG_IDtFROM_XCODE_PKG_IDtMAVERICKS_PKG_IDRRJR@((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyR$s cCsxtj|dtj}|jd}|jdkrktjj|dtd|j|dfn|j dS(sReturns the content of standard output returned by invoking |cmdlist|. Raises |GypError| if the command return with a non-zero return code.tstdoutis sError %d running %s( RNtPopentPIPEt communicatet returncodetsyststderrtwriteRtrstrip(tcmdlisttjobtout((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyR:s  cCsg|jdi}xN|djD]<}d|kr#|j}|j|d||dx;|D]3} t|| tsd j|| || R8(ttargetst target_dictRB((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt _HasIOSTargetcs  cCsx|jD]}|d}|d}xht|jD]T\}}tj|}|||d<|||d<|dkr:d|ddsJ          8 1j *    ( 0 T  #