MSVSToolFile.py 1.7 KB

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