OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
droger
2015/06/05 11:04:00
s/(c) 2012/2015/
sdefresne
2015/06/05 11:41:00
Done.
| |
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 repack paks for a list of locales. | |
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 repacking pak files, thus avoiding a | |
10 proliferation of mostly duplicate, cut-n-paste gyp actions. | |
11 """ | |
12 | |
13 import optparse | |
14 import os | |
15 import sys | |
16 | |
17 script_dir = os.path.dirname(__file__) | |
18 src_dir = os.path.join(script_dir, os.pardir, os.pardir, os.pardir, os.pardir) | |
19 sys.path.append(os.path.join(src_dir, 'tools', 'grit')) | |
20 | |
21 from grit.format import data_pack | |
22 | |
23 | |
24 def calc_output(options, locale): | |
25 """Determine the file that will be generated for the given locale.""" | |
26 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', | |
27 # For Fake Bidi, generate it at a fixed path so that tests can safely | |
28 # reference it. | |
29 if locale == 'fake-bidi': | |
30 return os.path.join(options.share_int_dir, locale + '.pak') | |
31 # For Cocoa to find the locale at runtime, it needs to use '_' instead | |
32 # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented | |
33 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). | |
34 if locale == 'en-US': | |
35 locale = 'en' | |
36 else: | |
37 locale = locale.replace('-', '_') | |
38 return os.path.join(options.out_dir, locale + '.lproj', 'locale.pak') | |
39 | |
40 | |
41 def calc_inputs(options, locale): | |
42 """Determine the files that need processing for the given locale.""" | |
43 inputs = [] | |
44 | |
45 #e.g. '<(SHARED_INTERMEDIATE_DIR)/components/strings/ | |
46 # components_strings_da.pak', | |
47 inputs.append(os.path.join(options.share_int_dir, 'components', 'strings', | |
48 'components_strings_%s.pak' % locale)) | |
49 | |
50 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/strings/ui_strings_da.pak', | |
51 inputs.append(os.path.join(options.share_int_dir, 'ui', 'strings', | |
52 'ui_strings_%s.pak' % locale)) | |
53 | |
54 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ios/chrome/ios_strings_resources_da.pak' | |
55 inputs.append(os.path.join(options.share_int_dir, 'ios', 'chrome', | |
56 'ios_strings_resources_%s.pak' % locale)) | |
57 | |
58 if options.branding: | |
59 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ios/chrome/google_chrome_strings_da.pak' | |
60 # or | |
61 # '<(SHARED_INTERMEDIATE_DIR)/ios/chrome/chromium_strings_da.pak' | |
62 inputs.append(os.path.join(options.share_int_dir, 'ios', 'chrome', | |
63 '%s_strings_%s.pak' % (options.branding, locale))) | |
64 | |
65 # Add any extra input files. | |
66 for extra_file in options.extra_input: | |
67 inputs.append('%s_%s.pak' % (extra_file, locale)) | |
68 | |
69 return inputs | |
70 | |
71 | |
72 def list_outputs(options, locales): | |
73 """Returns the names of files that will be generated for the given locales. | |
74 | |
75 This is to provide gyp the list of output files, so build targets can | |
76 properly track what needs to be built. | |
77 """ | |
78 outputs = [] | |
79 for locale in locales: | |
80 outputs.append(calc_output(options, locale)) | |
81 return outputs | |
82 | |
83 | |
84 def list_inputs(options, locales): | |
85 """Returns the names of files that will be processed for the given locales. | |
86 | |
87 This is to provide gyp the list of input files, so build targets can properly | |
88 track their prerequisites. | |
89 """ | |
90 inputs = [] | |
91 for locale in locales: | |
92 inputs.extend(calc_inputs(options, locale)) | |
93 return inputs | |
94 | |
95 | |
96 def quote_filenames(filenames): | |
97 """Quote each elements so filename spaces don't mess up gyp's attempt to parse | |
98 it into a list.""" | |
99 return " ".join(['"%s"' % x for x in filenames]) | |
100 | |
101 | |
102 def repack_locales(options, locales): | |
103 """ Loop over and repack the given locales.""" | |
104 for locale in locales: | |
105 inputs = calc_inputs(options, locale) | |
106 output = calc_output(options, locale) | |
107 data_pack.DataPack.RePack(output, inputs, whitelist_file=options.whitelist) | |
108 | |
109 | |
110 def DoMain(argv): | |
111 parser = optparse.OptionParser("usage: %prog [options] locales") | |
112 parser.add_option( | |
113 "-i", action="store_true", dest="print_inputs", default=False, | |
114 help="Print the expected input file list, then exit.") | |
115 parser.add_option( | |
116 "-o", action="store_true", dest="print_outputs", default=False, | |
117 help="Print the expected output file list, then exit.") | |
118 parser.add_option( | |
119 "-x", action="store", dest="out_dir", | |
120 help="Intermediate build files output directory.") | |
121 parser.add_option( | |
122 "-s", action="store", dest="share_int_dir", | |
123 help="Shared intermediate build files output directory.") | |
124 parser.add_option( | |
125 "-b", action="store", dest="branding", | |
126 help="Branding type of this build.") | |
127 parser.add_option( | |
128 "-e", action="append", dest="extra_input", default=[], | |
129 help="Full path to an extra input pak file without the " | |
130 "locale suffix and \".pak\" extension.") | |
131 parser.add_option( | |
132 "--whitelist", action="store", help="Full path to the " | |
133 "whitelist used to filter output pak file resource IDs") | |
134 options, locales = parser.parse_args(argv) | |
135 | |
136 if not locales: | |
137 parser.error('Please specificy at least one locale to process.\n') | |
138 | |
139 if not (options.out_dir and options.share_int_dir): | |
140 parser.error('Please specify all of "-x" and "-s".\n') | |
141 if options.print_inputs and options.print_outputs: | |
142 parser.error('Please specify only one of "-i" or "-o".\n') | |
143 | |
144 if options.print_inputs: | |
145 return quote_filenames(list_inputs(options, locales)) | |
146 | |
147 if options.print_outputs: | |
148 return quote_filenames(list_outputs(options, locales)) | |
149 | |
150 return repack_locales(options, locales) | |
151 | |
152 if __name__ == '__main__': | |
153 results = DoMain(sys.argv[1:]) | |
154 if results: | |
155 print results | |
OLD | NEW |