OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2014 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 import json | 6 import json |
7 import logging | 7 import logging |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import re | 10 import re |
11 import shutil | 11 import shutil |
| 12 import subprocess |
12 import sys | 13 import sys |
13 | 14 |
14 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' | 15 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' |
15 require_regex = re.compile(_BASE_REGEX_STRING % 'require') | 16 require_regex = re.compile(_BASE_REGEX_STRING % 'require') |
16 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') | 17 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') |
17 | 18 |
18 preamble = [ | 19 preamble = [ |
19 '# Copyright 2014 The Chromium Authors. All rights reserved.', | 20 '# Copyright 2014 The Chromium Authors. All rights reserved.', |
20 '# Use of this source code is governed by a BSD-style license that can be', | 21 '# Use of this source code is governed by a BSD-style license that can be', |
21 '# found in the LICENSE file.', | 22 '# found in the LICENSE file.', |
(...skipping 14 matching lines...) Expand all Loading... |
36 'i18n.input.chrome.inputview.EmojiType', | 37 'i18n.input.chrome.inputview.EmojiType', |
37 'i18n.input.chrome.inputview.layouts.CompactSpaceRow', | 38 'i18n.input.chrome.inputview.layouts.CompactSpaceRow', |
38 'i18n.input.chrome.inputview.layouts.RowsOf101', | 39 'i18n.input.chrome.inputview.layouts.RowsOf101', |
39 'i18n.input.chrome.inputview.layouts.RowsOf102', | 40 'i18n.input.chrome.inputview.layouts.RowsOf102', |
40 'i18n.input.chrome.inputview.layouts.RowsOfCompact', | 41 'i18n.input.chrome.inputview.layouts.RowsOfCompact', |
41 'i18n.input.chrome.inputview.layouts.RowsOfJP', | 42 'i18n.input.chrome.inputview.layouts.RowsOfJP', |
42 'i18n.input.chrome.inputview.layouts.SpaceRow', | 43 'i18n.input.chrome.inputview.layouts.SpaceRow', |
43 'i18n.input.chrome.inputview.layouts.util', | 44 'i18n.input.chrome.inputview.layouts.util', |
44 'i18n.input.hwt.util'] | 45 'i18n.input.hwt.util'] |
45 | 46 |
| 47 # Any additional required files. |
| 48 extras = [ |
| 49 'common.css', |
| 50 'emoji.css' |
| 51 ] |
46 | 52 |
47 def ProcessFile(filename): | 53 def ProcessFile(filename): |
48 """Extracts provided and required namespaces. | 54 """Extracts provided and required namespaces. |
49 | 55 |
50 Description: | 56 Description: |
51 Scans Javascript file for provied and required namespaces. | 57 Scans Javascript file for provied and required namespaces. |
52 | 58 |
53 Args: | 59 Args: |
54 filename: name of the file to process. | 60 filename: name of the file to process. |
55 | 61 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 """Copies a file from the source to the target location. | 183 """Copies a file from the source to the target location. |
178 | 184 |
179 Args: | 185 Args: |
180 source: Path to the source file to copy. | 186 source: Path to the source file to copy. |
181 target: Path to the target location to copy the file. | 187 target: Path to the target location to copy the file. |
182 """ | 188 """ |
183 | 189 |
184 if not os.path.exists(os.path.dirname(target)): | 190 if not os.path.exists(os.path.dirname(target)): |
185 os.makedirs(os.path.dirname(target)) | 191 os.makedirs(os.path.dirname(target)) |
186 shutil.copy(source, target) | 192 shutil.copy(source, target) |
| 193 # Ensure correct file permissions. |
| 194 if target.endswith('py'): |
| 195 subprocess.call(['chmod', '+x', target]) |
| 196 else: |
| 197 subprocess.call(['chmod', '-x', target]) |
187 | 198 |
188 | 199 |
189 def UpdateFile(filename, input_source, closure_source, target_files): | 200 def UpdateFile(filename, input_source, closure_source, target_files): |
190 """Updates files in third_party/google_input_tools. | 201 """Updates files in third_party/google_input_tools. |
191 | 202 |
192 Args: | 203 Args: |
193 filename: The file to update. | 204 filename: The file to update. |
194 input_source: Root of the google_input_tools sandbox. | 205 input_source: Root of the google_input_tools sandbox. |
195 closure_source: Root of the closure_library sandbox. | 206 closure_source: Root of the closure_library sandbox. |
196 target_files: List of relative paths to target files. | 207 target_files: List of relative paths to target files. |
(...skipping 18 matching lines...) Expand all Loading... |
215 """ | 226 """ |
216 | 227 |
217 sorted_files = sorted(target_files) | 228 sorted_files = sorted(target_files) |
218 with open('inputview.gypi', 'w') as file_handle: | 229 with open('inputview.gypi', 'w') as file_handle: |
219 file_handle.write(os.linesep.join(preamble)) | 230 file_handle.write(os.linesep.join(preamble)) |
220 json_data = {'variables': {'inputview_sources': sorted_files}} | 231 json_data = {'variables': {'inputview_sources': sorted_files}} |
221 json_str = json.dumps(json_data, indent=2, separators=(',', ': ')) | 232 json_str = json.dumps(json_data, indent=2, separators=(',', ': ')) |
222 file_handle.write(json_str.replace('\"', '\'')) | 233 file_handle.write(json_str.replace('\"', '\'')) |
223 | 234 |
224 | 235 |
| 236 def CopyDir(input_path, sub_dir): |
| 237 """Copies all files in a subdirectory of google-input-tools. |
| 238 |
| 239 Description: |
| 240 Recursive copy of a directory under google-input-tools. Used to copy |
| 241 localization and resource files. |
| 242 |
| 243 Args: |
| 244 input_path: Path to the google-input-tools-sandbox. |
| 245 """ |
| 246 dir = os.path.join(input_path, "chrome", "os", "inputview", sub_dir) |
| 247 for (root, dirs, files) in os.walk(dir): |
| 248 for name in files: |
| 249 filename = os.path.join(root, name) |
| 250 relative_path = filename[len(dir) + 1:] |
| 251 target = os.path.join('src', 'chrome', 'os', 'inputview', sub_dir, |
| 252 relative_path) |
| 253 CopyFile(filename, target) |
| 254 |
| 255 |
225 def main(): | 256 def main(): |
226 """The entrypoint for this script.""" | 257 """The entrypoint for this script.""" |
227 | 258 |
228 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO) | 259 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO) |
229 | 260 |
230 usage = 'usage: %prog [options] arg' | 261 usage = 'usage: %prog [options] arg' |
231 parser = optparse.OptionParser(usage) | 262 parser = optparse.OptionParser(usage) |
232 parser.add_option('-i', | 263 parser.add_option('-i', |
233 '--input', | 264 '--input', |
234 dest='input', | 265 dest='input', |
(...skipping 24 matching lines...) Expand all Loading... |
259 dependencies = set() | 290 dependencies = set() |
260 for name in namespaces: | 291 for name in namespaces: |
261 ExtractDependencies(name, providers, requirements, dependencies) | 292 ExtractDependencies(name, providers, requirements, dependencies) |
262 | 293 |
263 target_files = [] | 294 target_files = [] |
264 for name in dependencies: | 295 for name in dependencies: |
265 UpdateFile(name, input_path, closure_library_path, target_files) | 296 UpdateFile(name, input_path, closure_library_path, target_files) |
266 | 297 |
267 GenerateBuildFile(target_files) | 298 GenerateBuildFile(target_files) |
268 | 299 |
| 300 # Copy resources |
| 301 CopyDir(input_path, "_locales") |
| 302 CopyDir(input_path, "images") |
| 303 CopyDir(input_path, 'config') |
| 304 CopyDir(input_path, 'layouts') |
| 305 CopyDir(input_path, 'sounds') |
| 306 |
| 307 # Copy extra support files. |
| 308 for name in extras: |
| 309 source = os.path.join(input_path, 'chrome', 'os', 'inputview', name) |
| 310 target = os.path.join('src', 'chrome', 'os', 'inputview', name) |
| 311 CopyFile(source ,target) |
| 312 |
| 313 |
269 if __name__ == '__main__': | 314 if __name__ == '__main__': |
270 main() | 315 main() |
OLD | NEW |