U e3 @stddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZddlmZdd lmZzddlmZed Wnek reZYnXed dd l mZd dZdZdZdZejdkrdZn>ej dkr$zddl!Z!e"e!dZZWnek r"YnXddZ#ddZ$GdddeZesVej dkrbdddZ%ndZd ddZ%dS)!NEXTENSION_SUFFIXES) build_ext) copy_file) new_compiler)customize_compilerget_config_var)DistutilsError)log)LibraryzCython.Compiler.MainLDSHARED) _config_varsc CsZtjdkrNt}z$dtd<dtd<dtd<t|W5tt|Xnt|dS)Ndarwinz0gcc -Wl,-x -dynamiclib -undefined dynamic_lookupr z -dynamiclibCCSHAREDz.dylibSO)sysplatform _CONFIG_VARScopyclearupdater)compilertmprJ/opt/hc_python/lib/python3.8/site-packages/setuptools/command/build_ext.py_customize_compiler_for_shlibs  rFZsharedrTntRTLD_NOWcCs tr|SdS)N) have_rtld)srrrif_dl>sr!cCs.tD]$}d|kr|S|dkr|SqdS)z;Return the file extension for an abi3-compliant Extension()z.abi3z.pydNr)suffixrrrget_abi3_suffixBs r#c@sveZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdddZdS)rcCs.|jd}|_t|||_|r*|dS)z;Build extensions in build directory, then copy if --inplacerN)Zinplace _build_extruncopy_extensions_to_source)selfZ old_inplacerrrr%Ls  z build_ext.runc Cs|d}|jD]}||j}||}|d}d|dd}||}tj |tj |}tj |j |} t | ||j |jd|jr||ptj|dqdS)Nbuild_py.)verbosedry_runT)get_finalized_command extensionsget_ext_fullnamenameget_ext_filenamesplitjoinZget_package_dirospathbasename build_librr+r, _needs_stub write_stubcurdir) r'r(extfullnamefilenamemodpathpackage package_dirZ dest_filenameZ src_filenamerrrr&Ts&       z#build_ext.copy_extensions_to_sourcecCstd}|r&tjj|d|}nt||}td}||jkr|j|}t |do\t }|r|dt | }t }||}t |t rtj|\}}|j|tStr|jrtj|\}}tj|d|S|S)NZSETUPTOOLS_EXT_SUFFIXr) EXT_SUFFIXZpy_limited_apizdl-)r4getenvr5r3r2r$r1rext_mapgetattrr#len isinstancer splitextshlib_compilerlibrary_filenamelibtype use_stubs_links_to_dynamic)r'r<Zso_extr=r;Zuse_abi3fndrrrr1js&      zbuild_ext.get_ext_filenamecCs t|d|_g|_i|_dSN)r$initialize_optionsrHshlibsrCr'rrrrPs zbuild_ext.initialize_optionscCs,t||jpg|_||jdd|jD|_|jrB||jD]}||j|_qH|jD]}|j}||j |<||j | dd<|jr| |pd}|ot ot |t }||_||_||}|_tjtj|j|}|r||jkr|j||rbt rbtj|jkrb|jtjqbdS)NcSsg|]}t|tr|qSr)rFr .0r;rrr s z.build_ext.finalize_options..r)r*F)r$finalize_optionsr.Zcheck_extensions_listrQsetup_shlib_compilerr/r0 _full_namerCr2links_to_dynamicrKrFr rLr8r1 _file_namer4r5dirnamer3r7 library_dirsappendr:runtime_library_dirs)r'r;r<Zltdnsr=ZlibdirrrrrVs,       zbuild_ext.finalize_optionscCst|j|j|jd}|_t||jdk r8||j|jdk r^|jD]\}}| ||qH|j dk r~|j D]}| |qn|j dk r| |j |jdk r||j|jdk r||j|jdk r||jt||_dS)N)rr,force)rrr,r`rHr include_dirsZset_include_dirsZdefineZ define_macroZundefZundefine_macro librariesZ set_librariesr\Zset_library_dirsZrpathZset_runtime_library_dirsZ link_objectsZset_link_objectslink_shared_object__get__)r'rr0valueZmacrorrrrWs.               zbuild_ext.setup_shlib_compilercCst|tr|jSt||SrO)rFr export_symbolsr$get_export_symbolsr'r;rrrrgs zbuild_ext.get_export_symbolscCs\||j}z@t|tr"|j|_t|||jrL|dj }| ||W5||_XdS)Nr() Z_convert_pyx_sources_to_langrrFr rHr$build_extensionr8r-r7r9)r'r;Z _compilercmdrrrris   zbuild_ext.build_extensioncsPtdd|jDd|jddddgtfdd|jDS) z?Return true if 'ext' links to a dynamic lib in the same packagecSsg|] }|jqSr)rX)rTlibrrrrUsz.build_ext.links_to_dynamic..r)Nr*rc3s|]}|kVqdSrOr)rTlibnameZlibnamespkgrr sz-build_ext.links_to_dynamic..)dictfromkeysrQr3rXr2anyrbrhrrmrrYs zbuild_ext.links_to_dynamiccCst||SrO)r$ get_outputs_build_ext__get_stubs_outputsrRrrrrsszbuild_ext.get_outputscs6fddjD}t|}tdd|DS)Nc3s0|](}|jrtjjjf|jdVqdS)r)N)r8r4r5r3r7rXr2rSrRrrrosz0build_ext.__get_stubs_outputs..css|]\}}||VqdSrOr)rTbaseZfnextrrrros)r. itertoolsproduct!_build_ext__get_output_extensionslist)r'Z ns_ext_basespairsrrRrZ__get_stubs_outputss  zbuild_ext.__get_stubs_outputsccs"dVdV|djrdVdS)N.pyz.pycr(z.pyo)r-optimizerRrrrZ__get_output_extensionss z!build_ext.__get_output_extensionsFcCs2td|j|tjj|f|jdd}|rJtj|rJt|d|j st |d}| dddd t d d tj |jd d dt ddddt ddddddt ddddg||r.ddlm}||gdd|j d |d!j}|dkr||g|d|j d tj|r.|j s.t|dS)"Nz writing stub loader for %s to %sr)r{z already exists! Please delete.w zdef __bootstrap__():z- global __bootstrap__, __file__, __loader__z0 import sys, os, pkg_resources, importlib.utilz, dlz: __file__ = pkg_resources.resource_filename(__name__,%r)z del __bootstrap__z if '__loader__' in globals():z del __loader__z# old_flags = sys.getdlopenflags()z old_dir = os.getcwd()z try:z( os.chdir(os.path.dirname(__file__))z$ sys.setdlopenflags(dl.RTLD_NOW)z3 spec = importlib.util.spec_from_file_location(z# __name__, __file__)z0 mod = importlib.util.module_from_spec(spec)z! spec.loader.exec_module(mod)z finally:z" sys.setdlopenflags(old_flags)z os.chdir(old_dir)z__bootstrap__()rr) byte_compileT)r|r`r, install_lib)r inforXr4r5r3r2existsr r,openwriter!r6rZclosedistutils.utilrr-r|unlink)r' output_dirr;compileZ stub_filefrr|rrrr9sl       zbuild_ext.write_stubN)F)__name__ __module__ __qualname__r%r&r1rPrVrWrgrirYrsrtrxr9rrrrrKs   rc Cs(||j||||||||| | | | dSrO)linkZSHARED_LIBRARY) r'objectsoutput_libnamerrbr\r^rfdebug extra_preargsextra_postargs build_temp target_langrrrrc$srcZstaticc Cs^|dks ttj|\}} tj| \}}|ddrH|dd}|||||| dS)Nxrk)AssertionErrorr4r5r2rGrI startswithZcreate_static_lib)r'rrrrbr\r^rfrrrrrr=r6r;rrrrc3s  ) NNNNNrNNNN) NNNNNrNNNN)&r4rrvimportlib.machineryrZdistutils.command.build_extrZ _du_build_extdistutils.file_utilrdistutils.ccompilerrdistutils.sysconfigrrdistutils.errorsr distutilsr Zsetuptools.extensionr ZCython.Distutils.build_extr$ __import__ ImportErrorr rrrrKrJrr0dlhasattrr!r#rcrrrrsr              W