initial import
[vuplus_webkit] / Source / ThirdParty / gyp / pylib / gyp / MSVSToolFile.py
1 #!/usr/bin/python2.4
2
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.
6
7 """Visual Studio project reader/writer."""
8
9 import common
10 import xml.dom
11 import xml_fix
12
13
14 #------------------------------------------------------------------------------
15
16
17 class Writer(object):
18   """Visual Studio XML tool file writer."""
19
20   def __init__(self, tool_file_path):
21     """Initializes the tool file.
22
23     Args:
24       tool_file_path: Path to the tool file.
25     """
26     self.tool_file_path = tool_file_path
27     self.doc = None
28
29   def Create(self, name):
30     """Creates the tool file document.
31
32     Args:
33       name: Name of the tool file.
34     """
35     self.name = name
36
37     # Create XML doc
38     xml_impl = xml.dom.getDOMImplementation()
39     self.doc = xml_impl.createDocument(None, 'VisualStudioToolFile', None)
40
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)
45
46     # Add rules section
47     self.n_rules = self.doc.createElement('Rules')
48     self.n_root.appendChild(self.n_rules)
49
50   def AddCustomBuildRule(self, name, cmd, description,
51                          additional_dependencies,
52                          outputs, extensions):
53     """Adds a rule to the tool file.
54
55     Args:
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.
62     """
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)
72
73   def Write(self, writer=common.WriteOnDiff):
74     """Writes the tool file."""
75     f = writer(self.tool_file_path)
76     fix = xml_fix.XmlFix()
77     self.doc.writexml(f, encoding='Windows-1252', addindent='  ', newl='\r\n')
78     fix.Cleanup()
79     f.close()
80
81 #------------------------------------------------------------------------------