summaryrefslogtreecommitdiffstats
path: root/third_party/google_input_tools
diff options
context:
space:
mode:
authorkevers <kevers@chromium.org>2014-10-31 08:55:21 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-31 15:55:54 +0000
commit10278398d654619a49331d980052576eb67119b4 (patch)
tree7af95d86ebda488ecc614f0093e783671c2c8957 /third_party/google_input_tools
parent6352b1f7a0256aa1f5aecf1adb754b44d11b863a (diff)
downloadchromium_src-10278398d654619a49331d980052576eb67119b4.zip
chromium_src-10278398d654619a49331d980052576eb67119b4.tar.gz
chromium_src-10278398d654619a49331d980052576eb67119b4.tar.bz2
Add build target for inputview.
BUG=401729 Review URL: https://codereview.chromium.org/676423003 Cr-Commit-Position: refs/heads/master@{#302275}
Diffstat (limited to 'third_party/google_input_tools')
-rw-r--r--third_party/google_input_tools/README.chromium10
-rwxr-xr-xthird_party/google_input_tools/builder.py198
-rw-r--r--third_party/google_input_tools/closure.gni36
-rw-r--r--third_party/google_input_tools/inputview.gni10
-rw-r--r--third_party/google_input_tools/inputview.gyp36
-rw-r--r--third_party/google_input_tools/inputview.gypi185
-rwxr-xr-xthird_party/google_input_tools/update.py43
7 files changed, 509 insertions, 9 deletions
diff --git a/third_party/google_input_tools/README.chromium b/third_party/google_input_tools/README.chromium
index e5f351b..8c20868 100644
--- a/third_party/google_input_tools/README.chromium
+++ b/third_party/google_input_tools/README.chromium
@@ -19,4 +19,12 @@ update.py --input=_path_to_google_input_tools_ --lib=_path_to_closure_lib_
Local Modifications:
Only includes the portion of google-input-tools required to build an inputview-
-based virtual keyboard. \ No newline at end of file
+based virtual keyboard.
+
+builder.py: Python script for building inputview.js.
+closure.gni: GN template for calling the closure builder.
+inputview.gni: Convert build dependencies from gyp to gn format.
+inputview.gyp: Build file for generating inputview.js.
+inputview.gypi: Autogenerated by update script to define sources for inputview.
+update.py: Python script for updating revision of google-input-tools.
+
diff --git a/third_party/google_input_tools/builder.py b/third_party/google_input_tools/builder.py
new file mode 100755
index 0000000..7787380
--- /dev/null
+++ b/third_party/google_input_tools/builder.py
@@ -0,0 +1,198 @@
+#!/usr/bin/python
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import json
+import os
+import re
+import sys
+
+_BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)'
+require_regex = re.compile(_BASE_REGEX_STRING % 'require')
+provide_regex = re.compile(_BASE_REGEX_STRING % 'provide')
+
+
+def ProcessFile(filename):
+ """Extracts provided and required namespaces.
+
+ Description:
+ Scans Javascript file for provided and required namespaces.
+
+ Args:
+ filename: name of the file to process.
+
+ Returns:
+ Pair of lists, where the first list contains namespaces provided by the file
+ and the second contains a list of requirements.
+ """
+
+ provides = []
+ requires = []
+ with open(filename, 'r') as file_handle:
+ for line in file_handle:
+ if re.match(require_regex, line):
+ requires.append(re.search(require_regex, line).group(1))
+ if re.match(provide_regex, line):
+ provides.append(re.search(provide_regex, line).group(1))
+ return provides, requires
+
+
+def ExtractDependencies(filename, providers, requirements):
+ """Extracts provided and required namespaces for a file.
+
+ Description:
+ Updates maps for namespace providers and file prerequisites.
+
+ Args:
+ filename: Path of the file to process.
+ providers: Mapping of namespace to filename that provides the namespace.
+ requirements: Mapping of filename to a list of prerequisite namespaces.
+ """
+
+ p, r = ProcessFile(filename)
+
+ for name in p:
+ providers[name] = filename
+ for name in r:
+ if not filename in requirements:
+ requirements[filename] = []
+ requirements[filename].append(name)
+
+
+def Export(target_file, source_filename, providers, requirements, processed):
+ """Writes the contents of a file.
+
+ Description:
+ Appends the contents of the source file to the target file. In order to
+ preserve proper dependencies, each file has its required namespaces
+ processed before exporting the source file itself. The set of exported files
+ is tracked to guard against multiple exports of the same file. Comments as
+ well as 'provide' and 'require' statements are removed during to export to
+ reduce file size.
+
+ Args:
+ target_file: Handle to target file for export.
+ source_filename: Name of the file to export.
+ providers: Map of namespace to filename.
+ requirements: Map of filename to required namespaces.
+ processed: Set of processed files.
+ Returns:
+ """
+
+ # Filename may have already been processed if it was a requirement of a
+ # previous exported file.
+ if source_filename in processed:
+ return
+
+ # Export requirements before file.
+ if source_filename in requirements:
+ for namespace in requirements[source_filename]:
+ if namespace in providers:
+ dependency = providers[namespace]
+ if dependency:
+ Export(target_file, dependency, providers, requirements, processed)
+
+ # Export file
+ processed.add(source_filename)
+ for name in providers:
+ if providers[name] == source_filename:
+ target_file.write('// %s%s' % (name, os.linesep))
+ source_file = open(source_filename, 'r')
+ try:
+ comment_block = False
+ for line in source_file:
+ # Skip require and provide statements.
+ if (not re.match(require_regex, line) and not
+ re.match(provide_regex, line)):
+ formatted = line.rstrip()
+ if comment_block:
+ # Scan for trailing */ in multi-line comment.
+ index = formatted.find('*/')
+ if index >= 0:
+ formatted = formatted[index + 2:]
+ comment_block = False
+ else:
+ formatted = ''
+ # Remove // style comments.
+ index = formatted.find('//')
+ if index >= 0:
+ formatted = formatted[:index]
+ # Remove /* */ style comments.
+ start_comment = formatted.find('/*')
+ end_comment = formatted.find('*/')
+ while start_comment >= 0:
+ if end_comment > start_comment:
+ formatted = (formatted[:start_comment]
+ + formatted[end_comment + 2:])
+ start_comment = formatted.find('/*')
+ end_comment = formatted.find('*/')
+ else:
+ formatted = formatted[:start_comment]
+ comment_block = True
+ start_comment = -1
+ if formatted.strip():
+ target_file.write('%s%s' % (formatted, os.linesep))
+ finally:
+ source_file.close()
+ target_file.write('\n')
+
+
+def ExtractSources(options):
+ """Extracts list of sources based on command line options.
+
+ Args:
+ options: Parsed command line options.
+ Returns:
+ List of source files. If the path option is specified then file paths are
+ absolute. Otherwise, relative paths may be used.
+ """
+
+ sources = None
+ if options.json_file:
+ # Optionally load list of source files from a json file. Useful when the
+ # list of files to process is too long for the command line.
+ with open(options.json_file, 'r') as json_file:
+ data = []
+ # Strip leading comments.
+ for line in json_file:
+ if not line.startswith('#'):
+ data.append(line)
+ json_object = json.loads(os.linesep.join(data).replace('\'', '\"'))
+ path = options.json_sources.split('.')
+ sources = json_object
+ for key in path:
+ sources = sources[key]
+ if options.path:
+ sources = [os.path.join(options.path, source) for source in sources]
+ else:
+ sources = options.sources
+ return sources
+
+
+def main():
+ """The entrypoint for this script."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--sources', nargs='*')
+ parser.add_argument('--target', nargs=1)
+ parser.add_argument('--json_file', nargs='?')
+ parser.add_argument('--json_sources', nargs='?')
+ parser.add_argument('--path', nargs='?')
+ options = parser.parse_args()
+
+ sources = ExtractSources(options)
+ assert sources, 'Missing source files.'
+
+ providers = {}
+ requirements = {}
+ for file in sources:
+ ExtractDependencies(file, providers, requirements)
+
+ with open(options.target[0], 'w') as target_file:
+ processed = set()
+ for source_filename in sources:
+ Export(target_file, source_filename, providers, requirements, processed)
+
+if __name__ == '__main__':
+ main()
diff --git a/third_party/google_input_tools/closure.gni b/third_party/google_input_tools/closure.gni
new file mode 100644
index 0000000..526dbd0
--- /dev/null
+++ b/third_party/google_input_tools/closure.gni
@@ -0,0 +1,36 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+template("build_closure") {
+ assert(defined(invoker.sources))
+ assert(defined(invoker.target))
+ action_name = target_name + "_js_gen"
+ action(action_name) {
+ script = "//third_party/google_input_tools/builder.py"
+ sources = invoker.sources
+ outputs = [invoker.target]
+ args = ["--target",
+ rebase_path(invoker.target, root_build_dir)]
+ if(defined(invoker.json_file)) {
+ # Optionally parse list of sources from a json file. Useful when the list
+ # is sufficiently long to create problems with length restrictions on the
+ # command line.
+ assert(defined(invoker.json_sources))
+ args += ["--json_file",
+ rebase_path(invoker.json_file, root_build_dir),
+ "--json_sources",
+ invoker.json_sources]
+ } else {
+ # If the number of source files is short, they can be directly extracted
+ # from the command line.
+ args += ["--sources"] + sources
+ }
+ if(defined(invoker.path)) {
+ args += ["--path", invoker.path]
+ }
+ }
+ group(target_name) {
+ deps = [ ":$action_name" ]
+ }
+}
diff --git a/third_party/google_input_tools/inputview.gni b/third_party/google_input_tools/inputview.gni
new file mode 100644
index 0000000..0c6cede
--- /dev/null
+++ b/third_party/google_input_tools/inputview.gni
@@ -0,0 +1,10 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+inputview_gypi_values = exec_script(
+ "//build/gypi_to_gn.py",
+ [ rebase_path("inputview.gypi") ],
+ "scope",
+ [ "inputview.gypi" ])
+inputview_sources = rebase_path(inputview_gypi_values.inputview_sources) \ No newline at end of file
diff --git a/third_party/google_input_tools/inputview.gyp b/third_party/google_input_tools/inputview.gyp
new file mode 100644
index 0000000..764ec00
--- /dev/null
+++ b/third_party/google_input_tools/inputview.gyp
@@ -0,0 +1,36 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+{
+ 'targets': [
+ {
+ 'target_name': 'inputview',
+ 'type': 'none',
+ 'includes': [ 'inputview.gypi' ],
+ 'actions': [
+ {
+ 'action_name': 'inputview',
+ 'inputs': [
+ 'builder.py',
+ '<@(inputview_sources)',
+ ],
+ 'outputs': [
+ '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard/resources/inputview.js',
+ ],
+ 'action': [
+ 'python',
+ 'builder.py',
+ '--target',
+ '<@(_outputs)',
+ '--json_file',
+ 'inputview.gypi',
+ '--json_sources',
+ 'variables.inputview_sources'
+ ],
+ 'message': 'Generating <@(_outputs)'
+ },
+ ],
+ },
+ ],
+} \ No newline at end of file
diff --git a/third_party/google_input_tools/inputview.gypi b/third_party/google_input_tools/inputview.gypi
new file mode 100644
index 0000000..41ab132
--- /dev/null
+++ b/third_party/google_input_tools/inputview.gypi
@@ -0,0 +1,185 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# This file is auto-generated using update.py.
+{
+ 'variables': {
+ 'inputview_sources': [
+ 'src/chrome/os/datasource.js',
+ 'src/chrome/os/inputview/adapter.js',
+ 'src/chrome/os/inputview/candidatesinfo.js',
+ 'src/chrome/os/inputview/canvas.js',
+ 'src/chrome/os/inputview/conditionname.js',
+ 'src/chrome/os/inputview/config/compact_letter_characters.js',
+ 'src/chrome/os/inputview/config/compact_more_characters.js',
+ 'src/chrome/os/inputview/config/compact_numberpad_characters.js',
+ 'src/chrome/os/inputview/config/compact_symbol_characters.js',
+ 'src/chrome/os/inputview/config/compact_util.js',
+ 'src/chrome/os/inputview/config/constants.js',
+ 'src/chrome/os/inputview/config/contextlayoututil.js',
+ 'src/chrome/os/inputview/config/util.js',
+ 'src/chrome/os/inputview/controller.js',
+ 'src/chrome/os/inputview/covariance.js',
+ 'src/chrome/os/inputview/css.js',
+ 'src/chrome/os/inputview/direction.js',
+ 'src/chrome/os/inputview/dom.js',
+ 'src/chrome/os/inputview/elements/content/altdataview.js',
+ 'src/chrome/os/inputview/elements/content/candidate.js',
+ 'src/chrome/os/inputview/elements/content/candidatebutton.js',
+ 'src/chrome/os/inputview/elements/content/candidateview.js',
+ 'src/chrome/os/inputview/elements/content/canvasview.js',
+ 'src/chrome/os/inputview/elements/content/character.js',
+ 'src/chrome/os/inputview/elements/content/characterkey.js',
+ 'src/chrome/os/inputview/elements/content/charactermodel.js',
+ 'src/chrome/os/inputview/elements/content/compactkey.js',
+ 'src/chrome/os/inputview/elements/content/emojikey.js',
+ 'src/chrome/os/inputview/elements/content/emojiview.js',
+ 'src/chrome/os/inputview/elements/content/enswitcherkey.js',
+ 'src/chrome/os/inputview/elements/content/expandedcandidateview.js',
+ 'src/chrome/os/inputview/elements/content/functionalkey.js',
+ 'src/chrome/os/inputview/elements/content/gaussianestimator.js',
+ 'src/chrome/os/inputview/elements/content/handwritingview.js',
+ 'src/chrome/os/inputview/elements/content/indicator.js',
+ 'src/chrome/os/inputview/elements/content/keyboardview.js',
+ 'src/chrome/os/inputview/elements/content/keysetview.js',
+ 'src/chrome/os/inputview/elements/content/menuitem.js',
+ 'src/chrome/os/inputview/elements/content/menukey.js',
+ 'src/chrome/os/inputview/elements/content/menuview.js',
+ 'src/chrome/os/inputview/elements/content/modifierkey.js',
+ 'src/chrome/os/inputview/elements/content/morekeysshiftoperation.js',
+ 'src/chrome/os/inputview/elements/content/softkey.js',
+ 'src/chrome/os/inputview/elements/content/spacekey.js',
+ 'src/chrome/os/inputview/elements/content/switcherkey.js',
+ 'src/chrome/os/inputview/elements/content/tabbarkey.js',
+ 'src/chrome/os/inputview/elements/element.js',
+ 'src/chrome/os/inputview/elements/elementtype.js',
+ 'src/chrome/os/inputview/elements/layout/extendedlayout.js',
+ 'src/chrome/os/inputview/elements/layout/handwritinglayout.js',
+ 'src/chrome/os/inputview/elements/layout/linearlayout.js',
+ 'src/chrome/os/inputview/elements/layout/softkeyview.js',
+ 'src/chrome/os/inputview/elements/layout/verticallayout.js',
+ 'src/chrome/os/inputview/elements/weightable.js',
+ 'src/chrome/os/inputview/emojitype.js',
+ 'src/chrome/os/inputview/events.js',
+ 'src/chrome/os/inputview/events/keycodes.js',
+ 'src/chrome/os/inputview/globalsettings.js',
+ 'src/chrome/os/inputview/handler/pointeractionbundle.js',
+ 'src/chrome/os/inputview/handler/pointerhandler.js',
+ 'src/chrome/os/inputview/handler/swipestate.js',
+ 'src/chrome/os/inputview/hwt_css.js',
+ 'src/chrome/os/inputview/hwt_eventtype.js',
+ 'src/chrome/os/inputview/hwt_util.js',
+ 'src/chrome/os/inputview/inputtoolcode.js',
+ 'src/chrome/os/inputview/keyboardcontainer.js',
+ 'src/chrome/os/inputview/layouts/compactspacerow.js',
+ 'src/chrome/os/inputview/layouts/rowsof101.js',
+ 'src/chrome/os/inputview/layouts/rowsof102.js',
+ 'src/chrome/os/inputview/layouts/rowsofcompact.js',
+ 'src/chrome/os/inputview/layouts/rowsofjp.js',
+ 'src/chrome/os/inputview/layouts/spacerow.js',
+ 'src/chrome/os/inputview/layouts/util.js',
+ 'src/chrome/os/inputview/m17nmodel.js',
+ 'src/chrome/os/inputview/model.js',
+ 'src/chrome/os/inputview/pointerconfig.js',
+ 'src/chrome/os/inputview/readystate.js',
+ 'src/chrome/os/inputview/settings.js',
+ 'src/chrome/os/inputview/sizespec.js',
+ 'src/chrome/os/inputview/soundcontroller.js',
+ 'src/chrome/os/inputview/sounds.js',
+ 'src/chrome/os/inputview/specnodename.js',
+ 'src/chrome/os/inputview/statemanager.js',
+ 'src/chrome/os/inputview/statetype.js',
+ 'src/chrome/os/inputview/statistics.js',
+ 'src/chrome/os/inputview/strokehandler.js',
+ 'src/chrome/os/inputview/swipedirection.js',
+ 'src/chrome/os/inputview/util.js',
+ 'src/chrome/os/keyboard/eventtype.js',
+ 'src/chrome/os/keyboard/keycode.js',
+ 'src/chrome/os/keyboard/layoutevent.js',
+ 'src/chrome/os/keyboard/model.js',
+ 'src/chrome/os/keyboard/parsedlayout.js',
+ 'src/chrome/os/message/contenttype.js',
+ 'src/chrome/os/message/event.js',
+ 'src/chrome/os/message/name.js',
+ 'src/chrome/os/message/type.js',
+ 'third_party/closure_library/closure/goog/a11y/aria/announcer.js',
+ 'third_party/closure_library/closure/goog/a11y/aria/aria.js',
+ 'third_party/closure_library/closure/goog/a11y/aria/attributes.js',
+ 'third_party/closure_library/closure/goog/a11y/aria/datatables.js',
+ 'third_party/closure_library/closure/goog/a11y/aria/roles.js',
+ 'third_party/closure_library/closure/goog/array/array.js',
+ 'third_party/closure_library/closure/goog/asserts/asserts.js',
+ 'third_party/closure_library/closure/goog/async/delay.js',
+ 'third_party/closure_library/closure/goog/async/nexttick.js',
+ 'third_party/closure_library/closure/goog/async/run.js',
+ 'third_party/closure_library/closure/goog/debug/debug.js',
+ 'third_party/closure_library/closure/goog/debug/entrypointregistry.js',
+ 'third_party/closure_library/closure/goog/debug/error.js',
+ 'third_party/closure_library/closure/goog/debug/logbuffer.js',
+ 'third_party/closure_library/closure/goog/debug/logger.js',
+ 'third_party/closure_library/closure/goog/debug/logrecord.js',
+ 'third_party/closure_library/closure/goog/disposable/disposable.js',
+ 'third_party/closure_library/closure/goog/disposable/idisposable.js',
+ 'third_party/closure_library/closure/goog/dom/browserfeature.js',
+ 'third_party/closure_library/closure/goog/dom/classlist.js',
+ 'third_party/closure_library/closure/goog/dom/dom.js',
+ 'third_party/closure_library/closure/goog/dom/nodetype.js',
+ 'third_party/closure_library/closure/goog/dom/tagname.js',
+ 'third_party/closure_library/closure/goog/dom/vendor.js',
+ 'third_party/closure_library/closure/goog/events/browserevent.js',
+ 'third_party/closure_library/closure/goog/events/browserfeature.js',
+ 'third_party/closure_library/closure/goog/events/event.js',
+ 'third_party/closure_library/closure/goog/events/eventhandler.js',
+ 'third_party/closure_library/closure/goog/events/eventid.js',
+ 'third_party/closure_library/closure/goog/events/events.js',
+ 'third_party/closure_library/closure/goog/events/eventtarget.js',
+ 'third_party/closure_library/closure/goog/events/eventtype.js',
+ 'third_party/closure_library/closure/goog/events/keycodes.js',
+ 'third_party/closure_library/closure/goog/events/keyhandler.js',
+ 'third_party/closure_library/closure/goog/events/listenable.js',
+ 'third_party/closure_library/closure/goog/events/listener.js',
+ 'third_party/closure_library/closure/goog/events/listenermap.js',
+ 'third_party/closure_library/closure/goog/functions/functions.js',
+ 'third_party/closure_library/closure/goog/i18n/bidi.js',
+ 'third_party/closure_library/closure/goog/iter/iter.js',
+ 'third_party/closure_library/closure/goog/labs/useragent/browser.js',
+ 'third_party/closure_library/closure/goog/labs/useragent/engine.js',
+ 'third_party/closure_library/closure/goog/labs/useragent/util.js',
+ 'third_party/closure_library/closure/goog/log/log.js',
+ 'third_party/closure_library/closure/goog/math/box.js',
+ 'third_party/closure_library/closure/goog/math/coordinate.js',
+ 'third_party/closure_library/closure/goog/math/math.js',
+ 'third_party/closure_library/closure/goog/math/rect.js',
+ 'third_party/closure_library/closure/goog/math/size.js',
+ 'third_party/closure_library/closure/goog/net/jsloader.js',
+ 'third_party/closure_library/closure/goog/object/object.js',
+ 'third_party/closure_library/closure/goog/positioning/positioning.js',
+ 'third_party/closure_library/closure/goog/promise/promise.js',
+ 'third_party/closure_library/closure/goog/promise/resolver.js',
+ 'third_party/closure_library/closure/goog/promise/thenable.js',
+ 'third_party/closure_library/closure/goog/reflect/reflect.js',
+ 'third_party/closure_library/closure/goog/string/string.js',
+ 'third_party/closure_library/closure/goog/structs/collection.js',
+ 'third_party/closure_library/closure/goog/structs/map.js',
+ 'third_party/closure_library/closure/goog/structs/set.js',
+ 'third_party/closure_library/closure/goog/structs/structs.js',
+ 'third_party/closure_library/closure/goog/style/bidi.js',
+ 'third_party/closure_library/closure/goog/style/style.js',
+ 'third_party/closure_library/closure/goog/testing/watchers.js',
+ 'third_party/closure_library/closure/goog/timer/timer.js',
+ 'third_party/closure_library/closure/goog/ui/component.js',
+ 'third_party/closure_library/closure/goog/ui/container.js',
+ 'third_party/closure_library/closure/goog/ui/containerrenderer.js',
+ 'third_party/closure_library/closure/goog/ui/control.js',
+ 'third_party/closure_library/closure/goog/ui/controlcontent.js',
+ 'third_party/closure_library/closure/goog/ui/controlrenderer.js',
+ 'third_party/closure_library/closure/goog/ui/decorate.js',
+ 'third_party/closure_library/closure/goog/ui/idgenerator.js',
+ 'third_party/closure_library/closure/goog/ui/registry.js',
+ 'third_party/closure_library/closure/goog/uri/utils.js',
+ 'third_party/closure_library/closure/goog/useragent/useragent.js',
+ 'third_party/closure_library/third_party/closure/goog/mochikit/async/deferred.js'
+ ]
+ }
+} \ No newline at end of file
diff --git a/third_party/google_input_tools/update.py b/third_party/google_input_tools/update.py
index ce0e79f..7ccad7c 100755
--- a/third_party/google_input_tools/update.py
+++ b/third_party/google_input_tools/update.py
@@ -1,8 +1,9 @@
#!/usr/bin/python
-# Copyright (c) 2014 The Chromium Authors. All rights reserved.
+# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import json
import logging
import optparse
import os
@@ -14,6 +15,14 @@ _BASE_REGEX_STRING = '^\s*goog\.%s\(\s*[\'"](.+)[\'"]\s*\)'
require_regex = re.compile(_BASE_REGEX_STRING % 'require')
provide_regex = re.compile(_BASE_REGEX_STRING % 'provide')
+preamble = [
+ '# Copyright 2014 The Chromium Authors. All rights reserved.',
+ '# Use of this source code is governed by a BSD-style license that can be',
+ '# found in the LICENSE file.',
+ '',
+ '# This file is auto-generated using update.py.',
+ '']
+
# Entry-points required to build a virtual keyboard.
namespaces = [
'i18n.input.chrome.inputview.Controller',
@@ -171,19 +180,22 @@ def CopyFile(source, target):
source: Path to the source file to copy.
target: Path to the target location to copy the file.
"""
- print '%s --> %s' % (source, target)
+
if not os.path.exists(os.path.dirname(target)):
os.makedirs(os.path.dirname(target))
shutil.copy(source, target)
-def UpdateFile(filename, input_source, closure_source):
+def UpdateFile(filename, input_source, closure_source, target_files):
"""Updates files in third_party/google_input_tools.
+
Args:
filename: The file to update.
input_source: Root of the google_input_tools sandbox.
closure_source: Root of the closure_library sandbox.
+ target_files: List of relative paths to target files.
"""
+
target = ''
if filename.startswith(input_source):
target = os.path.join('src', filename[len(input_source)+1:])
@@ -192,6 +204,22 @@ def UpdateFile(filename, input_source, closure_source):
filename[len(closure_source)+1:])
if len(target) > 0:
CopyFile(filename, target)
+ target_files.append(os.path.relpath(target, os.getcwd()))
+
+
+def GenerateBuildFile(target_files):
+ """Updates inputview.gypi.
+
+ Args:
+ target_files: List of files required to build inputview.js.
+ """
+
+ sorted_files = sorted(target_files)
+ with open('inputview.gypi', 'w') as file_handle:
+ file_handle.write(os.linesep.join(preamble))
+ json_data = {'variables': {'inputview_sources': sorted_files}}
+ json_str = json.dumps(json_data, indent=2, separators=(',', ': '))
+ file_handle.write(json_str.replace('\"', '\''))
def main():
@@ -217,9 +245,6 @@ def main():
input_path = GetGoogleInputToolsSandboxFromOptions(options)
closure_library_path = GetClosureLibrarySandboxFromOptions(options)
- print 'iput_path = %s' % input_path
- print 'closure_library_path = %s' % closure_library_path
-
if not os.path.isdir(input_path):
print 'Could not find google-input-tools sandbox.'
exit(1)
@@ -232,12 +257,14 @@ def main():
closure_library_path])
dependencies = set()
-
for name in namespaces:
ExtractDependencies(name, providers, requirements, dependencies)
+ target_files = []
for name in dependencies:
- UpdateFile(name, input_path, closure_library_path)
+ UpdateFile(name, input_path, closure_library_path, target_files)
+
+ GenerateBuildFile(target_files)
if __name__ == '__main__':
main()