Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: android_webview/tools/webview_locales_rename_paks.py

Issue 868673003: [WebView] Repack the .pak files for all the locales. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inline android_webview_locales_rename_paks.gypi Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « android_webview/apk/system_webview_locales_paks.gypi ('k') | build/gyp_chromium » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
5
6 """Helper script to rename paks for a list of locales for the Android WebView.
7
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 """
12
13 import optparse
14 import os
15 import shutil
16 import sys
17
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')
22
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)
27
28 def list_outputs(locales):
29 """Returns the names of the files that will be generated for the given
30 locales.
31
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)
36
37 def list_inputs(locales):
38 """Returns the names of the files that will be processed for the given
39 locales.
40
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)
45
46 def list_files(locales, filename_func):
47 """Returns the names of the files generated by filename_func for a list of
48 locales.
49
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])
56
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))
61
62 def DoMain(argv):
63 global SHARE_INT_DIR
64 global PRODUCT_DIR
65
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')
78
79 print_inputs = options.inputs
80 print_outputs = options.outputs
81 SHARE_INT_DIR = options.share_int_dir
82 PRODUCT_DIR = options.product_dir
83
84 if print_inputs and print_outputs:
85 parser.error('Please specify only one of "-i" or "-o".\n')
86
87 if print_inputs:
88 return list_inputs(locales)
89
90 if print_outputs:
91 return list_outputs(locales)
92
93 return rename_locales(locales)
94
95 if __name__ == '__main__':
96 results = DoMain(sys.argv[1:])
97 if results:
98 print results
OLDNEW
« no previous file with comments | « android_webview/apk/system_webview_locales_paks.gypi ('k') | build/gyp_chromium » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698