;i$dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z ddlmZmZddlmZe jr ddlmcmZe jeZdZe jreje jZdZdZdd Z dd Z!d Z"d Z#d Z$ddZ%e%Z&e%Z'ddZ(dZ)dZ*dZ+dZ,dZ-e j.rdZ/dSe jrdZ/dSe jrdZ/dSdZ/dS)z1 Find external dependencies of binary libraries. N)compat)log)dylibutils)winutilscddl}|}||t jt jt jt jt jt j t jt j h}|d|Dz }t}|D]H}|st j|}| s.||vr3| |It|dd}|S)a Return list of paths that serve as prefixes for parent-directory preservation of collected binaries and/or shared libraries. If a binary is collected from a location that starts with a path from this list, the relative directory structure is preserved within the frozen application bundle; otherwise, the binary is collected to the frozen application's top-level directory. rNcZg|](}tj|)S)pathlibPathresolve.0paths PC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\PyInstaller/depend/bindepend.py z@_get_paths_for_parent_directory_preservation..Ms.GGGD7<%%--//GGGc*t|jSN)lenparents)xs rz>_get_paths_for_parent_directory_preservation..^sAIrT)keyreverse)sitegetsitepackagesappendgetusersitepackagesr r sys base_prefixr prefixsetis_diraddsorted)r orig_pathsexcluded_pathspathsrs r,_get_paths_for_parent_directory_preservationr*)s9$KKK%%''Jd..00111  S_%% S_%%--// SZ   SZ  ((** NGGJGGGGJ EEE    |D!!{{}}   > ! !  $ 566 E E EE LrcZ|D]"}||jvr||cS#|jSr)r relative_toname) src_filenameparent_dir_preservation_pathsparent_dir_preservation_paths r_select_destination_directoryr1csN(EJJ$ '<+? ? ?++,HII I I I @  rc t}t}t}g}|dd}|D]\}} } | dkrtj| } | |vr'|| t d| t| |D]\} t d| s|| | fz-binary_dependency_analysis..s1]]W\''00]]]]]]rzSkipping symbolic link from %r to top-level application directory due to source path matching one of symlink suppression path patterns.z@Adding symbolic link from %r to top-level application directory.cg|]H\}}}|dk tjtj|IS)r3)osrnormcasebasename)r dest_namesrc_nametypecodes rrz.binary_dependency_analysis..sS9VHh y  ))(3344 rz:Library not found: could not resolve %r, dependency of %r.)r*r#r r r%loggerdebug get_importsrrinclude_librarystrr1PurePathr is_darwinparentosxutilsis_framework_bundle_libr,is_winanyr-warn_missing_libr<rr=r>warning)binaries search_pathssymlink_suppression_patternsr/processed_binariesprocessed_dependenciesmissing_dependencies output_tocr?r@rAsrc_pathdep_name dep_dest_pathframework_parent_path seen_binariesdependency_namereferring_binaryr9s @rbinary_dependency_analysisr^ns%Q$R$R! UU !!!J)3J\J\% 8X y <)) ) ) ) x((( *H555'2(L&I&I; \; \ "Hl LLMxYe f f f  $++Xx,@AAA(66  TVbccc"< 55L555 NPST`PaPabbb " & &| 4 4 4 :,HeffM#,];;M  fM$8G)>>>]]]]@\]]]]] \ <=@=O=O  _aderasasttt!!3}'9#:#:C >- O O SUdfvwwww rctjrFt|drgSt ||Stjrt||St||S)a+ Analyze the given binary file (shared library or executable), and obtain the list of shared libraries it imports (i.e., link-time dependencies). Returns set of tuples (name, fullpath). The name component is the referenced name, and on macOS, may not be just a base name. If the library's full path cannot be resolved, fullpath element is None. Additional list of search paths may be specified via `search_paths`, to be used as a fall-back when the platform-specific resolution mechanism fails to resolve a library fullpath. z .manifest) rrLrFlowerendswith_get_imports_pefilerH_get_imports_macholib_get_imports_ldd)filenamerQs rrDrDsv}8 x==   ) )+ 6 6 I"8\:::  8$X|<<<,777rcddl}t}||d}||jd|jdgddt |dgD]1}|jd }||2t |d d}|r^|j D]V}|j M|j d } | d d} || d zW| tj|gpgzfd |D}|S)zo Windows-specific helper for `get_imports`, which uses the `pefile` library to walk through PE header. rNT fast_loadIMAGE_DIRECTORY_ENTRY_IMPORTIMAGE_DIRECTORY_ENTRY_EXPORT) directoriesforwarded_exports_onlyimport_dllnames_onlyDIRECTORY_ENTRY_IMPORTutf-8DIRECTORY_ENTRY_EXPORTr4z.dllc4h|]}|t|fSr )resolve_library_path)rlibrQs r z&_get_imports_pefile..-s) O O Os(l;;< O O Or)pefiler#PEparse_data_directoriesDIRECTORY_ENTRYgetattrdlldecoder%symbols forwardersplitcloser<rdirname) rerQruoutputpeentrydll_strexported_symbolssymbolr}rzs ` rrbrbsMMM UUF 8t , ,B  "#A B  "#A B  $! 5r::)""7++ 7r#;TBB)&. ) )F+",33G<< ooc**1- 3<(((HHJJJGOOH--.,2D"EL O O O O O O OF Mrct}tjrtjd}nwtjrtjd}nVtjrtjd}n5tjrtjd}ntjd}tj dtj |gtj tjtjd}g}|jD]`}|s|dr|d r0|d rFd |vrK||a|r/t(d |d ||jD]}d}d}||} | rtjr| d} | r8| }tj || dz}n| d}tj |}ntjr+| d| d}}n| d| d}}|ptj |}tjr4tjdtj |rq|dddvrtjr)|drtj |sd}n^|drG|d} tA| dkr| d!}d}n4|s-tEtj ||}|rtj #|}|$||f|S)z Helper for `get_imports`, which uses `ldd` to analyze shared libraries. Used on Linux and other POSIX-like platforms (with exception of macOS). zR^\s*(((?P(.*\.a))(?P\(.*\)))|((?P(.*\.so))))$z^\s+(.*)\s+=>\s+(.*)$z$^\s*(?:(.*?)\s+=>\s+)?(.*?)\s+\(.*\)z\s*(.*?)\s+=>\s+(.*?)\s+\(.*\)lddro)stdinstderrstdoutencodingzError relocating z symbol not foundz7ldd: warning: you do not have execution permission for znot a dynamic executablezldd warnings for %r: %s N libarchive objectmember libsharedz'ld(64)?(-linux|-musl)?(-.+)?\.so(\..+)? )z linux-gatez linux-vdsoz/cygdrive/c/windows/systemz not foundz=>r)%r#ris_aixrecompileis_hpuxis_solaris_linux subprocessrunr<rrealpathDEVNULLPIPEr splitlines startswithrarrBrOjoinrsearchgroupr> fullmatch is_cygwinr`existsr~rstrip%_resolve_library_path_in_search_pathsnormpathr%) rerQr LDD_PATTERNp ldd_warningsliner-rsmrtokenss rrdrd2s) UUF}D j!vww D j!9:: D j!9:: D j!HII j!BCC     **+     AL##%%""  __0 1 1 dmmDW6X6X  __V W W  (4 / / D!!!!V18TYY|=T=TUUU##%%A A    t $ $ - } !WW\22  1%C7++C00177>3J3JJDD''+..C7++C00DD !GGAJJ cGGAJJ c4rw//44?!|$NPRPWP`P`adPePeff! CRCy888 99;;))*FGG7>>#&&  ]]; ' ' ZZ%%F6{{a!9??$$DCC  7  &&C  ('""3''C  D#; Mrcbddlmddlmddlm ddlmn#t$rdYnwxYwt}tj tj }tj tj}tj |}dfdtjfd }tjfd }|\}} | ||z } | tj t&jd t+t,| } fd fd } |D]} d} | drtj j| tjdd} | D]}tj || }|dr| |||}nJtj |s tj |||}|r#tj |r|} nn.| dr| | ||} n | } | s-t;tj | |} | rtj | } | | | f|S)z| macOS-specific helper for `get_imports`, which uses `macholib` to analyze library load commands in Mach-O headers. r) dyld_find)LC_RPATH)MachO) _dyld_shared_cache_contains_pathNct}|jD]2}|D]\}}}||3|Sr)r#headerswalkRelocatablesr%)rreferenced_libsheaderidxr-rss r_get_referenced_libsz3_get_imports_macholib.._get_referenced_libss_%%i ) )F"("9"9";"; ) )T3##C(((( )rcrg}|jD]}|jD]}|dj}|kr|dd}|d}|dr2|dst d||||S)Nrrro@z@executable_pathz @loader_pathz._get_run_pathss i , ,F!? , , #1:>x''#AJ--g66E!LL00E'',,!U5E5EFj5k5k!'eglnvwww $$U+++ , rcF|}||fSrr )rerrrrs r!get_run_paths_and_referenced_libsz@_get_imports_macholib..get_run_paths_and_referenced_libss2 E(OO##A&&q(9(999rc,|Srr )rerrs r get_run_pathsz,_get_imports_macholib..get_run_pathss~eeHoo...rrsctj|r2 |r|Stj|r|SdS |S#t$rYdSwxYwr)r<risabsisfile ValueError)rsrrs r_resolve_using_pathz2_get_imports_macholib.._resolve_using_paths 7==   /;@`@`ad@e@e; w~~c""  4 9S>> !   44 s A A-,A-cb|dr|tdd}n,|dr|tdd}tj||}||Stj||S)Nz @loader_path/z@executable_path/)rrr<rr)rsbin_pathpython_bin_path resolved_librs r_resolve_using_loader_pathz9_get_imports_macholib.._resolve_using_loader_path(s >>/ * * 1c/**++,CC ^^/ 0 0 1c-..//0C+*27<<#+F+FGG  # #"27<<#E#EFFFrz@rpathrr)! macholib.dyldrmacholib.mach_ormacholib.MachOrr ImportErrorr#r<rrrr executable functools lru_cacherrrr!listdictfromkeysrr~seprrrr>rr%)rerQrr python_binrrrrrrreferenced_librrsrun_pathlib_pathrrrrrrrs` @@@@@@@rrcrcs('''''(((((($$$$$$0BBBBBBB 000+/(((0UUF wrw//99::H!!#.11Jgooj11O.::::::: ////// "C!B8!L!LOYz***IRW\\&"4e<<===T]]9--..I$GGGGG6*,3,3   $ $X . . C', 4 4RV < BB  @  00L  :7++L99L  NL12222 Ms # 22ctj|r|Stjr#t |}|r|St ||Stjr`t ||}|r|Sdtjdd tj D}t ||Stj |S)ad Given a library name, attempt to resolve full path to that library. The search for library is done via platform-specific mechanism and fall back to optionally-provided list of search paths. Returns None if library cannot be resolved. If give library name is already an absolute path, the given path is returned without any processing. cg|]}||Sr r rs rrz(resolve_library_path..saaaT\`aDaaarPATH)r<rrris_unix_resolve_library_path_unixrrLgetenvr~pathsepctypesutil find_library)r-rQfullpathwin_search_pathss rrrrrws w}}T  ~.-d33  O4T<HHH  .8|LL  ObaV]62-F-F-L-LRZ-X-Xaaa4T;KLLL{''---rcP|pgD]}tj||}tj|sBtjr2 t j|}n#t$rYpwxYw|tkrtj |cSdS)zg Low-level helper for resolving given library name to full path in given list of search paths. N) r<rrrrrLrget_pe_file_machine_type Exception_exe_machine_typer)r-rQ search_pathrdll_machine_types rrrs$)r** 7<< T22w~~h''   =  #+#DX#N#N       #444w))))) 4sA)) A65A6c *tjs Jd|dsd|vrt}nt}tjrtjdd}n7tjrtjdd}ntjdd}||td| tj }|Utj tj|}|r!tj|sJ|d d g}tjd kr|d d gn|ddgtjdkr=tjd kr|dgn|dgt+jd}|rStj|}|tjd |nt4dtjdr|dtjr|dnutjrrrrBrCisdirr is_freebsd is_openbsd)r-lib_search_funclprsr) arch_subdirs rrrs >`````> }}U)v~~@)}2 ]9b ) )  2 ]. 3 3 ],b 1 1 /$tRXXbj-A-A B B C CC { !###"&&t,,  '7>>#&& & && {$  ' ) ) LL(L1 2 2 2 2 LL(L1 2 2 2 >W $ $"g-- 789999 9:;;;  ./@AA  >'**;77K LLj+>> ? ? ? ? LL< = = = 7==> ? ? @ LL> ? ? ? = + LL, - - - - ^ +"g-- 45555 45555   +&"3 + LL) * * *odE** Jrct|}ttjj|D]H}tj|D]1}||r$tj||ccS2IdS)a9 Search for a shared library in a list of directories. Args: name: The library name including the `lib` prefix but excluding any `.so` suffix. dirs: An iterable of folders to search in. Returns: The path to the library if found or None otherwise. N)_library_matcherrr<rrlistdirr)r-dirsmatcherr_paths rrrst$$Grw~t,,11Z%% 1 1Ewu~~ 1w||D%0000000 1 111rc:tj|dzjS)zv Create a callable that matches libraries if **name** is a valid library prefix for input library full names. z[0-9]*\.)rrr7)r-s rrrs :d[( ) ) //rcd}tjr|tj}|r|Sttj}|D]]\}}|tjD]H}t jt j ||kr|ccSI^tj rhtd|DrOdtj ddz}t|t jtjgS|tjt jtjd}|r|Stjr$tjD]}t|}|r|cSdS)a Find Python shared library that belongs to the current interpreter. Return full path to Python dynamic library or None when not found. PyInstaller needs to collect the Python shared library, so that bootloader can load it, import Python C API symbols, and use them to set up the embedded Python interpreter. The name of the shared library is typically fixed (`python3.X.dll` on Windows, libpython3.X.so on Unix systems, and `libpython3.X.dylib` on macOS for shared library builds and `Python.framework/Python` for framework build). Its location can usually be inferred from the Python interpreter executable, when the latter is dynamically linked against the shared library. However, some situations require extra handling due to various quirks; for example, debian-based some linux distributions statically link the Python interpreter executable against the Python library, while also providing a shared library variant for external users. c6|D]}tjD]}tj||}tj|sBtj|}tj|s|ccSdSr)r PYDYLIB_NAMESr<rrrr)libdirslibdirr- full_paths r_find_lib_in_libdirsz5get_python_library_path.._find_lib_in_libdirs5s ! !F, ! !GLL66 w~~i00G,,Y77 w~~i00       !trNcZg|](\}}tj|dk)S)z version.dll)r<rr=)rlib_name_s rrz+get_python_library_path..Ws2pppkhXYbg..x88MIppprzpython%d%d.dllrrs)ris_ms_app_storer!rDpython_executablerr<rr=r>rLrMr version_inforrrrr)rpython_libnameimported_librariesrrr-pydlls rget_python_library_pathr&#s$   ""--f.@AA  "! !%V%=>>)  8   (  Dw 0 0 : :;;tCCD }Xpp]opppqqX 3#3BQB#77#EBGOOF>( # #t $H - --rcn t|d5}|d}dddn #1swxYwYn#t$rYdSwxYw|dkrdSdd|g} tj|tjtjtjd}n#t$rYdSwxYw|jd krd ndS) NrbsELFDATAobjdumpz-autf8)rrrrrr5)openreadrrrrr returncode)refpsigcmd_argsrs rr(r(s* h%% !ggajj ! ! ! ! ! ! ! ! ! ! ! ! ! ! !   44  *  6 tX. !! ( AA   44 <1,,xx&8s>A4 A8A8A A A7B B%$B%c\ddl} t|d5}|d}dddn #1swxYwYn#t$rYdSwxYw|dkrdS ||d5} dddn #1swxYwYdS#|j$rYdSt$rYnwxYwdS) Nrr,rsMZr.Trgr5)rur1r2rrv PEFormatError)rerur4r5rs rr(r(sl  h%% !ggajj ! ! ! ! ! ! ! ! ! ! ! ! ! ! !   44  %<<6 8t44                8#   66    D tsiA8 A<A<A AAB5B7 BBB B B B) B)(B)chddl} |j|}dS#t$rYnwxYwdS)Nrr5r.)rrr)remacholibmachos rr(r(sT N((22E8    D vs " //cdSrr r)s rr(r(str)NNr)0__doc__ ctypes.utilrrr<r rr rr PyInstallerrrloggingPyInstaller.dependrrPyInstaller.utils.win32rrHPyInstaller.utils.osxosxrJ getLogger__name__rBrrLrr!r*r1r^rDrbrdrcrr findLibraryfindSystemLibraryrrrrr&r*rr(r rrrIs  &&&&&&++++++++,,,,,, -,,,,,,,,,  8 $ $ =T99&:RSS 777tzzzz@8888*,,,^JJJZrrrpH# (0KKK\111(000MMMf . . . ?L999998 ].2      r