OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 getopt | 13 import getopt |
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. | 21 # The gyp "branding" variable. |
22 BRANDING = None | 22 BRANDING = None |
23 | 23 |
24 # Some build paths defined by gyp. | 24 # Some build paths defined by gyp. |
25 GRIT_DIR = None | 25 GRIT_DIR = None |
26 SHARE_INT_DIR = None | 26 SHARE_INT_DIR = None |
27 INT_DIR = None | 27 INT_DIR = None |
28 | 28 |
| 29 # The target platform. If it is not defined, sys.platform will be used. |
| 30 OS = None |
29 | 31 |
30 class Usage(Exception): | 32 class Usage(Exception): |
31 def __init__(self, msg): | 33 def __init__(self, msg): |
32 self.msg = msg | 34 self.msg = msg |
33 | 35 |
34 | 36 |
35 def calc_output(locale): | 37 def calc_output(locale): |
36 """Determine the file that will be generated for the given locale.""" | 38 """Determine the file that will be generated for the given locale.""" |
37 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', | 39 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', |
38 # For Fake Bidi, generate it at a fixed path so that tests can safely | 40 # For Fake Bidi, generate it at a fixed path so that tests can safely |
39 # reference it. | 41 # reference it. |
40 if locale == 'fake-bidi': | 42 if locale == 'fake-bidi': |
41 return '%s/%s.pak' % (INT_DIR, locale) | 43 return '%s/%s.pak' % (INT_DIR, locale) |
42 if sys.platform in ('darwin',): | 44 if OS == 'mac': |
43 # For Cocoa to find the locale at runtime, it needs to use '_' instead | 45 # For Cocoa to find the locale at runtime, it needs to use '_' instead |
44 # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented | 46 # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented |
45 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). | 47 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). |
46 if locale == 'en-US': | 48 if locale == 'en-US': |
47 locale = 'en' | 49 locale = 'en' |
48 return '%s/repack/%s.lproj/locale.pak' % (INT_DIR, locale.replace('-', '_')) | 50 return '%s/repack/%s.lproj/locale.pak' % (INT_DIR, locale.replace('-', '_')) |
49 else: | 51 else: |
50 return os.path.join(INT_DIR, 'repack', locale + '.pak') | 52 return os.path.join(INT_DIR, 'repack', locale + '.pak') |
51 | 53 |
52 | 54 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 inputs += calc_inputs(locale) | 126 inputs += calc_inputs(locale) |
125 output = calc_output(locale) | 127 output = calc_output(locale) |
126 data_pack.DataPack.RePack(output, inputs) | 128 data_pack.DataPack.RePack(output, inputs) |
127 | 129 |
128 | 130 |
129 def DoMain(argv): | 131 def DoMain(argv): |
130 global BRANDING | 132 global BRANDING |
131 global GRIT_DIR | 133 global GRIT_DIR |
132 global SHARE_INT_DIR | 134 global SHARE_INT_DIR |
133 global INT_DIR | 135 global INT_DIR |
| 136 global OS |
134 | 137 |
135 short_options = 'iog:s:x:b:h' | 138 short_options = 'iog:s:x:b:hp:' |
136 long_options = 'help' | 139 long_options = 'help' |
137 | 140 |
138 print_inputs = False | 141 print_inputs = False |
139 print_outputs = False | 142 print_outputs = False |
140 usage_msg = '' | 143 usage_msg = '' |
141 | 144 |
142 helpstr = """\ | 145 helpstr = """\ |
143 Usage: %s [-h] [-i | -o] -g <DIR> -x <DIR> -s <DIR> -b <branding> <locale> [...
] | 146 Usage: %s [-h] [-i | -o] -g <DIR> -x <DIR> -s <DIR> -b <branding> [-p <os>] |
| 147 <locale> [...] |
144 -h, --help Print this help, then exit. | 148 -h, --help Print this help, then exit. |
145 -i Print the expected input file list, then exit. | 149 -i Print the expected input file list, then exit. |
146 -o Print the expected output file list, then exit. | 150 -o Print the expected output file list, then exit. |
147 -g DIR GRIT build files output directory. | 151 -g DIR GRIT build files output directory. |
148 -x DIR Intermediate build files output directory. | 152 -x DIR Intermediate build files output directory. |
149 -s DIR Shared intermediate build files output directory. | 153 -s DIR Shared intermediate build files output directory. |
150 -b branding Branding type of this build. | 154 -b branding Branding type of this build. |
| 155 -p os The target os. (e.g. mac, linux, win, etc.) |
151 locale [...] One or more locales to repack.""" % ( | 156 locale [...] One or more locales to repack.""" % ( |
152 os.path.basename(__file__)) | 157 os.path.basename(__file__)) |
153 | 158 |
154 try: | 159 try: |
155 opts, locales = getopt.getopt(argv, short_options, long_options) | 160 opts, locales = getopt.getopt(argv, short_options, long_options) |
156 except getopt.GetoptError, msg: | 161 except getopt.GetoptError, msg: |
157 raise Usage(str(msg)) | 162 raise Usage(str(msg)) |
158 | 163 |
159 if not locales: | 164 if not locales: |
160 usage_msg = 'Please specificy at least one locale to process.\n' | 165 usage_msg = 'Please specificy at least one locale to process.\n' |
161 | 166 |
162 for o, a in opts: | 167 for o, a in opts: |
163 if o in ('-i'): | 168 if o == '-i': |
164 print_inputs = True | 169 print_inputs = True |
165 elif o in ('-o'): | 170 elif o == '-o': |
166 print_outputs = True | 171 print_outputs = True |
167 elif o in ('-g'): | 172 elif o == '-g': |
168 GRIT_DIR = a | 173 GRIT_DIR = a |
169 elif o in ('-s'): | 174 elif o == '-s': |
170 SHARE_INT_DIR = a | 175 SHARE_INT_DIR = a |
171 elif o in ('-x'): | 176 elif o == '-x': |
172 INT_DIR = a | 177 INT_DIR = a |
173 elif o in ('-b'): | 178 elif o == '-b': |
174 BRANDING = a | 179 BRANDING = a |
| 180 elif o == '-p': |
| 181 OS = a |
175 elif o in ('-h', '--help'): | 182 elif o in ('-h', '--help'): |
176 raise Usage(helpstr) | 183 raise Usage(helpstr) |
177 | 184 |
| 185 if not OS: |
| 186 if sys.platform == 'darwin': |
| 187 OS = 'mac' |
| 188 elif sys.platform.startswith('linux'): |
| 189 OS = 'linux' |
| 190 elif sys.platform in ('cygwin', 'win32'): |
| 191 OS = 'win' |
| 192 else: |
| 193 OS = sys.platform |
| 194 |
178 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): | 195 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): |
179 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' | 196 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' |
180 if print_inputs and print_outputs: | 197 if print_inputs and print_outputs: |
181 usage_msg += 'Please specify only one of "-i" or "-o".\n' | 198 usage_msg += 'Please specify only one of "-i" or "-o".\n' |
182 # Need to know the branding, unless we're just listing the outputs. | 199 # Need to know the branding, unless we're just listing the outputs. |
183 if not print_outputs and not BRANDING: | 200 if not print_outputs and not BRANDING: |
184 usage_msg += 'Please specify "-b" to determine the input files.\n' | 201 usage_msg += 'Please specify "-b" to determine the input files.\n' |
185 | 202 |
186 if usage_msg: | 203 if usage_msg: |
187 raise Usage(usage_msg) | 204 raise Usage(usage_msg) |
188 | 205 |
189 if print_inputs: | 206 if print_inputs: |
190 return list_inputs(locales) | 207 return list_inputs(locales) |
191 | 208 |
192 if print_outputs: | 209 if print_outputs: |
193 return list_outputs(locales) | 210 return list_outputs(locales) |
194 | 211 |
195 return repack_locales(locales) | 212 return repack_locales(locales) |
196 | 213 |
197 if __name__ == '__main__': | 214 if __name__ == '__main__': |
198 results = DoMain(sys.argv[1:]) | 215 results = DoMain(sys.argv[1:]) |
199 if results: | 216 if results: |
200 print results | 217 print results |
OLD | NEW |