MSVSToolFile.py 1.8 KB

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