
    ;e{6                         	 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 ej        ej        	                    d          d           G d dej
                              Zedk    r ej                     dS dS )    N)	os_helperdarwinzrequires OS Xc                   z    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd ZdS )Test_OSXSupportc                 2   d | _         d| _        t          j                            t          j                              | _        |                     t          j	                              | _
        dD ]%}|| j
        v r| j
                            |           &d S )Nbogus_program_xxxx)CFLAGSLDFLAGSCPPFLAGS
BASECFLAGS	BLDSHAREDLDSHAREDCCCXX	PY_CFLAGS
PY_LDFLAGSPY_CPPFLAGSPY_CORE_CFLAGSPY_CORE_LDFLAGS)maxDiff	prog_nameospathabspathgetcwdtemp_path_direnterContextr   EnvironmentVarGuardenvunset)selfcvs     -/usr/lib/python3.11/test/test__osx_support.pysetUpzTest_OSXSupport.setUp   s    -W__RY[[99$$Y%B%D%DEEA 	# 	#B TX~~r"""	# 	#    c                 N                         fdD                        d S )Nc              3   V   K   | ]#}|         |         k    d |z   |         fV  $dS )_OSX_SUPPORT_INITIAL_N ).0kconfig_varsexpected_varss     r#   	<genexpr>zDTest_OSXSupport.add_expected_saved_initial_values.<locals>.<genexpr>!   sT       ; ;$%"1~q)999 6q8A 9999; ;r%   )updater!   r,   r-   s    ``r#   !add_expected_saved_initial_valuesz1Test_OSXSupport.add_expected_saved_initial_values   sS     	 ; ; ; ; ;)4; ; ; 	; 	; 	; 	; 	;r%   c                    | j         d         r| j         d         dz   | j         d<   | j         d         t          j                            | j                  z   | j         d<   t          j        | j                   |                     t          j
        | j                             |                     t
          j        | j                   t          | j        d          5 }|                    d           d d d            n# 1 swxY w Y   t          j        | j        t          j                   |                     | j        t          j
        | j                             d S )NPATH:wz#!/bin/sh
/bin/echo OK
)r   r   r   r   r   r   unlinkr   assertIsNone_osx_support_find_executable
addCleanupopenwritechmodstatS_IRWXUassertEqualr!   fs     r#   test__find_executablez%Test_OSXSupport.test__find_executable%   sg   8F 	6#x/#5DHV8F+bgood>P.Q.QQ(((,7GGHHH	($.999$.#&& 	1!GG/000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1
...(9$.II	K 	K 	K 	K 	Ks   DDDc                 f   | j         d         r| j         d         dz   | j         d<   | j         d         t          j                            | j                  z   | j         d<   t          j        | j                   |                     t
          j        | j                   t          | j        d          5 }|
                    d           d d d            n# 1 swxY w Y   t          j        | j        t          j                   |                     dt          j        | j                             d S )Nr3   r4   r5   z##!/bin/sh
/bin/echo ExpectedOutput
ExpectedOutput)r   r   r   r   r   r   r6   r   r:   r;   r<   r=   r>   r?   r@   r8   _read_outputrA   s     r#   test__read_outputz!Test_OSXSupport.test__read_output2   sE   8F 	6#x/#5DHV8F+bgood>P.Q.QQ(((	($.999$.#&& 	=!GG;<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=
...)(5dnEE	G 	G 	G 	G 	Gs   3CCCc                     t          j        d          }|                     t          j                            |          d           d S )Nccz!cc not found - check xcode-select)r8   _find_build_tool
assertTruer   r   isfile)r!   outs     r#   test__find_build_toolz%Test_OSXSupport.test__find_build_tool>   sJ    +D11s++?	A 	A 	A 	A 	Ar%   c                     |                      t          j                    d                             t	          j                                         d S )Nr   )rK   platformmac_ver
startswithr8   _get_system_version)r!   s    r#   test__get_system_versionz(Test_OSXSupport.test__get_system_versionC   sU    (**1-88$0$D$F$FH H 	I 	I 	I 	I 	Ir%   c                     ddi}ddi}d}d}t          j        |||           |                     ||           t          j        |           |                     ||           d S Nr   gcc-test -pthreadsclang -pthreads)r8   _save_modified_valueassertNotEqual_remove_original_valuesr@   r!   r,   r-   r"   newvalues        r#   test__remove_original_valuesz,Test_OSXSupport.test__remove_original_valuesG   s    "
 	
 $)+r8DDDM;777,[99944444r%   c                     ddi}ddi}|                      ||           d}d}t          j        |||           |                     ||           d S rV   )r1   r8   rY   r@   r\   s        r#   test__save_modified_valuez)Test_OSXSupport.test__save_modified_valueU   sq    "
 	
 	..{MJJJ$)+r8DDD44444r%   c                     ddi}|                                 }d}d}t          j        |||           |                     ||           d S )Nr   rW   )copyr8   rY   r@   r\   s        r#   #test__save_modified_value_unchangedz3Test_OSXSupport.test__save_modified_value_unchangedb   s]    "
 $((**')+r8DDD44444r%   c                     dd l }t          d  |j                    d                             d          dd         D                       }|                     |dk    t          j                               d S )Nr   c              3   4   K   | ]}t          |          V  d S )N)int)r*   is     r#   r.   zBTest_OSXSupport.test__supports_universal_builds.<locals>.<genexpr>n   s@       C Cc!ff C C C C C Cr%   .   )
      )rP   tuplerQ   splitr@   r8   _supports_universal_builds)r!   rP   mac_ver_tuples      r#   test__supports_universal_buildsz/Test_OSXSupport.test__supports_universal_buildsl   s     C C,H,..q177<<QqSAC C C C C'1(CEE	G 	G 	G 	G 	Gr%   c                    d}dddddddd	}d
ddddddd	}|                      ||           | j        d         rd| j        d         z   nd}t          j                            | j                  |z   | j        d<   |D ]\  }}t          j        |           |                     t          j        |           t          |d          5 }|
                    d|z              d d d            n# 1 swxY w Y   t          j        |t          j                   |                     |t          j        |                     d S )N))zgcc-testz i686-apple-darwin11-llvm-gcc-4.2)clangzclang version 3.1rW   z	cc++-test3-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -arch ppc -arch i386   -g--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   rX   zclang++z%clang -bundle -arch ppc -arch i386 -gzOclang -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr3   r4    r5   z#!/bin/sh
/bin/echo )r1   r   r   r   r   r   r   r6   r:   r;   r<   r=   r>   r?   r@   r8   _find_appropriate_compiler)r!   	compilersr,   r-   suffixc_namec_outputrB   s           r#   test__find_appropriate_compilerz/Test_OSXSupport.test__find_appropriate_compilers   s   	
 #G.C?G	
 	
  G.C<G	
 	
 	..{MJJJ-1Xf-=E#(((27??4+=>>G ) 	+ 	+FHV$$$OOI,f555fc"" <a/(:;;;< < < < < < < < < < < < < < <HVT\****(C$/1 1	2 	2 	2 	2 	2s   C++C/	2C/	c                     dddddd}ddd	d
dd}|                      ||           |                     |t          j        |                     d S )Nrs   rt   ru   (gcc-4.0 -bundle  -arch ppc -arch i386 -gRgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr	   r
   r   r   r    -fno-strict-aliasing  -g -O3        -g-I.  gcc-4.0 -bundle    -ggcc-4.0 -bundle      -gr1   r@   r8   _remove_universal_flagsr0   s      r#   test__remove_universal_flagsz,Test_OSXSupport.test__remove_universal_flags   s    G.C?G
 
 5,-
 
 	..{MJJJ(@$/1 1	2 	2 	2 	2 	2r%   c                     dddddd}ddd	d
dd}|                      ||           |                     |t          j        |                     d S )Nrs   rt   z,-I. -isysroot/Developer/SDKs/MacOSX10.4u.sdkr~   zQgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -gr   r   r   r   r   r   r   r0   s      r#   &test__remove_universal_flags_alternatez6Test_OSXSupport.test__remove_universal_flags_alternate   s     H.B?F
 
 5,-
 
 	..{MJJJ(@$/1 1	2 	2 	2 	2 	2r%   c                 f   ddddddd}ddd	dd
dd}|                      ||           | j        d         rd| j        d         z   nd}t          j                            | j                  |z   | j        d<   d}t          j        |           |                     t          j        |           t          |d          5 }|
                    d           d d d            n# 1 swxY w Y   t          j        |t          j                   |                     |t          j        |                     d S )Nrr   rs   rt   ru   r~   r   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 -gr3   r4   rv   r5   z#!/bin/sh
exit 255)r1   r   r   r   r   r   r   r6   r:   r;   r<   r=   r>   r?   r@   r8   _remove_unsupported_archs)r!   r,   r-   ry   rz   rB   s         r#   test__remove_unsupported_archsz.Test_OSXSupport.test__remove_unsupported_archs   s   G.C?G
 
 >%C6G
 
 	..{MJJJ-1Xf-=E#(((27??4+=>>G   	(&111&# 	+!GG)***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+
&&&(B$/1 1	2 	2 	2 	2 	2s   =CC#&C#c                     d| j         d<   ddddddd	}dd
ddddd	}|                     ||           |                     |t          j        |                     d S )Nz-arch x86_64	ARCHFLAGSrr   rs   rt   ru   r~   zQgcc-4.0 -bundle -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -gr   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   r1   r@   r8   _override_all_archsr0   s      r#   test__override_all_archsz(Test_OSXSupport.test__override_all_archs   s     .G.C?G
 
 A(C9J
 
 	..{MJJJ(<$/1 1	2 	2 	2 	2 	2r%   c                     ddddddd}dddd	dd
d}|                      ||           |                     |t          j        |                     d S )Nrr   [-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot /Developer/SDKs/MacOSX10.1.sdkrt   z,-I. -isysroot /Developer/SDKs/MacOSX10.1.sdkr~   zQgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.1.sdk -gr   4-fno-strict-aliasing  -g -O3 -arch ppc -arch i386   r   )gcc-4.0 -bundle  -arch ppc -arch i386  -gr1   r@   r8   _check_for_unavailable_sdkr0   s      r#   test__check_for_unavailable_sdkz/Test_OSXSupport.test__check_for_unavailable_sdk  s    C.B?F	
 	
 .?	
 	
 	..{MJJJ(C$/1 1	2 	2 	2 	2 	2r%   c                     ddddddd}dddd	dd
d}|                      ||           |                     |t          j        |                     d S )Nrr   zZ-fno-strict-aliasing  -g -O3 -arch ppc -arch i386  -isysroot/Developer/SDKs/MacOSX10.1.sdkrt   z+-I. -isysroot/Developer/SDKs/MacOSX10.1.sdkr~   zPgcc-4.0 -bundle  -arch ppc -arch i386 -isysroot/Developer/SDKs/MacOSX10.1.sdk -gr   r   r   r   r   r0   s      r#   )test__check_for_unavailable_sdk_alternatez9Test_OSXSupport.test__check_for_unavailable_sdk_alternate  s     B.A?E	
 	
 .?	
 	
 	..{MJJJ(C$/1 1	2 	2 	2 	2 	2r%   c                 j    ddd}t          j        |ddd          }|                     d|           d S )Nr   10.6)r	   MACOSX_DEPLOYMENT_TARGET )macosxr   fat)r8   get_platform_osxr@   )r!   r,   results      r#   test_get_platform_osxz%Test_OSXSupport.test_get_platform_osx:  sL    C$*
 

 .{CcJJ2F;;;;;r%   N)__name__
__module____qualname__r$   r1   rC   rG   rN   rT   r^   r`   rc   rp   r|   r   r   r   r   r   r   r   r)   r%   r#   r   r      s3       
# 
# 
#; ; ;K K K
G 
G 
GA A A
I I I5 5 55 5 55 5 5G G G%2 %2 %2N2 2 2,2 2 2. 2  2  2D2 2 242 2 262 2 28	< 	< 	< 	< 	<r%   r   __main__)r   rP   r>   sysunittesttest.supportr   r8   
skipUnlessrR   TestCaser   r   mainr)   r%   r#   <module>r      s    
			   



  " " " " " "    S\,,X66HHs< s< s< s< s<h' s< s< IHs<j	 zHMOOOOO r%   