| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 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 logging | 7 import logging |
| 7 import optparse | 8 import optparse |
| 8 import os | 9 import os |
| 9 import re | 10 import re |
| 10 import shutil | 11 import shutil |
| 11 import sys | 12 import sys |
| 12 | 13 |
| 13 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' | 14 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' |
| 14 require_regex = re.compile(_BASE_REGEX_STRING % 'require') | 15 require_regex = re.compile(_BASE_REGEX_STRING % 'require') |
| 15 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') | 16 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') |
| 16 | 17 |
| 18 preamble = [ |
| 19 '# 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 '# found in the LICENSE file.', |
| 22 '', |
| 23 '# This file is auto-generated using update.py.', |
| 24 ''] |
| 25 |
| 17 # Entry-points required to build a virtual keyboard. | 26 # Entry-points required to build a virtual keyboard. |
| 18 namespaces = [ | 27 namespaces = [ |
| 19 'i18n.input.chrome.inputview.Controller', | 28 'i18n.input.chrome.inputview.Controller', |
| 20 'i18n.input.chrome.inputview.content.compact.letter', | 29 'i18n.input.chrome.inputview.content.compact.letter', |
| 21 'i18n.input.chrome.inputview.content.compact.util', | 30 'i18n.input.chrome.inputview.content.compact.util', |
| 22 'i18n.input.chrome.inputview.content.compact.symbol', | 31 'i18n.input.chrome.inputview.content.compact.symbol', |
| 23 'i18n.input.chrome.inputview.content.compact.more', | 32 'i18n.input.chrome.inputview.content.compact.more', |
| 24 'i18n.input.chrome.inputview.content.compact.numberpad', | 33 'i18n.input.chrome.inputview.content.compact.numberpad', |
| 25 'i18n.input.chrome.inputview.content.ContextlayoutUtil', | 34 'i18n.input.chrome.inputview.content.ContextlayoutUtil', |
| 26 'i18n.input.chrome.inputview.content.util', | 35 'i18n.input.chrome.inputview.content.util', |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 return path | 173 return path |
| 165 | 174 |
| 166 | 175 |
| 167 def CopyFile(source, target): | 176 def CopyFile(source, target): |
| 168 """Copies a file from the source to the target location. | 177 """Copies a file from the source to the target location. |
| 169 | 178 |
| 170 Args: | 179 Args: |
| 171 source: Path to the source file to copy. | 180 source: Path to the source file to copy. |
| 172 target: Path to the target location to copy the file. | 181 target: Path to the target location to copy the file. |
| 173 """ | 182 """ |
| 174 print '%s --> %s' % (source, target) | 183 |
| 175 if not os.path.exists(os.path.dirname(target)): | 184 if not os.path.exists(os.path.dirname(target)): |
| 176 os.makedirs(os.path.dirname(target)) | 185 os.makedirs(os.path.dirname(target)) |
| 177 shutil.copy(source, target) | 186 shutil.copy(source, target) |
| 178 | 187 |
| 179 | 188 |
| 180 def UpdateFile(filename, input_source, closure_source): | 189 def UpdateFile(filename, input_source, closure_source, target_files): |
| 181 """Updates files in third_party/google_input_tools. | 190 """Updates files in third_party/google_input_tools. |
| 191 |
| 182 Args: | 192 Args: |
| 183 filename: The file to update. | 193 filename: The file to update. |
| 184 input_source: Root of the google_input_tools sandbox. | 194 input_source: Root of the google_input_tools sandbox. |
| 185 closure_source: Root of the closure_library sandbox. | 195 closure_source: Root of the closure_library sandbox. |
| 196 target_files: List of relative paths to target files. |
| 186 """ | 197 """ |
| 198 |
| 187 target = '' | 199 target = '' |
| 188 if filename.startswith(input_source): | 200 if filename.startswith(input_source): |
| 189 target = os.path.join('src', filename[len(input_source)+1:]) | 201 target = os.path.join('src', filename[len(input_source)+1:]) |
| 190 elif filename.startswith(closure_source): | 202 elif filename.startswith(closure_source): |
| 191 target = os.path.join('third_party/closure_library', \ | 203 target = os.path.join('third_party/closure_library', \ |
| 192 filename[len(closure_source)+1:]) | 204 filename[len(closure_source)+1:]) |
| 193 if len(target) > 0: | 205 if len(target) > 0: |
| 194 CopyFile(filename, target) | 206 CopyFile(filename, target) |
| 207 target_files.append(os.path.relpath(target, os.getcwd())) |
| 208 |
| 209 |
| 210 def GenerateBuildFile(target_files): |
| 211 """Updates inputview.gypi. |
| 212 |
| 213 Args: |
| 214 target_files: List of files required to build inputview.js. |
| 215 """ |
| 216 |
| 217 sorted_files = sorted(target_files) |
| 218 with open('inputview.gypi', 'w') as file_handle: |
| 219 file_handle.write(os.linesep.join(preamble)) |
| 220 json_data = {'variables': {'inputview_sources': sorted_files}} |
| 221 json_str = json.dumps(json_data, indent=2, separators=(',', ': ')) |
| 222 file_handle.write(json_str.replace('\"', '\'')) |
| 195 | 223 |
| 196 | 224 |
| 197 def main(): | 225 def main(): |
| 198 """The entrypoint for this script.""" | 226 """The entrypoint for this script.""" |
| 199 | 227 |
| 200 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO) | 228 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO) |
| 201 | 229 |
| 202 usage = 'usage: %prog [options] arg' | 230 usage = 'usage: %prog [options] arg' |
| 203 parser = optparse.OptionParser(usage) | 231 parser = optparse.OptionParser(usage) |
| 204 parser.add_option('-i', | 232 parser.add_option('-i', |
| 205 '--input', | 233 '--input', |
| 206 dest='input', | 234 dest='input', |
| 207 action='append', | 235 action='append', |
| 208 help='Path to the google-input-tools sandbox.') | 236 help='Path to the google-input-tools sandbox.') |
| 209 parser.add_option('-l', | 237 parser.add_option('-l', |
| 210 '--lib', | 238 '--lib', |
| 211 dest='lib', | 239 dest='lib', |
| 212 action='store', | 240 action='store', |
| 213 help='Path to the closure-library sandbox.') | 241 help='Path to the closure-library sandbox.') |
| 214 | 242 |
| 215 (options, args) = parser.parse_args() | 243 (options, args) = parser.parse_args() |
| 216 | 244 |
| 217 input_path = GetGoogleInputToolsSandboxFromOptions(options) | 245 input_path = GetGoogleInputToolsSandboxFromOptions(options) |
| 218 closure_library_path = GetClosureLibrarySandboxFromOptions(options) | 246 closure_library_path = GetClosureLibrarySandboxFromOptions(options) |
| 219 | 247 |
| 220 print 'iput_path = %s' % input_path | |
| 221 print 'closure_library_path = %s' % closure_library_path | |
| 222 | |
| 223 if not os.path.isdir(input_path): | 248 if not os.path.isdir(input_path): |
| 224 print 'Could not find google-input-tools sandbox.' | 249 print 'Could not find google-input-tools sandbox.' |
| 225 exit(1) | 250 exit(1) |
| 226 if not os.path.isdir(closure_library_path): | 251 if not os.path.isdir(closure_library_path): |
| 227 print 'Could not find closure-library sandbox.' | 252 print 'Could not find closure-library sandbox.' |
| 228 exit(1) | 253 exit(1) |
| 229 | 254 |
| 230 (providers, requirements) = \ | 255 (providers, requirements) = \ |
| 231 ExpandDirectories([os.path.join(input_path, 'chrome'), | 256 ExpandDirectories([os.path.join(input_path, 'chrome'), |
| 232 closure_library_path]) | 257 closure_library_path]) |
| 233 | 258 |
| 234 dependencies = set() | 259 dependencies = set() |
| 235 | |
| 236 for name in namespaces: | 260 for name in namespaces: |
| 237 ExtractDependencies(name, providers, requirements, dependencies) | 261 ExtractDependencies(name, providers, requirements, dependencies) |
| 238 | 262 |
| 263 target_files = [] |
| 239 for name in dependencies: | 264 for name in dependencies: |
| 240 UpdateFile(name, input_path, closure_library_path) | 265 UpdateFile(name, input_path, closure_library_path, target_files) |
| 266 |
| 267 GenerateBuildFile(target_files) |
| 241 | 268 |
| 242 if __name__ == '__main__': | 269 if __name__ == '__main__': |
| 243 main() | 270 main() |
| OLD | NEW |