diff options
author | dtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 14:20:35 +0000 |
---|---|---|
committer | dtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 14:20:35 +0000 |
commit | acc30488ef4d359b5e323029f3ddba0014adbb20 (patch) | |
tree | 70691ef725c5bc392df40b23958bb04fafcf1ed3 | |
parent | 1edbb1dbeae78ac3d7ef9b6f15b6e0bcf79b38a2 (diff) | |
download | chromium_src-acc30488ef4d359b5e323029f3ddba0014adbb20.zip chromium_src-acc30488ef4d359b5e323029f3ddba0014adbb20.tar.gz chromium_src-acc30488ef4d359b5e323029f3ddba0014adbb20.tar.bz2 |
Add a wrapper script for deps.js file generation, make misc changes to jinja template, and update ChromeVox Next to be a consumer.
- adds a python script for deps file generation with the ability to ermap path dirnames.
- add a gypi file to invoke the python script based on top level js files (root of a goog.provide/require dependency graph). Reuses jsbundler to get the topological listing.
- add a new jinja option (use_chromevox_next), which hinges upon the existing use_chromevox_next gyp variable.
- copy all js files using the new copy_js gypi for Cvox next. (we're not flattening at all for cv next).
BUG=none
Review URL: https://codereview.chromium.org/310743002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275092 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 264 insertions, 93 deletions
diff --git a/chrome/browser/resources/chromeos/braille_ime/braille_ime.gyp b/chrome/browser/resources/chromeos/braille_ime/braille_ime.gyp new file mode 100644 index 0000000..be1059a --- /dev/null +++ b/chrome/browser/resources/chromeos/braille_ime/braille_ime.gyp @@ -0,0 +1,24 @@ +# 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. + +{ + 'conditions': [ + ['chromeos==1', { + 'targets': [ + { + 'target_name': 'braille_ime_manifest', + 'type': 'none', + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)/resources/chromeos/braille_ime', + 'files': [ + 'manifest.json', + ], + }, + ], + }, + ], + }], + ], +} diff --git a/chrome/browser/resources/chromeos/chromevox/chromevox.gyp b/chrome/browser/resources/chromeos/chromevox/chromevox.gyp index da65582..591fa22 100644 --- a/chrome/browser/resources/chromeos/chromevox/chromevox.gyp +++ b/chrome/browser/resources/chromeos/chromevox/chromevox.gyp @@ -5,38 +5,36 @@ { 'conditions': [ ['chromeos==1', { + 'includes': ['common.gypi'], 'variables': { # Whether to compress the 4 main ChromeVox scripts. Applicable if # use_migrated_chromevox is true. 'chromevox_compress_js%': '1', - 'chromevox_third_party_dir': '<(DEPTH)/chrome/third_party/chromevox', - 'closure_goog_dir': '<(chromevox_third_party_dir)/third_party/closure-library/closure/goog', - 'chromevox_dest_dir': '<(PRODUCT_DIR)/resources/chromeos/chromevox', - 'js_root_flags': [ - '-r', '.', - '-r', '<(closure_goog_dir)', - ], - 'path_rewrite_flags': [ - '-w', '<(closure_goog_dir):closure', - ], 'background_script_loader_file': 'chromevox/background/loader.js', 'content_script_loader_file': 'chromevox/injected/loader.js', 'options_script_loader_file': 'chromevox/background/options_loader.js', 'kbexplorer_loader_file': 'chromevox/background/kbexplorer_loader.js', - 'template_manifest_path': 'manifest.json.jinja2', }, 'targets': [ { + 'target_name': 'chromevox', + 'type': 'none', + 'dependencies': [ + 'chromevox_resources', + 'chromevox_manifest', + 'chromevox_guest_manifest', + ], + }, + { 'target_name': 'chromevox_resources', 'type': 'none', 'dependencies': [ 'chromevox_assets', 'chromevox_static_files', - 'chromevox_manifest', - 'chromevox_guest_manifest', 'chromevox_strings', 'chromevox_uncompiled_js_files', '<(chromevox_third_party_dir)/chromevox.gyp:chromevox_third_party_resources', + '../braille_ime/braille_ime.gyp:braille_ime_manifest', ], 'conditions': [ ['disable_nacl==0 and disable_nacl_untrusted==0', { diff --git a/chrome/browser/resources/chromeos/chromevox/common.gypi b/chrome/browser/resources/chromeos/chromevox/common.gypi new file mode 100644 index 0000000..a4e9dd2 --- /dev/null +++ b/chrome/browser/resources/chromeos/chromevox/common.gypi @@ -0,0 +1,20 @@ +# 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. +# Common variables shared amongst all ChromeVox targets. + +{ + 'variables': { + 'chromevox_third_party_dir': '<(DEPTH)/chrome/third_party/chromevox', + 'closure_goog_dir': '<(chromevox_third_party_dir)/third_party/closure-library/closure/goog', + 'chromevox_dest_dir': '<(PRODUCT_DIR)/resources/chromeos/chromevox', + 'js_root_flags': [ + '-r', '.', + '-r', '<(closure_goog_dir)', + ], + 'path_rewrite_flags': [ + '-w', '<(closure_goog_dir):closure', + ], + 'template_manifest_path': 'manifest.json.jinja2', + }, +} diff --git a/chrome/browser/resources/chromeos/chromevox/copy_js.gypi b/chrome/browser/resources/chromeos/chromevox/copy_js.gypi index 94c654a..487d315 100644 --- a/chrome/browser/resources/chromeos/chromevox/copy_js.gypi +++ b/chrome/browser/resources/chromeos/chromevox/copy_js.gypi @@ -18,20 +18,21 @@ 'action_name': 'copy_js', 'message': 'Copy JS for <(_target_name)', 'variables': { + 'js_bundler_path': 'tools/jsbundler.py', 'js_files': [ - '<!@(python tools/jsbundler.py <(js_root_flags) <(_sources))' + '<!@(python <(js_bundler_path) <(js_root_flags) <(_sources))' ], }, 'inputs': [ - 'tools/jsbundler.py', + '<(js_bundler_path)', '<@(js_files)', ], 'outputs': [ - '<!@(python tools/jsbundler.py <@(path_rewrite_flags) -d <(dest_dir) <@(js_files))' + '<!@(python <(js_bundler_path) <@(path_rewrite_flags) -d <(dest_dir) <@(js_files))' ], 'action': [ 'python', - 'tools/jsbundler.py', + '<(js_bundler_path)', '-m', 'copy', '-d', '<(dest_dir)', '<@(path_rewrite_flags)', diff --git a/chrome/browser/resources/chromeos/chromevox/generate_deps.gypi b/chrome/browser/resources/chromeos/chromevox/generate_deps.gypi new file mode 100644 index 0000000..39b5596 --- /dev/null +++ b/chrome/browser/resources/chromeos/chromevox/generate_deps.gypi @@ -0,0 +1,43 @@ +# 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. + +# Include this file in a target to generate a Closure style deps.js file. +# +# The following variables must be available when this file is included: +# js_root_flags: List of '-r' flags to jsbundler.py for locating the +# .js files. +# deps_js_output_file: Where to write the generated deps file. + +{ + 'includes': ['common.gypi'], + 'actions': [ + { + 'action_name': 'generate_deps', + 'message': 'Generate deps for <(_target_name)', + 'variables': { + 'js_bundler_path': 'tools/jsbundler.py', + 'closure_depswriter_path': 'tools/generate_deps.py', + 'js_files': [ + '<!@(python <(js_bundler_path) <(js_root_flags) <(_sources))' + ], + }, + 'inputs': [ + '<(js_bundler_path)', + '<(closure_depswriter_path)', + '<@(js_files)', + ], + 'outputs': [ + 'deps_js_output_file', + ], + 'action': [ + 'python', + '<(closure_depswriter_path)', + '-w', '<(closure_goog_dir):../closure/', + '-w', ':../', + '--output_file', '<(deps_js_output_file)', + '<@(js_files)', + ], + }, + ] +} diff --git a/chrome/browser/resources/chromeos/chromevox/generate_manifest.gypi b/chrome/browser/resources/chromeos/chromevox/generate_manifest.gypi index 797b230..d79b6db 100644 --- a/chrome/browser/resources/chromeos/chromevox/generate_manifest.gypi +++ b/chrome/browser/resources/chromeos/chromevox/generate_manifest.gypi @@ -11,18 +11,20 @@ # # The following variable is optional: # -# is_guest_manifest: 1 or 0; generates a manifest usable while in guest mode. +# guest_manifest: 1 or 0; generates a manifest usable while in guest +# mode. { + 'variables': { + 'generate_manifest_script_path': 'tools/generate_manifest.py', + 'is_guest_manifest%': 0, + }, 'actions': [ { 'action_name': 'generate_manifest', 'message': 'Generate manifest for <(_target_name)', - 'variables': { - 'is_guest_manifest%': 0, - }, 'inputs': [ - 'tools/generate_manifest.py', + '<(generate_manifest_script_path)', '<(template_manifest_path)', ], 'outputs': [ @@ -30,10 +32,11 @@ ], 'action': [ 'python', - 'tools/generate_manifest.py', + '<(generate_manifest_script_path)', + '--is_guest_manifest=<(is_guest_manifest)', + '--use_chromevox_next=<(use_chromevox_next)', '-o', '<(output_manifest_path)', - '-g', '<(is_guest_manifest)', - '<(template_manifest_path)' + '<(template_manifest_path)', ], }, ], diff --git a/chrome/browser/resources/chromeos/chromevox/manifest.json.jinja2 b/chrome/browser/resources/chromeos/chromevox/manifest.json.jinja2 index 068062f..9ffddfb 100644 --- a/chrome/browser/resources/chromeos/chromevox/manifest.json.jinja2 +++ b/chrome/browser/resources/chromeos/chromevox/manifest.json.jinja2 @@ -5,10 +5,14 @@ "version": "1.0", "description": "ChromeVox - Giving Voice to Chrome.", {% if is_guest_manifest == '1' %} - "incognito": "split", + "incognito": "split", {% endif %} "background": { +{% if use_chromevox_next == '1' %} + "page": "cvox2/background/background.html" +{% else %} "page": "chromevox/background/background.html" +{% endif %} }, "permissions": [ "accessibilityPrivate", @@ -29,7 +33,14 @@ "exclude_globs": [ "chrome-extension://mndnfokpggljbaajbnioimlmbfngpief/chromevox/background/background.html" ], "all_frames": true, "js": [ +{% if use_chromevox_next == '1' %} + "closure/closure_preinit.js", + "closure/base.js", + "deps.js", + "cvox2/injected/loader.js" +{% else %} "chromeVoxChromePageScript.js" +{% endif %} ] } ], @@ -39,5 +50,10 @@ "chromevox/injected/mathjax.js", "chromevox/injected/mathjax_external_util.js" ], +{% if use_chromevox_next == '1' %} + "automation": { + "desktop": true + }, +{% endif %} "default_locale": "en" } diff --git a/chrome/browser/resources/chromeos/chromevox/tools/generate_deps.py b/chrome/browser/resources/chromeos/chromevox/tools/generate_deps.py new file mode 100755 index 0000000..42cd613 --- /dev/null +++ b/chrome/browser/resources/chromeos/chromevox/tools/generate_deps.py @@ -0,0 +1,56 @@ +#!/usr/bin/env 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. + +''' Generates a deps.js file based on an input list of javascript files using +Closure style provide/require calls. +''' + +import optparse +import os +import sys + +from jsbundler import PathRewriter + +_SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) +_CHROME_SOURCE = os.path.realpath( + os.path.join(_SCRIPT_DIR, *[os.path.pardir] * 6)) +sys.path.insert(0, os.path.join( + _CHROME_SOURCE, ('chrome/third_party/chromevox/third_party/' + + 'closure-library/closure/bin/build'))) +import source + + +def main(): + parser = optparse.OptionParser(description=__doc__) + parser.add_option('-w', '--rewrite_prefix', action='append', default=[], + dest='prefix_map', metavar='SPEC', + help=('Two path prefixes, separated by colons ' + + 'specifying that a file whose (relative) path ' + + 'name starts with the first prefix should have ' + + 'that prefix replaced by the second prefix to ' + + 'form a path relative to the output directory. ' + + 'The resulting path is used in the deps mapping ' + + 'file path to a list of provided and required ' + + 'namespaces.')) + parser.add_option('-o', '--output_file', action='store', default=[], + metavar='SPEC', + help=('Where to output the generated deps file.')) + options, args = parser.parse_args() + + path_rewriter = PathRewriter(options.prefix_map) + + # Write the generated deps file. + with open(options.output_file, 'w') as output: + for path in args: + js_deps = source.Source(source.GetFileContents(path)) + path = path_rewriter.RewritePath(path) + line = 'goog.addDependency(\'%s\', %s, %s);\n' % ( + path, sorted(js_deps.provides), sorted(js_deps.requires)) + output.write(line) + + +if __name__ == '__main__': + main() diff --git a/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py b/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py index cce1050..6dcf9a9 100755 --- a/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py +++ b/chrome/browser/resources/chromeos/chromevox/tools/generate_manifest.py @@ -25,7 +25,8 @@ from json_comment_eater import Nom def processJinjaTemplate(input_file, output_file, context): (template_path, template_name) = os.path.split(input_file) - env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path)) + env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path), + trim_blocks=True) template = env.get_template(template_name) rendered = template.render(context) rendered_without_comments = Nom(rendered) @@ -44,6 +45,9 @@ def main(): parser.add_option( '-g', '--is_guest_manifest', action='store', metavar='GUEST_MANIFEST', help='Generate a guest mode capable manifest') + parser.add_option( + '--use_chromevox_next', action='store', metavar='CHROMEVOX2', + help='Generate a ChromeVox next manifest') options, args = parser.parse_args() if len(args) != 1: diff --git a/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py b/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py index 051813e..cb16fca 100755 --- a/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py +++ b/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py @@ -120,9 +120,10 @@ class PathRewriter(): parts = spec.split(':') if len(parts) != 2: Die('Invalid prefix rewrite spec %s' % spec) - if not parts[0].endswith('/'): + if not parts[0].endswith('/') and parts[0] != '': parts[0] += '/' self._prefix_map.append(parts) + self._prefix_map.sort(reverse=True) def RewritePath(self, in_path): '''Rewrites an input path according to the list of rules. diff --git a/chrome/browser/resources/chromeos/chromevox2/chromevox.gyp b/chrome/browser/resources/chromeos/chromevox2/chromevox.gyp index 5772ca0..ec85be4 100644 --- a/chrome/browser/resources/chromeos/chromevox2/chromevox.gyp +++ b/chrome/browser/resources/chromeos/chromevox2/chromevox.gyp @@ -5,8 +5,49 @@ { 'conditions': [ ['chromeos==1 and disable_nacl==0 and disable_nacl_untrusted==0', { + 'includes': [ '../chromevox/common.gypi', ], 'targets': [ { + 'target_name': 'chromevox2', + 'type': 'none', + 'dependencies': [ + 'chromevox2_copied_scripts', + 'chromevox2_deps', + 'chromevox2_manifest', + 'chromevox2_guest_manifest', + 'chromevox2_resources', + '../chromevox/chromevox.gyp:chromevox_resources', + ], + }, + { + 'target_name': 'chromevox2_copied_scripts', + 'type': 'none', + 'variables': { + 'dest_dir': '<(chromevox_dest_dir)', + 'js_root_flags': [ + '-r', '.', + '-r', '<(closure_goog_dir)', + ], + }, + 'sources': [ + 'cvox2/background/loader.js', + 'cvox2/injected/loader.js', + ], + 'includes': [ '../chromevox/copy_js.gypi', ], + }, + { + 'target_name': 'chromevox2_deps', + 'type': 'none', + 'variables': { + 'deps_js_output_file': '<(chromevox_dest_dir)/deps.js', + }, + 'sources': [ + 'cvox2/background/loader.js', + 'cvox2/injected/loader.js', + ], + 'includes': ['../chromevox/generate_deps.gypi'], + }, + { 'target_name': 'chromevox2_resources', 'type': 'none', 'copies': [ @@ -14,17 +55,27 @@ 'destination': '<(PRODUCT_DIR)/resources/chromeos/chromevox/cvox2/background', 'files': [ 'cvox2/background/background.html', - 'cvox2/background/background.js', - ], - }, - { - 'destination': '<(PRODUCT_DIR)/resources/chromeos/chromevox/cvox2/injected', - 'files': [ - 'cvox2/injected/injected.js', ], }, ], }, + { + 'target_name': 'chromevox2_manifest', + 'type': 'none', + 'variables': { + 'output_manifest_path': '<(chromevox_dest_dir)/manifest.json' + }, + 'includes': [ '../chromevox/generate_manifest.gypi', ], + }, + { + 'target_name': 'chromevox2_guest_manifest', + 'type': 'none', + 'variables': { + 'output_manifest_path': '<(chromevox_dest_dir)/manifest_guest.json', + 'is_guest_manifest': 1, + }, + 'includes': [ '../chromevox/generate_manifest.gypi', ], + }, ], }], ], diff --git a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.html b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.html index 429931d..a42edfe 100644 --- a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.html +++ b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.html @@ -2,4 +2,7 @@ <script src="../../chromeVoxChromeBackgroundScript.js"></script> <!-- ChromeVox Next --> -<script src="background.js"></script> +<!-- Components to load uncompressed ChromeVox --> +<script src="../../closure/base.js"></script> +<script src="../../deps.js"></script> +<script src="loader.js"></script> diff --git a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js index dcd93fb..6d1c697 100644 --- a/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js +++ b/chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js @@ -7,11 +7,8 @@ * background page. */ -/** ChromeVox2 namespace */ -var cvox2 = function() {}; - -/** Namespace for global objects in the background page. */ -cvox2.global = function() {}; +goog.provide('cvox2.Background'); +goog.provide('cvox2.global'); /** Classic Chrome accessibility API. */ cvox2.global.accessibility = diff --git a/chrome/browser/resources/chromeos/chromevox2/cvox2/injected/injected.js b/chrome/browser/resources/chromeos/chromevox2/cvox2/injected/injected.js index 2174053..d8c0d06 100644 --- a/chrome/browser/resources/chromeos/chromevox2/cvox2/injected/injected.js +++ b/chrome/browser/resources/chromeos/chromevox2/cvox2/injected/injected.js @@ -10,8 +10,7 @@ * keyboard events). */ -/** namespace */ -var cvox2 = function() {}; +goog.provide('cvox2.Injected'); var port = chrome.extension.connect({name: 'chromevox2'}); document.body.addEventListener('keydown', function(evt) { diff --git a/chrome/browser/resources/chromeos/chromevox2/manifest.json b/chrome/browser/resources/chromeos/chromevox2/manifest.json deleted file mode 100644 index 259514e..0000000 --- a/chrome/browser/resources/chromeos/chromevox2/manifest.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDltVl1k15pjRzuZfMc3B69inxwm2bZeZ2O8/zFO+NluHnBm3GJ3fzdOoFGJd+M16I8p7zxxQyHeDMfWYASyCeB8XnUEDKjqNLQfCnncsANzHsYoEbYj2nEUML2P13b9q+AAvpCBpAJ4cZp81e9n1y/vbSXHE4385cgkKueItzikQIDAQAB", - "manifest_version": 2, - "name": "ChromeVox", - "version": "1.0", - "description": "ChromeVox - Giving Voice to Chrome.", - "background": { - "page": "cvox2/background/background.html" - }, - "content_scripts": [ - { - "matches": [ "<all_urls>" ], - "exclude_globs": [ "chrome-extension://mndnfokpggljbaajbnioimlmbfngpief/chromevox/background/background.html" ], - "all_frames": true, - "js": [ - "cvox2/injected/injected.js" - ] - } - ], - "permissions": [ - "accessibilityPrivate", - "automation", - "bookmarks", - "tabs", - "experimental", - "history", - "tts", - "systemPrivate", - "brailleDisplayPrivate", - "commandLinePrivate", - "<all_urls>" - ], - "automation": { - "desktop": true, - "interact": true - }, - "default_locale": "en" -} diff --git a/chrome/chrome_resources.gyp b/chrome/chrome_resources.gyp index 4491351..315079e 100644 --- a/chrome/chrome_resources.gyp +++ b/chrome/chrome_resources.gyp @@ -118,20 +118,13 @@ # TODO(dtseng): Remove use_chromevox_next once ChromeVox Next is ready for testing. ['use_chromevox_next==1', { 'dependencies': [ - 'browser/resources/chromeos/chromevox2/chromevox.gyp:chromevox2_resources', + 'browser/resources/chromeos/chromevox2/chromevox.gyp:chromevox2', ], - }], - ], - 'copies' : [ - { - 'destination': '<(PRODUCT_DIR)/resources/chromeos/braille_ime', - 'files': [ - 'browser/resources/chromeos/braille_ime/manifest.json', + }, { # else use_chromevox_next == 0 + 'dependencies': [ + 'browser/resources/chromeos/chromevox/chromevox.gyp:chromevox', ], - }, - ], - 'dependencies': [ - 'browser/resources/chromeos/chromevox/chromevox.gyp:chromevox_resources', + }], ], }], ], |