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 PLATFORM = None | |
tony
2012/07/31 16:47:00
I would call this OS since we call it OS in the gy
newt (away)
2012/07/31 21:13:54
Done.
| |
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 PLATFORM == 'mac' or (PLATFORM == None and sys.platform in ('darwin',)): |
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 PLATFORM | |
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 <platform >] <locale> [...] |
144 -h, --help Print this help, then exit. | 147 -h, --help Print this help, then exit. |
145 -i Print the expected input file list, then exit. | 148 -i Print the expected input file list, then exit. |
146 -o Print the expected output file list, then exit. | 149 -o Print the expected output file list, then exit. |
147 -g DIR GRIT build files output directory. | 150 -g DIR GRIT build files output directory. |
148 -x DIR Intermediate build files output directory. | 151 -x DIR Intermediate build files output directory. |
149 -s DIR Shared intermediate build files output directory. | 152 -s DIR Shared intermediate build files output directory. |
150 -b branding Branding type of this build. | 153 -b branding Branding type of this build. |
154 -p platform The target platform. (e.g. mac, linux, win and etc.) | |
tony
2012/07/31 16:47:00
Nit: os
newt (away)
2012/07/31 21:13:54
Done.
| |
151 locale [...] One or more locales to repack.""" % ( | 155 locale [...] One or more locales to repack.""" % ( |
152 os.path.basename(__file__)) | 156 os.path.basename(__file__)) |
153 | 157 |
154 try: | 158 try: |
155 opts, locales = getopt.getopt(argv, short_options, long_options) | 159 opts, locales = getopt.getopt(argv, short_options, long_options) |
156 except getopt.GetoptError, msg: | 160 except getopt.GetoptError, msg: |
157 raise Usage(str(msg)) | 161 raise Usage(str(msg)) |
158 | 162 |
159 if not locales: | 163 if not locales: |
160 usage_msg = 'Please specificy at least one locale to process.\n' | 164 usage_msg = 'Please specificy at least one locale to process.\n' |
161 | 165 |
162 for o, a in opts: | 166 for o, a in opts: |
163 if o in ('-i'): | 167 if o in ('-i'): |
164 print_inputs = True | 168 print_inputs = True |
165 elif o in ('-o'): | 169 elif o in ('-o'): |
166 print_outputs = True | 170 print_outputs = True |
167 elif o in ('-g'): | 171 elif o in ('-g'): |
168 GRIT_DIR = a | 172 GRIT_DIR = a |
169 elif o in ('-s'): | 173 elif o in ('-s'): |
170 SHARE_INT_DIR = a | 174 SHARE_INT_DIR = a |
171 elif o in ('-x'): | 175 elif o in ('-x'): |
172 INT_DIR = a | 176 INT_DIR = a |
173 elif o in ('-b'): | 177 elif o in ('-b'): |
174 BRANDING = a | 178 BRANDING = a |
179 elif o in ('-p'): | |
tony
2012/07/31 16:47:00
Hmm, the use of 'in' here happens to work, but it'
newt (away)
2012/07/31 21:13:54
I figured I might as well fix these.
| |
180 PLATFORM = a | |
175 elif o in ('-h', '--help'): | 181 elif o in ('-h', '--help'): |
176 raise Usage(helpstr) | 182 raise Usage(helpstr) |
177 | 183 |
tony
2012/07/31 16:47:00
I would probably normalize OS around here. E.g.,
newt (away)
2012/07/31 21:13:54
Done. This is much cleaner.
| |
178 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): | 184 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): |
179 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' | 185 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' |
180 if print_inputs and print_outputs: | 186 if print_inputs and print_outputs: |
181 usage_msg += 'Please specify only one of "-i" or "-o".\n' | 187 usage_msg += 'Please specify only one of "-i" or "-o".\n' |
182 # Need to know the branding, unless we're just listing the outputs. | 188 # Need to know the branding, unless we're just listing the outputs. |
183 if not print_outputs and not BRANDING: | 189 if not print_outputs and not BRANDING: |
184 usage_msg += 'Please specify "-b" to determine the input files.\n' | 190 usage_msg += 'Please specify "-b" to determine the input files.\n' |
185 | 191 |
186 if usage_msg: | 192 if usage_msg: |
187 raise Usage(usage_msg) | 193 raise Usage(usage_msg) |
188 | 194 |
189 if print_inputs: | 195 if print_inputs: |
190 return list_inputs(locales) | 196 return list_inputs(locales) |
191 | 197 |
192 if print_outputs: | 198 if print_outputs: |
193 return list_outputs(locales) | 199 return list_outputs(locales) |
194 | 200 |
195 return repack_locales(locales) | 201 return repack_locales(locales) |
196 | 202 |
197 if __name__ == '__main__': | 203 if __name__ == '__main__': |
198 results = DoMain(sys.argv[1:]) | 204 results = DoMain(sys.argv[1:]) |
199 if results: | 205 if results: |
200 print results | 206 print results |
OLD | NEW |