OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 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 repack paks for a list of locales. | 6 """Helper script to repack paks for a list of locales. |
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 repacking pak files, thus avoiding a | 9 loop over a list of locales when repacking pak files, thus avoiding a |
10 proliferation of mostly duplicate, cut-n-paste gyp actions. | 10 proliferation of mostly duplicate, cut-n-paste gyp actions. |
11 """ | 11 """ |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
15 import sys | 15 import sys |
16 | 16 |
17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', | 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', |
18 'tools', 'grit')) | 18 'tools', 'grit')) |
19 from grit.format import data_pack | 19 from grit.format import data_pack |
20 | 20 |
21 # The gyp "branding" variable. | |
22 BRANDING = None | |
23 | |
24 # Some build paths defined by gyp. | 21 # Some build paths defined by gyp. |
25 GRIT_DIR = None | 22 GRIT_DIR = None |
26 SHARE_INT_DIR = None | |
27 INT_DIR = None | 23 INT_DIR = None |
28 | 24 |
29 # The target platform. If it is not defined, sys.platform will be used. | 25 # The target platform. If it is not defined, sys.platform will be used. |
30 OS = None | 26 OS = None |
31 | 27 |
32 # Extra input files. | 28 # Extra input files. |
33 EXTRA_INPUT_FILES = [] | 29 EXTRA_INPUT_FILES = [] |
34 | 30 |
35 class Usage(Exception): | 31 class Usage(Exception): |
36 def __init__(self, msg): | 32 def __init__(self, msg): |
37 self.msg = msg | 33 self.msg = msg |
38 | 34 |
39 | 35 |
40 def calc_output(locale): | 36 def calc_output(locale): |
41 """Determine the file that will be generated for the given locale.""" | 37 """Determine the file that will be generated for the given locale.""" |
42 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', | 38 #e.g. '<(INTERMEDIATE_DIR)/remoting_locales/da.pak', |
43 # For Fake Bidi, generate it at a fixed path so that tests can safely | |
44 # reference it. | |
45 if locale == 'fake-bidi': | |
46 return '%s/%s.pak' % (INT_DIR, locale) | |
47 if OS == 'mac' or OS == 'ios': | 39 if OS == 'mac' or OS == 'ios': |
48 # For Cocoa to find the locale at runtime, it needs to use '_' instead | 40 # For Cocoa to find the locale at runtime, it needs to use '_' instead |
49 # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented | 41 # of '-' (http://crbug.com/20441). |
50 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). | 42 return os.path.join(INT_DIR, 'remoting', 'resources', |
51 if locale == 'en-US': | 43 '%s.lproj' % locale.replace('-', '_'), 'locale.pak') |
52 locale = 'en' | |
53 return '%s/repack/%s.lproj/locale.pak' % (INT_DIR, locale.replace('-', '_')) | |
54 else: | 44 else: |
55 return os.path.join(INT_DIR, 'repack', locale + '.pak') | 45 return os.path.join(INT_DIR, 'remoting_locales', locale + '.pak') |
56 | 46 |
57 | 47 |
58 def calc_inputs(locale): | 48 def calc_inputs(locale): |
59 """Determine the files that need processing for the given locale.""" | 49 """Determine the files that need processing for the given locale.""" |
60 inputs = [] | 50 inputs = [] |
61 | 51 |
62 #e.g. '<(grit_out_dir)/generated_resources_da.pak' | 52 #e.g. '<(grit_out_dir)/remoting/resources/da.pak' |
63 inputs.append(os.path.join(GRIT_DIR, 'generated_resources_%s.pak' % locale)) | 53 inputs.append(os.path.join(GRIT_DIR, 'remoting/resources/%s.pak' % locale)) |
64 | |
65 #e.g. '<(grit_out_dir)/locale_settings_da.pak' | |
66 inputs.append(os.path.join(GRIT_DIR, 'locale_settings_%s.pak' % locale)) | |
67 | |
68 #e.g. '<(grit_out_dir)/platform_locale_settings_da.pak' | |
69 inputs.append(os.path.join(GRIT_DIR, | |
70 'platform_locale_settings_%s.pak' % locale)) | |
71 | |
72 #e.g. '<(SHARED_INTERMEDIATE_DIR)/components/strings/ | |
73 # component_strings_da.pak', | |
74 inputs.append(os.path.join(SHARE_INT_DIR, 'components', 'strings', | |
75 'component_strings_%s.pak' % locale)) | |
76 | |
77 if OS != 'ios': | |
78 #e.g. '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_da.pak' | |
79 inputs.append(os.path.join(SHARE_INT_DIR, 'webkit', | |
80 'webkit_strings_%s.pak' % locale)) | |
81 | |
82 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/ui_strings_da.pak', | |
83 inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'ui_strings', | |
84 'ui_strings_%s.pak' % locale)) | |
85 | |
86 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ash_strings/ash_strings_da.pak', | |
87 inputs.append(os.path.join(SHARE_INT_DIR, 'ash_strings', | |
88 'ash_strings_%s.pak' % locale)) | |
89 | |
90 #e.g. '<(SHARED_INTERMEDIATE_DIR)/device/bluetooth/strings/ | |
91 # device_bluetooth_strings_da.pak', | |
92 inputs.append(os.path.join(SHARE_INT_DIR, 'device', 'bluetooth', 'strings', | |
93 'device_bluetooth_strings_%s.pak' % locale)) | |
94 | |
95 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/app_locale_settings_da.pak', | |
96 inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'app_locale_settings', | |
97 'app_locale_settings_%s.pak' % locale)) | |
98 | |
99 #e.g. '<(grit_out_dir)/google_chrome_strings_da.pak' | |
100 # or | |
101 # '<(grit_out_dir)/chromium_strings_da.pak' | |
102 inputs.append(os.path.join( | |
103 GRIT_DIR, '%s_strings_%s.pak' % (BRANDING, locale))) | |
104 | 54 |
105 # Add any extra input files. | 55 # Add any extra input files. |
106 for extra_file in EXTRA_INPUT_FILES: | 56 for extra_file in EXTRA_INPUT_FILES: |
107 inputs.append('%s_%s.pak' % (extra_file, locale)) | 57 inputs.append('%s_%s.pak' % (extra_file, locale)) |
108 | 58 |
109 return inputs | 59 return inputs |
110 | 60 |
111 | 61 |
112 def list_outputs(locales): | 62 def list_outputs(locales): |
113 """Returns the names of files that will be generated for the given locales. | 63 """Returns the names of files that will be generated for the given locales. |
(...skipping 19 matching lines...) Expand all Loading... |
133 for locale in locales: | 83 for locale in locales: |
134 inputs += calc_inputs(locale) | 84 inputs += calc_inputs(locale) |
135 # Quote each element so filename spaces don't mess up gyp's attempt to parse | 85 # Quote each element so filename spaces don't mess up gyp's attempt to parse |
136 # it into a list. | 86 # it into a list. |
137 return " ".join(['"%s"' % x for x in inputs]) | 87 return " ".join(['"%s"' % x for x in inputs]) |
138 | 88 |
139 | 89 |
140 def repack_locales(locales): | 90 def repack_locales(locales): |
141 """ Loop over and repack the given locales.""" | 91 """ Loop over and repack the given locales.""" |
142 for locale in locales: | 92 for locale in locales: |
143 inputs = [] | 93 inputs = calc_inputs(locale) |
144 inputs += calc_inputs(locale) | |
145 output = calc_output(locale) | 94 output = calc_output(locale) |
146 data_pack.DataPack.RePack(output, inputs) | 95 data_pack.DataPack.RePack(output, inputs) |
147 | 96 |
148 | 97 |
149 def DoMain(argv): | 98 def DoMain(argv): |
150 global BRANDING | |
151 global GRIT_DIR | 99 global GRIT_DIR |
152 global SHARE_INT_DIR | |
153 global INT_DIR | 100 global INT_DIR |
154 global OS | 101 global OS |
155 global EXTRA_INPUT_FILES | 102 global EXTRA_INPUT_FILES |
156 | 103 |
157 parser = optparse.OptionParser("usage: %prog [options] locales") | 104 parser = optparse.OptionParser("usage: %prog [options] locales") |
158 parser.add_option("-i", action="store_true", dest="inputs", default=False, | 105 parser.add_option("-i", action="store_true", dest="inputs", default=False, |
159 help="Print the expected input file list, then exit.") | 106 help="Print the expected input file list, then exit.") |
160 parser.add_option("-o", action="store_true", dest="outputs", default=False, | 107 parser.add_option("-o", action="store_true", dest="outputs", default=False, |
161 help="Print the expected output file list, then exit.") | 108 help="Print the expected output file list, then exit.") |
162 parser.add_option("-g", action="store", dest="grit_dir", | 109 parser.add_option("-g", action="store", dest="grit_dir", |
163 help="GRIT build files output directory.") | 110 help="GRIT build files output directory.") |
164 parser.add_option("-x", action="store", dest="int_dir", | 111 parser.add_option("-x", action="store", dest="int_dir", |
165 help="Intermediate build files output directory.") | 112 help="Intermediate build files output directory.") |
166 parser.add_option("-s", action="store", dest="share_int_dir", | |
167 help="Shared intermediate build files output directory.") | |
168 parser.add_option("-b", action="store", dest="branding", | |
169 help="Branding type of this build.") | |
170 parser.add_option("-e", action="append", dest="extra_input", default=[], | 113 parser.add_option("-e", action="append", dest="extra_input", default=[], |
171 help="Full path to an extra input pak file without the\ | 114 help="Full path to an extra input pak file without the\ |
172 locale suffix and \".pak\" extension.") | 115 locale suffix and \".pak\" extension.") |
173 parser.add_option("-p", action="store", dest="os", | 116 parser.add_option("-p", action="store", dest="os", |
174 help="The target OS. (e.g. mac, linux, win, etc.)") | 117 help="The target OS. (e.g. mac, linux, win, etc.)") |
175 options, locales = parser.parse_args(argv) | 118 options, locales = parser.parse_args(argv) |
176 | 119 |
177 if not locales: | 120 if not locales: |
178 parser.error('Please specificy at least one locale to process.\n') | 121 parser.error('Please specificy at least one locale to process.\n') |
179 | 122 |
180 print_inputs = options.inputs | 123 print_inputs = options.inputs |
181 print_outputs = options.outputs | 124 print_outputs = options.outputs |
182 GRIT_DIR = options.grit_dir | 125 GRIT_DIR = options.grit_dir |
183 INT_DIR = options.int_dir | 126 INT_DIR = options.int_dir |
184 SHARE_INT_DIR = options.share_int_dir | |
185 BRANDING = options.branding | |
186 EXTRA_INPUT_FILES = options.extra_input | 127 EXTRA_INPUT_FILES = options.extra_input |
187 OS = options.os | 128 OS = options.os |
188 | 129 |
189 if not OS: | 130 if not OS: |
190 if sys.platform == 'darwin': | 131 if sys.platform == 'darwin': |
191 OS = 'mac' | 132 OS = 'mac' |
192 elif sys.platform.startswith('linux'): | 133 elif sys.platform.startswith('linux'): |
193 OS = 'linux' | 134 OS = 'linux' |
194 elif sys.platform in ('cygwin', 'win32'): | 135 elif sys.platform in ('cygwin', 'win32'): |
195 OS = 'win' | 136 OS = 'win' |
196 else: | 137 else: |
197 OS = sys.platform | 138 OS = sys.platform |
198 | 139 |
199 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): | |
200 parser.error('Please specify all of "-g" and "-x" and "-s".\n') | |
201 if print_inputs and print_outputs: | 140 if print_inputs and print_outputs: |
202 parser.error('Please specify only one of "-i" or "-o".\n') | 141 parser.error('Please specify only one of "-i" or "-o".\n') |
203 # Need to know the branding, unless we're just listing the outputs. | 142 if print_inputs and not GRIT_DIR: |
204 if not print_outputs and not BRANDING: | 143 parser.error('Please specify "-g".\n') |
205 parser.error('Please specify "-b" to determine the input files.\n') | 144 if print_outputs and not INT_DIR: |
| 145 parser.error('Please specify "-x".\n') |
| 146 if not (print_inputs or print_outputs or (GRIT_DIR and INT_DIR)): |
| 147 parser.error('Please specify both "-g" and "-x".\n') |
206 | 148 |
207 if print_inputs: | 149 if print_inputs: |
208 return list_inputs(locales) | 150 return list_inputs(locales) |
209 | 151 |
210 if print_outputs: | 152 if print_outputs: |
211 return list_outputs(locales) | 153 return list_outputs(locales) |
212 | 154 |
213 return repack_locales(locales) | 155 return repack_locales(locales) |
214 | 156 |
215 if __name__ == '__main__': | 157 if __name__ == '__main__': |
216 results = DoMain(sys.argv[1:]) | 158 results = DoMain(sys.argv[1:]) |
217 if results: | 159 if results: |
218 print results | 160 print results |
OLD | NEW |