| 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. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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. | 29 # The target platform. If it is not defined, sys.platform will be used. |
| 30 OS = None | 30 OS = None |
| 31 | 31 |
| 32 USE_ASH = False | 32 USE_ASH = False |
| 33 | 33 |
| 34 WHITELIST = None |
| 35 |
| 34 # Extra input files. | 36 # Extra input files. |
| 35 EXTRA_INPUT_FILES = [] | 37 EXTRA_INPUT_FILES = [] |
| 36 | 38 |
| 37 class Usage(Exception): | 39 class Usage(Exception): |
| 38 def __init__(self, msg): | 40 def __init__(self, msg): |
| 39 self.msg = msg | 41 self.msg = msg |
| 40 | 42 |
| 41 | 43 |
| 42 def calc_output(locale): | 44 def calc_output(locale): |
| 43 """Determine the file that will be generated for the given locale.""" | 45 """Determine the file that will be generated for the given locale.""" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 # it into a list. | 148 # it into a list. |
| 147 return " ".join(['"%s"' % x for x in inputs]) | 149 return " ".join(['"%s"' % x for x in inputs]) |
| 148 | 150 |
| 149 | 151 |
| 150 def repack_locales(locales): | 152 def repack_locales(locales): |
| 151 """ Loop over and repack the given locales.""" | 153 """ Loop over and repack the given locales.""" |
| 152 for locale in locales: | 154 for locale in locales: |
| 153 inputs = [] | 155 inputs = [] |
| 154 inputs += calc_inputs(locale) | 156 inputs += calc_inputs(locale) |
| 155 output = calc_output(locale) | 157 output = calc_output(locale) |
| 156 data_pack.DataPack.RePack(output, inputs) | 158 data_pack.DataPack.RePack(output, inputs, whitelist_file=WHITELIST) |
| 157 | 159 |
| 158 | 160 |
| 159 def DoMain(argv): | 161 def DoMain(argv): |
| 160 global BRANDING | 162 global BRANDING |
| 161 global GRIT_DIR | 163 global GRIT_DIR |
| 162 global SHARE_INT_DIR | 164 global SHARE_INT_DIR |
| 163 global INT_DIR | 165 global INT_DIR |
| 164 global OS | 166 global OS |
| 165 global USE_ASH | 167 global USE_ASH |
| 168 global WHITELIST |
| 166 global EXTRA_INPUT_FILES | 169 global EXTRA_INPUT_FILES |
| 167 | 170 |
| 168 parser = optparse.OptionParser("usage: %prog [options] locales") | 171 parser = optparse.OptionParser("usage: %prog [options] locales") |
| 169 parser.add_option("-i", action="store_true", dest="inputs", default=False, | 172 parser.add_option("-i", action="store_true", dest="inputs", default=False, |
| 170 help="Print the expected input file list, then exit.") | 173 help="Print the expected input file list, then exit.") |
| 171 parser.add_option("-o", action="store_true", dest="outputs", default=False, | 174 parser.add_option("-o", action="store_true", dest="outputs", default=False, |
| 172 help="Print the expected output file list, then exit.") | 175 help="Print the expected output file list, then exit.") |
| 173 parser.add_option("-g", action="store", dest="grit_dir", | 176 parser.add_option("-g", action="store", dest="grit_dir", |
| 174 help="GRIT build files output directory.") | 177 help="GRIT build files output directory.") |
| 175 parser.add_option("-x", action="store", dest="int_dir", | 178 parser.add_option("-x", action="store", dest="int_dir", |
| 176 help="Intermediate build files output directory.") | 179 help="Intermediate build files output directory.") |
| 177 parser.add_option("-s", action="store", dest="share_int_dir", | 180 parser.add_option("-s", action="store", dest="share_int_dir", |
| 178 help="Shared intermediate build files output directory.") | 181 help="Shared intermediate build files output directory.") |
| 179 parser.add_option("-b", action="store", dest="branding", | 182 parser.add_option("-b", action="store", dest="branding", |
| 180 help="Branding type of this build.") | 183 help="Branding type of this build.") |
| 181 parser.add_option("-e", action="append", dest="extra_input", default=[], | 184 parser.add_option("-e", action="append", dest="extra_input", default=[], |
| 182 help="Full path to an extra input pak file without the\ | 185 help="Full path to an extra input pak file without the\ |
| 183 locale suffix and \".pak\" extension.") | 186 locale suffix and \".pak\" extension.") |
| 184 parser.add_option("-p", action="store", dest="os", | 187 parser.add_option("-p", action="store", dest="os", |
| 185 help="The target OS. (e.g. mac, linux, win, etc.)") | 188 help="The target OS. (e.g. mac, linux, win, etc.)") |
| 186 parser.add_option("--use-ash", action="store", dest="use_ash", | 189 parser.add_option("--use-ash", action="store", dest="use_ash", |
| 187 help="Whether to include ash strings") | 190 help="Whether to include ash strings") |
| 191 parser.add_option("--whitelist", action="store", help="Full path to the " |
| 192 "whitelist used to filter output pak file resource IDs") |
| 188 options, locales = parser.parse_args(argv) | 193 options, locales = parser.parse_args(argv) |
| 189 | 194 |
| 190 if not locales: | 195 if not locales: |
| 191 parser.error('Please specificy at least one locale to process.\n') | 196 parser.error('Please specificy at least one locale to process.\n') |
| 192 | 197 |
| 193 print_inputs = options.inputs | 198 print_inputs = options.inputs |
| 194 print_outputs = options.outputs | 199 print_outputs = options.outputs |
| 195 GRIT_DIR = options.grit_dir | 200 GRIT_DIR = options.grit_dir |
| 196 INT_DIR = options.int_dir | 201 INT_DIR = options.int_dir |
| 197 SHARE_INT_DIR = options.share_int_dir | 202 SHARE_INT_DIR = options.share_int_dir |
| 198 BRANDING = options.branding | 203 BRANDING = options.branding |
| 199 EXTRA_INPUT_FILES = options.extra_input | 204 EXTRA_INPUT_FILES = options.extra_input |
| 200 OS = options.os | 205 OS = options.os |
| 201 USE_ASH = options.use_ash == '1' | 206 USE_ASH = options.use_ash == '1' |
| 207 WHITELIST = options.whitelist |
| 202 | 208 |
| 203 if not OS: | 209 if not OS: |
| 204 if sys.platform == 'darwin': | 210 if sys.platform == 'darwin': |
| 205 OS = 'mac' | 211 OS = 'mac' |
| 206 elif sys.platform.startswith('linux'): | 212 elif sys.platform.startswith('linux'): |
| 207 OS = 'linux' | 213 OS = 'linux' |
| 208 elif sys.platform in ('cygwin', 'win32'): | 214 elif sys.platform in ('cygwin', 'win32'): |
| 209 OS = 'win' | 215 OS = 'win' |
| 210 else: | 216 else: |
| 211 OS = sys.platform | 217 OS = sys.platform |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 | 229 |
| 224 if print_outputs: | 230 if print_outputs: |
| 225 return list_outputs(locales) | 231 return list_outputs(locales) |
| 226 | 232 |
| 227 return repack_locales(locales) | 233 return repack_locales(locales) |
| 228 | 234 |
| 229 if __name__ == '__main__': | 235 if __name__ == '__main__': |
| 230 results = DoMain(sys.argv[1:]) | 236 results = DoMain(sys.argv[1:]) |
| 231 if results: | 237 if results: |
| 232 print results | 238 print results |
| OLD | NEW |