o
    ;i                     @  sT   d Z ddlmZ ddlZddlmZmZmZ eeee	f  Z
dd
dZdddZdS )z
This is refactored from cmake.py to avoid circular imports issue with env.py,
which calls get_cmake_cache_variables_from_file
    )annotationsN)IOOptionalUnioncmake_valuestr
cmake_typereturn
CMakeValuec                 C  sJ   |  }|   }|dkr|dv p|d S |dkr#|dr!dS | S | S )aH  Convert a CMake value in a string form to a Python value.

    Args:
      cmake_value (string): The CMake value in a string form (e.g., "ON", "OFF", "1").
      cmake_type (string): The CMake type of :attr:`cmake_value`.

    Returns:
      A Python value corresponding to :attr:`cmake_value` with type :attr:`cmake_type`.
    ZBOOL)FALSEOFFNZNO0 ZNOTFOUNDz	-NOTFOUNDZFILEPATHN)upperendswith)r   r   Zup_val r   </home/app/PyTorch/pytorch/tools/setup_helpers/cmake_utils.py#convert_cmake_value_to_python_value   s   
r   cmake_cache_fileIO[str]dict[str, CMakeValue]c           	      C  s   i }t | dD ]E\}}| }|r|drqtd|}|du r0td| dt|  d| | \}}}}|du r>d}| d	v rEqt	||||< q|S )
zGets values in CMakeCache.txt into a dictionary.

    Args:
      cmake_cache_file: A CMakeCache.txt file object.
    Returns:
      dict: A ``dict`` containing the value of cached CMake variables.
       )#z//z:("?)(.+?)\1(?::\s*([a-zA-Z_-][a-zA-Z0-9_-]*)?)?\s*=\s*(.*)NzUnexpected line z in z: r   )ZINTERNALZSTATIC)
	enumeratestrip
startswithrematch
ValueErrorreprgroupsr   r   )	r   resultsilineZmatched_variabletype_valuer   r   r   #get_cmake_cache_variables_from_file-   s"   r)   )r   r   r   r   r	   r
   )r   r   r	   r   )__doc__
__future__r   r   typingr   r   r   boolr   r
   r   r)   r   r   r   r   <module>   s    
