Skip to content

Commit

Permalink
[hack]: fix gyp for duplicate basename
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Sep 29, 2020
1 parent dacc6b9 commit d5ae6d4
Show file tree
Hide file tree
Showing 40 changed files with 26,448 additions and 23,703 deletions.
510 changes: 272 additions & 238 deletions tools/gyp/pylib/gyp/MSVSNew.py

Large diffs are not rendered by default.

226 changes: 112 additions & 114 deletions tools/gyp/pylib/gyp/MSVSProject.py
Expand Up @@ -4,55 +4,55 @@

"""Visual Studio project reader/writer."""

import gyp.common
import gyp.easy_xml as easy_xml

#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------


class Tool(object):
"""Visual Studio tool."""
"""Visual Studio tool."""

def __init__(self, name, attrs=None):
"""Initializes the tool.
def __init__(self, name, attrs=None):
"""Initializes the tool.
Args:
name: Tool name.
attrs: Dict of tool attributes; may be None.
"""
self._attrs = attrs or {}
self._attrs['Name'] = name
self._attrs = attrs or {}
self._attrs["Name"] = name

def _GetSpecification(self):
"""Creates an element for the tool.
def _GetSpecification(self):
"""Creates an element for the tool.
Returns:
A new xml.dom.Element for the tool.
"""
return ['Tool', self._attrs]
return ["Tool", self._attrs]


class Filter(object):
"""Visual Studio filter - that is, a virtual folder."""
"""Visual Studio filter - that is, a virtual folder."""

def __init__(self, name, contents=None):
"""Initializes the folder.
def __init__(self, name, contents=None):
"""Initializes the folder.
Args:
name: Filter (folder) name.
contents: List of filenames and/or Filter objects contained.
"""
self.name = name
self.contents = list(contents or [])
self.name = name
self.contents = list(contents or [])


#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------


class Writer(object):
"""Visual Studio XML project writer."""
"""Visual Studio XML project writer."""

def __init__(self, project_path, version, name, guid=None, platforms=None):
"""Initializes the project.
def __init__(self, project_path, version, name, guid=None, platforms=None):
"""Initializes the project.
Args:
project_path: Path to the project file.
Expand All @@ -61,36 +61,36 @@ def __init__(self, project_path, version, name, guid=None, platforms=None):
guid: GUID to use for project, if not None.
platforms: Array of string, the supported platforms. If null, ['Win32']
"""
self.project_path = project_path
self.version = version
self.name = name
self.guid = guid
self.project_path = project_path
self.version = version
self.name = name
self.guid = guid

# Default to Win32 for platforms.
if not platforms:
platforms = ['Win32']
# Default to Win32 for platforms.
if not platforms:
platforms = ["Win32"]

# Initialize the specifications of the various sections.
self.platform_section = ['Platforms']
for platform in platforms:
self.platform_section.append(['Platform', {'Name': platform}])
self.tool_files_section = ['ToolFiles']
self.configurations_section = ['Configurations']
self.files_section = ['Files']
# Initialize the specifications of the various sections.
self.platform_section = ["Platforms"]
for platform in platforms:
self.platform_section.append(["Platform", {"Name": platform}])
self.tool_files_section = ["ToolFiles"]
self.configurations_section = ["Configurations"]
self.files_section = ["Files"]

# Keep a dict keyed on filename to speed up access.
self.files_dict = dict()
# Keep a dict keyed on filename to speed up access.
self.files_dict = dict()

def AddToolFile(self, path):
"""Adds a tool file to the project.
def AddToolFile(self, path):
"""Adds a tool file to the project.
Args:
path: Relative path from project to tool file.
"""
self.tool_files_section.append(['ToolFile', {'RelativePath': path}])
self.tool_files_section.append(["ToolFile", {"RelativePath": path}])

def _GetSpecForConfiguration(self, config_type, config_name, attrs, tools):
"""Returns the specification for a configuration.
def _GetSpecForConfiguration(self, config_type, config_name, attrs, tools):
"""Returns the specification for a configuration.
Args:
config_type: Type of configuration node.
Expand All @@ -99,58 +99,57 @@ def _GetSpecForConfiguration(self, config_type, config_name, attrs, tools):
tools: List of tools (strings or Tool objects); may be None.
Returns:
"""
# Handle defaults
if not attrs:
attrs = {}
if not tools:
tools = []

# Add configuration node and its attributes
node_attrs = attrs.copy()
node_attrs['Name'] = config_name
specification = [config_type, node_attrs]

# Add tool nodes and their attributes
if tools:
for t in tools:
if isinstance(t, Tool):
specification.append(t._GetSpecification())
else:
specification.append(Tool(t)._GetSpecification())
return specification


def AddConfig(self, name, attrs=None, tools=None):
"""Adds a configuration to the project.
# Handle defaults
if not attrs:
attrs = {}
if not tools:
tools = []

# Add configuration node and its attributes
node_attrs = attrs.copy()
node_attrs["Name"] = config_name
specification = [config_type, node_attrs]

# Add tool nodes and their attributes
if tools:
for t in tools:
if isinstance(t, Tool):
specification.append(t._GetSpecification())
else:
specification.append(Tool(t)._GetSpecification())
return specification

def AddConfig(self, name, attrs=None, tools=None):
"""Adds 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.
"""
spec = self._GetSpecForConfiguration('Configuration', name, attrs, tools)
self.configurations_section.append(spec)
spec = self._GetSpecForConfiguration("Configuration", name, attrs, tools)
self.configurations_section.append(spec)

def _AddFilesToNode(self, parent, files):
"""Adds files and/or filters to the parent node.
def _AddFilesToNode(self, parent, files):
"""Adds 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.
"""
for f in files:
if isinstance(f, Filter):
node = ['Filter', {'Name': f.name}]
self._AddFilesToNode(node, f.contents)
else:
node = ['File', {'RelativePath': f}]
self.files_dict[f] = node
parent.append(node)

def AddFiles(self, files):
"""Adds files to the project.
for f in files:
if isinstance(f, Filter):
node = ["Filter", {"Name": f.name}]
self._AddFilesToNode(node, f.contents)
else:
node = ["File", {"RelativePath": f}]
self.files_dict[f] = node
parent.append(node)

def AddFiles(self, files):
"""Adds files to the project.
Args:
files: A list of Filter objects and/or relative paths to files.
Expand All @@ -159,12 +158,12 @@ def AddFiles(self, files):
later add files to a Filter object which was passed into a previous call
to AddFiles(), it will not be reflected in this project.
"""
self._AddFilesToNode(self.files_section, files)
# TODO(rspangler) This also doesn't handle adding files to an existing
# filter. That is, it doesn't merge the trees.
self._AddFilesToNode(self.files_section, files)
# TODO(rspangler) This also doesn't handle adding files to an existing
# filter. That is, it doesn't merge the trees.

def AddFileConfig(self, path, config, attrs=None, tools=None):
"""Adds a configuration to a file.
def AddFileConfig(self, path, config, attrs=None, tools=None):
"""Adds a configuration to a file.
Args:
path: Relative path to the file.
Expand All @@ -175,34 +174,33 @@ def AddFileConfig(self, path, config, attrs=None, tools=None):
Raises:
ValueError: Relative path does not match any file added via AddFiles().
"""
# Find the file node with the right relative path
parent = self.files_dict.get(path)
if not parent:
raise ValueError('AddFileConfig: file "%s" not in project.' % path)

# Add the config to the file node
spec = self._GetSpecForConfiguration('FileConfiguration', config, attrs,
tools)
parent.append(spec)

def WriteIfChanged(self):
"""Writes the project file."""
# First create XML content definition
content = [
'VisualStudioProject',
{'ProjectType': 'Visual C++',
'Version': self.version.ProjectVersion(),
'Name': self.name,
'ProjectGUID': self.guid,
'RootNamespace': self.name,
'Keyword': 'Win32Proj'
},
self.platform_section,
self.tool_files_section,
self.configurations_section,
['References'], # empty section
self.files_section,
['Globals'] # empty section
]
easy_xml.WriteXmlIfChanged(content, self.project_path,
encoding="Windows-1252")
# Find the file node with the right relative path
parent = self.files_dict.get(path)
if not parent:
raise ValueError('AddFileConfig: file "%s" not in project.' % path)

# Add the config to the file node
spec = self._GetSpecForConfiguration("FileConfiguration", config, attrs, tools)
parent.append(spec)

def WriteIfChanged(self):
"""Writes the project file."""
# First create XML content definition
content = [
"VisualStudioProject",
{
"ProjectType": "Visual C++",
"Version": self.version.ProjectVersion(),
"Name": self.name,
"ProjectGUID": self.guid,
"RootNamespace": self.name,
"Keyword": "Win32Proj",
},
self.platform_section,
self.tool_files_section,
self.configurations_section,
["References"], # empty section
self.files_section,
["Globals"], # empty section
]
easy_xml.WriteXmlIfChanged(content, self.project_path, encoding="Windows-1252")

0 comments on commit d5ae6d4

Please sign in to comment.