• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7import gyp.easy_xml as easy_xml
8
9
10class Writer(object):
11    """Visual Studio XML tool file writer."""
12
13    def __init__(self, tool_file_path, name):
14        """Initializes the tool file.
15
16    Args:
17      tool_file_path: Path to the tool file.
18      name: Name of the tool file.
19    """
20        self.tool_file_path = tool_file_path
21        self.name = name
22        self.rules_section = ["Rules"]
23
24    def AddCustomBuildRule(
25        self, name, cmd, description, additional_dependencies, outputs, extensions
26    ):
27        """Adds a rule to the tool file.
28
29    Args:
30      name: Name of the rule.
31      description: Description of the rule.
32      cmd: Command line of the rule.
33      additional_dependencies: other files which may trigger the rule.
34      outputs: outputs of the rule.
35      extensions: extensions handled by the rule.
36    """
37        rule = [
38            "CustomBuildRule",
39            {
40                "Name": name,
41                "ExecutionDescription": description,
42                "CommandLine": cmd,
43                "Outputs": ";".join(outputs),
44                "FileExtensions": ";".join(extensions),
45                "AdditionalDependencies": ";".join(additional_dependencies),
46            },
47        ]
48        self.rules_section.append(rule)
49
50    def WriteIfChanged(self):
51        """Writes the tool file."""
52        content = [
53            "VisualStudioToolFile",
54            {"Version": "8.00", "Name": self.name},
55            self.rules_section,
56        ]
57        easy_xml.WriteXmlIfChanged(
58            content, self.tool_file_path, encoding="Windows-1252"
59        )
60