| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 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 optparse | |
| 14 import os | |
| 15 import sys | |
| 16 | |
| 17 # Prepend the grit module from the source tree so it takes precedence over other | |
| 18 # grit versions that might present in the search path. | |
| 19 sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..', '..', '..', | |
| 20 'tools', 'grit')) | |
| 21 from grit.format import data_pack | |
| 22 | |
| 23 # Some build paths defined by gyp. | |
| 24 GRIT_DIR = None | |
| 25 INT_DIR = None | |
| 26 CHROMECAST_BRANDING = None | |
| 27 | |
| 28 class Usage(Exception): | |
| 29 def __init__(self, msg): | |
| 30 self.msg = msg | |
| 31 | |
| 32 | |
| 33 def calc_output(locale): | |
| 34 """Determine the file that will be generated for the given locale.""" | |
| 35 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', | |
| 36 # For Fake Bidi, generate it at a fixed path so that tests can safely | |
| 37 # reference it. | |
| 38 if locale == 'fake-bidi': | |
| 39 return '%s/%s.pak' % (INT_DIR, locale) | |
| 40 return os.path.join(INT_DIR, locale + '.pak') | |
| 41 | |
| 42 | |
| 43 def calc_inputs(locale): | |
| 44 """Determine the files that need processing for the given locale.""" | |
| 45 inputs = [] | |
| 46 if CHROMECAST_BRANDING != 'public': | |
| 47 inputs.append(os.path.join(GRIT_DIR, 'app_strings_%s.pak' % locale)) | |
| 48 if CHROMECAST_WEBUI: | |
| 49 inputs.append(os.path.join(GRIT_DIR, 'webui_localized_%s.pak' % locale)) | |
| 50 inputs.append(os.path.join(GRIT_DIR, 'chromecast_settings_%s.pak' % locale)) | |
| 51 return inputs | |
| 52 | |
| 53 | |
| 54 def list_outputs(locales): | |
| 55 """Returns the names of files that will be generated for the given locales. | |
| 56 | |
| 57 This is to provide gyp the list of output files, so build targets can | |
| 58 properly track what needs to be built. | |
| 59 """ | |
| 60 outputs = [] | |
| 61 for locale in locales: | |
| 62 outputs.append(calc_output(locale)) | |
| 63 # Quote each element so filename spaces don't mess up gyp's attempt to parse | |
| 64 # it into a list. | |
| 65 return " ".join(['"%s"' % x for x in outputs]) | |
| 66 | |
| 67 | |
| 68 def list_inputs(locales): | |
| 69 """Returns the names of files that will be processed for the given locales. | |
| 70 | |
| 71 This is to provide gyp the list of input files, so build targets can properly | |
| 72 track their prerequisites. | |
| 73 """ | |
| 74 inputs = [] | |
| 75 for locale in locales: | |
| 76 inputs += calc_inputs(locale) | |
| 77 # Quote each element so filename spaces don't mess up gyp's attempt to parse | |
| 78 # it into a list. | |
| 79 return " ".join(['"%s"' % x for x in inputs]) | |
| 80 | |
| 81 | |
| 82 def repack_locales(locales): | |
| 83 """ Loop over and repack the given locales.""" | |
| 84 for locale in locales: | |
| 85 inputs = [] | |
| 86 inputs += calc_inputs(locale) | |
| 87 output = calc_output(locale) | |
| 88 data_pack.DataPack.RePack(output, inputs) | |
| 89 | |
| 90 | |
| 91 def DoMain(argv): | |
| 92 global CHROMECAST_BRANDING | |
| 93 global CHROMECAST_WEBUI | |
| 94 global GRIT_DIR | |
| 95 global INT_DIR | |
| 96 | |
| 97 parser = optparse.OptionParser("usage: %prog [options] locales") | |
| 98 parser.add_option("-i", action="store_true", dest="inputs", default=False, | |
| 99 help="Print the expected input file list, then exit.") | |
| 100 parser.add_option("-o", action="store_true", dest="outputs", default=False, | |
| 101 help="Print the expected output file list, then exit.") | |
| 102 parser.add_option("-g", action="store", dest="grit_dir", | |
| 103 help="GRIT build files output directory.") | |
| 104 parser.add_option("-x", action="store", dest="int_dir", | |
| 105 help="Intermediate build files output directory.") | |
| 106 parser.add_option("-b", action="store", dest="chromecast_branding", | |
| 107 help="Chromecast branding " + | |
| 108 "('public', 'internal' or 'google').") | |
| 109 parser.add_option("-u", action="store_true", dest="chromecast_webui", | |
| 110 default=False, | |
| 111 help="Include Chromecast webui related resources.") | |
| 112 options, locales = parser.parse_args(argv) | |
| 113 | |
| 114 if not locales: | |
| 115 parser.error('Please specificy at least one locale to process.\n') | |
| 116 | |
| 117 print_inputs = options.inputs | |
| 118 print_outputs = options.outputs | |
| 119 GRIT_DIR = options.grit_dir | |
| 120 INT_DIR = options.int_dir | |
| 121 CHROMECAST_BRANDING = options.chromecast_branding | |
| 122 CHROMECAST_WEBUI = options.chromecast_webui | |
| 123 | |
| 124 if (CHROMECAST_BRANDING != 'public' and | |
| 125 CHROMECAST_BRANDING != 'internal' and | |
| 126 CHROMECAST_BRANDING != 'google'): | |
| 127 parser.error('Chromecast branding (-b) must be ' + | |
| 128 '"public", "internal" or "google".\n') | |
| 129 if not (GRIT_DIR and INT_DIR): | |
| 130 parser.error('Please specify all of "-g" and "-x".\n') | |
| 131 if print_inputs and print_outputs: | |
| 132 parser.error('Please specify only one of "-i" or "-o".\n') | |
| 133 | |
| 134 if print_inputs: | |
| 135 return list_inputs(locales) | |
| 136 | |
| 137 if print_outputs: | |
| 138 return list_outputs(locales) | |
| 139 | |
| 140 return repack_locales(locales) | |
| 141 | |
| 142 if __name__ == '__main__': | |
| 143 results = DoMain(sys.argv[1:]) | |
| 144 if results: | |
| 145 print results | |
| OLD | NEW |