o
    ǉf                     @   s   d Z ddlZddl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mZ ddlmZ ddlZed	ZG d
d deZG dd deeZdS )zRdistutils.command.build_scripts

Implements the Distutils 'build_scripts' command.    N)ST_MODE)	sysconfig)Command)newer)convert_path	Mixin2to3)logs   ^#!.*python[0-9.]*([ 	].*)?$c                   @   sF   e Zd ZdZg dZdgZdd Zdd Zdd	 Zd
d Z	dd Z
dS )build_scriptsz("build" scripts (copy and fixup #! line)))z
build-dir=dzdirectory to "build" (copy) to)forcefz1forcibly build everything (ignore file timestamps)zexecutable=ez*specify final destination interpreter pathr   c                 C   s"   d | _ d | _d | _d | _d | _d S N)	build_dirscriptsr   
executableoutfilesself r   {/home/ych/rk3568/buildroot/output/rockchip_rk3568_recovery/build/host-python3-3.10.5/Lib/distutils/command/build_scripts.pyinitialize_options   s
   
z build_scripts.initialize_optionsc                 C   s   |  dddd | jj| _d S )Nbuild)r	   r   )r   r   )r   r   )set_undefined_optionsdistributionr   r   r   r   r   finalize_options%   s   zbuild_scripts.finalize_optionsc                 C   s   | j S r   )r   r   r   r   r   get_source_files,   s   zbuild_scripts.get_source_filesc                 C   s   | j sd S |   d S r   )r   copy_scriptsr   r   r   r   run/   s   zbuild_scripts.runc              	   C   s  |  | j g }g }| jD ]}d}t|}tj| jtj|}|| | j	s6t
||s6td| qzt|d}W n tyL   | jsH d}Y n,w t|j\}}|d | }	|	sh| d|  qt|	}
|
rxd}|
dpwd	}|rd
tjvrtd|| j || | js	tjs| j}ntjtddtdtdf }t|}d| | d }z|d W n t y   t!d"|w z|| W n t y   t!d"||w t|d}|#| |$|%  W d   n	1 sw   Y  |r|&  q|r|&  || | '|| qtj(dkr^|D ]1}| jr:td| q,t)|t* d@ }|dB d@ }||kr\td||| t+|| q,||fS )a"  Copy each script listed in 'self.scripts'; if it's marked as a
        Python script in the Unix way (first line matches 'first_line_re',
        ie. starts with "\#!" and contains "python"), then adjust the first
        line to refer to the current Python interpreter as we copy.
        Fznot copying %s (up-to-date)rbNr   z%s is an empty file (skipping)T       _python_sysrootzcopying and adjusting %s -> %sBINDIRz
python%s%sVERSIONEXEs   #!   
zutf-8z.The shebang ({!r}) is not decodable from utf-8zAThe shebang ({!r}) is not decodable from the script encoding ({})wbposixzchanging mode of %si  im  z!changing mode of %s from %o to %o),mkpathr   r   r   ospathjoinbasenameappendr   r   r   debugopenOSErrordry_runtokenizedetect_encodingreadlineseekwarnfirst_line_rematchgroupenvironinfor   python_buildr   get_config_varfsencodedecodeUnicodeDecodeError
ValueErrorformatwrite
writelines	readlinesclose	copy_filenamestatr   chmod)r   r   updated_filesscriptZadjustoutfiler   encodinglinesZ
first_liner9   Zpost_interpr   ZshebangZoutffileZoldmodeZnewmoder   r   r   r   5   s   








zbuild_scripts.copy_scriptsN)__name__
__module____qualname__descriptionuser_optionsboolean_optionsr   r   r   r   r   r   r   r   r   r	      s    r	   c                   @   s   e Zd Zdd ZdS )build_scripts_2to3c                 C   s&   t | \}}| js| | ||fS r   )r	   r   r2   run_2to3)r   r   rL   r   r   r   r      s   
zbuild_scripts_2to3.copy_scriptsN)rR   rS   rT   r   r   r   r   r   rX      s    rX   )__doc__r*   rerJ   r   	distutilsr   distutils.corer   distutils.dep_utilr   distutils.utilr   r   r   r3   compiler8   r	   rX   r   r   r   r   <module>   s    
 
