OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 optparse | 13 import optparse |
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 # Some build paths defined by gyp. | 21 # Some build paths defined by gyp. |
22 GRIT_DIR = None | 22 GRIT_DIR = None |
23 INT_DIR = None | 23 INT_DIR = None |
24 | 24 CHROMECAST_BRANDING = None |
25 # The target platform. If it is not defined, sys.platform will be used. | |
26 OS = None | |
27 | |
28 # Extra input files. | |
29 EXTRA_INPUT_FILES = [] | |
30 | 25 |
31 class Usage(Exception): | 26 class Usage(Exception): |
32 def __init__(self, msg): | 27 def __init__(self, msg): |
33 self.msg = msg | 28 self.msg = msg |
34 | 29 |
35 | 30 |
36 def calc_output(locale): | 31 def calc_output(locale): |
37 """Determine the file that will be generated for the given locale.""" | 32 """Determine the file that will be generated for the given locale.""" |
38 #e.g. '<(INTERMEDIATE_DIR)/remoting_locales/da.pak', | 33 #e.g. '<(INTERMEDIATE_DIR)/repack/da.pak', |
39 if OS == 'mac' or OS == 'ios': | 34 # For Fake Bidi, generate it at a fixed path so that tests can safely |
40 # For Cocoa to find the locale at runtime, it needs to use '_' instead | 35 # reference it. |
41 # of '-' (http://crbug.com/20441). | 36 if locale == 'fake-bidi': |
42 return os.path.join(INT_DIR, 'remoting', 'resources', | 37 return '%s/%s.pak' % (INT_DIR, locale) |
43 '%s.lproj' % locale.replace('-', '_'), 'locale.pak') | 38 return os.path.join(INT_DIR, locale + '.pak') |
44 else: | |
45 return os.path.join(INT_DIR, 'remoting_locales', locale + '.pak') | |
46 | 39 |
47 | 40 |
48 def calc_inputs(locale): | 41 def calc_inputs(locale): |
49 """Determine the files that need processing for the given locale.""" | 42 """Determine the files that need processing for the given locale.""" |
50 inputs = [] | 43 inputs = [] |
51 | 44 if CHROMECAST_BRANDING == 'Chrome': |
52 #e.g. '<(grit_out_dir)/remoting/resources/da.pak' | 45 inputs.append(os.path.join(GRIT_DIR, 'app_strings_%s.pak' % locale)) |
53 inputs.append(os.path.join(GRIT_DIR, 'remoting/resources/%s.pak' % locale)) | 46 inputs.append(os.path.join(GRIT_DIR, 'chromecast_settings_%s.pak' % locale)) |
54 | |
55 # Add any extra input files. | |
56 for extra_file in EXTRA_INPUT_FILES: | |
57 inputs.append('%s_%s.pak' % (extra_file, locale)) | |
58 | |
59 return inputs | 47 return inputs |
60 | 48 |
61 | 49 |
62 def list_outputs(locales): | 50 def list_outputs(locales): |
63 """Returns the names of files that will be generated for the given locales. | 51 """Returns the names of files that will be generated for the given locales. |
64 | 52 |
65 This is to provide gyp the list of output files, so build targets can | 53 This is to provide gyp the list of output files, so build targets can |
66 properly track what needs to be built. | 54 properly track what needs to be built. |
67 """ | 55 """ |
68 outputs = [] | 56 outputs = [] |
(...skipping 14 matching lines...) Expand all Loading... | |
83 for locale in locales: | 71 for locale in locales: |
84 inputs += calc_inputs(locale) | 72 inputs += calc_inputs(locale) |
85 # Quote each element so filename spaces don't mess up gyp's attempt to parse | 73 # Quote each element so filename spaces don't mess up gyp's attempt to parse |
86 # it into a list. | 74 # it into a list. |
87 return " ".join(['"%s"' % x for x in inputs]) | 75 return " ".join(['"%s"' % x for x in inputs]) |
88 | 76 |
89 | 77 |
90 def repack_locales(locales): | 78 def repack_locales(locales): |
91 """ Loop over and repack the given locales.""" | 79 """ Loop over and repack the given locales.""" |
92 for locale in locales: | 80 for locale in locales: |
93 inputs = calc_inputs(locale) | 81 inputs = [] |
82 inputs += calc_inputs(locale) | |
94 output = calc_output(locale) | 83 output = calc_output(locale) |
95 data_pack.DataPack.RePack(output, inputs) | 84 data_pack.DataPack.RePack(output, inputs) |
96 | 85 |
97 | 86 |
98 def DoMain(argv): | 87 def DoMain(argv): |
88 global CHROMECAST_BRANDING | |
99 global GRIT_DIR | 89 global GRIT_DIR |
100 global INT_DIR | 90 global INT_DIR |
101 global OS | |
102 global EXTRA_INPUT_FILES | |
103 | 91 |
104 parser = optparse.OptionParser("usage: %prog [options] locales") | 92 parser = optparse.OptionParser("usage: %prog [options] locales") |
105 parser.add_option("-i", action="store_true", dest="inputs", default=False, | 93 parser.add_option("-i", action="store_true", dest="inputs", default=False, |
106 help="Print the expected input file list, then exit.") | 94 help="Print the expected input file list, then exit.") |
107 parser.add_option("-o", action="store_true", dest="outputs", default=False, | 95 parser.add_option("-o", action="store_true", dest="outputs", default=False, |
108 help="Print the expected output file list, then exit.") | 96 help="Print the expected output file list, then exit.") |
109 parser.add_option("-g", action="store", dest="grit_dir", | 97 parser.add_option("-g", action="store", dest="grit_dir", |
110 help="GRIT build files output directory.") | 98 help="GRIT build files output directory.") |
111 parser.add_option("-x", action="store", dest="int_dir", | 99 parser.add_option("-x", action="store", dest="int_dir", |
112 help="Intermediate build files output directory.") | 100 help="Intermediate build files output directory.") |
113 parser.add_option("-e", action="append", dest="extra_input", default=[], | 101 parser.add_option("-b", action="store", dest="chromecast_branding", |
114 help="Full path to an extra input pak file without the\ | 102 help="Chromecast branding ('Chrome' or 'Chromium').") |
115 locale suffix and \".pak\" extension.") | |
116 parser.add_option("-p", action="store", dest="os", | |
117 help="The target OS. (e.g. mac, linux, win, etc.)") | |
118 options, locales = parser.parse_args(argv) | 103 options, locales = parser.parse_args(argv) |
119 | 104 |
120 if not locales: | 105 if not locales: |
121 parser.error('Please specificy at least one locale to process.\n') | 106 parser.error('Please specificy at least one locale to process.\n') |
122 | 107 |
123 print_inputs = options.inputs | 108 print_inputs = options.inputs |
124 print_outputs = options.outputs | 109 print_outputs = options.outputs |
125 GRIT_DIR = options.grit_dir | 110 GRIT_DIR = options.grit_dir |
126 INT_DIR = options.int_dir | 111 INT_DIR = options.int_dir |
127 EXTRA_INPUT_FILES = options.extra_input | 112 CHROMECAST_BRANDING = options.chromecast_branding |
byungchul
2014/08/14 20:34:11
check if CHROMECAST_BRANDING is Chrome or Chromium
gunsch
2014/08/15 00:04:28
Done.
| |
128 OS = options.os | |
129 | 113 |
130 if not OS: | 114 if not (GRIT_DIR and INT_DIR): |
131 if sys.platform == 'darwin': | 115 parser.error('Please specify all of "-g" and "-x".\n') |
132 OS = 'mac' | |
133 elif sys.platform.startswith('linux'): | |
134 OS = 'linux' | |
135 elif sys.platform in ('cygwin', 'win32'): | |
136 OS = 'win' | |
137 else: | |
138 OS = sys.platform | |
139 | |
140 if print_inputs and print_outputs: | 116 if print_inputs and print_outputs: |
141 parser.error('Please specify only one of "-i" or "-o".\n') | 117 parser.error('Please specify only one of "-i" or "-o".\n') |
142 if print_inputs and not GRIT_DIR: | |
143 parser.error('Please specify "-g".\n') | |
144 if print_outputs and not INT_DIR: | |
145 parser.error('Please specify "-x".\n') | |
146 if not (print_inputs or print_outputs or (GRIT_DIR and INT_DIR)): | |
147 parser.error('Please specify both "-g" and "-x".\n') | |
148 | 118 |
149 if print_inputs: | 119 if print_inputs: |
150 return list_inputs(locales) | 120 return list_inputs(locales) |
151 | 121 |
152 if print_outputs: | 122 if print_outputs: |
153 return list_outputs(locales) | 123 return list_outputs(locales) |
154 | 124 |
155 return repack_locales(locales) | 125 return repack_locales(locales) |
156 | 126 |
157 if __name__ == '__main__': | 127 if __name__ == '__main__': |
158 results = DoMain(sys.argv[1:]) | 128 results = DoMain(sys.argv[1:]) |
159 if results: | 129 if results: |
160 print results | 130 print results |
OLD | NEW |