B
    XM\™ç ã               @   sH  d Z ddlmZmZmZ ddlmZmZ ddlZddl	m	Z	 ddl
Z
ddlZddlZddlZddlmZmZmZmZmZ ddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlZddl m!Z! ddl"Z"ydd	l#m$Z$ W n( e%k
r   dd
l#m&Z& e&fZ$Y nX ddl'm(Z(m)Z)m*Z* ddl'm+Z+ ddl'm,Z, ddl'm-Z- ddl'm.Z. ddl'm/Z/ ddl'm0Z0 ddl'm1Z1m2Z2 ddl'm3Z3 ddl'm4Z4 ddl'm5Z5 ddl'm6Z6 ddl'm7Z7 ddl'm8Z8 ddl'm9Z9 ddl'm:Z: ddl'm;Z; ddl'm<Z< ddl'm=Z= ddl'm>Z> dd l?m@Z@mAZA dd!lBmCZC dd"lBmDZDmEZEmFZFm?Z? dd#lGmHZHmIZI dd$lJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmV  mWZW dd%lXmYZYmZZZm[Z[ dd&l\m]Z]m^Z^m_Z_m`Z` dd'lambZbmcZcmdZd dd(lemfZfmgZgmhZh dd)limjZj ddlkmlZl dd!lmmCZn dd!lBmCZo ejpd*kr8ddlqmrZr d+ejpkrJd,Zsne?jtrXd-Zsnd.Zsd/d0„ Zud1d2„ Zvd3d4„ Zwd5d6„ Zxd7d8„ Zyd9d:„ Zzd§d;d<„Z{d=d>„ Z|d?d@„ Z}dAdB„ Z~dCdD„ ZdEdF„ Z€dGdH„ ZdIdJ„ Z‚dKdL„ ZƒdMdN„ Z„dOdP„ Z…dQdR„ Z†dSdT„ Z‡dUdV„ ZˆdWdX„ Z‰dYdZ„ ZŠd[d\„ Z‹d]d^„ ZŒd_d`„ Zdadb„ ZŽdcdd„ Zdedf„ Zdgdh„ Z‘didj„ Z’dkdl„ Z“dmdn„ Z”dodp„ Z•dqdr„ Z–dsdt„ Z—dudv„ Z˜e–e—dwœZ™dxdy„ Zšdzd{„ Z›d|d}„ Zœd¨d€d„Zd‚dƒ„ Zžd„d…„ ZŸd†d‡„ Z dˆd‰„ Z¡dŠd‹„ Z¢dŒd„ Z£dŽd„ Z¤dd‘„ Z¥d©d“d”„Z¦dªd•d–„Z§d—d˜„ Z¨d™dš„ Z©d«d›dœ„Zªddž„ Z«dŸd „ Z¬d¡d¢„ Z­d¬d£d¤„Z®d­d¥d¦„Z¯dS )®zM
Module that does most of the heavy lifting for the ``conda build`` command.
é    )Úabsolute_importÚdivisionÚprint_function)ÚdequeÚOrderedDictN)Úglob)ÚisdirÚisfileÚislinkÚjoinÚdirname)ÚNamedTemporaryFile)ÚUnicodeDammit)ÚCONDA_TARBALL_EXTENSIONS)ÚCONDA_TARBALL_EXTENSIONé   )Úenv_path_backup_var_existsÚconda_45Úconda_46)ÚPY3)Úprefix_placeholder)ÚTemporaryDirectory)ÚVersionOrder)Ú	text_type)ÚCrossPlatformStLink)ÚPathTypeÚFileMode)ÚEntityEncoder)Úget_rc_urls)Úurl_path)Úroot_dir)Úconda_private)Ú	MatchSpec)Úreset_context)Úcontext)ÚUnsatisfiableError)ÚNoPackagesFoundError)Ú
CondaError)Ú	pkgs_dirs)Úenv_varÚ	tmp_chdir)Ú__version__)ÚenvironÚsourceÚtarcheckÚutils)Úget_build_indexÚupdate_index)
Úoutput_yamlÚbldpkg_pathÚrender_recipeÚreparseÚfinalize_metadataÚdistribute_variantsÚexpand_outputsÚtry_downloadÚadd_upstream_pinsÚexecute_download_actions)ÚFIELDSÚMetaDataÚdefault_structs)Úpost_processÚ
post_buildÚfix_permissionsÚget_build_metadata)ÚindentÚDependencyNeedsBuildingErrorÚCondaBuildException)Úset_language_env_varsÚdict_of_lists_to_list_of_dictsÚget_package_variants)Úcreate_all_test_filesZwin32Zbsdz/bin/shZbashz	/bin/bashc                s†   ˆ   ¡ }d ‡ fdd„|D ƒ¡}ˆ jj d¡}|rR|ˆ jjkrRd|krR|d| 7 }ˆ  ¡ ˆ  ¡ g}|rp| |¡ d |¡}|| }|S )Nú-c                s,   g | ]$}|d kr|d t ˆ jj| ƒ ‘qS )Útarget_platformÚ_)ÚstrÚconfigÚvariant)Ú.0Úk)Úmetadata© ú0lib/python3.7/site-packages/conda_build/build.pyú
<listcomp>a   s    zstats_key.<locals>.<listcomp>rK   z-target_)	Zget_used_loop_varsr   rN   rO   ÚgetÚsubdirÚnameÚversionÚappend)rR   ZdescZused_loop_varsZ
build_varsÚtpÚkeyrS   )rR   rT   Ú	stats_key^   s    

r]   c             C   s.   t | dƒ\}}t t|ƒdƒ\}}d |||¡S )Né<   z{:d}:{:02d}:{:04.1f})ÚdivmodÚintÚformat)ZsecsÚmÚsÚhrS   rS   rT   Úseconds_to_textp   s    re   c          	   C   sÂ   t d |¡ƒ t d |  dd¡¡ƒ |  d¡rXt d t|  dd¡ƒt|  dd¡ƒ¡ƒ nt d	ƒ |  d
¡rˆt d t |  d
d¡¡¡ƒ nt dƒ t d t | d ¡¡ƒ t d t| d ƒ¡ƒ d S )Nz#
Resource usage statistics from {}:z   Process count: {}Z	processesr   Úcpu_sysz   CPU time: Sys={}, User={}r   Úcpu_userz   CPU time: unavailableÚrssz   Memory: {}z   Memory: unavailablez   Disk usage: {}Údiskz   Time elapsed: {}
Úelapsed)Úprintra   rV   re   r/   Úbytes2human)Z
stats_dictZ
descriptorrS   rS   rT   Ú	log_statsv   s    

rm   c       	      C   s  t jr
dnd}xîdD ]æ}d|  ¡ k}|}|rb| j di ¡ |d¡rR| jd | }n|  ¡ d | }||7 }d|  ¡  d | | }t| j|ƒ}t|ƒrt| j	j
| j	j d	¡r°d
ndƒ}t|ƒsÊt |d¡ t||ƒ}t j||| j	j| j	jd t |d¡ qW dS )z0
    Create scripts to run after build step
    z.batz.sh)zpre-linkz	post-linkz
pre-unlinkzpackage:ÚbuildÚ rJ   Ú.zwin-ÚScriptsÚbiniý  )ÚlockingN)r/   Úon_winÚget_recipe_textÚmetarV   rX   r   Úpathr	   rN   Úhost_prefixÚhost_subdirÚ
startswithr   ÚosÚmakedirsÚ	copy_intoÚtimeoutrs   Úchmod)	rb   Úextr[   Ú	is_outputZ
scriptnameZdst_nameÚsrcZdst_dirÚdstrS   rS   rT   Úcreate_post_scripts‰   s&    

r„   c          	   c   s<  |  tj¡}t  tj¡}tjrN| dd¡}|  tj¡}| dd¡}|  tj¡}xæ| D ]Ü}| d¡rhqVt||ƒ}	t|	ƒs|qVt	j
dkrt|	ƒrqVt |	¡jdkr¢qVyt|	dƒ}
W n. tk
rÞ   t t¡}| d| ¡ wVY nX ytj|
 ¡ dd	tjd
}W n tk
r   |
 ¡ }Y nX | d¡dkr0dnd}|dkr¢tjs¢| |¡dkr¢|d	d	… }| ¡  |
 ¡  t|	|||ƒ t|	dƒ}
tj|
 ¡ dd	tjd
}| |¡dkr¾|||fV  tjrä| |¡dkrä|||fV  n$tjr| |¡dkr|||fV  | |¡dkr$t||fV  | ¡  |
 ¡  qVW d	S )a	  
    Yields files that contain the current prefix in them, and modifies them
    to replace the prefix with a placeholder.

    :param files: Filenames to check for instances of prefix
    :type files: list of tuples containing strings (prefix, mode, filename)
    ú\ú/z\\)z.pycz.pyoÚdarwinr   zrb+z5failed to open %s for detecting prefix.  Skipping it.N)ZtagnameÚflagsó    éÿÿÿÿÚbinaryÚtext)Úencoder/   Úcodecr   rt   ÚreplaceÚendswithr   r	   ÚsysÚplatformr
   r{   ÚstatÚst_sizeÚopenÚIOErrorÚ
get_loggerÚ__name__ÚwarnZ	mmap_mmapÚfilenoZmmap_MAP_PRIVATEÚOSErrorÚreadÚfindÚcloseÚrewrite_file_with_new_prefix)ÚfilesÚprefixZprefix_bytesZprefix_placeholder_bytesZforward_slash_prefixZforward_slash_prefix_bytesZdouble_backslash_prefixZdouble_backslash_prefix_bytesÚfrw   ÚfiÚlogZmmÚmodeÚdatarS   rS   rT   Úhave_prefix_files¥   s\    	




r§   c          	   C   sT   t  | ¡}| ||¡}t| dƒ}| |¡ W d Q R X t  | t |j¡tjB ¡ |S )NÚwb)	r{   r“   r   r•   Úwriter   ÚS_IMODEÚst_modeÚS_IWUSR)rw   r¦   Z
old_prefixZ
new_prefixÚstÚforS   rS   rT   rŸ   ê   s    
rŸ   c                s‚   t  ˆ d¡}t‡ fdd„|D ƒƒ}|r2t||ƒ}ndd„ |D ƒ}t  |ˆ ¡}x0|D ](}t jtˆ |ƒt||ƒ|j|jdd qRW d S )NÚ*c                s   g | ]}|  ˆ tj d ¡‘qS )ro   )r   r{   Úsep)rP   r¢   )rw   rS   rT   rU   ø   s    z*_copy_top_level_recipe.<locals>.<listcomp>c             S   s    g | ]}|d ks|dks|‘qS )z	meta.yamlzconda_build_config.yamlrS   )rP   r¢   rS   rS   rT   rU      s    
T)r~   rs   Úclobber)r/   Zrec_globÚsortedr   Úfilter_filesr}   r~   rs   )rw   rN   Údest_dirZdestination_subdirr    Ú
file_pathsr¢   rS   )rw   rT   Ú_copy_top_level_recipeö   s    
r¶   c             C   s”   t | j| j|dƒ |  |  ¡ ¡p"i }| d¡}g }|g| }dd„ |D ƒ}t || j¡}x6|D ].}tjt	| j|ƒt	||ƒ| jj
| jjdd q^W d S )NÚparentÚscriptc             S   s   g | ]}|r|‘qS rS   rS   )rP   r¸   rS   rS   rT   rU     s    z'_copy_output_recipe.<locals>.<listcomp>T)r~   rs   r±   )r¶   rw   rN   Zget_rendered_outputrX   rV   r/   r³   r}   r   r~   rs   )rb   r´   Zthis_outputZinstall_scriptZbuild_inputsZinputsrµ   r¢   rS   rS   rT   Ú_copy_output_recipe	  s    


r¹   c          	   C   sà  | j jrÜ|  ¡ rÜt| j jdƒ}yt |¡ W n   Y nX d}| jrTt| |ƒ nt| j	| j |ƒ | j
}|  ¡ }|j di ¡}| ¡ |d< ||jd< d|jkr¨|jd= d|j di ¡krÆ|jd d= t |jd¡ t|ƒ}|rt|d	ƒ}t| ¡ ƒj}W d Q R X |r||ks¬tt|d
ƒdƒT}| d t¡¡ |rb| d¡ | dt | j	¡ d ¡ | d¡ | |¡ W d Q R X |r¬tj|tj	 |d¡| j j| j jdd ttj	 |d¡dƒ}t | j j |¡ W d Q R X d S )NÚrecipero   rn   ÚstringÚoutputsZparent_recipeÚextra)zbuild/scriptztest/commandsÚrbz	meta.yamlÚwz&# This file created by conda-build {}
z&# meta.yaml template originally from:
z# Ú
z4# ------------------------------------------------

zmeta.yaml.templateT)r~   rs   r±   zconda_build_config.yaml)!rN   Zinclude_reciper   Úinfo_dirr{   r|   r   r¹   r¶   rw   Ú	meta_pathÚcopyrv   rV   Úbuild_idr/   Zsort_list_in_nested_structurer2   r•   r   rœ   Zunicode_markupr©   ra   r+   r-   Zget_repository_infor}   r~   rs   ÚyamlÚdumprO   )rb   Ú
recipe_dirZoriginal_recipeZoutput_metadatarn   Zrenderedr¢   Zoriginal_recipe_textrS   rS   rT   Úcopy_recipe  sL    



rÈ   c             C   s€   |   d¡}|r|t| jj|ƒ}t|ƒs2t d| ¡ t| jj|ƒ}tj	||| jj
| jjd tj |¡d dkr|tdtjd d S )Nzabout/readmezError: no readme file: %s)rs   r   >   ÚREADMEú	README.mdú
README.rstzNWARNING: anaconda.org only recognizes about/readme as README.md and README.rst)Úfile)Ú	get_valuer   rN   Úwork_dirr	   r‘   ÚexitrÁ   r/   r}   r~   rs   r{   rw   Úsplitrk   Ústderr)rb   Zreadmer‚   rƒ   rS   rS   rT   Úcopy_readmeQ  s    
rÒ   c             C   s„   |   d¡}|r€t| jj|ƒ}tj |¡s8tj | j|¡}tj |¡rrtj|t| jj	dƒ| jj
| jjd tdƒ ntd |¡ƒ‚d S )Nzabout/license_filezLICENSE.txt)rs   zPackaged license file.zvLicense file given in about/license_file ({}) does not exist in source root dir or in recipe root dir (with meta.yaml))rÍ   r   rN   rÎ   r{   rw   r	   r/   r}   rÁ   r~   rs   rk   Ú
ValueErrorra   )rb   Zlicense_fileÚsrc_filerS   rS   rT   Úcopy_license^  s    

rÕ   c             C   sl   |   d¡pd}tj | j|¡}tj |¡s8t| jj|ƒ}tj |¡rhtj|t| jj	dƒ| jj
| jjd d S )Nzabout/recipe_log_filezrecipe_log.json)rs   )rÍ   r{   rw   r   r	   rN   rÎ   r/   r}   rÁ   r~   rs   )rb   Zlog_filerÔ   rS   rS   rT   Úcopy_recipe_logn  s    rÖ   c             C   s@  d}t  | jj¡r| jj}n(t| jdƒrD| jjrDt j | jjdd¡}|g}t j t j |d¡¡rt| 	t j |d¡¡ x&|D ]}|r|t j |¡r|||kr|xþt
 |  dg ¡¡D ]è}t
jrÈd|krÈtdƒ‚tt||ƒƒ}|sìd	}t| |¡ƒ‚xv|D ]n}y$t
j|| ||¡| jjd
dd W qò tk
r^ } z$t
 t¡}	|	 d |t|ƒ¡¡ W d d }~X Y qòX qòW x0dD ](}
x t
 ||
¡D ]}t  |¡ q|W qjW q®W q|W |  d¡}|r<| j}x†|D ]~}tt||ƒƒ}xh|D ]`}|}t j |¡söt j |d¡}| ||¡}||krÒt
j|| ||¡| jj| jjdd qÒW qºW d S )Nro   rÇ   ÚinfoÚtestr·   ztest/source_filesr…   zCtest/source_files paths must use / as the path delimiter on Windowsz7Did not find any source_files for test with pattern {0}FT)rs   r±   z3Failed to copy {0} into test files.  Error was: {1})z.pycz.pyoz
test/files)r~   rs   r±   )r{   ÚlistdirrN   rÎ   ÚhasattrrÇ   rw   r   r   rZ   r/   Úensure_listrÍ   rt   ÚRuntimeErrorr   ra   r}   r   r~   r›   r—   r˜   r™   rM   Zget_ext_filesÚremover	   rs   )rb   ZdestinationÚsrc_dirZsrc_dirsÚpatternr    Úmsgr¢   Úer¤   r€   Zrecipe_test_filesZorig_recipe_dirZbasedirÚdestrS   rS   rT   Úcopy_test_source_files|  sT    



"




rã   c          	   C   s@   |   ¡ }ttj | jjd¡dƒ}tj||dd W d Q R X d S )Nzhash_input.jsonr¿   é   )rC   )	Úget_hash_contentsr•   r{   rw   r   rN   rÁ   ÚjsonrÆ   )rb   Zrecipe_inputr¢   rS   rS   rT   Úwrite_hash_input¯  s    rç   c                s”   t t||ƒƒ}|  ¡ ‰ tƒ ‰tˆ dƒsHˆ dkrDˆ tjjtj	jf¡ g ‰ |  
dd¡sdˆ tj	jf¡ ˆ  ‡ ‡fdd„|D ƒ¡ ‡ fdd„|D ƒ}|S )NÚ__iter__Tz%build/detect_binary_files_with_prefixc             3   s.   | ]&}|d  ˆkr|d ˆ kr|d V  qdS )r   rä   NrS   )rP   r¢   )Úignore_filesÚignore_typesrS   rT   ú	<genexpr>Â  s    z(get_files_with_prefix.<locals>.<genexpr>c                s   g | ]}|d  ˆ kr|‘qS )rä   rS   )rP   r¢   )ré   rS   rT   rU   Ã  s    z)get_files_with_prefix.<locals>.<listcomp>)r²   r§   Zignore_prefix_filesÚsetrÚ   Úupdater   rŒ   rX   r‹   rÍ   Úextend)rb   r    r¡   Úfiles_with_prefixrS   )ré   rê   rT   Úget_files_with_prefixµ  s    
rð   c          	   C   s  t | ||ƒ}|  ¡ }|  ¡ }|rÄ| jsÄtjr2d}nd}tt| jj	dƒdƒt}xl|D ]d\}}	}
t
d|	|
f ƒ | |||	|
f ¡ |	dkrœ|
|krœ| |
¡ qR|	dkrR|
|krR| |
¡ qRW W d Q R X d}x|D ]}|d	| 7 }qÎW x|D ]}|d
| 7 }qèW |r
t|ƒ‚d S )Nz"%s" %s "%s"
z	%s %s %s
Ú
has_prefixr¿   z&Detected hard-coded path in %s file %sr‹   rŒ   ro   z;Did not detect hard-coded path in %s from has_prefix_files
zBDid not detect hard-coded path in %s from binary_has_prefix_files
)rð   Úbinary_has_prefix_filesZhas_prefix_filesÚnoarchr/   rt   r•   r   rN   rÁ   rk   r©   rÝ   rÜ   )rb   r    r¡   rï   rò   Ztext_has_prefix_filesZfmt_strr®   Zpfixr¥   ÚfnZerrstrr¢   rS   rS   rT   Údetect_and_record_prefix_filesÇ  s,    


rõ   c             C   s   t  dd| ¡S )Nz\/t\/[a-zA-Z0-9\-]*\/z/t/<TOKEN>/)ÚreÚsub)ÚchannelrS   rS   rT   Úsanitize_channelì  s    rù   c          	   C   s  |   d¡}t|ƒ}tr dddœnddi}tt| jjdƒf|ŽÒ}| jdkrìxÀt|ƒD ]’}| 	d	¡d
kr„| 
|| 	d	¡d … d ¡ qT| d¡r®||kr®| 
| dd¡d ¡ qT| d¡rØ||krØ| 
| dd¡d ¡ qT| 
|d ¡ qTW n xt|ƒD ]}| 
|d ¡ qöW W d Q R X d S )Nzbuild/entry_pointsr¿   zutf-8)r¥   Úencodingr¥   r¨   r    Úpythonzsite-packagesr   rÀ   rr   zpython-scriptsrq   )rÍ   Úget_entry_point_script_namesr   r•   r   rN   rÁ   ró   r²   r   r©   rz   r   )rb   r    Úentry_point_scriptsÚentry_point_script_namesÚ	mode_dictr®   r¢   rS   rS   rT   Úwrite_info_files_fileð  s    

r   c       	   	   C   sÖ   t ƒ }|  d¡}|rPt t|ƒd}t|ƒ ¡ dkrH|  d¡}|rH||d< ||d< |  d¡}|rŠt t|ƒd}|  d	¡}|r‚||d
< ||d< |rÒd|d< ttj | jj	d¡dƒ}| 
tj|dddd¡ W d Q R X d S )Nzbuild/noarch)Útyperû   zbuild/entry_pointsÚentry_pointsró   zbuild/preferred_env)rX   z$build/preferred_env_executable_pathsÚexecutable_pathsÚpreferred_envr   Zpackage_metadata_versionz	link.jsonr¿   Trä   )ú,z: )Ú	sort_keysrC   Ú
separators)r   rÍ   r   Úlowerr•   r{   rw   r   rN   rÁ   r©   ræ   Údumps)	rb   Zpackage_metadataZnoarch_typeZnoarch_dictr  r  Zpreferred_env_dictr  ÚfhrS   rS   rT   Úwrite_link_json  s(    



r  c       	   
   C   s0  t t| jjdƒdƒ}i }xJtd D ]>}|  d| ¡}|rD|||< t d| ¡tkr&t	 
|¡||< q&W t|d< t|d< g }x(tƒ t| jjƒ D ]}| t|ƒ¡ qW ||d< dg}d	d
„ |D ƒ|d< yt|d< W n ttfk
rê   Y nX t t¡}| ¡ |d< |  d¡|d< tj||ddd W d Q R X d S )Nz
about.jsonr¿   Zaboutzabout/%sÚconda_versionÚconda_build_versionÚchannelsZCIO_TESTc             S   s   i | ]}t  |d ¡|“qS )z	<not set>)r{   Úgetenv)rP   ZevrS   rS   rT   ú
<dictcomp>5  s    z$write_about_json.<locals>.<dictcomp>Úenv_varsr!   Z	root_pkgsr½   rä   T)rC   r  )r•   r   rN   rÁ   r<   rÍ   r>   rV   Úlistr/   rÛ   r  r  r   Úchannel_urlsrZ   rù   r!   ÚKeyErrorÚAttributeErrorr,   ZEnvironmentr    Zpackage_specsÚget_sectionræ   rÆ   )	rb   r®   Údr\   ÚvalueZstripped_channelsrø   ZevarsÚenvrS   rS   rT   Úwrite_about_json   s0    
r  c          	   C   s  |   ¡ }| jrÀ| jdkr8| j di ¡ dg ¡}||d< nt | d¡}tt| jj	dƒdƒb}| 
d|  ¡ | jjf ¡ x@t|d |  ¡  d	d
¡¡g ƒD ]}| 
dd | ¡ ¡ ¡ q–W W d Q R X trÎdddœnddi}tt| jj	dƒf|Ž}tj||d
dd W d Q R X d S )NÚstrictÚrequirementsÚrunÚdependsÚrequiresr¿   zÁ# This file as created when building:
#
#     %s.tar.bz2  (on '%s')
#
# It can be used to create the runtime environment of this package using:
# $ conda create --name <env> --file <this file>
ú rJ   rä   z%s
ú=zutf-8)r¥   rú   r¥   r¨   z
index.jsonT)rC   r  )Ú
info_indexZpin_dependsrv   rV   r,   Zget_pinned_depsr•   r   rN   rÁ   r©   ÚdistÚbuild_subdirr²   ÚrsplitrÐ   r   ræ   rÆ   )rb   r"  Zruntime_depsr®   r#  rÿ   rS   rS   rT   Úwrite_info_jsonB  s    

&&r&  c          	      st   |   d¡}|rpt|tƒs|g}tt| jjdƒdƒ8}x0|D ](‰ t‡ fdd„|D ƒƒr:| ˆ d ¡ q:W W d Q R X d S )Nzbuild/no_linkÚno_linkr¿   c             3   s   | ]}t   ˆ |¡V  qd S )N)Úfnmatch)rP   Úp)r¢   rS   rT   rë   d  s    z write_no_link.<locals>.<genexpr>rÀ   )	rÍ   Ú
isinstancer  r•   r   rN   rÁ   Úanyr©   )rb   r    r'  r®   rS   )r¢   rT   Úwrite_no_link]  s    


r,  c             C   s^   g }xT| D ]L}|d |  d¡…  ¡ }tjrH| d| ¡ | d| ¡ q
| d| ¡ q
W |S )Nr!  zScripts\%s-script.pyzScripts\%s.exezbin/%s)r   Ústripr/   rt   rZ   )rý   ZscriptsZentry_pointÚcmdrS   rS   rT   rü   h  s    
rü   c          	   C   sˆ   | j  di ¡ di ¡}|r„ttj | jjd¡dƒL}t|dƒsFd|i}x&dD ]}||krLt	 
|| ¡||< qLW t ||¡ W d Q R X d S )Nrn   Úrun_exportszrun_exports.jsonr¿   ÚkeysÚweak)r1  Zstrong)rv   rV   r•   r{   rw   r   rN   rÁ   rÚ   r/   rÛ   ræ   rÆ   )rb   r/  r¢   rQ   rS   rS   rT   Úwrite_run_exportst  s    

r2  c          
   C   sž  t jrdd„ |D ƒ}| jjr$t| ƒ t| ƒ t| ƒ t| ƒ t| ƒ t	| ƒ t
| ƒ t| ƒ t| ƒ t| t| jjdƒd | jjr–t| t| jjdƒƒ t| |ƒ t| ||ƒ}t| | jj|||ƒ}t| ||ƒ t| |ƒ |  d¡}t|dƒrð|g}tjt| jjdƒdd	d
L}xD|D ]<}| d¡rtjtj | jj| dd¡¡| jj |d qW W dQ R X |  !d¡ršt j"t| j|  !d¡ƒt| jjdƒ| jj#| jj$d |S )zØ
    Creates the metadata files that will be stored in the built package.

    :param m: Package metadata
    :type m: Metadata
    :param files: Paths to files to include in package
    :type files: list of str
    c             S   s   g | ]}|  d d¡‘qS )r…   r†   )r   )rP   Ú_frS   rS   rT   rU   ‹  s    z%create_info_files.<locals>.<listcomp>rØ   )Útest_dirr-   r0  Zgitr¿   zutf-8)rú   Zgit_urlÚfolderro   )Úverboser®   Nzapp/iconzicon.png)rs   )%r/   rt   rN   Úfilename_hashingrç   r&  r  r  r2  rÈ   rÒ   rÕ   rÖ   rI   r   rÁ   rã   r   rð   Úcreate_info_files_json_v1rõ   r,  r  rÚ   Úior•   rV   r-   Zgit_infor{   rw   rÎ   r6  rÍ   r}   r~   rs   )rb   r    r¡   rï   Ú	checksumsZsourcesr®   r‚   rS   rS   rT   Úcreate_info_files€  sB    	




r;  c             C   s’   t |  d¡ƒ}| jdkrz| d¡dkr8|| d¡d … S | d¡rV||krV| dd¡S | d¡rt||krt| dd¡S |S n|  dd ¡rŠd S |S d S )	Nzbuild/entry_pointsrû   zsite-packagesr   rr   zpython-scriptsrq   zbuild/noarch_python)rü   rÍ   ró   r   rz   r   )rb   Ztarget_filerþ   rS   rS   rT   Úget_short_path¶  s    
r<  c             C   s(   x"|D ]\}}}| |kr||fS qW dS )N)NNrS   )Ú
short_pathrï   r¡   r¥   ÚfilenamerS   rS   rT   rñ   Ç  s    rñ   c                s(   t  | ¡} t‡ fdd„| D ƒƒr$dS d S )Nc             3   s   | ]}t   ˆ |¡V  qd S )N)r(  )rP   r)  )r=  rS   rT   rë   Ð  s    zis_no_link.<locals>.<genexpr>T)r/   rÛ   r+  )r'  r=  rS   )r=  rT   Ú
is_no_linkÎ  s    
r?  c                s8   t  | ¡ t tˆ |ƒ¡j‰‡ ‡fdd„| D ƒ}t|ƒS )Nc                s&   g | ]}t  tˆ |ƒ¡jˆkr|‘qS rS   )r{   Úlstatr   Úst_ino)rP   Zsp)r¡   Útarget_short_path_inoderS   rT   rU   ×  s    z#get_inode_paths.<locals>.<listcomp>)r/   rÛ   r{   r@  r   rA  r²   )r    Ztarget_short_pathr¡   Zhardlinked_filesrS   )r¡   rB  rT   Úget_inode_pathsÔ  s    
rC  c             C   s   t | ƒrtjS tjS )N)r
   r   ZsoftlinkÚhardlink)rw   rS   rS   rT   Ú	path_typeÜ  s    rE  c             C   sò   |   d¡}g }xÞt|ƒD ]Ò}t||ƒ\}}tj ||¡}	t| |ƒ}
|
rZ|
 dd¡ dd¡}
|
t 	|	¡tj 
|	¡t|	ƒdœ}t||ƒ}|r||d< |r¨|r¨||d< ||d< | d	¡tjkràt t||ƒ¡d
kràt|||ƒ}||d< | |¡ qW |S )Nzbuild/no_linkr…   r†   z\\)Ú_pathÚsha256Zsize_in_bytesrE  r'  r   Ú	file_moderE  r   Úinode_paths)rÍ   r²   rñ   r{   rw   r   r<  r   r/   Zsha256_checksumÚgetsizerE  r?  rV   r   rD  r   Úst_nlinkrC  rZ   )rb   r¡   r    rï   Zno_link_filesÚ
files_jsonr£   r   rH  rw   r=  Ú	file_infor'  rI  rS   rS   rT   Úbuild_info_files_json_v1à  s0    



rN  c       
   	   C   sx   t | |||ƒ}d|dœ}| jsPtt|dƒdƒ}tj||dddtd W d Q R X tƒ }x|D ]}	|	d	 ||	d
 < q\W |S )Nr   )Zpaths_versionÚpathsz
paths.jsonr¿   Trä   )r  z: )r  rC   r  ÚclsrG  rF  )rN  Únoarch_pythonr•   r   ræ   rÆ   r   Údict)
rb   rÁ   r¡   r    rï   Zfiles_json_filesZfiles_json_inforL  r:  rÌ   rS   rS   rT   r8  ý  s    
r8  c                sÂ  t ˆƒ tˆƒ ˆjdkr0tjˆ d¡ˆjd tjˆjjd}t	j
 ˆjj¡rXˆjjnˆjj}tˆ d¡ˆ d¡t|| ƒˆjjˆjtˆ d¡ƒˆ d¡ˆ d	¡d
 tjˆjjd}t|| ƒ}tj|ˆjjd}t‡fdd„|D ƒƒrt‡fdd„|D ƒƒf}t td| ƒ¡ tˆ||d tˆ d¡ƒ‰ ˆjdkrT‡ fdd„|D ƒ}n|}ˆ d¡rxt ˆ|ˆjj¡ n ˆjdkr˜t ˆ|ˆjjˆ ¡ tjˆjjd}|| }t|ˆjjƒ |S )Nrû   zbuild/entry_points)rN   )r¡   zpackage/namezpackage/versionzbuild/preserve_egg_dirzbuild/noarchzbuild/skip_compile_pyc)r¡   rN   Zpreserve_egg_dirró   Zskip_compile_pycc             3   s$   | ]}ˆ j jtˆ j j|ƒkV  qd S )N)rN   Úmeta_dirr   rx   )rP   r¢   )rb   rS   rT   rë   ,  s    z%post_process_files.<locals>.<genexpr>c             3   s(   | ] }ˆ j jtˆ j j|ƒkr|V  qd S )N)rN   rS  r   rx   )rP   r¢   )rb   rS   rT   rë   -  s    zÈError: Untracked file(s) %s found in conda-meta directory.
This error usually comes from using conda in the build script.  Avoid doing this, as it
can lead to packages that include their dependencies.)Úbuild_pythonc                s   g | ]}|ˆ kr|‘qS rS   rS   )rP   r£   )rþ   rS   rT   rU   6  s    z&post_process_files.<locals>.<listcomp>zbuild/noarch_python)rB   r„   ró   r/   Zcreate_entry_pointsrÍ   rN   Úprefix_filesrx   r{   rw   r	   rT  Zhost_pythonr?   r²   Úboolr³   r+  Útupler‘   rÏ   rC   r@   rü   rQ  Z	transformZpopulate_filesrA   )rb   Zinitial_prefix_filesZcurrent_prefix_filesrû   Z	new_filesZ
meta_filesZ	pkg_filesrS   )rþ   rb   rT   Úpost_process_files  sD    

rX  c       :         sÌ  t  t¡}| dˆ ¡ ¡ |  dg ¡}yt ˆjj	¡ W n t
k
rL   Y nX t  ˆ dd ¡¡}dˆ ¡ k}ˆ ¡  di ¡p~i }	ˆj}
|r&|  d¡s&|s¨|	 d¡s&ˆjj}
d |¡}t jrÄdnd	}|  d¡pÚd
 |¡}ttj ˆjj|¡dƒ$}| d¡ | |¡ | d¡ W d Q R X || d< |  d¡rÊtjˆd}|  d¡}|s˜t| d ƒ}t |d ˆjj¡|d< |d s¢| d | d |d ¡¡ n
| d¡}t   ˆjj	¡}| !¡ }|d |d< |d |d< ˆ "¡ |d< ˆ d¡|d< xBt  ˆ d¡¡D ].}|tjkrt#d |¡ƒ‚tj| ||< qüW tj ˆjj| d ¡}t  $tj ˆj| d ¡|¡ |
rpt%|ˆƒ i }t j&||g ˆjj||d t'|d ˆ (¡ ¡ƒ |d k	r||t)ˆd ˆ (¡ ¡ƒ< nD|r6t*dd„ t  +|ˆjj	¡D ƒƒ‰t*t   ˆjj	¡ƒ}t*‡fdd„|ˆ D ƒƒ}t*‡fdd„|ˆ D ƒƒ}nØˆ ,¡ sü| -d |  d ¡¡¡ ˆ d!¡}ˆ d"¡}d#d$„ |D ƒ}d%d$„ |D ƒ}d&d'd(œ}xj| .¡ D ]^\‰ }t/‡ fd)d„||fD ƒƒrÐt0d* ˆ |¡ƒ‚n&ˆ |kršˆj1ršd+}t0d, ˆ |¡ƒ‚qšW t*t   ˆjj	¡ƒ}xbˆ ,¡ D ]V}d-}x8t*|ƒD ],}t2 2||¡r*t3d.|ƒ | 4|¡ d/}q*W |s| -d0|¡ qW t5ˆ|ƒ}|  d ¡r´|  d ¡d1kr´d2|kr¬d3|ks´t6d4ƒ‚t j7|ˆjj	d5}t  8tj ˆjj9d6¡¡ t:ˆjj	ƒ t;ˆ|ˆjj	d5| d7< W d Q R X t*t   ˆjj	¡ƒ}t j7|| ˆjj	d5}d8 | d  ˆ "¡ ˆ <¡ g¡} g }!g }"t=ƒ <}#tj |#| ¡}$‡fd9d:„}%tj t>j?d;d<¡}&tj @|&¡rHtAdd=d-d>–}'t:ˆjj	ƒ~ |' BtCd?d@„ |ƒ¡ |' D¡  |&dA |'j(¡ }(tEjF|(d/tEjGdB H¡ \})}*|) IdC¡ J¡  d¡}+‡fdDd$„|+D ƒ}+t K|'j(¡ W d Q R X W d Q R X ntLdEd„ tM||%dFD ƒƒ}+x‚dGD ]z\},}-}.|,tNkr€qh|$|, }/t3dH |/¡ƒ t:ˆjj	ƒ8 tOjP|/dI|-|.dJ}0|0jQ|+Ž  W d Q R X |! R|/¡ W d Q R X qhW x®|!D ]¤}$|$ SdK¡rtT U|$ˆj¡ tj V|$¡}1yddLlWmX}2 W n$ tYk
rN   d }2| -dM¡ Y nX tZˆjdNd-ƒrÐ|2rÐ|2ƒ }3t  ˆjj[¡ˆ [¡  }4y|3j\|$|4ˆjj]dO W n4 t^k
rÎ }5 z| -dP |5¡¡ W d d }5~5X Y nX yˆjj_}6W n t`k
rú   ˆjja}6Y nX ˆjbsˆjcrdQn|6}7ˆjjdr2tj ˆjjd|7¡}8ntj tj eˆjjf¡|7¡}8tj |8|1¡}9tj g|9¡rrt  8|9¡ t j$|$|9ˆjjhd-dR |" R|9¡ qîW W d Q R X titj e|8¡ˆjjjdS t  8ˆjj	¡ |"S )TNzPackaging %sr    zbuild/scriptzpackage:rn   r¸   rÀ   ÚbatÚshzoutput_script.{}r¿   )rb   Zscript_interpreterr   z4Did not find an interpreter to run {}, looked for {}r   ÚPKG_NAMEÚTOP_PKG_NAMEÚPKG_VERSIONÚTOP_PKG_VERSIONzpackage/namezbuild/script_envz5env var '{}' specified in script_env, but is not set.)Úcwdr  Ústatszbundling {}z	bundle_{}c             s   s   | ]}t j |¡V  qd S )N)r{   rw   Únormpath)rP   ZpthrS   rS   rT   rë     s   zbundle_conda.<locals>.<genexpr>c             3   s(   | ] ‰ t ‡ fd d„ˆD ƒƒsˆ V  qdS )c             3   s    | ]}|  ˆ tjj ¡V  qd S )N)rz   r{   rw   r°   )rP   Ú	keep_file)ÚitemrS   rT   rë   ”  s   z)bundle_conda.<locals>.<genexpr>.<genexpr>N)r+  )rP   )Ú
keep_files)rc  rT   rë   “  s    c             3   s(   | ] ‰ t ‡ fd d„ˆD ƒƒsˆ V  qdS )c             3   s    | ]}|  ˆ tjj ¡V  qd S )N)rz   r{   rw   r°   )rP   rb  )rc  rS   rT   rë   —  s   z)bundle_conda.<locals>.<genexpr>.<genexpr>N)r+  )rP   )rd  )rc  rT   rë   –  s    z&No files or script found for output {}rX   zrequirements/buildzrequirements/hostc             S   s   g | ]}|  ¡ d  ‘qS )r   )rÐ   )rP   ÚpkgrS   rS   rT   rU   ž  s    z bundle_conda.<locals>.<listcomp>c             S   s   g | ]}|  ¡ d  ‘qS )r   )rÐ   )rP   re  rS   rS   rT   rU   Ÿ  s    ZPYTHONÚR)rû   zr-basec             3   s   | ]}ˆ |kV  qd S )NrS   )rP   Z	pkgs_list)ÚdeprS   rT   rë   ¢  s    zÑEmpty package; {0} present in build and host deps.  You probably picked up the build environment's {0}  executable.  You need to alter your recipe to  use the {1} env var in your recipe to run that executable.zOhttps://conda.io/docs/user-guide/tasks/build-packages/define-metadata.html#hostz›Empty package; {0} dep present in build but not host requirements.  You need to move your {0} dep to the host requirements section.  See {1} for more info.Fz"Including in package existing fileTz:Glob %s from always_include_files does not match any filesÚcondaz	bin/condazScripts/conda.exezmBug in conda-build has included conda binary in package. Please report this on the conda-build issue tracker.)r¡   rØ   r:  rJ   c                sŠ   t  tˆ jj| ƒ¡jpd}tt j | ¡dkƒ}|r‚t j 	| ¡\}}t
 dd|¡}|sndtt j | ¡ƒd  }ndtt|ƒƒd  }||fS )Ni † r×   z(\.dylib|\.so).*$z.sor   i áõ)r{   r“   r   rN   rx   r”   r`   rw   r   Úsplitextrö   r÷   ÚhashÚabs)r¢   ZfsizeZ
info_orderrL   r€   )rR   rS   rT   ÚorderÓ  s    zbundle_conda.<locals>.orderrr   Úbinsortz	.filelist)r¥   ÚsuffixÚdeletec             S   s   dt j |  d S )Nrp   rÀ   )r{   r°   )ÚxrS   rS   rT   Ú<lambda>ç  s    zbundle_conda.<locals>.<lambda>z -t 1 -q -d -o 1000 {})ÚshellÚstdoutzutf-8c                s&   g | ]}|  ˆ jjtj d ¡d ‘qS )r   rŠ   )rÐ   rN   rx   r{   r°   )rP   r¢   )rR   rS   rT   rU   î  s   c             s   s   | ]
}|V  qd S )NrS   )rP   r¢   rS   rS   rT   rë   ò  s    )r\   ))z.tar.bz2Zbzip2ro   )z.tar.zstZzstdzzstd:compression-level=22zCompressing to {}Zgnutar)Zfilter_nameZoptionsz.tar.bz2)ÚVerifyzImporting conda-verify failed.  Please be sure to test your packages.  conda install conda-verify to make this message go away.Zverify)Zpath_to_packageÚchecks_to_ignoreZexit_on_errorz„Package doesn't have necessary files.  It might be too old to inspect.Legacy noarch packages are known to fail.  Full message was {}ró   )rs   )r6  )kr/   r—   r˜   r×   r#  rV   r{   r|   rN   rx   r›   rÛ   rÍ   ru   Z$get_top_level_recipe_without_outputsÚactivate_build_scriptÚactivater   rt   ra   r•   rw   rÎ   r©   r,   Úget_dictÚguess_interpreterÚexternalÚfind_executableÚbuild_prefixÚerrorrÐ   rU  rÃ   rY   rÓ   r}   Ú_write_activation_textÚcheck_call_envrm   rX   r]   rì   Zexpand_globsZalways_include_filesr™   ÚitemsÚallrE   Z"uses_new_style_compiler_activationr(  rk   rÝ   rX  ÚAssertionErrorr³   Úrm_rfrÁ   r*   r;  rÄ   r   r‘   r¡   Úexistsr   Ú
writelinesÚmaprž   Ú
subprocessÚPopenÚPIPEZcommunicateÚdecoder-  Úunlinkr  r²   r   Ú
libarchiveZfile_writerZ	add_filesrZ   r   r.   Z	check_allÚbasenameZconda_verify.verifyrt  ÚImportErrorÚgetattrZignore_verify_codesZverify_packageZexit_on_verify_errorr  Ztarget_subdirr  ry   ró   rQ  Úoutput_folderr   Úbldpkgs_dirr	   r~   r1   Údebug):ÚoutputrR   r  r`  Úkwr¤   r    r¸   r   Z	top_buildZactivate_scriptrn  Z	script_fnr¢   ZinterpreterÚinterpreter_and_argsÚinitial_filesZ
env_outputÚvarÚ	dest_fileÚbundle_statsZ	pfx_filesZ
build_depsZ	host_depsZ
build_pkgsZ	host_pkgsZdangerous_double_depsZenv_var_nameÚlinkZpatZhas_matchesrU  r  Ztmp_archivesZfinal_outputsZtmpZtmp_pathrl  rm  Zflr.  ÚoutrL   Z
files_listr€   ÚfilterZoptsZfullpathÚarchiveZoutput_filenamert  Zverifierru  rá   Zcrossed_subdirrW   r  Zfinal_outputrS   )rg  rd  rR   rT   Úbundle_condaH  s>   
"
















 

"



rž  c             C   s¼  t jr
dnd}tƒ Š}t  |jj¡n tj |jjd| ¡}t	|dƒ*}| 
d¡ | 
d |¡¡ | 
d¡ W d Q R X |jjrŒt||ƒ tj|d ¡ }|d |d	< |d
 |d< | ¡ |d
< | d¡|d< t|ƒ}i }	t j||g |jj||	d t|	d | ¡ ¡ƒ |d k	r,|	|t|d | ¡ ¡ƒ< ttj |d¡ƒ}
|
sLtdƒ‚|
d }|jjrvtj |jj|jj¡}n|jj}t j|||jjd W d Q R X W d Q R X tj |tj |¡¡S )Nz.batz.shZwheel_outputr¿   rÀ   z$pip wheel --wheel-dir {} --no-deps .)rb   r[  r\  r]  r^  zpackage/name)r_  r  r`  zbundling wheel {}zbundle_wheel_{}z*.whlz9Wheel creation failed.  Please see output above to debug.r   )rs   ) r/   rt   r   r*   rN   rÎ   r{   rw   r   r•   r©   ra   rw  r~  r,   rx  rÃ   rY   rÍ   ry  r  rm   rX   r]   r   rÜ   r  rW   r‘  r}   rs   r  )r“  rR   r  r`  r€   Útmpdirr˜  r¢   r•  r™  Zwheel_filesZ
wheel_filer  rS   rS   rT   Úbundle_wheel5  s<    



(r   c          
   C   sP   t ƒ }xDttj | d¡ƒD ].}t|ƒ}t |¡}|||d < W dQ R X qW |S )zˆ
    Scan all json files in 'path' and return a dictionary with their contents.
    Files are assumed to be in 'index.json' format.
    z*.jsonrX   N)rR  r   r{   rw   r   r•   ræ   Úload)rw   Z	installedr>  rÌ   r¦   rS   rS   rT   Úscan_metadata[  s    

r¢  )rh  Úwheelc             C   s„  t jr
dnd}t jrdnd}d |tj t jd¡ dd¡|f¡}trX|  dj	t
jd¡ |jröt|jjd	d
ƒ}t|ƒsžtt|ƒƒst t|ƒ¡ t|dƒ ¡  d ||jj dd¡|f¡}trÐ|  d 	|¡¡ n&|  d 	||¡¡ |  d¡ |  d¡ d ||jj dd¡|f¡}tr*|  d 	|¡¡ n|  d 	||¡¡ t|jjd	d
ƒ}t|ƒs€tt|ƒƒsrt t|ƒ¡ t|dƒ ¡  d S )Nz$(cygpath -u ro   z )rw  r…   z\\z2eval "$('{sys_python}' -m conda shell.bash hook)"
)Z
sys_pythonz
conda-metaÚhistoryÚazconda activate "{0}"
zsource "{0}" "{1}"
zunset CONDA_PATH_BACKUP
zexport CONDA_MAX_SHLVL=2
zconda activate --stack "{0}"
)r/   rt   r   r{   rw   Úroot_script_dirr   r   r©   ra   r‘   Ú
executableÚis_crossrN   rx   r	   r   r   r|   r•   rž   r|  )Zfile_handlerb   Zcygpath_prefixZcygpath_suffixZactivate_pathZhistory_fileZhost_prefix_pathZbuild_prefix_pathrS   rS   rT   Ú_write_sh_activation_textn  sB    


r©  c          	   C   sš   t | dƒ†}| ¡ }| d¡ tj | ¡d  ¡ dkrDt ||¡ n>tj | ¡d  ¡ dkrht	||ƒ nt
 t¡}| d | ¡¡ | |¡ W d Q R X d S )Nzr+r   r   z.batz.shzJnot adding activation to {} - I don't know how to do so for this file type)r•   rœ   Úseekr{   rw   ri  r  ÚwindowsZ_write_bat_activation_textr©  r/   r—   r˜   r™   ra   r©   )Zscript_pathrb   r
  r¦   r¤   rS   rS   rT   r~  ¬  s    

r~  c       
         sâ  |   d¡}dd„ |D ƒ}|   d¡}dd„ |D ƒ}| j| j_| jræ| jsættƒtdƒk r^tdƒ‚tj	| jj
t|ƒd| jj| jj| jj| jjt| jjƒ| jj| jj| jj| jjt| jjƒd}tj| jj
|d| j| jj| j|  ¡ d	kd
 | jrö| |¡ tj	| jjt|ƒd| jj| jj| jj| jjt| jjƒ| jj| jj| jj| jjt| jjƒd}y¦|söt | j di ¡| jjd¡ t  |  !dg ¡¡t  |  !dg ¡¡ }tj	| jj"t|ƒd| jj| jj| jj| jjt| jjƒ| jj| jj| jj| jjt| jjƒd W nŒ t#k
r„ } zlddl$m%‰  t&| dƒr.| j' (¡ n
| j)dd}t*‡ fdd„|j+D ƒƒt*dd„ |D ƒƒ }	|	rt|	|_+|‚W d d }~X Y nX | jj,r²t-j. /| jj¡r²t- 0| jj¡sÞtj| jj|d| j| jj| j|  ¡ d	kd
 d S )Nrn   c             S   s   g | ]}t  |¡‘qS rS   )r/   Úensure_valid_spec)rP   ÚspecrS   rS   rT   rU   ½  s    z%create_build_envs.<locals>.<listcomp>Úhostc             S   s   g | ]}t  |¡‘qS rS   )r/   r¬  )rP   r­  rS   rS   rT   rU   ¿  s    z4.3.2z0Non-native subdir support only in conda >= 4.3.2)
rW   r’  r6  rs   Úbldpkgs_dirsr~   Údisable_pipÚmax_env_retryr  r  rh  )r  rN   rW   r¨  Úis_condar  r  ztest/requireszrequirements/runrØ   r   )r"   Úother_outputsT)Úpermit_undefined_jinjac             3   s   | ]}ˆ |ƒj V  qd S )N)rX   )rP   re  )r"   rS   rT   rë   þ  s    z$create_build_envs.<locals>.<genexpr>c             s   s   | ]\}}|  ¡ V  qd S )N)rX   )rP   rL   r›  rS   rS   rT   rë   þ  s    )1Ú
ms_dependsÚbuild_is_hostrN   Ú_merge_build_hostr¨  r   r  rÜ   r,   Úget_install_actionsrx   rW  ry   r’  r6  rs   r¯  r~   r°  r±  r  r  Ú
create_envrX   rî   r|  r$  r/   Úinsert_variant_versionsrv   rV   rO   rÛ   rÍ   Útest_prefixrD   Úconda_interfacer"   rÚ   r³  ÚvaluesÚget_output_metadata_setrì   ÚpackagesÚdirtyr{   rw   r   rÙ   )
rb   ÚnotestZbuild_ms_depsÚhost_ms_depsÚhost_actionsÚbuild_actionsZtest_run_ms_depsrá   r³  Zmissing_depsrS   )r"   rT   Úcreate_build_envs»  s†    










*,
rÅ  TFc       >         sö  i }ˆ si ‰ |   ¡ r&tt | ¡ƒ |S t t¡}	g }
g }g }t | jj¡ t	j
| d‰W dQ R X dˆd< tr|tj	d ˆd< | jrŽt| dd |dkrDt| ||fgƒ}g }g }xH|D ]@\}}|  ¡ sØ| jjrèt|d	ƒrè| t|ƒ¡ q¶| t|ƒ¡ q¶W |s&td
| jp|  ¡ d |  ¡ ¡ƒ |S |s’g }xV|D ]N‰tj ˆ¡d rxt‡fdd„tD ƒƒrx| tj ˆ¡¡ n
| ˆ¡ q6W td|ƒ t	 | jjg‡ fdd„|D ƒ| j¡ dd„ |  d¡D ƒ}tdd„ | j  dg ¡D ƒƒrö| !ddg¡ | j"}|r€||kr€|dkrdn|}tj #t$ %|| jj¡p8d¡}|s€|dks`tdd„ |D ƒƒsx| |¡ |	 &d|¡ nt'dƒ‚d}t(| jj)  dg ¡ƒ}x2| jj)  di ¡ *¡ D ]}||kr®| +|¡ q®W t(ƒ }t,| d ƒröt(d!d„ | j- *¡ D ƒƒ}|s|r t. /d" 0d#d„ ||B D ƒ¡¡}t 1| j  d$i ¡| jj)d¡ t 1| j  d$i ¡| jj)d	¡ t2| d|ƒ t3| |ƒ t4| ƒ t | jj¡ t| dd%d& W dQ R X |rº| j5sº| j6d%d' n|rÈt7| ƒ} | jj8}t9|ƒrð| jj:rtd(|ƒ n| jj:rtd)ƒ t ;|¡ t <| jj=¡ tj>| jj?d*}t@t0| jjAd+ƒd,ƒ(}| Bd- 0tCtD|ƒƒ¡¡ | Bd-¡ W dQ R X t E|  Fd.d¡¡}|rŽd- 0|¡}t9|ƒrDi }tjGröt0| jd/ƒ}|ràt0|d/ƒ}t@|d,ƒ} |  B|¡ W dQ R X tHjI| |||d0 nt0| jd1ƒ}t#|ƒr|rtJd2ƒ‚t#|ƒs*|rtK| ||ƒ\}!}|stLg| jjMrTd3gng  d4|!g }"| jjMsv| jjNr|d}#nhd5d6g}$| jOs˜|$ Pdd7¡ ‡fd8d9„|$D ƒ}#x8|# Q¡ D ],\}%}&td: | Rd;¡rÒd<nd=|%|&¡ƒ q´W ˆd>= tjS|"ˆ|#||d? t T| jj?¡ |rD|sDtU|d@ |  ¡ ¡ƒ |dk	rD||tV| dƒ< t0| jjAd+ƒ}'t(ƒ }(tj #|'¡rŠt@|'ƒ}t(| W¡  X¡ ƒ}(W dQ R X tj>| jj?d*|( })|}*|sÞ|dAkrÞ|pÂ| jYddB}+| },t0| jjAd+ƒ}'tj #|'¡r
t@|'ƒ}t(| W¡  X¡ ƒ}(W dQ R X nt(ƒ }(| jjZdCkr&| jjZn| jj[}-t\ƒ  }.x6|)D ].}tj]tj 0| jj?|¡tj 0|.|¡d%dD q>W x^|+D ]T\}/} |   ¡ ržtt | ¡ƒ qx| jjrÖt| d	ƒrÖtt | ¡ƒ |/| f|*t| ƒ< qx|, ¡ |/  dE¡kr|/  dF¡s|/  dG¡stj>| jj?d*|( |/dF< dG|/krDt ]tj 0| j|/dG ¡| jj8¡ |/  dHi ¡  dG¡}0|0rªtj #tj 0| j|0¡¡s„t'dI |0¡ƒ‚t ]tj 0| j|0¡tj 0| jj8|0¡¡ |/  dJ¡dKksÔ| j5sÔt^dL |  _¡ ¡ƒ‚t| ƒ}1|1ˆ krx|1|*krx|	 `dM |  ¡ ¡¡ | ja	sDtj 9| jj?¡	r6tbt c| jj?¡ƒdk	sD|	 MdN¡ np| jO| j_dt <| jj?¡ t <| jj¡ t <| jje¡ |  d	¡}2|  d¡}3| jf
r"| jO
s"t	jg| jj?th|2ƒd	| jjZ| jjM| jj:| jjith| jjjƒ| jjk| jjl| jjm| jjnth| jjoƒdO}
t	jp| jj?|
d	| j|-| jf|  ¡ dKkdP n
|3 !|2¡ t	jg| jjth|3ƒd| jjq| jjM| jj:| jjith| jjjƒ| jjk| jjl| jjm| jjnth| jjoƒdO}t	jp| jj|d| j| jjq| jf|  ¡ dKkdP t(ƒ }4x,|/  dFg ¡D ]}| rdQ¡
rÈ|4 s|¡ 
qÈW dF|/krt(|/dF ƒ|4 |/dF< x6|)D ].}tj]tj 0|.|¡tj 0| jj?|¡d%dD qW t | jj¡ t	j
| d‰W dQ R X t,| dJƒstdKn| jt}5tu|5 |/| ˆ|ƒ}6dR|/kr xˆ|/dR  Q¡ D ]x\}7}8xl|* Q¡ D ]`\}}9|9\}:}|7|:  dRi ¡kr¶|:dR |7 };|8|;kròdSndT}<|	 &dU |<|7|/dE |:dE ¡¡ q¶W q¤W x|6D ]}=|/| f|*|=< q&W | jvsL| jwrPdCn| jjZ}-| jfr–tx|-| jj| jjn| jjo| jjM| jj:| jji| jjkd%dV	 tx|-| jj| jjn| jjo| jjM| jj:| jji| jjkd%dV	 qxW W dQ R X n|sòtdW|  _¡ ƒ |*S )Xa‚  
    Build the package with the specified metadata.

    :param m: Package metadata
    :type m: Metadata
    :type post: bool or None. None means run the whole build. True means run
    post only. False means stop just before the post.
    :type need_source_download: bool: if rendering failed to download source
    (due to missing tools), retry here after build env is populated
    )rb   NÚBUILDÚCONDA_BUILD_STATEÚCONDA_PATH_BACKUPF)Úno_download_source)FNr®  zPackages for z‰with variant {} are already built and available from your configured channels (including local) or are otherwise specified to be skipped.r   c             3   s"   | ]}t j ˆ ¡d  |kV  qdS )r   N)r{   rw   ri  )rP   r€   )re  rS   rT   rë   B  s    zbuild.<locals>.<genexpr>zBUILD START:c                s   g | ]}|ˆ kr|‘qS rS   rS   )rP   re  )Úbuilt_packagesrS   rT   rU   I  s    zbuild.<locals>.<listcomp>c             S   s   g | ]
}|j ‘qS rS   )r­  )rP   ZmsrS   rS   rT   rU   K  s    rn   c             s   s   | ]}|  d ¡dkV  qdS )r  r£  N)rV   )rP   r›  rS   rS   rT   rë   L  s    r¼   Zpipr£  Z	mercurialZhgro   c             s   s    | ]}|  d ¡od|kV  qdS )rû   z3.N)rz   )rP   r­  rS   rS   rT   rë   U  s    z„Your recipe depends on %s at build time (for templates), but you have not listed it as a build dependency.  Doing so for this build.zœYour recipe uses mercurial in build, but mercurial does not yet support Python 3.  Please handle all of your mercurial actions outside of your build script.Zignore_versionZpin_run_as_buildr³  c             s   s   | ]\}}|V  qd S )NrS   )rP   rX   rO   rS   rS   rT   rë   i  s    ú|c             s   s   | ]}d   |¡V  qdS )z(?:^{}(?:\s|$|\Z))N)ra   )rP   ÚexcrS   rS   rT   rë   l  s   r  T)rÉ  Zraise_error)Zallow_no_other_outputszsource tree in:z&no source - creating empty work folder)r¡   zprefix_files.txtr¿   rÀ   zbuild/scriptzbld.bat)r`  Úprovision_onlyzbuild.shz–Found a build.sh script and a build/script sectioninside meta.yaml. Either remove the build.sh script or remove the build/script section in meta.yaml.z-xz-eÚPREFIXÚSRC_DIRÚBUILD_PREFIXc                s   i | ]}|ˆ krˆ | |“qS rS   rS   )rP   rQ   )r  rS   rT   r  ¸  s   zbuild.<locals>.<dictcomp>z{0} {1}={2}z.batrì   ÚexportZCONDA_BUILD)r  Úrewrite_stdout_envr_  r`  zbuilding {})TN)Úpermit_unsatisfiable_variantsró   )ÚsymlinksrX   r    r¸   rØ   zetest script specified as {} does not exist.  Please check for typos or create the file and try again.r  rh  z'output metadata for {} is not finalizedzPackaging {}z?Not creating new env for output - already exists from top-level)
rW   r’  r6  rs   r¯  r~   r°  r±  r  r  )r  rN   rW   r¨  r²  z
conda-metar:  ZExactZInexactz+{} overlap between {} in packages {} and {})	rW   r‘  r  r  r’  r6  rs   r~   Úclear_cachezSTOPPING BUILD BEFORE POST:)yÚskiprk   r/   Zget_skip_messager—   r˜   Úpath_prependedrN   r|  r,   rx  r   r{   Zneeds_source_for_renderr9   r8   Zskip_existingÚis_package_builtrZ   r3   rw   rX   ra   rå   ri  r+  r   r  Zremove_existing_packagesr‘  rµ  rv   rV   rî   Zuses_vcs_in_buildr	   rz  r{  r™   rÓ   rì   rO   r0  rÝ   rÚ   r³  rö   Úcompiler   rº  r:   rÅ  Úwarn_on_use_of_SRC_DIRÚfinalZparse_until_resolvedr5   rÎ   r   r6  r|   rƒ  rÁ   rU  rx   r•   Úbuild_folderr©   r²   r  rÛ   rÍ   rt   r«  rn   rE   Úwrite_build_scriptsÚ
shell_pathr’  Úno_rewrite_stdout_envr¶  Úinsertr€  r   r  Zremove_pycache_from_scriptsrm   r]   rœ   Ú
splitlinesr¾  ry   rW   r   r}   r‚  r#  r×   r   ÚlenrÙ   r·  r»  r¨  r¸  rW  rs   r¯  r~   r°  r±  r  r  r¹  r$  rz   Úaddr  Úbundlersró   rQ  r0   )>rb   r`  ÚpostÚneed_source_downloadÚneed_reparse_in_envrÊ  rÁ  rÍ  Zdefault_returnr¤   rÃ  rÄ  Zoutput_metasZskippedZpackage_locationsrL   ZomZprinted_fnsÚspecsZ
vcs_sourceZvcs_executableZhas_vcs_availableZexclude_patternZexcludesr\   Zoutput_excludesrÞ   Zfiles1r¢   r¸   Zbuild_statsÚ
build_fileÚbfÚ	work_filer.  Úrewrite_envZrewrite_varsrQ   ÚvZprefix_file_listr–  Znew_prefix_filesZnew_pkgsr¼   Ztop_level_metarW   Zprefix_files_backupZoutput_dÚtest_scriptZpkg_pathrÂ  Zsub_build_ms_depsZ	to_removeZpkg_typeZnewly_built_packagesrÌ   ZcsumZprev_omZprev_output_dZ	prev_csumZnatureZbuilt_packagerS   )rÊ  r  re  rT   rn     sþ   













"
"







 

 
















 rn   c             C   sˆ   d  tjrdnd¡gtj dd¡ddgdd	d
dgdgdœ}tj | ¡d }x8| ¡ D ]\}}| 	¡  
|¡rT|}P qTW td  || ¡ƒ‚|S )Nzbash{}z.exero   ÚCOMSPECzcmd.exez/dz/cZ
powershellz-executionpolicyZbypassz-Filerû   )z.shz.batz.ps1z.pyr   zRDon't know how to run {0} file.   Please specify script_interpreter for {1} output)ra   r/   rt   r{   r,   rV   rw   ri  r€  r  rz   ÚNotImplementedError)Zscript_filenameZextensions_to_run_commandsZfile_extr€   ZcommandZinterpreter_commandrS   rS   rT   ry    s    

ry  c          
   C   sh   t tj | jd¡ƒ}xN|D ]F}t|ƒ}| ¡ }W d Q R X d|krd|  d¡kr| jjrt	dƒ‚qW d S )Nz	run_test*rÏ  Úsource_filesrØ   a)  In conda-build 2.1+, the work dir is removed by default before the test scripts run.  You are using the SRC_DIR variable in your test script, but these files have been deleted.  Please see the  documentation regarding the test/source_files meta.yaml section, or pass the --no-remove-work-dir flag.)
r   r{   rw   r   r•   rœ   r  rN   Úremove_work_dirrÓ   )rR   Ú
test_filesr¢   r3  ÚcontentsrS   rS   rT   rÚ  –  s    

rÚ  c             C   sˆ   d|_ d |_i }tt| |ddƒd d }t t¡}| d¡ t |j	j
¡ |j di ¡ d¡rr|jsrt|dd |js€t|ƒ}||fS )	NF)rN   Úreset_build_idr   r   zTesting based on recipes is deprecated as of conda-build 3.16.0.  Please adjust your code to pass your desired conda package to test instead.rØ   rñ  )rÉ  )Úneed_cleanuprÇ   r8   r4   r/   r—   r˜   r™   rƒ  rN   r4  rv   rV   Úsource_providedr9   rÛ  r6   )rÇ   rN   Ú
hash_inputrR   r¤   rS   rS   rT   Ú(_construct_metadata_for_test_from_recipe¤  s    

rù  c          
      sž  t  | ¡\}}||_||_i }tj tj |d¡¡}ttj |d¡ƒ}t	 
|¡}W d Q R X |d dkrr|d |_tj |d¡}tj |¡r¶ttj |d¡ƒ}t	 
|¡}W d Q R X n
d|_i }||_t  t¡}tj tj tj | ¡¡¡}	tj |	¡}
d}xdD ]}|
 |¡rd}qW |s€| d	¡ tj |j|j¡}yt |¡ W n   Y nX tj |tj | ¡¡}	t  | |	¡ |}	tj |	¡}t||jd
 y$ttj |d¡|ddd d }W nZ tttfk
r   tj |d |d dœt!|d ƒ|d dœd|d idœ|d}Y nX |j"r.d|j#jd< t$| %¡ ƒ|j#_&t$t  '|j#j(¡ƒ}t)|ƒ‰ ‡ fdd„|D ƒ}ˆ |kr€| *dˆ ¡ ||j#_(t  +|j#j,¡ ||fS )Nr×   z
index.jsonrW   ró   zhash_input.jsonF)zwin-zlinux-zosx-ró   TaM  Copying package to conda-build croot.  No packages otherwise alongside yours will be available unless you specify -c local.  To avoid this warning, your package must reside in a channel structure with platform-subfolders.  See more info on what a valid channel is at https://conda.io/docs/user-guide/tasks/create-custom-channels.html)r6  rº   )rN   rõ  r   rX   rY   )rX   rY   Zbuild_numberrn   )Znumberr»   r  r  )Úpackagern   r  )rN   rK   c                s   g | ]}|d kr|nˆ ‘qS )ÚlocalrS   )rP   Zurl)Ú
local_pathrS   rT   rU   	  s    z=_construct_metadata_for_test_from_package.<locals>.<listcomp>)-r/   Zget_recipe_abspathrö  rÇ   r{   rw   ra  r   r•   ræ   r¡  ry   r	   r7  rO   r—   r˜   Úabspathr   r  rz   r™   Úcrootr|   r}   r1   r’  r4   r–   Ú
SystemExitr›   r=   Zfromdictr`   ró   rN   r  r0  Z	used_varsrÛ   r  r   rà  rƒ  r4  )rú  rN   rÇ   rö  rø  rÁ   r¢   Zpackage_datar¤   Zlocal_pkg_locationZlast_elementZ
is_channelr’   Z	local_dirZlocal_channelrR   ÚurlsrS   )rü  rT   Ú)_construct_metadata_for_test_from_package¸  sp    









r  c          	   C   s
  t | jdƒr| jjn| j}|rtj tj |d¡¡}tj |d¡}tj |¡rÜtj |¡rÜt	j
|| jj| jjd| jjdd tj |d¡}g }tj |¡rºt|ƒ}t |¡}W d Q R X | j di ¡}||d< || jd< n*| j di ¡ d¡r| jst| d	d
 d S )NrÇ   r×   rØ   T)rÔ  rs   r±   ztest_time_dependencies.jsonr  rñ  F)rÉ  )rÚ   rN   rÇ   rw   r{   ra  r   r„  r   r/   r}   r4  r~   rs   r	   r•   ræ   r¡  rv   rV   r÷  r9   )rR   rÇ   rÁ   ró  Zdependencies_fileZ	test_depsr¢   Ztest_sectionrS   rS   rT   Ú _extract_test_files_from_package  s&    
r  c             C   sB   t j | ¡st j | ¡dkr,t| |ƒ\}}nt| |ƒ\}}||fS )Nz	meta.yaml)r{   rw   r   r  rù  r  )Zrecipedir_or_packagerN   rb   rø  rS   rS   rT   Úconstruct_metadata_for_test/  s    r  c       	   
   C   s€  t  | jj¡, t  | jj¡ tj| d}W d Q R X W d Q R X d|d< d|d< d|d< d|d< | jj|d	< d|d
< | jdkr†d|d< t	| jj
dƒ}t	| jj
dƒ}t|dƒN}x6| ¡ D ]*\}}|dkr¸|d k	r¸| d ||¡¡ q¸W | jröt|| ƒ W d Q R X t|dƒ\}| d¡ | d |¡¡ | d¡ |r@| |¡ t|ƒrb|sb| t|ƒ ¡ ¡ W d Q R X t |d¡ ||fS )N)rb   rÆ  rÇ  ÚFalseZPIP_NO_BUILD_ISOLATIONTZPIP_NO_DEPENDENCIESZPIP_IGNORE_INSTALLEDZPIP_CACHE_DIRZPIP_NO_INDEXrû   ZPYTHONDONTWRITEBYTECODEzconda_build.shzbuild_env_setup.shr¿   ro   zexport {0}="{1}"
z!if [ -z ${CONDA_BUILD+x} ]; then
z	source {}
zfi
iö  )r/   r×  rN   rx   r|  r,   rx  Zpip_cache_dirró   r   rÎ   r•   r€  r©   ra   rv  r©  r	   rœ   r{   r   )	rb   r¸   ré  r  rë  Zenv_filerê  rQ   rí  rS   rS   rT   rÝ  7  s:     



rÝ  c	          	   C   s  t  t¡}	t|dƒè}
|
 djt jr*dnd|d¡ t jrF|
 d¡ |rœ| jj}|  	d¡rnt
jdkrn|d }|
 d	j|t| jjd
ƒd¡ t jrœ|
 d¡ |rà|
 dj| j | jj| jj¡t| jjdƒd¡ t jrà|
 d¡ |r(|
 dj| j | jj| jj¡t| jjdƒd¡ t jr(|
 d¡ |rp|
 dj| j | jj| jj¡t| jjdƒd¡ t jrp|
 d¡ |rúx‚|D ]z}t jrÈtj |¡d dkr¼|
 dj|d¡ |
 d¡ n
|	 d¡ n,tj |¡d dkr||
 djt||d¡ q|W W d Q R X d S )Nr¿   z{source} "{test_env_script}"
Úcallr-   )r-   Útest_env_scriptzIF %ERRORLEVEL% NEQ 0 exit 1
zbuild/osx_is_appr‡   z"{python}" -s "{test_file}"
zrun_test.py)rû   Ú	test_filez"{perl}" "{test_file}"
zrun_test.pl)Úperlr  z"{lua}" "{test_file}"
zrun_test.lua)Úluar  z"{r}" "{test_file}"
z
run_test.r)Úrr  r   z.batzcall "{test_file}"
)r  zCFound sh test file on windows.  Ignoring this for now (PRs welcome)z.shz'"{shell_path}" {trace}-e "{test_file}"
)rÞ  r  Útrace)r/   r—   r˜   r•   r©   ra   rt   rN   Útest_pythonrÍ   r‘   r’   r   r4  Zperl_binr»  Zhost_platformZlua_binZrscript_binr{   rw   ri  r™   rÞ  )rR   Útest_run_scriptr  Úpy_filesÚpl_filesÚ	lua_filesÚr_filesÚshell_filesr  r¤   Útfr  Z
shell_filerS   rS   rT   Ú_write_test_run_scriptm  s`    








r  ro   c          
   C   s^  | j jr|  ¡ dkrHtj|| j jdd}tjrH| j jtj |d  |d< | 	t
| j jƒ¡ dd„ | ¡ D ƒ}tjrvdnd}t| j jd	j|d
ƒ}	t| j jdj|d
ƒ}
t|	dƒˆ}tjsÊ| dj|d¡ | j jr4|  ¡ dks4tjrìdnd}| djtjtjj tjrdnd|| j jd¡ tjr4| d¡ W d Q R X t| |
|	||||||ƒ	 |
|	fS )Nrh  T)Úprepend_prefixÚPATHc             S   s   i | ]\}}t |ƒt |ƒ“qS rS   )rM   )rP   r\   r  rS   rS   rT   r  ¯  s    z&write_test_scripts.<locals>.<dictcomp>rY  rZ  zconda_test_env_vars.{suffix})rn  zconda_test_runner.{suffix}r¿   zset {trace}-e
)r  z.batro   z2{source} "{conda_root}activate{ext}" "{test_env}"
r  r-   )Z
conda_rootr-   r€   Ztest_envzIF %ERRORLEVEL% NEQ 0 exit 1
)rN   rw  rX   r/   Úprepend_bin_pathr»  rt   r{   Úpathseprí   rF   rO   r€  r   r4  ra   r•   r©   r¦  rw   r°   r  )rR   r  r  r  r  r  r  r  rn  r  r  r  r€   rS   rS   rT   Úwrite_test_scripts¤  s4    r  c                s  t  t¡}i }t| dƒr |  ¡ n| }|s2td|ƒ t| dƒrP| }t  |jj¡ nt	| |ƒ\}}|jj
rjdnd}	t|ƒ t| dƒ oªtj | ¡oª|  t¡oªtj | ¡td k}
|
sÂt | ¡ |j¡ t||jjƒ t|ƒ\}}}}}}t|||||gƒstd|ƒ dS |jjròxˆd	|jjfd
|jjffD ]l\}}tj |¡r*tj tj |¡d d| | ¡ t|jd| ƒf¡¡}td| |d|ƒ t ||¡ q*W |j rütj tj |jj!¡d d| ¡ |jj"f¡¡}td|jj!d|ƒ t |j!|¡ n
| #d¡ t$|ƒ | %||||¡}t  &|jj'¡F t(tj )¡ ƒ‰ ˆ  *tj+||j'd¡ dˆ d< t,rdtjd ˆ d< W dQ R X |jj-r†| .¡ dkršt j/ˆ |jj'dd‰ t j0r¼|jj'tj1 ˆ d  ˆ d< |jj'ˆ d< dˆ krØˆ d= |j2sè|j3rìdn|jj"}t  |jj'¡ y\tj4|jj't5|ƒd	||jj
|jj6|jj7t5|jj8ƒ|jj9|jj:|jj;|jj<t5|jj=ƒd}W nV t>t?t@tAtBfk
r´ } z,| #dtC|ƒ¡ tD|||jjE|jd  ‚ W dd}~X Y nX tCtFjGƒd!krÊd"ntCtFjGƒ}tHd#|tIƒ. tjJ|jj'||jd	||jK| .¡ dkd$ W dQ R X t  &|jj'¡H t(tj )¡ ƒ‰ ˆ  *tj+||jj'd¡ dˆ d< t,rftjd ˆ d< W dQ R X |jjr†|jjˆ d%< tL|ˆ ||||||	ƒ\}}t j0rÀtj Md&d'¡d(d)|g}n"tNg|jj
rÔd*gng  d+|g }yài }|sÀ|jj
s|jjOrd}nV‡ fd,d-„d.D ƒ}|jj6r^x8| P¡ D ],\}}td/ Q| d0¡rLd1nd2||¡ƒ q.W t jR|ˆ |jj||d3 tS|d4 Q| .¡ ¡ƒ |dk	r¶|jjTr¶||tU|d5 Q| .¡ ¡ƒ< td6|ƒ W n0 tVjWk
rò   tD|||jjE|jd  ‚ Y nX |jXr|jYdk	r|st  |jY¡ dS )7zr
    Execute any test scripts for the given package.

    :param m: Package's metadata.
    :type m: Metadata
    r#  zTEST START:rN   z-x ro   r   zNothing to test for:Tr®  rn   rL   z%s_prefix_movedz	%s_subdirzRenaming %s prefix directory, z to Ú
work_movedzRenaming work directory, z†Not moving work directory after build.  Your package may depend on files in the work directory that are not included with your package)rb   r¡   ZTESTrÇ  rÈ  Nrh  )r  r  rÎ  rÐ  ró   )
rW   r’  r6  rs   r¯  r~   r°  r±  r  r  z;failed to get install actions, retrying.  exception was: %s)Úmove_brokenÚ
broken_dirrN   r±   r™   ZCONDA_PATH_CONFLICT)rN   r  rW   r¨  r²  rÏ  rï  zcmd.exez/dz/cz-xz-ec                s   i | ]}|ˆ krˆ | |“qS rS   rS   )rP   rQ   )r  rS   rT   r  l  s   ztest.<locals>.<dictcomp>)rÎ  rÏ  z{0} {1}={2}z.batrì   rÑ  )r  r_  r`  rÒ  z
testing {}ztest_{}z	TEST END:)Zr/   r—   r˜   rÚ   r#  rk   rƒ  rN   r4  r  r’  r  r{   rw   r	   r   r   r   r(   r,   Zclean_pkg_cacherã   rI   r+  rò  rx   r|  r   r   r  ÚshutilÚmover÷  rÎ   ry   r™   rB   Zget_test_depsr×  r»  rR  rÃ   rí   rx  r   rw  rX   r  rt   r  ró   rQ  r¸  rW  r6  rs   r¯  r~   r°  r±  r  r  rD   r&   r%   r'   r‚  rM   Útests_failedr  r$   Zpath_conflictr)   r#   r¹  r¨  r  rV   rÞ  rß  r€  ra   r  rm   Úvariantsr]   r‡  ÚCalledProcessErrorrö  rÇ   )Z recipedir_or_package_or_metadatarN   r`  r  rÍ  r¤   rø  Ztest_package_namerR   r  Zin_pkg_cacherL   r  r  r  r  r  rX   r¡   râ   rè  rW   ÚactionsrÌ  Zconflict_verbosityrî  r.  Z
test_statsrì  rQ   rí  rS   )r  rT   rØ   È  sî    














"

"
rØ   c             C   sÂ   t |ƒst |¡ t| dƒr&t| ƒ}n| }t|tj |¡ƒ}|r¨t 	t
¡}y*t ||¡ | dtj |¡|f ¡ W n tk
rˆ   Y nX ttj tj |¡¡|jd t dtj |¡ ¡ dS )z‚
    Causes conda to exit if any of the given package's tests failed.

    :param m: Package's metadata
    :type m: Metadata
    rN   z*Tests failed for %s - moving package to %s)r6  zTESTS FAILED: N)r   r{   r|   rÚ   r3   r   rw   r  r/   r—   r˜   r  r  r™   r›   r1   r   r’  r‘   rÏ   )Zpackage_or_metadatar  r  rN   re  râ   r¤   rS   rS   rT   r  „  s     



r  c              C   s:   t j d¡r6t d¡} | d kr6t  dtj tj	¡ ¡ d S )NZlinuxÚpatchelfzËError:
    Did not find 'patchelf' in: %s
    'patchelf' is necessary for building conda packages on Linux with
    relocatable ELF libraries.  You can install patchelf using conda install
    patchelf.
)
r‘   r’   rz   rz  r{  rÏ   r{   r  r   Z	dir_paths)r#  rS   rS   rT   Úcheck_external   s
    
r$  c	       7         s 	  g }	t | ƒ} tjrLtj tj tj¡dd¡}
tj 	|
¡rLt
jd |
¡dd d}tƒ }g }t ¡ }|j}d }xH| r¶|rŠd}d}d|_n|ršd}d|_nd }y”|  ¡ }t|dƒr¼| ¡ n|}t|d	ƒrb|}|j|j_|j}|jr
| ¡ |jkr
|j| ¡ dd
 tj |j¡}|	 | ¡ ¡ |jsT|r<t|ƒnt|ƒ}t||dd}n|ddff}nFtj |¡}| d¡ d¡}|	 tj |¡¡ t|||d|j  dd}|dkr¾|d d… }xh|D ]^\}}}|d krt !|jj"¡ t !|jj#¡ t !|jj$¡ | ¡ |jj%kr,|jj| ¡ dd
 t&|||||||d}|sXx| '¡ D ]ü\}}| (t)¡rŒtj *|¡rŒt+||j ,¡ |d |\}}|j- .di ¡ .d¡}|rBt/t 0|jj1¡t 2tj 3tj tj |¡¡¡¡g ƒ}t 4t5¡}t|dƒrt6| 7¡ ƒ}| 8d¡ n
t 0|¡}x"|D ]}| 9d |¡¡ d dd„ t:dƒD ƒ¡}| ;d¡t<|ƒt<d | =¡  >dd¡¡ƒg } dd „ | D ƒ} y:t?d!|d"$}!t@jA|!| d|jjB|jjC|d#}"W d Q R X W n> tDtEfk
r }# z| 8d$ ||#¡¡ w$W d d }#~#X Y nX tF||"d%|dd&}$t+t6|$ G¡ ƒd' d' |j ,¡ |d q$W | H||i¡ qTW n
| H|¡ tj I|jjJ¡rÆ|jj sÆ|jjKsÆ| Ld(¡sÆd|_tj tj |jjJ¡d! d)| =¡ |jjBd*f¡¡}%tMd+|jjJd,|%ƒ ytN O|jjJ|%¡ W n2 tNjPk
r"   t !|%¡ tN O|jjJ|%¡ Y nX qÆW | Q¡  W qp tEk
r² }# z\d-d.d/d0d1d2g}&d3d „ | '¡ D ƒ}'g }(|  R|g¡ x®tS|#jT|#jUƒD ]š\}})| Vd¡d'  Vd4¡d' ‰ |rØtW‡ fd5d„|jXdd6D ƒƒrØ‚ ||	kr|jQdd7 tYd8 |¡tZ|#j[ƒ d9 | ƒ‚||&kr&|	 |¡ d:}t\tj |ˆ ¡ƒ}*|*sRt\tj |d;ˆ ¡ƒ}*t\tj |ˆ d< ¡ƒ}+|+s†t\tj |d;ˆ d< ¡ƒ}+d},|*s–|+rx||*|+ D ]p‰tW‡fd=d„|'D ƒƒs tˆ|jd>}-xB|-D ]:}.t ]t<|)ƒ|.d' |¡rÐtMd? |¡ƒ |( ˆ¡ d},qÐW q W |,sŽ|jQdd7 ‚ qŽW |s†| ^|¡r†| ^|¡t_| ;d@¡ƒkr†|jQdd7 tYd8 |¡tZ|#j[ƒ d9 | ƒ‚| tj |¡¡ |  R|(¡ W d d }#~#X Y qpX qpW |dAkrödBd „ |D ƒ}/dCd „ |D ƒ}0t`|/|d> ta|0|d> t ¡ | }1tbdDd „ | G¡ D ƒpd'gƒ}2tcdEd „ | G¡ D ƒp:d'gƒ}3tcdFd „ | G¡ D ƒpXd'gƒ}4tcdGd „ | G¡ D ƒpvd'gƒ}5tMdHƒ tMdIƒ tMdJ td|1ƒ¡ƒ tMdK td|4ƒtd|5ƒ¡ƒ tMdL t e|2¡¡ƒ tMdM t e|3¡¡ƒ |1|2|3dNœ|dO< |	rtf|dPƒ}6tg h||6¡ W d Q R X t6| 7¡ ƒS )QNZpkgsz.trashzdel /s /q "{0}\*.*" >nul 2>&1T)rr  ro   FrX   rN   )Úreset)rÓ  r†   r…   )rN   r   rÓ  rõ  Zbypass_env_check)TFr   )rå  ræ  rç  rÊ  rÁ  )rN   r`  rØ   Údownstreamsr0  zLDictionary keys for downstreams are being ignored right now.  Coming soon...zTesting downstream package: {}c             s   s    | ]}t  tjtj ¡V  qd S )N)ÚrandomZchoicer»   Zascii_uppercaseZdigits)rP   rL   rS   rS   rT   rë   #	  s   zbuild_tree.<locals>.<genexpr>é
   r  r   rJ   rä   c             S   s   g | ]}t  |¡‘qS rS   )r/   r¬  )rP   r­  rS   rS   rT   rU   '	  s    zbuild_tree.<locals>.<listcomp>rL   )r¡   rn  )r  rW   r¯  r  zFSkipping downstream test for spec {}; was unsatisfiable.  Error was {}r®  )Zpackage_subsetZrequire_filesr   z%build/no_move_top_level_workdir_loopsr  Zmain_build_loopzRenaming work directory, z to rû   r
  zr-basezmro-baser  r	  c             S   s   g | ]}|d  d  j ‘qS )r   )rw   )rP   ÚentryrS   rS   rT   rU   U	  s    r!  c             3   s   | ]\}}ˆ |  ¡ kV  qd S )N)rX   )rP   rL   Zoutput_meta)Úpkg_namerS   rT   rë   ^	  s    )r´  )Zremove_foldersz3Can't build {0} due to environment creation error:
rÀ   a   Typically if a conflict is with the Python or R
packages, the other package or one of its dependencies
needs to be rebuilt (e.g., a conflict with 'python 3.5*'
and 'x' means 'x' or one of 'x' dependencies isn't built
for Python 3.5 and needs to be rebuilt.z..z
-feedstockc             3   s   | ]}|  ˆ ¡V  qd S )N)rz   )rP   rw   )rÇ   rS   rT   rë   y	  s    )rN   zIMissing dependency {0}, but found recipe directory, so building {0} firstrn   )TNc             S   s   g | ]}|  t¡r|‘qS rS   )r   r   )rP   r¢   rS   rS   rT   rU   ’	  s    c             S   s   g | ]}|  d ¡r|‘qS )z.whl)r   )rP   r¢   rS   rS   rT   rU   “	  s    c             S   s   g | ]}|  d ¡‘qS )rh   )rV   )rP   ÚsteprS   rS   rT   rU   ˜	  s    c             S   s   g | ]}|  d ¡‘qS )ri   )rV   )rP   r+  rS   rS   rT   rU   ™	  s    c             S   s   g | ]}|  d ¡‘qS )rf   )rV   )rP   r+  rS   rS   rT   rU   š	  s    c             S   s   g | ]}|  d ¡‘qS )rg   )rV   )rP   r+  rS   rS   rT   rU   ›	  s    zT####################################################################################zResource usage summary:z
Total time: {}zCPU usage: sys={}, user={}z!Maximum memory usage observed: {}z2Total disk usage observed (not including envs): {})ÚtimeZmemoryri   Ztotalr¿   )ir   r/   rt   r{   rw   r   r   r‘   r§  r   r‡  r  ra   r   r,  Ú
stats_fileÚanaconda_uploadÚpopleftrÚ   rX   rN   Zset_build_idrÄ   Zcompute_build_idrZ   rÛ  rG   rH   r7   Úrstripr  r4   rÀ  rƒ  rx   r|  r»  rÜ  rn   r€  r   r   r	   rØ   rÃ   rv   rV   rW  rÛ   r  Zpath2urlrý  r—   r˜   r  r0  r™   r×   Úrangerµ  r"   r#  r%  r   r,   r¸  ry   r¯  r%   rD   r;   r½  rí   r„  rÎ   Zkeep_old_workrÍ   rk   r  r  ÚErrorZcleanÚ
extendleftÚzipr¿  Z
matchspecsrÐ   r+  r¾  rÜ   rM   Úmessager   Zmatch_peer_jobÚcountrâ  Úhandle_anaconda_uploadÚhandle_pypi_uploadÚmaxÚsumre   rl   r•   ræ   rÆ   )7Zrecipe_listrN   r`  Z
build_onlyrå  rÁ  ræ  rç  r   Zto_build_recursiveZ	trash_dirZ
extra_helprÊ  Zretried_recipesZinitial_timer-  rR   rº   rX   Zrecipe_parent_dirZ	variants_Zmetadata_tuplesZpackages_from_thisre  Zdict_and_metarL   rv   r&  r  r¤   rg  Zr_stringrè  rŸ  r"  rá   Z
local_filerâ   Z
skip_namesZbuilt_package_pathsZadd_recipesZ	matchspecZrecipe_globZfeedstock_globZ	availableZ	dep_metasZdep_metaZtarballsÚwheelsZ
total_timeZmax_memory_usedZ
total_diskZtotal_cpu_sysZtotal_cpu_userr¢   rS   )r*  rÇ   rT   Ú
build_tree­  st   















 
r<  c       	   	   C   sf  ddl m} t | ¡} d}|js&|jr,d}n|js<tdƒ nd}d}x| D ]}|d |¡7 }qJW |d7 }|sxt|ƒ d S |d	ƒ}|d kršt|ƒ t	 
d
¡ |g}|jr¶| d|jg¡ | d¡ |jrÐ| d¡ |jræ| d|jg¡ x|jD ]}| d|g¡ qîW x\| D ]T}y*td tj |¡¡ƒ t ||g ¡ W n" tjk
rZ   t|ƒ ‚ Y nX q
W d S )Nr   )r{  FTz!# Automatic uploading is disabledzA# If you want to upload package(s) to anaconda.org later, type:

zanaconda upload {}
zl
# To have conda build upload to anaconda.org automatically, use
# $ conda config --set anaconda_upload yes
Úanacondazf
Error: cannot locate anaconda command (required for upload)
# Try:
# $ conda install anaconda-client
z--tokenÚuploadz--forcez--userz--labelzUploading {} to anaconda.org)Úconda_build.os_utils.externalr{  r/   rÛ   ÚtokenÚuserr.  rk   ra   r‘   rÏ   rî   rZ   Zforce_uploadÚlabelsr{   rw   r  r‡  r  r!  )	rO  rN   r{  r>  Zno_upload_messagerú  r=  r.  ZlabelrS   rS   rT   r7  ¯	  sL    





r7  c          	   C   s  ddd|j d|jg}|jr*| d|jg¡ |jr@| d|jg¡ |jrR| dg¡ |jrh| d|jg¡ |jr~| d	|jg¡ |jr”| d|jg¡ t 	| ¡} |j
rxr| D ]Z}td
 |¡ƒ yt ||g ¡ W q¬   t t¡ d¡ t t¡ d |¡¡ Y q¬X q¬W ntd | ¡ƒ d S )NZtwiner>  z--sign-withz--repositoryz--userz
--passwordz--signz
--identityz--config-filezUploading {}zFwheel upload failed - is twine installed?  Is this package registered?zWheel file left in {}z5anaconda_upload is not set.  Not uploading wheels: {})Z	sign_withZ
repositoryrA  rî   ZpasswordZsignZidentityZconfig_filer/   rÛ   r.  rk   ra   r  r—   r˜   r™   )r;  rN   Úargsr¢   rS   rS   rT   r8  ë	  s.    

"r8  c             C   sN   t dƒ t dƒ t d| j d ƒ t | j¡}t djt|ƒdƒ t dƒ d S )NrÀ   zT####################################################################################z1Source and build intermediates have been left in rp   z-There are currently {num_builds} accumulated.)Z
num_buildsz?To remove them, you can run the ```conda build purge``` command)rk   rþ  r/   Úget_build_foldersra   râ  )rN   Zbuild_foldersrS   rS   rT   Ú print_build_intermediate_warning

  s    rE  c             C   s,   |st  | j¡}x|D ]}t  |¡ qW d S )N)r/   rD  rþ  rƒ  )rN   Zfoldersr5  rS   rS   rT   Úclean_build
  s    
rF  c       	         s  x8| j jD ],}tj |¡s$t |¡ t|| j jdd q
W t| j d 	|¡ƒ}|r`t
| j jƒdgng }|tƒ 7 }| j jr„| | j j¡ t|  ¡ |  ¡ |  ¡ d‰ trÆddlm} t|jˆ ||dfd	ƒS t|| j j| j j|| j j| j j| j j| j jd
d	\}}}t‡ fdd„| ¡ D ƒƒS d S )NF)r6  r™   z	{}_subdirrû  )rX   rY   rn   r   )Ú
SubdirDataró   )r  ZsubdirsT)	rW   r‘  r  r  r’  r6  rs   r~   rÕ  c             3   s   | ]}ˆ   |¡V  qd S )N)Úmatch)rP   Zprec)r­  rS   rT   rë   1
  s    z#is_package_built.<locals>.<genexpr>)rN   r¯  r{   rw   r   r|   r1   r’  r  ra   r   r  r   r  rî   r"   rX   rY   rÄ   r   Z	conda.apirG  rV  Z	query_allr0   r‘  r6  rs   r~   r+  r½  )	rR   r  Zinclude_localr  rW   r   rG  ÚindexrL   rS   )r­  rT   rØ  
  s&    


rØ  )N)NTFNFF)ro   )TF)FFFTFN)N)T)°Ú__doc__Z
__future__r   r   r   Úcollectionsr   r   r(  r   r9  ræ   rŒ  r{   Úos.pathr   r	   r
   r   r   r'  rö   r  r“   r»   r‡  r‘   r,  Ztempfiler   Zencodings.idnaZ	encodingsZbs4r   rÅ   Zconda.base.constantsr   Ú	Exceptionr   r¼  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r/   r)   r*   Zconda_buildr+   r,   r-   r.   Zconda_build.indexr0   r1   Zconda_build.renderr2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r?  Zos_utilsrz  Zconda_build.metadatar<   r=   r>   Zconda_build.postr?   r@   rA   rB   Zconda_build.exceptionsrC   rD   rE   Zconda_build.variantsrF   rG   rH   Zconda_build.create_testrI   Zconda_build.noarch_pythonrQ  rh  r  r  r’   Zconda_build.windowsr«  rÞ  rt   r]   re   rm   r„   r§   rŸ   r¶   r¹   rÈ   rÒ   rÕ   rÖ   rã   rç   rð   rõ   rù   r   r  r  r&  r,  rü   r2  r;  r<  rñ   r?  rC  rE  rN  r8  rX  rž  r   r¢  rä  r©  r~  rÅ  rn   ry  rÚ  rù  r  r  r  rÝ  r  r  rØ   r  r$  r<  r7  r8  rE  rF  rØ  rS   rS   rS   rT   Ú<module>   s  0E
83%"64 n&>M 
  zY67
$
 = 
  <	
