Initial commit
[yaffs-website] / node_modules / node-gyp / gyp / pylib / gyp / MSVSToolFile.py
1 # Copyright (c) 2012 Google Inc. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Visual Studio project reader/writer."""
6
7 import gyp.common
8 import gyp.easy_xml as easy_xml
9
10
11 class Writer(object):
12   """Visual Studio XML tool file writer."""
13
14   def __init__(self, tool_file_path, name):
15     """Initializes the tool file.
16
17     Args:
18       tool_file_path: Path to the tool file.
19       name: Name of the tool file.
20     """
21     self.tool_file_path = tool_file_path
22     self.name = name
23     self.rules_section = ['Rules']
24
25   def AddCustomBuildRule(self, name, cmd, description,
26                          additional_dependencies,
27                          outputs, extensions):
28     """Adds a rule to the tool file.
29
30     Args:
31       name: Name of the rule.
32       description: Description of the rule.
33       cmd: Command line of the rule.
34       additional_dependencies: other files which may trigger the rule.
35       outputs: outputs of the rule.
36       extensions: extensions handled by the rule.
37     """
38     rule = ['CustomBuildRule',
39             {'Name': name,
40              'ExecutionDescription': description,
41              'CommandLine': cmd,
42              'Outputs': ';'.join(outputs),
43              'FileExtensions': ';'.join(extensions),
44              'AdditionalDependencies':
45                  ';'.join(additional_dependencies)
46             }]
47     self.rules_section.append(rule)
48
49   def WriteIfChanged(self):
50     """Writes the tool file."""
51     content = ['VisualStudioToolFile',
52                {'Version': '8.00',
53                 'Name': self.name
54                },
55                self.rules_section
56                ]
57     easy_xml.WriteXmlIfChanged(content, self.tool_file_path,
58                                encoding="Windows-1252")