Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / android_webview / tools / webview_repack_locales.py
blob19c9286786ca7cf2be8709b26c4d8bb9b990017f
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
6 """Helper script to rename paks for a list of locales for the Android WebView.
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
10 chrome/tools/build/repack_locales.py
11 """
13 import optparse
14 import os
15 import shutil
16 import sys
18 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..',
19 'tools', 'grit'))
20 from grit.format import data_pack
22 def calc_output(locale):
23 """Determine the file that will be generated for the given locale."""
24 return os.path.join(PRODUCT_DIR, 'android_webview_assets',
25 'locales', locale + '.pak')
27 def calc_inputs(locale):
28 """Determine the files that need processing for the given locale."""
29 inputs = []
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
37 def list_outputs(locales):
38 """Returns the names of files that will be generated for the given locales.
40 This is to provide gyp the list of output files, so build targets can
41 properly track what needs to be built.
42 """
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])
50 def list_inputs(locales):
51 """Returns the names of files that will be processed for the given locales.
53 This is to provide gyp the list of input files, so build targets can properly
54 track their prerequisites.
55 """
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])
63 def repack_locales(locales):
64 """ Loop over and repack the given locales."""
65 for locale in locales:
66 inputs = []
67 inputs += calc_inputs(locale)
68 output = calc_output(locale)
69 data_pack.DataPack.RePack(output, inputs)
71 def DoMain(argv):
72 global SHARE_INT_DIR
73 global PRODUCT_DIR
75 parser = optparse.OptionParser("usage: %prog [options] locales")
76 parser.add_option("-i", action="store_true", dest="inputs", default=False,
77 help="Print the expected input file list, then exit.")
78 parser.add_option("-o", action="store_true", dest="outputs", default=False,
79 help="Print the expected output file list, then exit.")
80 parser.add_option("-p", action="store", dest="product_dir",
81 help="Product build files output directory.")
82 parser.add_option("-s", action="store", dest="share_int_dir",
83 help="Shared intermediate build files output directory.")
84 options, locales = parser.parse_args(argv)
85 if not locales:
86 parser.error('Please specify at least one locale to process.\n')
88 print_inputs = options.inputs
89 print_outputs = options.outputs
90 SHARE_INT_DIR = options.share_int_dir
91 PRODUCT_DIR = options.product_dir
93 if print_inputs and print_outputs:
94 parser.error('Please specify only one of "-i" or "-o".\n')
96 if print_inputs:
97 return list_inputs(locales)
99 if print_outputs:
100 return list_outputs(locales)
102 return repack_locales(locales)
104 if __name__ == '__main__':
105 results = DoMain(sys.argv[1:])
106 if results:
107 print results