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