C :Uc@s0dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z de fdYZ de fdYZdZd Zd Zd Zed Zd ZdZdZedZedZdZdZdZdS(s~ This module contains classes that help to emulate xcodebuild behavior on top of other build systems, such as make and ninja. iN(tGypErrort XcodeSettingscBs~eZdZiZiZiZiZd?ZdZdZ dZ dZ d@dZ dZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#d@dZ$dZ%dZ&d@dZ'd Z(d!Z)d"Z*d#Z+d$Z,d%Z-d&Z.d'Z/d(Z0d)Z1d*Z2d@d+Z3d,Z4d-Z5d@d.Z6d@d/Z7d0Z8d1Z9e:d2Z;d3Z<d4Z=ge:d5Z>d@d6Z?d@d7Z@d8ZAd9ZBd:ZCd;ZDd@d<ZEd=ZFd>ZGRS(As9A 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)$( tspectFalsetisIOSRt iteritemstgett_ConvertConditionalKeystNonetTruet confignametretcompilet library_re(tselfRtconfigsR tconfig((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt__init__)s       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.R RRJRHRIR(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetBundleResourceFolders  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.R3R;R4s Info.plistRKN(s executablesloadable_module(R.R RRHRIRRJ(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetBundlePlistPaths cCs_|jr0idd6dd6dd6|jdSidd6d d6d d6d d 6|jdSd S( s(Returns the PRODUCT_TYPE of this target.s"com.apple.product-type.applicationR;scom.apple.product-type.bundleR4s com.apple.product-type.frameworkR5R3scom.apple.product-type.tools&com.apple.product-type.library.dynamics%com.apple.product-type.library.statictstatic_libraryN(R.R(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetProductTypes  cCsO|j r$|jddkr$dSidd6dd6dd6d d 6|jdS( s'Returns the MACH_O_TYPE of this target.R3R;tt mh_executet staticlibRNtmh_dylibR5t mh_bundleR4(R.R(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetMachOTypes 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.R3R5R;R4tMacOS(s executablesloadable_module( R.R RRRJRHRIRtGetExecutableName(RRI((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetBundleBinaryPaths cCsId|jkrd|jdSidd6dd6dd6d d 6|jd S( NR:R9RPR;s.aRNs.dylibR5s.soR4R3(R(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStandaloneExecutableSuffixscCs:|jjdidd6dd6dd6dd6|jdS( Ntproduct_prefixRPR;tlibRNR5R4R3(RR (R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStandaloneExecutablePrefixs 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.R3R;R5RNR4sUnexpected type %sR=iR[RA(s executablesshared_librarysstatic_librarysloadable_module(sloadable_modulesshared_library(R.R RR\R RY(Rttargett target_prefixt target_ext((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRDs     cCs4|jr&|jjd|jdS|jSdS(sXReturns the executable name of the bundle represented by this target. E.g. Chromium.RAR=N(R.RR RD(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRWs cCs$|jr|jS|jSdS(ssReturns the directory name of the bundle represented by this target. E.g. Chromium.app/Contents/MacOS/Chromium.N(R.RXRD(R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetExecutablePaths  cCs |j|jd|jgS(s:Returns the architectures this target should be built for.tARCHS(RR t _DefaultArch(RR ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetActiveArchs scCsxtj|dtj}|jd}|jdkrktjj|dtd|j|dfn|j dS(Ntstdoutis sError %d running %s( t subprocesstPopentPIPEt communicatet returncodetsyststderrtwriteRtrstrip(Rtcmdlisttjobtout((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt _GetStdouts  cCs.y |jddd||gSWnnXdS(Nt xcodebuilds-versions-sdk(Rq(Rtsdktinfoitem((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetSdkVersionInfoItems cCs.|dkr|j}n|jd|ddS(NtSDKROOTR$RP(R R tGetPerConfigSetting(RR ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_SdkRoot$s  cCs/|j|}|jdr"|S|j|S(Nt/(Rxt startswitht _XcodeSdkPath(RR tsdk_root((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_SdkPath)scCsR|tjkrG|j|d}|tj|<|rG|tj|kr4|jd/dddr|jd0n|jd1dddr|jd2n|jd3dddr |jd4n|jd5dddr4|jd6q4n||jjd7g7}|r_|}nd8}|j d9|j}|jd:g} x+| D]#} |jd;| jd<|qWd=|_|S(?sMReturns flags that need to be added to .c, .cc, .m, and .mm compilations.Rvs -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-eoftCOPY_PHASE_STRIPtGCC_DEBUGGING_SYMBOLStGCC_ENABLE_OBJC_EXCEPTIONSt MACH_O_TYPEt PRODUCT_TYPERaiti386s-arch itx86_64tGCC_ENABLE_SSE3_EXTENSIONSs-msse3t)GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONSs-mssse3tGCC_ENABLE_SSE41_EXTENSIONSs-msse4.1tGCC_ENABLE_SSE42_EXTENSIONSs-msse4.2tWARNING_CFLAGSRPRtmac_framework_dirss-Fs $(SDKROOT)N(si386sx86_64(R R}R!R&R%R*R tNotImplementedErrorRR+R RbtlenRtreplace( RR tarchtcflagsR|t dbg_formattarchstframework_rootRtframework_dirst directory((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsCs            !     ! 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_STANDARDRPtansis-ansis-std=%st OTHER_CFLAGSN(R R!R R&R*R (RR tcflags_c((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsCs  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 R!R R&R*R%R (RR t cflags_cctclang_cxx_language_standardt other_ccflagstflag((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetCflagsCCs6   "     cCsT|jjdd}|dkr4|jdn|dkrP|jdndS(NtGCC_ENABLE_OBJC_GCt unsupportedt supporteds -fobjc-gctrequireds-fobjc-gc-only(R!R R&(Rtflagst gc_policy((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt$_AddObjectiveCGarbageCollectionFlagss   cCs,|jddddr(|jdndS(NtCLANG_ENABLE_OBJC_ARCRR$Rs -fobjc-arc(R%R&(RR((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_AddObjectiveCARCFlagsscCs,|jddddr(|jdndS(Nt*CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESISRR$Rs!-Wobjc-missing-property-synthesis(R%R&(RR((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 (RR 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 RRRR%R&R (RR 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.R3R5R4tDYLIB_INSTALL_NAME_BASER$s/Library/Frameworkss/usr/local/libN(RR.R R1(Rt install_base((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetInstallNameBase scCsqd|krmd|}}|jdrC|jdd\}}ntjj|}tjj||}n|S(s(Do :standardizepath processing for path.RyRPt@i(RzRRHRItnormpathR(RRItprefixtrest((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.R3R5R4s=$(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')R=s*$(DYLIB_INSTALL_NAME_BASE:standardizepath)s$(WRAPPER_NAME)s$(PRODUCT_NAME)s$(EXECUTABLE_PATH)N( RR.R R1R RRRRCRBR`(Rtdefault_install_namet install_name((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetInstallName!s0  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( RRRtmatchtstarttgrouptendRzR( Rtldflagtgyp_to_build_patht LINKER_FILEtWORDt linker_flagst flag_patterntregextm((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_MapLinkerFlagFilenameGs    #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!|jjd|j g}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$| qWd&|_|S('sReturns 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 %sRvs -isysroot tLIBRARY_SEARCH_PATHSs-Lt ORDER_FILEs-Wl,-order_file s-Wl,RaiRs-arch iR3R4s-install_name Rs\ tLD_RUNPATH_SEARCH_PATHSs -Wl,-rpath,RPRRs-Fs $(SDKROOT)s-Wl,-order_file -Wl,N(R R!R R&RR%R*RR}R RbRR+RRR(RR t product_dirRRtldflagsRt library_pathRRtrpathR|RRR((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt GetLdflagscsV      !       ! 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 R!R R&R (RR t libtoolflagst libtoolflag((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetLibtoolflagss   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 tsortedRtkeystdictRR(Rt first_passtresultR Rtvalue((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pytGetPerTargetSettingss   cCs:||jkr&|j|j||S|j||SdS(N(RR R1(RtsettingR R$((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRwscCst}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)R=N( R R RRRR RR R(RRR$t is_first_passRR ((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyR1s " c Cs=||_g}|jddddr0|jddddr0d}|jddkrm|jrmd }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 debuggingR3R4s non-globalR;tallt STRIP_STYLERPs-xs-St STRIPFLAGSRsecho STRIP\(%s\)R=s strip %s %sN( R R%RR.R!R t_NormalizeEnvVarReferencesR&R ( RR t output_binarytquietRtdefault_strip_stylet strip_stylet strip_flagstexplicit_strip_flags((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetStripPostbuildss.    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-dsymRR3RNsecho DSYMUTIL\(%s\)R=sdsymutil %s -o %ss.dSYMN(R R%RR&R (RR toutputR RR((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.(RR(RR RR R((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetTargetPostbuildsscCs|jo|jddks gS|j|}|j|}|sFgSdg}t|t|j|j@}|rddjt|GHndtj jdd||j d d |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.R3R;tOTHER_CODE_SIGN_FLAGSs9Warning: Some codesign keys not implemented, ignoring: %ss, s'%s code-sign-bundle "%s" "%s" "%s" "%s"s${TARGET_BUILD_DIR}s gyp-mac-tooltCODE_SIGN_RESOURCE_RULES_PATHRPtCODE_SIGN_ENTITLEMENTStPROVISIONING_PROFILE( RRRt_GetIOSCodeSignIdentityKeytsetRRRRHRIR (RR R RRtunimpl((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_GetIOSPostbuilds"s   #cCs|jd}|sdS|tjkrtjdddddg}xx|jD]g}||krS|jd}tj}||ks|||kstd||tj|.+)s/usr/sbin/pkgutils --pkg-infotversion(RRRqtsearcht groupdict(RtSTANDALONE_PKG_IDtFROM_XCODE_PKG_IDtMAVERICKS_PKG_IDRRR((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt _CLTVersionpscCs%ttjdkry=|jddgj}t|dkrQtdnWnM|j}|rtjd|j d}n td|dg}nX|d}|d }|j d j d d}|d d t|j d }|r |j d }n||ft_ntjS(NiRrs-versionis&xcodebuild returned unexpected resultss(\d\.\d\.?\d*)s!No Xcode or CLT version detected!RPiR9t0ii( RRt_xcode_version_cacheRqR$RR<RRtgroupsRRtzfill(Rt version_listR6tbuild((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt _XcodeVersions&     !cCs?|j|jdd}g|jdD]}t|^q)S(NtTARGETED_DEVICE_FAMILYt1t,(RR RR-(RR tfamilytx((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyt_XcodeIOSDeviceFamilyscCsN|tjkri}|j|d<|j\}}||d<||d<|j|}|so|j}n||d<|dkr|j|d|dRR R!R%R R*R+R.R2R@RBRERCRJRLRMRORURXRYR\RDRWR`RcRqRuRxR}R{RRRRRRRRRRRRRRRRRwR1RRRRRRR,R1R3R5R<RCRIR]RYRb(((s4ext/snowcrash/tools/gyp/pylib/gyp/xcode_emulation.pyRs                       l )    &  I     "         %  % tMacPrefixHeadercBsMeZdZdZdZddZdZddZddZ RS(sA 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. cCsd |_t|_|rK|jd|_|jddddk|_ni|_|jr|jrx6ddddgD]}||j||j|x;|D]3} t|| tsdj|| || s8         j   ( 0 M  #