Instrumented libraries: work around a build issue in pixman.
[chromium-blink-merge.git] / android_webview / tools / webview_locales_rename_paks.py
blob4bc77e56806b93a80135f282f995fbf05cab8608
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 def calc_output(locale):
19 """Determine the file that will be generated for the given locale."""
20 return os.path.join(PRODUCT_DIR, 'android_webview_assets',
21 'locales', locale + '.pak')
23 def calc_input(locale):
24 """Determine the file that needs processing for the given locale."""
25 return os.path.join(SHARE_INT_DIR, 'content', 'app', 'strings',
26 'content_strings_%s.pak' % locale)
28 def list_outputs(locales):
29 """Returns the names of the files that will be generated for the given
30 locales.
32 This is to provide gyp the list of output files, so build targets can
33 properly track what needs to be built.
34 """
35 return list_files(locales, calc_output)
37 def list_inputs(locales):
38 """Returns the names of the files that will be processed for the given
39 locales.
41 This is to provide gyp the list of input files, so build targets can properly
42 track their prerequisites.
43 """
44 return list_files(locales, calc_input)
46 def list_files(locales, filename_func):
47 """Returns the names of the files generated by filename_func for a list of
48 locales.
50 :param filename_func: function that generates a filename for a given locale
51 """
52 files = []
53 for locale in locales:
54 files.append(filename_func(locale))
55 return " ".join(['"%s"' % x for x in files])
57 def rename_locales(locales):
58 """ Loop over and renames the given locales."""
59 for locale in locales:
60 shutil.copy(calc_input(locale), calc_output(locale))
62 def DoMain(argv):
63 global SHARE_INT_DIR
64 global PRODUCT_DIR
66 parser = optparse.OptionParser("usage: %prog [options] locales")
67 parser.add_option("-i", action="store_true", dest="inputs", default=False,
68 help="Print the expected input file list, then exit.")
69 parser.add_option("-o", action="store_true", dest="outputs", default=False,
70 help="Print the expected output file list, then exit.")
71 parser.add_option("-p", action="store", dest="product_dir",
72 help="Product build files output directory.")
73 parser.add_option("-s", action="store", dest="share_int_dir",
74 help="Shared intermediate build files output directory.")
75 options, locales = parser.parse_args(argv)
76 if not locales:
77 parser.error('Please specify at least one locale to process.\n')
79 print_inputs = options.inputs
80 print_outputs = options.outputs
81 SHARE_INT_DIR = options.share_int_dir
82 PRODUCT_DIR = options.product_dir
84 if print_inputs and print_outputs:
85 parser.error('Please specify only one of "-i" or "-o".\n')
87 if print_inputs:
88 return list_inputs(locales)
90 if print_outputs:
91 return list_outputs(locales)
93 return rename_locales(locales)
95 if __name__ == '__main__':
96 results = DoMain(sys.argv[1:])
97 if results:
98 print results