11cb0ef41Sopenharmony_ci# Copyright (c) 2012 Google Inc. All rights reserved. 21cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci# found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci"""Visual Studio project reader/writer.""" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciimport gyp.easy_xml as easy_xml 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciclass Writer: 111cb0ef41Sopenharmony_ci """Visual Studio XML tool file writer.""" 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci def __init__(self, tool_file_path, name): 141cb0ef41Sopenharmony_ci """Initializes the tool file. 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci Args: 171cb0ef41Sopenharmony_ci tool_file_path: Path to the tool file. 181cb0ef41Sopenharmony_ci name: Name of the tool file. 191cb0ef41Sopenharmony_ci """ 201cb0ef41Sopenharmony_ci self.tool_file_path = tool_file_path 211cb0ef41Sopenharmony_ci self.name = name 221cb0ef41Sopenharmony_ci self.rules_section = ["Rules"] 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci def AddCustomBuildRule( 251cb0ef41Sopenharmony_ci self, name, cmd, description, additional_dependencies, outputs, extensions 261cb0ef41Sopenharmony_ci ): 271cb0ef41Sopenharmony_ci """Adds a rule to the tool file. 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci Args: 301cb0ef41Sopenharmony_ci name: Name of the rule. 311cb0ef41Sopenharmony_ci description: Description of the rule. 321cb0ef41Sopenharmony_ci cmd: Command line of the rule. 331cb0ef41Sopenharmony_ci additional_dependencies: other files which may trigger the rule. 341cb0ef41Sopenharmony_ci outputs: outputs of the rule. 351cb0ef41Sopenharmony_ci extensions: extensions handled by the rule. 361cb0ef41Sopenharmony_ci """ 371cb0ef41Sopenharmony_ci rule = [ 381cb0ef41Sopenharmony_ci "CustomBuildRule", 391cb0ef41Sopenharmony_ci { 401cb0ef41Sopenharmony_ci "Name": name, 411cb0ef41Sopenharmony_ci "ExecutionDescription": description, 421cb0ef41Sopenharmony_ci "CommandLine": cmd, 431cb0ef41Sopenharmony_ci "Outputs": ";".join(outputs), 441cb0ef41Sopenharmony_ci "FileExtensions": ";".join(extensions), 451cb0ef41Sopenharmony_ci "AdditionalDependencies": ";".join(additional_dependencies), 461cb0ef41Sopenharmony_ci }, 471cb0ef41Sopenharmony_ci ] 481cb0ef41Sopenharmony_ci self.rules_section.append(rule) 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci def WriteIfChanged(self): 511cb0ef41Sopenharmony_ci """Writes the tool file.""" 521cb0ef41Sopenharmony_ci content = [ 531cb0ef41Sopenharmony_ci "VisualStudioToolFile", 541cb0ef41Sopenharmony_ci {"Version": "8.00", "Name": self.name}, 551cb0ef41Sopenharmony_ci self.rules_section, 561cb0ef41Sopenharmony_ci ] 571cb0ef41Sopenharmony_ci easy_xml.WriteXmlIfChanged( 581cb0ef41Sopenharmony_ci content, self.tool_file_path, encoding="Windows-1252" 591cb0ef41Sopenharmony_ci ) 60