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

Side by Side Diff: chrome/tools/build/repack_locales.py

Issue 7648001: Enable the packed_resources target on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
« chrome/chrome.gyp ('K') | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 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(sys.argv[0]), '..', '..', '..', 17 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..',
18 'tools', 'data_pack')) 18 'tools', 'data_pack'))
19 import repack 19 import repack
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
(...skipping 12 matching lines...) Expand all
40 if locale == 'fake-bidi': 40 if locale == 'fake-bidi':
41 return '%s/%s.pak' % (INT_DIR, locale) 41 return '%s/%s.pak' % (INT_DIR, locale)
42 if sys.platform in ('darwin',): 42 if sys.platform in ('darwin',):
43 # For Cocoa to find the locale at runtime, it needs to use '_' instead 43 # 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 44 # of '-' (http://crbug.com/20441). Also, 'en-US' should be represented
45 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578). 45 # simply as 'en' (http://crbug.com/19165, http://crbug.com/25578).
46 if locale == 'en-US': 46 if locale == 'en-US':
47 locale = 'en' 47 locale = 'en'
48 return '%s/repack/%s.lproj/locale.pak' % (INT_DIR, locale.replace('-', '_')) 48 return '%s/repack/%s.lproj/locale.pak' % (INT_DIR, locale.replace('-', '_'))
49 else: 49 else:
50 return '%s/repack/%s.pak' % (INT_DIR, locale) 50 return os.path.join(INT_DIR, 'repack', locale + '.pak')
51 51
52 52
53 def calc_inputs(locale): 53 def calc_inputs(locale):
54 """Determine the files that need processing for the given locale.""" 54 """Determine the files that need processing for the given locale."""
55 inputs = [] 55 inputs = []
56 56
57 #e.g. '<(grit_out_dir)/generated_resources_da.pak' 57 #e.g. '<(grit_out_dir)/generated_resources_da.pak'
58 inputs.append('%s/generated_resources_%s.pak' % (GRIT_DIR, locale)) 58 inputs.append(os.path.join(GRIT_DIR, 'generated_resources_%s.pak' % locale))
59 59
60 #e.g. '<(grit_out_dir)/locale_settings_da.pak' 60 #e.g. '<(grit_out_dir)/locale_settings_da.pak'
61 inputs.append('%s/locale_settings_%s.pak' % (GRIT_DIR, locale)) 61 inputs.append(os.path.join(GRIT_DIR, 'locale_settings_%s.pak' % locale))
62 62
63 #e.g. '<(grit_out_dir)/platform_locale_settings_da.pak' 63 #e.g. '<(grit_out_dir)/platform_locale_settings_da.pak'
64 inputs.append('%s/platform_locale_settings_%s.pak' % (GRIT_DIR, locale)) 64 inputs.append(os.path.join(GRIT_DIR,
65 'platform_locale_settings_%s.pak' % locale))
65 66
66 #e.g. '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_da.pak' 67 #e.g. '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_da.pak'
67 inputs.append('%s/webkit/webkit_strings_%s.pak' % (SHARE_INT_DIR, locale)) 68 inputs.append(os.path.join(SHARE_INT_DIR, 'webkit',
69 'webkit_strings_%s.pak' % locale))
68 70
69 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/ui_strings_da.pak', 71 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/ui_strings_da.pak',
70 inputs.append('%s/ui/ui_strings/ui_strings_%s.pak' % ( 72 inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'ui_strings',
71 SHARE_INT_DIR, locale)) 73 'ui_strings_%s.pak' % locale))
72 74
73 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/app_locale_settings_da.pak', 75 #e.g. '<(SHARED_INTERMEDIATE_DIR)/ui/app_locale_settings_da.pak',
74 inputs.append('%s/ui/app_locale_settings/app_locale_settings_%s.pak' % ( 76 inputs.append(os.path.join(SHARE_INT_DIR, 'ui', 'app_locale_settings',
75 SHARE_INT_DIR, locale)) 77 'app_locale_settings_%s.pak' % locale))
76 78
77 #e.g. '<(grit_out_dir)/google_chrome_strings_da.pak' 79 #e.g. '<(grit_out_dir)/google_chrome_strings_da.pak'
78 # or 80 # or
79 # '<(grit_out_dir)/chromium_strings_da.pak' 81 # '<(grit_out_dir)/chromium_strings_da.pak'
80 inputs.append('%s/%s_strings_%s.pak' % (GRIT_DIR, BRANDING, locale)) 82 inputs.append(os.path.join(
83 GRIT_DIR, '%s_strings_%s.pak' % (BRANDING, locale)))
81 84
82 return inputs 85 return inputs
83 86
84 87
85 def list_outputs(locales): 88 def list_outputs(locales):
86 """Print the names of files that will be generated for the given locales. 89 """Returns the names of files that will be generated for the given locales.
87 90
88 This is to provide gyp the list of output files, so build targets can 91 This is to provide gyp the list of output files, so build targets can
89 properly track what needs to be built. 92 properly track what needs to be built.
90 """ 93 """
91 outputs = [] 94 outputs = []
92 for locale in locales: 95 for locale in locales:
93 outputs.append(calc_output(locale)) 96 outputs.append(calc_output(locale))
94 # Quote each element so filename spaces don't mess up gyp's attempt to parse 97 # Quote each element so filename spaces don't mess up gyp's attempt to parse
95 # it into a list. 98 # it into a list.
96 print " ".join(['"%s"' % x for x in outputs]) 99 return " ".join(['"%s"' % x for x in outputs])
97 100
98 101
99 def list_inputs(locales): 102 def list_inputs(locales):
100 """Print the names of files that will be processed for the given locales. 103 """Returns the names of files that will be processed for the given locales.
101 104
102 This is to provide gyp the list of input files, so build targets can properly 105 This is to provide gyp the list of input files, so build targets can properly
103 track their prerequisites. 106 track their prerequisites.
104 """ 107 """
105 inputs = [] 108 inputs = []
106 for locale in locales: 109 for locale in locales:
107 inputs += calc_inputs(locale) 110 inputs += calc_inputs(locale)
108 # Quote each element so filename spaces don't mess up gyp's attempt to parse 111 # Quote each element so filename spaces don't mess up gyp's attempt to parse
109 # it into a list. 112 # it into a list.
110 print " ".join(['"%s"' % x for x in inputs]) 113 return " ".join(['"%s"' % x for x in inputs])
111 114
112 115
113 def repack_locales(locales): 116 def repack_locales(locales):
114 """ Loop over and repack the given locales.""" 117 """ Loop over and repack the given locales."""
115 for locale in locales: 118 for locale in locales:
116 inputs = [] 119 inputs = []
117 inputs += calc_inputs(locale) 120 inputs += calc_inputs(locale)
118 output = calc_output(locale) 121 output = calc_output(locale)
119 repack.RePack(output, inputs) 122 repack.RePack(output, inputs)
120 123
121 124
122 def main(argv=None): 125 def DoMain(argv):
123 global BRANDING 126 global BRANDING
124 global GRIT_DIR 127 global GRIT_DIR
125 global SHARE_INT_DIR 128 global SHARE_INT_DIR
126 global INT_DIR 129 global INT_DIR
127 130
128 if argv is None:
129 argv = sys.argv
130
131 short_options = 'iog:s:x:b:h' 131 short_options = 'iog:s:x:b:h'
132 long_options = 'help' 132 long_options = 'help'
133 133
134 print_inputs = False 134 print_inputs = False
135 print_outputs = False 135 print_outputs = False
136 usage_msg = '' 136 usage_msg = ''
137 137
138 helpstr = """\ 138 helpstr = """\
139 Usage: %s [-h] [-i | -o] -g <DIR> -x <DIR> -s <DIR> -b <branding> <locale> [... ] 139 Usage: %s [-h] [-i | -o] -g <DIR> -x <DIR> -s <DIR> -b <branding> <locale> [... ]
140 -h, --help Print this help, then exit. 140 -h, --help Print this help, then exit.
141 -i Print the expected input file list, then exit. 141 -i Print the expected input file list, then exit.
142 -o Print the expected output file list, then exit. 142 -o Print the expected output file list, then exit.
143 -g DIR GRIT build files output directory. 143 -g DIR GRIT build files output directory.
144 -x DIR Intermediate build files output directory. 144 -x DIR Intermediate build files output directory.
145 -s DIR Shared intermediate build files output directory. 145 -s DIR Shared intermediate build files output directory.
146 -b branding Branding type of this build. 146 -b branding Branding type of this build.
147 locale [...] One or more locales to repack.""" % (argv[0]) 147 locale [...] One or more locales to repack.""" % (
148 os.path.basename(__file__))
148 149
149 try: 150 try:
150 try: 151 opts, locales = getopt.getopt(argv, short_options, long_options)
151 opts, locales = getopt.getopt(argv[1:], short_options, long_options) 152 except getopt.GetoptError, msg:
152 except getopt.GetoptError, msg: 153 raise Usage(str(msg))
153 raise Usage(str(msg))
154 154
155 if not locales: 155 if not locales:
156 usage_msg = 'Please specificy at least one locale to process.\n' 156 usage_msg = 'Please specificy at least one locale to process.\n'
157 157
158 for o, a in opts: 158 for o, a in opts:
159 if o in ('-i'): 159 if o in ('-i'):
160 print_inputs = True 160 print_inputs = True
161 elif o in ('-o'): 161 elif o in ('-o'):
162 print_outputs = True 162 print_outputs = True
163 elif o in ('-g'): 163 elif o in ('-g'):
164 GRIT_DIR = a 164 GRIT_DIR = a
165 elif o in ('-s'): 165 elif o in ('-s'):
166 SHARE_INT_DIR = a 166 SHARE_INT_DIR = a
167 elif o in ('-x'): 167 elif o in ('-x'):
168 INT_DIR = a 168 INT_DIR = a
169 elif o in ('-b'): 169 elif o in ('-b'):
170 BRANDING = a 170 BRANDING = a
171 elif o in ('-h', '--help'): 171 elif o in ('-h', '--help'):
172 print helpstr 172 raise Usage(helpstr)
173 return 0
174 173
175 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): 174 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR):
176 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' 175 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n'
177 if print_inputs and print_outputs: 176 if print_inputs and print_outputs:
178 usage_msg += 'Please specify only one of "-i" or "-o".\n' 177 usage_msg += 'Please specify only one of "-i" or "-o".\n'
179 # Need to know the branding, unless we're just listing the outputs. 178 # Need to know the branding, unless we're just listing the outputs.
180 if not print_outputs and not BRANDING: 179 if not print_outputs and not BRANDING:
181 usage_msg += 'Please specify "-b" to determine the input files.\n' 180 usage_msg += 'Please specify "-b" to determine the input files.\n'
182 181
183 if usage_msg: 182 if usage_msg:
184 raise Usage(usage_msg) 183 raise Usage(usage_msg)
185 except Usage, err:
186 sys.stderr.write(err.msg + '\n')
187 sys.stderr.write(helpstr + '\n')
188 return 2
189 184
190 if print_inputs: 185 if print_inputs:
191 list_inputs(locales) 186 return list_inputs(locales)
192 return 0
193 187
194 if print_outputs: 188 if print_outputs:
195 list_outputs(locales) 189 return list_outputs(locales)
196 return 0
197 190
198 repack_locales(locales) 191 return repack_locales(locales)
199 192
200 if __name__ == '__main__': 193 if __name__ == '__main__':
201 sys.exit(main(sys.argv)) 194 results = DoMain(sys.argv[1:])
195 if results:
196 print results
OLDNEW
« chrome/chrome.gyp ('K') | « chrome/chrome.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698