o
    p.a                     @   sL   d Z ddlZddlmZ G dd deZG dd deZG dd deZdS )	z$Visual Studio project reader/writer.    Nc                   @   s"   e Zd ZdZdddZdd ZdS )ToolzVisual Studio tool.Nc                 C   s   |pi | _ || j d< dS )zoInitializes the tool.

    Args:
      name: Tool name.
      attrs: Dict of tool attributes; may be None.
    NameN_attrs)selfnameattrs r	   1/usr/lib/python3/dist-packages/gyp/MSVSProject.py__init__   s   
zTool.__init__c                 C   s
   d| j gS )z]Creates an element for the tool.

    Returns:
      A new xml.dom.Element for the tool.
    r   r   )r   r	   r	   r
   _GetSpecification   s   
zTool._GetSpecificationN)__name__
__module____qualname____doc__r   r   r	   r	   r	   r
   r      s    

r   c                   @   s   e Zd ZdZdddZdS )Filterz1Visual Studio filter - that is, a virtual folder.Nc                 C   s   || _ t|pg | _dS )zInitializes the folder.

    Args:
      name: Filter (folder) name.
      contents: List of filenames and/or Filter objects contained.
    N)r   listcontents)r   r   r   r	   r	   r
   r   %   s   zFilter.__init__r   )r   r   r   r   r   r	   r	   r	   r
   r   "   s    r   c                   @   sV   e Zd ZdZdddZdd Zdd Zdd	d
Zdd Zdd Z	dddZ
dd ZdS )Writerz!Visual Studio XML project writer.Nc                 C   sl   || _ || _|| _|| _|sdg}dg| _|D ]}| jdd|ig qdg| _dg| _dg| _t	 | _
dS )	a  Initializes the project.

    Args:
      project_path: Path to the project file.
      version: Format version to emit.
      name: Name of the project.
      guid: GUID to use for project, if not None.
      platforms: Array of string, the supported platforms.  If null, ['Win32']
    Win32	PlatformsPlatformr   	ToolFilesConfigurationsFilesN)project_pathversionr   guidplatform_sectionappendtool_files_sectionconfigurations_sectionfiles_sectiondict
files_dict)r   r   r   r   r   	platformsplatformr	   r	   r
   r   6   s   
zWriter.__init__c                 C   s   | j dd|ig dS )zeAdds a tool file to the project.

    Args:
      path: Relative path from project to tool file.
    ToolFileRelativePathN)r!   r    )r   pathr	   r	   r
   AddToolFileT   s   zWriter.AddToolFilec                 C   sf   |si }|sg }|  }||d< ||g}|r1|D ]}t|tr'||  q|t|  q|S )a   Returns the specification for a configuration.

    Args:
      config_type: Type of configuration node.
      config_name: Configuration name.
      attrs: Dict of configuration attributes; may be None.
      tools: List of tools (strings or Tool objects); may be None.
    Returns:
    r   )copy
isinstancer   r    r   )r   config_typeconfig_namer   tools
node_attrsspecificationtr	   r	   r
   _GetSpecForConfiguration\   s   
zWriter._GetSpecForConfigurationc                 C   s    |  d|||}| j| dS )zAdds a configuration to the project.

    Args:
      name: Configuration name.
      attrs: Dict of configuration attributes; may be None.
      tools: List of tools (strings or Tool objects); may be None.
    ConfigurationN)r4   r"   r    )r   r   r   r0   specr	   r	   r
   	AddConfig{   s   zWriter.AddConfigc                 C   sV   |D ]&}t |trdd|jig}| ||j ndd|ig}|| j|< || qdS )zAdds files and/or filters to the parent node.

    Args:
      parent: Destination node
      files: A list of Filter objects and/or relative paths to files.

    Will call itself recursively, if the files list contains Filter objects.
    r   r   Filer)   N)r-   r   r   _AddFilesToNoder   r%   r    )r   parentfilesfnoder	   r	   r
   r9      s   	

zWriter._AddFilesToNodec                 C   s   |  | j| dS )aK  Adds files to the project.

    Args:
      files: A list of Filter objects and/or relative paths to files.

    This makes a copy of the file/filter tree at the time of this call.  If you
    later add files to a Filter object which was passed into a previous call
    to AddFiles(), it will not be reflected in this project.
    N)r9   r#   )r   r;   r	   r	   r
   AddFiles   s   
zWriter.AddFilesc                 C   s:   | j |}|std| | d|||}|| dS )a\  Adds a configuration to a file.

    Args:
      path: Relative path to the file.
      config: Name of configuration to add.
      attrs: Dict of configuration attributes; may be None.
      tools: List of tools (strings or Tool objects); may be None.

    Raises:
      ValueError: Relative path does not match any file added via AddFiles().
    z(AddFileConfig: file "%s" not in project.FileConfigurationN)r%   get
ValueErrorr4   r    )r   r*   configr   r0   r:   r6   r	   r	   r
   AddFileConfig   s   
zWriter.AddFileConfigc                 C   sP   dd| j  | j| j| jdd| j| j| jdg| jdgg}tj	|| j
dd d	S )
zWrites the project file.VisualStudioProjectz
Visual C++	Win32Proj)ProjectTypeVersionr   ProjectGUIDRootNamespaceKeyword
ReferencesGlobalszWindows-1252)encodingN)r   ProjectVersionr   r   r   r!   r"   r#   easy_xmlWriteXmlIfChangedr   )r   contentr	   r	   r
   WriteIfChanged   s$   

zWriter.WriteIfChanged)NN)r   r   r   r   r   r+   r4   r7   r9   r>   rC   rR   r	   r	   r	   r
   r   3   s    


r   )	r   
gyp.commongypgyp.easy_xmlrO   objectr   r   r   r	   r	   r	   r
   <module>   s   