3
# Copyright (c) 2009 Google Inc. All rights reserved.
4
# Use of this source code is governed by a BSD-style license that can be
5
# found in the LICENSE file.
7
"""Visual Studio project reader/writer."""
11
import xml.dom.minidom
14
#------------------------------------------------------------------------------
18
"""Visual Studio XML tool file writer."""
20
def __init__(self, tool_file_path):
21
"""Initializes the tool file.
24
tool_file_path: Path to the tool file.
26
self.tool_file_path = tool_file_path
29
def Create(self, name):
30
"""Creates the tool file document.
33
name: Name of the tool file.
38
xml_impl = xml.dom.getDOMImplementation()
39
self.doc = xml_impl.createDocument(None, 'VisualStudioToolFile', None)
41
# Add attributes to root element
42
self.n_root = self.doc.documentElement
43
self.n_root.setAttribute('Version', '8.00')
44
self.n_root.setAttribute('Name', self.name)
47
self.n_rules = self.doc.createElement('Rules')
48
self.n_root.appendChild(self.n_rules)
50
def AddCustomBuildRule(self, name, cmd, description,
51
additional_dependencies,
53
"""Adds a rule to the tool file.
56
name: Name of the rule.
57
description: Description of the rule.
58
cmd: Command line of the rule.
59
additional_dependencies: other files which may trigger the rule.
60
outputs: outputs of the rule.
61
extensions: extensions handled by the rule.
63
n_rule = self.doc.createElement('CustomBuildRule')
64
n_rule.setAttribute('Name', name)
65
n_rule.setAttribute('ExecutionDescription', description)
66
n_rule.setAttribute('CommandLine', cmd)
67
n_rule.setAttribute('Outputs', ';'.join(outputs))
68
n_rule.setAttribute('FileExtensions', ';'.join(extensions))
69
n_rule.setAttribute('AdditionalDependencies',
70
';'.join(additional_dependencies))
71
self.n_rules.appendChild(n_rule)
73
def Write(self, writer=common.WriteOnDiff):
74
"""Writes the tool file."""
75
f = writer(self.tool_file_path)
76
self.doc.writexml(f, encoding='Windows-1252', addindent=' ', newl='\r\n')
79
#------------------------------------------------------------------------------