Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: third_party/google_input_tools/update.py

Issue 676423003: Add build target for inputview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix documentation. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 logging 6 import logging
7 import optparse 7 import optparse
8 import os 8 import os
9 import re 9 import re
10 import shutil 10 import shutil
11 import sys 11 import sys
12 12
13 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)' 13 _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)'
14 require_regex = re.compile(_BASE_REGEX_STRING % 'require') 14 require_regex = re.compile(_BASE_REGEX_STRING % 'require')
15 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide') 15 provide_regex = re.compile(_BASE_REGEX_STRING % 'provide')
16 16
17 preamble = [
bruthig 2014/10/28 19:20:44 You could do preamble = os.linesep.join(['Line1',
kevers 2014/10/29 14:27:19 Done.
18 '# Copyright 2014 The Chromium Authors. All rights reserved.',
19 '# Use of this source code is governed by a BSD-style license that can be',
20 '# found in the LICENSE file.',
21 '',
22 '# This file is auto-generated using update.py.',
23 '']
24
17 # Entry-points required to build a virtual keyboard. 25 # Entry-points required to build a virtual keyboard.
18 namespaces = [ 26 namespaces = [
19 'i18n.input.chrome.inputview.Controller', 27 'i18n.input.chrome.inputview.Controller',
20 'i18n.input.chrome.inputview.content.compact.letter', 28 'i18n.input.chrome.inputview.content.compact.letter',
21 'i18n.input.chrome.inputview.content.compact.util', 29 'i18n.input.chrome.inputview.content.compact.util',
22 'i18n.input.chrome.inputview.content.compact.symbol', 30 'i18n.input.chrome.inputview.content.compact.symbol',
23 'i18n.input.chrome.inputview.content.compact.more', 31 'i18n.input.chrome.inputview.content.compact.more',
24 'i18n.input.chrome.inputview.content.compact.numberpad', 32 'i18n.input.chrome.inputview.content.compact.numberpad',
25 'i18n.input.chrome.inputview.content.ContextlayoutUtil', 33 'i18n.input.chrome.inputview.content.ContextlayoutUtil',
26 'i18n.input.chrome.inputview.content.util', 34 'i18n.input.chrome.inputview.content.util',
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return path 172 return path
165 173
166 174
167 def CopyFile(source, target): 175 def CopyFile(source, target):
168 """Copies a file from the source to the target location. 176 """Copies a file from the source to the target location.
169 177
170 Args: 178 Args:
171 source: Path to the source file to copy. 179 source: Path to the source file to copy.
172 target: Path to the target location to copy the file. 180 target: Path to the target location to copy the file.
173 """ 181 """
174 print '%s --> %s' % (source, target) 182
175 if not os.path.exists(os.path.dirname(target)): 183 if not os.path.exists(os.path.dirname(target)):
176 os.makedirs(os.path.dirname(target)) 184 os.makedirs(os.path.dirname(target))
177 shutil.copy(source, target) 185 shutil.copy(source, target)
178 186
179 187
180 def UpdateFile(filename, input_source, closure_source): 188 def UpdateFile(filename, input_source, closure_source, target_files):
181 """Updates files in third_party/google_input_tools. 189 """Updates files in third_party/google_input_tools.
190
182 Args: 191 Args:
183 filename: The file to update. 192 filename: The file to update.
184 input_source: Root of the google_input_tools sandbox. 193 input_source: Root of the google_input_tools sandbox.
185 closure_source: Root of the closure_library sandbox. 194 closure_source: Root of the closure_library sandbox.
195 target_files: List of relative paths to target files.
186 """ 196 """
197
187 target = '' 198 target = ''
188 if filename.startswith(input_source): 199 if filename.startswith(input_source):
189 target = os.path.join('src', filename[len(input_source)+1:]) 200 target = os.path.join('src', filename[len(input_source)+1:])
190 elif filename.startswith(closure_source): 201 elif filename.startswith(closure_source):
191 target = os.path.join('third_party/closure_library', \ 202 target = os.path.join('third_party/closure_library', \
192 filename[len(closure_source)+1:]) 203 filename[len(closure_source)+1:])
193 if len(target) > 0: 204 if len(target) > 0:
194 CopyFile(filename, target) 205 CopyFile(filename, target)
206 target_files.append(os.path.relpath(target, os.getcwd()))
195 207
196 208
209 def GenerateBuildFile(target_files):
210 """Updates inputview.gypi.
211
212 Args:
213 target_files: List of files required to build inputview.js.
214 """
215
bruthig 2014/10/28 19:20:45 I'm not 100% sure if it will work for the formatti
kevers 2014/10/29 14:27:20 Done.
216 sorted_files = sorted(target_files)
217 file_handle = open('inputview.gypi', 'w')
218 try:
219 for line in preamble:
220 file_handle.write('%s\n' % line)
221 file_handle.write("{\n")
222 file_handle.write(" 'variables': {\n")
223 file_handle.write(" 'inputview_sources': [\n")
224 for name in sorted_files:
225 file_handle.write(" '%s',\n" % name)
226 file_handle.write(" ],\n")
227 file_handle.write(" }\n")
228 file_handle.write("}\n")
229 finally:
230 file_handle.close()
231
197 def main(): 232 def main():
198 """The entrypoint for this script.""" 233 """The entrypoint for this script."""
199 234
200 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO) 235 logging.basicConfig(format='update.py: %(message)s', level=logging.INFO)
201 236
202 usage = 'usage: %prog [options] arg' 237 usage = 'usage: %prog [options] arg'
203 parser = optparse.OptionParser(usage) 238 parser = optparse.OptionParser(usage)
204 parser.add_option('-i', 239 parser.add_option('-i',
205 '--input', 240 '--input',
206 dest='input', 241 dest='input',
207 action='append', 242 action='append',
208 help='Path to the google-input-tools sandbox.') 243 help='Path to the google-input-tools sandbox.')
209 parser.add_option('-l', 244 parser.add_option('-l',
210 '--lib', 245 '--lib',
211 dest='lib', 246 dest='lib',
212 action='store', 247 action='store',
213 help='Path to the closure-library sandbox.') 248 help='Path to the closure-library sandbox.')
214 249
215 (options, args) = parser.parse_args() 250 (options, args) = parser.parse_args()
216 251
217 input_path = GetGoogleInputToolsSandboxFromOptions(options) 252 input_path = GetGoogleInputToolsSandboxFromOptions(options)
218 closure_library_path = GetClosureLibrarySandboxFromOptions(options) 253 closure_library_path = GetClosureLibrarySandboxFromOptions(options)
219 254
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): 255 if not os.path.isdir(input_path):
224 print 'Could not find google-input-tools sandbox.' 256 print 'Could not find google-input-tools sandbox.'
225 exit(1) 257 exit(1)
226 if not os.path.isdir(closure_library_path): 258 if not os.path.isdir(closure_library_path):
227 print 'Could not find closure-library sandbox.' 259 print 'Could not find closure-library sandbox.'
228 exit(1) 260 exit(1)
229 261
230 (providers, requirements) = \ 262 (providers, requirements) = \
231 ExpandDirectories([os.path.join(input_path, 'chrome'), 263 ExpandDirectories([os.path.join(input_path, 'chrome'),
232 closure_library_path]) 264 closure_library_path])
233 265
234 dependencies = set() 266 dependencies = set()
235
236 for name in namespaces: 267 for name in namespaces:
237 ExtractDependencies(name, providers, requirements, dependencies) 268 ExtractDependencies(name, providers, requirements, dependencies)
238 269
270 target_files = []
239 for name in dependencies: 271 for name in dependencies:
240 UpdateFile(name, input_path, closure_library_path) 272 UpdateFile(name, input_path, closure_library_path, target_files)
273
274 GenerateBuildFile(target_files)
241 275
242 if __name__ == '__main__': 276 if __name__ == '__main__':
243 main() 277 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698