Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Helper script to repack paks for a list of locales. | |
| 7 | |
| 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 | |
| 10 proliferation of mostly duplicate, cut-n-paste gyp actions. | |
| 11 """ | |
| 12 | |
| 13 import getopt | |
| 14 import os | |
| 15 import sys | |
| 16 | |
| 17 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..', '..', '..', | |
| 18 'tools', 'data_pack')) | |
| 19 import repack | |
| 20 | |
| 21 # The gyp "branding" variable. | |
| 22 BRANDING = None | |
| 23 | |
| 24 # Some build paths defined by gyp. | |
| 25 GRIT_DIR = None | |
| 26 SHARE_INT_DIR = None | |
| 27 INT_DIR = None | |
| 28 | |
| 29 | |
| 30 class Usage(Exception): | |
| 31 def __init__(self, msg): | |
| 32 self.msg = msg | |
| 33 | |
| 34 | |
| 35 def calc_output(locale): | |
| 36 """Determine the file that will be generated for the given locale.""" | |
| 37 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', | |
| 38 return '%s/repack/%s.pak' % (INT_DIR, locale) | |
| 39 | |
| 40 | |
| 41 def calc_inputs(locale): | |
| 42 """Determine the files that need processing for the given locale.""" | |
| 43 inputs = [] | |
| 44 | |
| 45 #e.g. '<(grit_out_dir)/generated_resources_da.pak' | |
| 46 inputs.append('%s/generated_resources_%s.pak' % (GRIT_DIR, locale)) | |
| 47 | |
| 48 #e.g. '<(grit_out_dir)/locale_settings_da.pak' | |
| 49 inputs.append('%s/locale_settings_%s.pak' % (GRIT_DIR, locale)) | |
| 50 | |
| 51 #e.g. '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_strings_da.pak' | |
| 52 inputs.append('%s/webkit/webkit_strings_%s.pak' % (SHARE_INT_DIR, locale)) | |
| 53 | |
| 54 #e.g. '<(grit_out_dir)/google_chrome_strings_da.pak' | |
| 55 # or | |
| 56 # '<(grit_out_dir)/chromium_strings_da.pak' | |
| 57 inputs.append('%s/%s_strings_%s.pak' % (GRIT_DIR, BRANDING, locale)) | |
| 58 | |
| 59 return inputs | |
| 60 | |
| 61 | |
| 62 def list_outputs(locales): | |
| 63 """Print the names of files that will be generated for the given locales. | |
| 64 | |
| 65 This is to provide gyp the list of output files, so build targets can | |
| 66 properly track what needs to be built. | |
| 67 """ | |
| 68 outputs = [] | |
| 69 for locale in locales: | |
| 70 outputs.append(calc_output(locale)) | |
| 71 # Quote each element so filename spaces don't mess up gyp's attempt to parse | |
| 72 # it into a list. | |
| 73 print " ".join(['"%s"' % x for x in outputs]) | |
| 74 | |
| 75 | |
| 76 def list_inputs(locales): | |
| 77 """Print the names of files that will be processed for the given locales. | |
| 78 | |
| 79 This is to provide gyp the list of input files, so build targets can properly | |
| 80 track their prerequisites. | |
| 81 """ | |
| 82 inputs = [] | |
| 83 for locale in locales: | |
| 84 inputs += calc_inputs(locale) | |
| 85 # Quote each element so filename spaces don't mess up gyp's attempt to parse | |
| 86 # it into a list. | |
| 87 print " ".join(['"%s"' % x for x in inputs]) | |
| 88 | |
| 89 | |
| 90 def repack_locales(locales): | |
| 91 """ Loop over and repack the given locales.""" | |
| 92 for locale in locales: | |
| 93 inputs = [] | |
| 94 inputs += calc_inputs(locale) | |
| 95 output = calc_output(locale) | |
| 96 print 'Repacking %s -> %s' % (inputs, output) | |
| 97 repack.RePack(output, inputs) | |
| 98 | |
| 99 | |
| 100 def main(argv=None): | |
| 101 global BRANDING | |
| 102 global GRIT_DIR | |
| 103 global SHARE_INT_DIR | |
| 104 global INT_DIR | |
| 105 | |
| 106 short_options = 'iog:s:x:b:h' | |
| 107 long_options = 'help' | |
| 108 | |
| 109 print_inputs = False | |
| 110 print_outputs = False | |
| 111 usage_msg = '' | |
| 112 | |
| 113 helpstr = """\ | |
| 114 Usage: %s [-h] [-i | -o] -g <DIR> -x <DIR> -s <DIR> -b <branding> <locale> [... ] | |
| 115 -h, --help Print this help, then exit. | |
| 116 -i Print the expected input file list, then exit. | |
| 117 -o Print the expected output file list, then exit. | |
| 118 -g DIR GRIT build files output directory. | |
| 119 -x DIR Intermediate build files output directory. | |
| 120 -s DIR Shared intermediate build files output directory. | |
| 121 -b branding Branding type of this build. | |
| 122 locale [...] One or more locales to repack.""" % (argv[0]) | |
| 123 | |
| 124 try: | |
| 125 try: | |
| 126 opts, locales = getopt.getopt(argv[1:], short_options, long_options) | |
|
sgk
2009/08/04 19:26:40
Not worth redoing this script (I know the structur
sgk
2009/08/04 19:26:40
argv[1:] will fail if the default argv=None value
| |
| 127 except getopt.GetoptError, msg: | |
| 128 raise Usage(str(msg)) | |
| 129 | |
| 130 if not locales: | |
| 131 usage_msg = 'Please specificy at least one locale to process.\n' | |
| 132 | |
| 133 for o, a in opts: | |
| 134 if o in ('-i'): | |
| 135 print_inputs = True | |
| 136 elif o in ('-o'): | |
| 137 print_outputs = True | |
| 138 elif o in ('-g'): | |
| 139 GRIT_DIR = a | |
| 140 elif o in ('-s'): | |
| 141 SHARE_INT_DIR = a | |
| 142 elif o in ('-x'): | |
| 143 INT_DIR = a | |
| 144 elif o in ('-b'): | |
| 145 BRANDING = a | |
| 146 elif o in ('-h', '--help'): | |
| 147 print helpstr | |
| 148 return 0 | |
| 149 | |
| 150 if not (GRIT_DIR and INT_DIR and SHARE_INT_DIR): | |
| 151 usage_msg += 'Please specify all of "-g" and "-x" and "-s".\n' | |
| 152 if print_inputs and print_outputs: | |
| 153 usage_msg += 'Please specify only one of "-i" or "-o".\n' | |
| 154 # Need to know the branding, unless we're just listing the outputs. | |
| 155 if not print_outputs and not BRANDING: | |
| 156 usage_msg += 'Please specify "-b" to determine the input files.\n' | |
| 157 | |
| 158 if usage_msg: | |
| 159 raise Usage(usage_msg) | |
| 160 except Usage, err: | |
| 161 sys.stderr.write(err.msg + '\n') | |
| 162 sys.stderr.write(helpstr + '\n') | |
| 163 return 2 | |
| 164 | |
| 165 if print_inputs: | |
| 166 list_inputs(locales) | |
| 167 return 0 | |
| 168 | |
| 169 if print_outputs: | |
| 170 list_outputs(locales) | |
| 171 return 0 | |
| 172 | |
| 173 repack_locales(locales) | |
| 174 | |
| 175 if __name__ == '__main__': | |
| 176 sys.exit(main(sys.argv)) | |
| OLD | NEW |