Skip to content

Commit

Permalink
Add a wrapper script for deps.js file generation, make misc changes t…
Browse files Browse the repository at this point in the history
…o 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
  • Loading branch information
dtseng@chromium.org committed Jun 5, 2014
1 parent 1edbb1d commit acc3048
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 93 deletions.
24 changes: 24 additions & 0 deletions chrome/browser/resources/chromeos/braille_ime/braille_ime.gyp
Original file line number Diff line number Diff line change
@@ -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',
],
},
],
},
],
}],
],
}
24 changes: 11 additions & 13 deletions chrome/browser/resources/chromeos/chromevox/chromevox.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
20 changes: 20 additions & 0 deletions chrome/browser/resources/chromeos/chromevox/common.gypi
Original file line number Diff line number Diff line change
@@ -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',
},
}
9 changes: 5 additions & 4 deletions chrome/browser/resources/chromeos/chromevox/copy_js.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand Down
43 changes: 43 additions & 0 deletions chrome/browser/resources/chromeos/chromevox/generate_deps.gypi
Original file line number Diff line number Diff line change
@@ -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)',
],
},
]
}
19 changes: 11 additions & 8 deletions chrome/browser/resources/chromeos/chromevox/generate_manifest.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@
#
# 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': [
'<(output_manifest_path)'
],
'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)',
],
},
],
Expand Down
18 changes: 17 additions & 1 deletion chrome/browser/resources/chromeos/chromevox/manifest.json.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 %}
]
}
],
Expand All @@ -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"
}
56 changes: 56 additions & 0 deletions chrome/browser/resources/chromeos/chromevox/tools/generate_deps.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ def __init__(self, specs):
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.
Expand Down
Loading

0 comments on commit acc3048

Please sign in to comment.