| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''The 'grit build' tool along with integration for this tool with the | 6 '''The 'grit build' tool along with integration for this tool with the |
| 7 SCons build system. | 7 SCons build system. |
| 8 ''' | 8 ''' |
| 9 | 9 |
| 10 import codecs |
| 10 import filecmp | 11 import filecmp |
| 11 import getopt | 12 import getopt |
| 12 import os | 13 import os |
| 13 import shutil | 14 import shutil |
| 14 import sys | 15 import sys |
| 15 | 16 |
| 16 from grit import grd_reader | 17 from grit import grd_reader |
| 17 from grit import util | 18 from grit import util |
| 18 from grit.tool import interface | 19 from grit.tool import interface |
| 19 from grit import shortcuts | 20 from grit import shortcuts |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 if assert_output_files: | 232 if assert_output_files: |
| 232 if not self.CheckAssertedOutputFiles(assert_output_files): | 233 if not self.CheckAssertedOutputFiles(assert_output_files): |
| 233 return 2 | 234 return 2 |
| 234 | 235 |
| 235 if depfile and depdir: | 236 if depfile and depdir: |
| 236 self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp) | 237 self.GenerateDepfile(depfile, depdir, first_ids_file, depend_on_stamp) |
| 237 | 238 |
| 238 return 0 | 239 return 0 |
| 239 | 240 |
| 240 def __init__(self, defines=None): | 241 def __init__(self, defines=None): |
| 241 # Default file-creation function is built-in open(). Only done to allow | 242 # Default file-creation function is codecs.open(). Only done to allow |
| 242 # overriding by unit test. | 243 # overriding by unit test. |
| 243 self.fo_create = open | 244 self.fo_create = codecs.open |
| 244 | 245 |
| 245 # key/value pairs of C-preprocessor like defines that are used for | 246 # key/value pairs of C-preprocessor like defines that are used for |
| 246 # conditional output of resources | 247 # conditional output of resources |
| 247 self.defines = defines or {} | 248 self.defines = defines or {} |
| 248 | 249 |
| 249 # self.res is a fully-populated resource tree if Run() | 250 # self.res is a fully-populated resource tree if Run() |
| 250 # has been called, otherwise None. | 251 # has been called, otherwise None. |
| 251 self.res = None | 252 self.res = None |
| 252 | 253 |
| 253 # Set to a list of filenames for the output nodes that are relative | 254 # Set to a list of filenames for the output nodes that are relative |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 output_file = os.path.join(self.output_directory, | 481 output_file = os.path.join(self.output_directory, |
| 481 outputs[0].GetFilename()) | 482 outputs[0].GetFilename()) |
| 482 | 483 |
| 483 output_file = os.path.relpath(output_file, depdir) | 484 output_file = os.path.relpath(output_file, depdir) |
| 484 # The path prefix to prepend to dependencies in the depfile. | 485 # The path prefix to prepend to dependencies in the depfile. |
| 485 prefix = os.path.relpath(os.getcwd(), depdir) | 486 prefix = os.path.relpath(os.getcwd(), depdir) |
| 486 deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) | 487 deps_text = ' '.join([os.path.join(prefix, i) for i in infiles]) |
| 487 | 488 |
| 488 depfile_contents = output_file + ': ' + deps_text | 489 depfile_contents = output_file + ': ' + deps_text |
| 489 self.MakeDirectoriesTo(depfile) | 490 self.MakeDirectoriesTo(depfile) |
| 490 outfile = self.fo_create(depfile, 'wb') | 491 outfile = self.fo_create(depfile, 'w', encoding='utf-8') |
| 491 outfile.writelines(depfile_contents) | 492 outfile.writelines(depfile_contents) |
| 492 | 493 |
| 493 @staticmethod | 494 @staticmethod |
| 494 def MakeDirectoriesTo(file): | 495 def MakeDirectoriesTo(file): |
| 495 '''Creates directories necessary to contain |file|.''' | 496 '''Creates directories necessary to contain |file|.''' |
| 496 dir = os.path.split(file)[0] | 497 dir = os.path.split(file)[0] |
| 497 if not os.path.exists(dir): | 498 if not os.path.exists(dir): |
| 498 os.makedirs(dir) | 499 os.makedirs(dir) |
| OLD | NEW |