o ca:> @srdZddlZddlZddlZ dZdZdZdZdZdZ d Z d Z d Z d Z d ZdejfdejfdejfdejfdejfdejfdejfgZ edejfgZ dejfdejfgZ dejfdejfdejfdejfdejfgZ dejfdejfdejfdejfdejfdejfgZ dejfdejfgZ dejfdejfdejdfdejfdejfd ejfd!ejfd"ejfd#ejfd$ejfdejfg Z dejfdejfdejdfdejfdejfd ejfd!ejfd"ejfd#ejfd$ejfdejfg Z ed%ejfd&ejfgZ ed'ejfd(ejfd&ejfd)ejfgZ d*d+Zd8d,d-Zd.d/Zd0d1Z d8d2d3Z!d4d5Z"d6d7Z#dS)9a This module contains function to analyse dynamic library headers to extract system information Currently only for MacOSX Library file on macosx system starts with Mach-O or Fat field. This can be distinguish by first 32 bites and it is called magic number. Proper value of magic number is with suffix _MAGIC. Suffix _CIGAM means reversed bytes order. Both fields can occur in two types: 32 and 64 bytes. FAT field inform that this library contains few version of library (typically for different types version). It contains information where Mach-O headers starts. Each section started with Mach-O header contains one library (So if file starts with this field it contains only one version). After filed Mach-O there are section fields. Each of them starts with two fields: cmd - magic number for this command cmdsize - total size occupied by this section information. In this case only sections LC_VERSION_MIN_MACOSX (for macosx 10.13 and earlier) and LC_BUILD_VERSION (for macosx 10.14 and newer) are interesting, because them contains information about minimal system version. Important remarks: - For fat files this implementation looks for maximum number version. It not check if it is 32 or 64 and do not compare it with currently built package. So it is possible to false report higher version that needed. - All structures signatures are taken form macosx header files. - I think that binary format will be more stable than `otool` output. and if apple introduce some changes both implementation will need to be updated. - The system compile will set the deployment target no lower than 11.0 for arm64 builds. For "Universal 2" builds use the x86_64 deployment target when the arm64 target is 11.0. Nl:l~u}l:l~ulz}lmlz}lm$2i magiccputype cpusubtypefiletypencmds sizeofcmdsflagsreserved nfat_archoffsetsizealigncmdcmdsizesegnamevmaddrvmsizefileofffilesizemaxprotinitprotnsectsversionsdkplatformminosntoolscCs0|d>d@|d>d@B|d?d@B|d?d@BS)Nl~i)xr$r$6/usr/lib/python3/dist-packages/wheel/macosx_libfile.pyswap32s    r'cCs|dur |}n||tj|ttjj}|tt t t fvr5t j dkr-tj}ntj}t|}ntj}||||fS)Nlittle)tellseekctypesc_uint32from_buffer_copyreadsizeofvalue FAT_CIGAM FAT_CIGAM_64MH_CIGAM MH_CIGAM_64sys byteorderBigEndianStructureLittleEndianStructurer' Structure)lib_filer* magic_number BaseClassr$r$r&get_base_class_and_magic_numbers      r=cCs||t|SN)r-r.r+r/) struct_classr:r$r$r& read_datasr@c st|dtd\}}|ttttfvr WddS|ttfvrGddd|}t|}|tkr>Gddd|nGddd|fdd t|j D}g}|D]-}z"t |j }|durz|j t krut|d kru|d kruWqW||WqWtyYqWwt|dkrt|WdS WddSz t dWWdSty YWddSw1swYdS) Nrbrc@eZdZeZdS)z4extract_macosx_min_system_version..FatHeaderN)__name__ __module__ __qualname__fat_header_fields_fields_r$r$r$r& FatHeaderrHc@rBz2extract_macosx_min_system_version..FatArchN)rCrDrEfat_arch_fieldsrGr$r$r$r&FatArchrIrLc@rBrJ)rCrDrEfat_arch_64_fieldsrGr$r$r$r&rL rIcsg|]}tqSr$)r@).0_rLr:r$r& sz5extract_macosx_min_system_version..) rr)openr= FAT_MAGIC FAT_MAGIC_64MH_MAGIC MH_MAGIC_64r2r@ranger read_mach_headerr rCPU_TYPE_ARM64lenappend ValueErrormax) path_to_libr<r;rH fat_header fat_arch_list versions_listelrr$rPr&!extract_macosx_min_system_versionsN       +.  00recCs|dur ||t|\}}|tkrdnd}Gddd|}|dkr,Gddd|}nGddd|}t||}t|jD]J}|} t||} || | jtkrgGd d d |} t| |} t | j S| jt krGd d d |} t| |} t | j S|| | j q>dS) z This funcition parse mach-O header and extract information about minimal system version :param lib_file: reference to opened library file with pointer N3264c@rB)z%read_mach_header..SegmentBaseN)rCrDrEsegment_base_fieldsrGr$r$r$r& SegmentBase=rIric@rBz$read_mach_header..MachHeaderN)rCrDrEmach_header_fieldsrGr$r$r$r& MachHeaderBrIrlc@rBrj)rCrDrEmach_header_fields_64rGr$r$r$r&rlGrIc@rB)z+read_mach_header..VersionMinCommandN)rCrDrEversion_min_command_fieldsrGr$r$r$r&VersionMinCommandPrIroc@rB)z&read_mach_header..VersionBuildN)rCrDrEbuild_version_command_fieldsrGr$r$r$r& VersionBuildVrIrq)r*r=rWr@rYrr)rLC_VERSION_MIN_MACOSX parse_versionrLC_BUILD_VERSIONrr)r:r* base_classr;archrirl mach_header_ipos segment_basero version_inforqr$r$r&rZ1s0         rZcCs*|d@d?}|d@d?}|d@}|||fS)Nlrr"r!r#r$)rr%yzr$r$r&rs`s   rsc sP|d\}}}tdd|dD}|dd}|ddkr&|ddf}t|dks.Jd tjvrutd dtjd dD}|dd}|ddkrT|ddf}||krstjd d d d |Dd dd |Dn|}t|dks}J|i}t |D]9\}}} | D]1} | ds| drtj || } t | } | dur| dd} | ddkr| ddf} | || <qqt|dkrt|t|}d dd|D} |krfdd|D}d |}t|dkrd}nd}d| d|d|}d tjvr|d}n|d}tj||d| d|}|S)z Calculate proper macosx platform tag basing on files which are included to wheel Example platform tag `macosx-10.14-x86_64` -cSg|]}t|qSr$intrNr%r$r$r&rQnz1calculate_macosx_platform_tag...Nr MACOSX_DEPLOYMENT_TARGETcSrr$rrr$r$r&rQtrz[WARNING] MACOSX_DEPLOYMENT_TARGET is set to a lower value ({}) than the version on which the Python interpreter was compiled ({}), and will be ignored. cs|]}t|VqdSr>strrr$r$r& }z0calculate_macosx_platform_tag..csrr>rrr$r$r&r~rz.dylibz.sorOcSrr$rrr$r$r&rQrcsg|] \}}|kr|qSr$r$)rNkv start_versionr$r&rQs rRz this filez these filesz}[WARNING] This wheel needs a higher macOS version than {} To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least z or recreate z( with lower MACOSX_DEPLOYMENT_TARGET: z,is set in MACOSX_DEPLOYMENT_TARGET variable.z8the version your Python interpreter is compiled against.)splittupler\osenvironr5stderrwriteformatjoinwalkendswithpathrer_valuesitems) archive_root platform_tagprefix base_versionsuffix deploy_target versions_dictdirpathdirnames filenamesfilenamelib_pathmin_verfin_base_versionproblematic_files files_form error_messager$rr&calculate_macosx_platform_taggs                  rr>)$__doc__r+rr5rUr1rVr2rWr3rXr4rrrtr[r,c_intrkrmrFrKc_uint64rMrhc_charsegment_command_fieldssegment_command_fields_64rnrpr'r=r@rerZrsrr$r$r$r&s(      6/