B
    u9a£-  ã               @   sr   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e ej 	d¡d¡G dd„ dej
ƒƒZedkrne ¡  dS )é    NÚdarwinzrequires OS Xc               @   sŒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚTest_OSXSupportc             C   s`   d | _ d| _tj t ¡ ¡| _tj 	¡ | _
|  | j
j¡ x"dD ]}|| j
kr>| j
 |¡ q>W d S )NZbogus_program_xxxx)ÚCFLAGSÚLDFLAGSÚCPPFLAGSZ
BASECFLAGSÚ	BLDSHAREDÚLDSHAREDÚCCÚCXXZ	PY_CFLAGSZ
PY_LDFLAGSZPY_CPPFLAGSZPY_CORE_CFLAGSZPY_CORE_LDFLAGS)ZmaxDiffÚ	prog_nameÚosÚpathÚabspathÚgetcwdÚtemp_path_dirÚtestÚsupportZEnvironmentVarGuardÚenvÚ
addCleanupÚ__exit__Zunset)ÚselfÚcv© r   ú'/usr/lib/python3.7/test__osx_support.pyÚsetUp   s    

zTest_OSXSupport.setUpc                s   ˆ  ‡ ‡fdd„ˆ D ƒ¡ d S )Nc             3   s.   | ]&}ˆ | ˆ| krd | ˆ | fV  qdS )Z_OSX_SUPPORT_INITIAL_Nr   )Ú.0Úk)Úconfig_varsÚexpected_varsr   r   ú	<genexpr>"   s   zDTest_OSXSupport.add_expected_saved_initial_values.<locals>.<genexpr>)Úupdate)r   r   r   r   )r   r   r   Ú!add_expected_saved_initial_values   s    z1Test_OSXSupport.add_expected_saved_initial_valuesc          	   C   sº   | j d r| j d d | j d< | j d tj | j¡ | j d< tj | j¡ |  	t
 | j¡¡ |  tjj| j¡ t| jdƒ}| d¡ W d Q R X t | jtj¡ |  | jt
 | j¡¡ d S )NÚPATHú:Úwz#!/bin/sh
/bin/echo OK
)r   r   r   r   r   r   r   Úunlinkr   ZassertIsNoneÚ_osx_supportZ_find_executabler   ÚopenÚwriteÚchmodÚstatÚS_IRWXUÚassertEqual)r   Úfr   r   r   Útest__find_executable&   s    
z%Test_OSXSupport.test__find_executablec          	   C   s¦   | j d r| j d d | j d< | j d tj | j¡ | j d< tj | j¡ |  	tjj| j¡ t
| jdƒ}| d¡ W d Q R X t | jtj¡ |  dt | j¡¡ d S )Nr"   r#   r$   z##!/bin/sh
/bin/echo ExpectedOutput
ZExpectedOutput)r   r   r   r   r   r   r   r%   r   r   r'   r(   r)   r*   r+   r,   r&   Z_read_output)r   r-   r   r   r   Útest__read_output3   s    
z!Test_OSXSupport.test__read_outputc             C   s"   t  d¡}|  tj |¡d¡ d S )NZccz!cc not found - check xcode-select)r&   Z_find_build_toolÚ
assertTruer   r   Úisfile)r   Úoutr   r   r   Útest__find_build_tool?   s    
z%Test_OSXSupport.test__find_build_toolc             C   s    |   t ¡ d  t ¡ ¡¡ d S )Nr   )r0   ÚplatformÚmac_verÚ
startswithr&   Z_get_system_version)r   r   r   r   Útest__get_system_versionD   s    z(Test_OSXSupport.test__get_system_versionc             C   sL   ddi}ddi}d}d}t  |||¡ |  ||¡ t  |¡ |  ||¡ d S )Nr	   zgcc-test -pthreadszclang -pthreads)r&   Ú_save_modified_valueZassertNotEqualZ_remove_original_valuesr,   )r   r   r   r   Únewvaluer   r   r   Útest__remove_original_valuesH   s    
z,Test_OSXSupport.test__remove_original_valuesc             C   sB   ddi}ddi}|   ||¡ d}d}t |||¡ |  ||¡ d S )Nr	   zgcc-test -pthreadszclang -pthreads)r!   r&   r8   r,   )r   r   r   r   r9   r   r   r   Útest__save_modified_valueV   s    z)Test_OSXSupport.test__save_modified_valuec             C   s6   ddi}|  ¡ }d}d}t |||¡ |  ||¡ d S )Nr	   zgcc-test -pthreads)Úcopyr&   r8   r,   )r   r   r   r   r9   r   r   r   Ú#test__save_modified_value_unchangedc   s    z3Test_OSXSupport.test__save_modified_value_unchangedc             C   sH   dd l }tdd„ | ¡ d  d¡dd… D ƒƒ}|  |dkt ¡ ¡ d S )Nr   c             s   s   | ]}t |ƒV  qd S )N)Úint)r   Úir   r   r   r   o   s    zBTest_OSXSupport.test__supports_universal_builds.<locals>.<genexpr>Ú.é   )é
   é   )r4   Útupler5   Úsplitr,   r&   Z_supports_universal_builds)r   r4   Zmac_ver_tupler   r   r   Útest__supports_universal_buildsm   s
     
z/Test_OSXSupport.test__supports_universal_buildsc          
   C   sâ   d}dddddddd	œ}d
ddddddd	œ}|   ||¡ | jd rPd| jd  nd}tj | j¡| | jd< x^|D ]V\}}tj |¡ |  	tjj|¡ t
|dƒ}| d| ¡ W d Q R X t |tj¡ qrW |  |t |¡¡ d S )N))zgcc-testz i686-apple-darwin11-llvm-gcc-4.2)Úclangzclang version 3.1zgcc-test -pthreadsz	cc++-testz3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-test -bundle -arch ppc -arch i386 -gzRgcc-test -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r	   r
   r   r   r   r   r   zclang -pthreadszclang++z%clang -bundle -arch ppc -arch i386 -gzOclang -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr"   r#   Ú r$   z#!/bin/sh
/bin/echo )r!   r   r   r   r   r   r   r   r%   r   r'   r(   r)   r*   r+   r,   r&   Z_find_appropriate_compiler)r   Z	compilersr   r   ÚsuffixÚc_nameZc_outputr-   r   r   r   Útest__find_appropriate_compilert   s6    z/Test_OSXSupport.test__find_appropriate_compilerc             C   sB   ddddddœ}ddd	d
ddœ}|   ||¡ |  |t |¡¡ d S )Nz3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzRgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r   r   r   r   r   z -fno-strict-aliasing  -g -O3    z    -gz-I.  zgcc-4.0 -bundle    -gzgcc-4.0 -bundle      -g)r!   r,   r&   Z_remove_universal_flags)r   r   r   r   r   r   Útest__remove_universal_flags›   s    z,Test_OSXSupport.test__remove_universal_flagsc          	   C   sÈ   dddddddœ}ddd	dd
ddœ}|   ||¡ | jd rHd| jd  nd}tj | j¡| | jd< d}tj |¡ |  	tjj|¡ t
|dƒ}| d¡ W d Q R X t |tj¡ |  |t |¡¡ d S )NrG   z3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzRgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r	   r   r   r   r   r   z*-fno-strict-aliasing  -g -O3  -arch i386  z -arch i386   -gzgcc-4.0 -bundle   -arch i386 -gzIgcc-4.0 -bundle   -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr"   r#   rH   r$   z#!/bin/sh
exit 255)r!   r   r   r   r   r   r   r   r%   r   r'   r(   r)   r*   r+   r,   r&   Z_remove_unsupported_archs)r   r   r   rI   rJ   r-   r   r   r   Útest__remove_unsupported_archs±   s0    z.Test_OSXSupport.test__remove_unsupported_archsc             C   sP   d| j d< ddddddd	œ}dd
ddddd	œ}|  ||¡ |  |t |¡¡ d S )Nz-arch x86_64Z	ARCHFLAGSrG   z3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  z-arch ppc -arch i386   -gz--I. -isysroot /Developer/SDKs/MacOSX10.4u.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzQgcc-4.0 -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g)r	   r   r   r   r   r   z--fno-strict-aliasing  -g -O3     -arch x86_64z    -g -arch x86_64z"gcc-4.0 -bundle    -g -arch x86_64zKgcc-4.0 -bundle   -isysroot /Developer/SDKs/MacOSX10.4u.sdk -g -arch x86_64)r   r!   r,   r&   Z_override_all_archs)r   r   r   r   r   r   Útest__override_all_archsÓ   s"    
z(Test_OSXSupport.test__override_all_archsc             C   sF   dddddddœ}dddd	dd
dœ}|   ||¡ |  |t |¡¡ d S )NrG   z[-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot /Developer/SDKs/MacOSX10.1.sdkz-arch ppc -arch i386   -gz,-I. -isysroot /Developer/SDKs/MacOSX10.1.sdkz(gcc-4.0 -bundle  -arch ppc -arch i386 -gzQgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.1.sdk -g)r	   r   r   r   r   r   z4-fno-strict-aliasing  -g -O3 -arch ppc -arch i386   z-I.  z)gcc-4.0 -bundle  -arch ppc -arch i386  -g)r!   r,   r&   Z_check_for_unavailable_sdk)r   r   r   r   r   r   Útest__check_for_unavailable_sdkí   s     z/Test_OSXSupport.test__check_for_unavailable_sdkc             C   s*   dddœ}t  |ddd¡}|  d|¡ d S )Nz[-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot /Developer/SDKs/MacOSX10.1.sdkz10.6)r   ZMACOSX_DEPLOYMENT_TARGETú )Zmacosxz10.6Zfat)r&   Zget_platform_osxr,   )r   r   Úresultr   r   r   Útest_get_platform_osx  s    z%Test_OSXSupport.test_get_platform_osxN)Ú__name__Ú
__module__Ú__qualname__r   r!   r.   r/   r3   r7   r:   r;   r=   rF   rK   rL   rM   rN   rO   rR   r   r   r   r   r      s    
'"r   Ú__main__)r   r4   r*   ÚsysZunittestZtest.supportr   r&   Z
skipUnlessr6   ZTestCaser   rS   Úmainr   r   r   r   Ú<module>   s   
  