| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 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 """Helper script to rename paks for a list of locales for the Android WebView. | 6 """Helper script to rename paks for a list of locales for the Android WebView. |
| 7 | 7 |
| 8 Gyp doesn't have any built-in looping capability, so this just provides a way to | 8 Gyp doesn't have any built-in looping capability, so this just provides a way to |
| 9 loop over a list of locales when renaming pak files. Based on | 9 loop over a list of locales when renaming pak files. Based on |
| 10 chrome/tools/build/repack_locales.py | 10 chrome/tools/build/repack_locales.py |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import shutil | 15 import shutil |
| 16 import sys | 16 import sys |
| 17 | 17 |
| 18 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', |
| 19 'tools', 'grit')) |
| 20 from grit.format import data_pack |
| 21 |
| 18 def calc_output(locale): | 22 def calc_output(locale): |
| 19 """Determine the file that will be generated for the given locale.""" | 23 """Determine the file that will be generated for the given locale.""" |
| 20 return os.path.join(PRODUCT_DIR, 'android_webview_assets', | 24 return os.path.join(PRODUCT_DIR, 'android_webview_assets', |
| 21 'locales', locale + '.pak') | 25 'locales', locale + '.pak') |
| 22 | 26 |
| 23 def calc_input(locale): | 27 def calc_inputs(locale): |
| 24 """Determine the file that needs processing for the given locale.""" | 28 """Determine the files that need processing for the given locale.""" |
| 25 return os.path.join(SHARE_INT_DIR, 'content', 'app', 'strings', | 29 inputs = [] |
| 26 'content_strings_%s.pak' % locale) | 30 |
| 31 inputs.append(os.path.join(SHARE_INT_DIR, 'content', 'app', 'strings', |
| 32 'content_strings_%s.pak' % locale)) |
| 33 inputs.append(os.path.join(SHARE_INT_DIR, 'android_webview', |
| 34 'aw_strings_%s.pak' % locale)) |
| 35 return inputs |
| 27 | 36 |
| 28 def list_outputs(locales): | 37 def list_outputs(locales): |
| 29 """Returns the names of the files that will be generated for the given | 38 """Returns the names of files that will be generated for the given locales. |
| 30 locales. | |
| 31 | 39 |
| 32 This is to provide gyp the list of output files, so build targets can | 40 This is to provide gyp the list of output files, so build targets can |
| 33 properly track what needs to be built. | 41 properly track what needs to be built. |
| 34 """ | 42 """ |
| 35 return list_files(locales, calc_output) | 43 outputs = [] |
| 44 for locale in locales: |
| 45 outputs.append(calc_output(locale)) |
| 46 # Quote each element so filename spaces don't mess up gyp's attempt to parse |
| 47 # it into a list. |
| 48 return " ".join(['"%s"' % x for x in outputs]) |
| 36 | 49 |
| 37 def list_inputs(locales): | 50 def list_inputs(locales): |
| 38 """Returns the names of the files that will be processed for the given | 51 """Returns the names of files that will be processed for the given locales. |
| 39 locales. | |
| 40 | 52 |
| 41 This is to provide gyp the list of input files, so build targets can properly | 53 This is to provide gyp the list of input files, so build targets can properly |
| 42 track their prerequisites. | 54 track their prerequisites. |
| 43 """ | 55 """ |
| 44 return list_files(locales, calc_input) | 56 inputs = [] |
| 57 for locale in locales: |
| 58 inputs += calc_inputs(locale) |
| 59 # Quote each element so filename spaces don't mess up gyp's attempt to parse |
| 60 # it into a list. |
| 61 return " ".join(['"%s"' % x for x in inputs]) |
| 45 | 62 |
| 46 def list_files(locales, filename_func): | 63 def repack_locales(locales): |
| 47 """Returns the names of the files generated by filename_func for a list of | 64 """ Loop over and repack the given locales.""" |
| 48 locales. | |
| 49 | |
| 50 :param filename_func: function that generates a filename for a given locale | |
| 51 """ | |
| 52 files = [] | |
| 53 for locale in locales: | 65 for locale in locales: |
| 54 files.append(filename_func(locale)) | 66 inputs = [] |
| 55 return " ".join(['"%s"' % x for x in files]) | 67 inputs += calc_inputs(locale) |
| 56 | 68 output = calc_output(locale) |
| 57 def rename_locales(locales): | 69 data_pack.DataPack.RePack(output, inputs) |
| 58 """ Loop over and renames the given locales.""" | |
| 59 for locale in locales: | |
| 60 shutil.copy(calc_input(locale), calc_output(locale)) | |
| 61 | 70 |
| 62 def DoMain(argv): | 71 def DoMain(argv): |
| 63 global SHARE_INT_DIR | 72 global SHARE_INT_DIR |
| 64 global PRODUCT_DIR | 73 global PRODUCT_DIR |
| 65 | 74 |
| 66 parser = optparse.OptionParser("usage: %prog [options] locales") | 75 parser = optparse.OptionParser("usage: %prog [options] locales") |
| 67 parser.add_option("-i", action="store_true", dest="inputs", default=False, | 76 parser.add_option("-i", action="store_true", dest="inputs", default=False, |
| 68 help="Print the expected input file list, then exit.") | 77 help="Print the expected input file list, then exit.") |
| 69 parser.add_option("-o", action="store_true", dest="outputs", default=False, | 78 parser.add_option("-o", action="store_true", dest="outputs", default=False, |
| 70 help="Print the expected output file list, then exit.") | 79 help="Print the expected output file list, then exit.") |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 | 92 |
| 84 if print_inputs and print_outputs: | 93 if print_inputs and print_outputs: |
| 85 parser.error('Please specify only one of "-i" or "-o".\n') | 94 parser.error('Please specify only one of "-i" or "-o".\n') |
| 86 | 95 |
| 87 if print_inputs: | 96 if print_inputs: |
| 88 return list_inputs(locales) | 97 return list_inputs(locales) |
| 89 | 98 |
| 90 if print_outputs: | 99 if print_outputs: |
| 91 return list_outputs(locales) | 100 return list_outputs(locales) |
| 92 | 101 |
| 93 return rename_locales(locales) | 102 return repack_locales(locales) |
| 94 | 103 |
| 95 if __name__ == '__main__': | 104 if __name__ == '__main__': |
| 96 results = DoMain(sys.argv[1:]) | 105 results = DoMain(sys.argv[1:]) |
| 97 if results: | 106 if results: |
| 98 print results | 107 print results |
| OLD | NEW |