Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py |
| diff --git a/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py b/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py |
| index 42da7a145853cdc1000aad860c4cfff101efe1bb..ea999e7b617fb632dbb312bc42b3127ae8942b5b 100755 |
| --- a/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py |
| +++ b/chrome/browser/resources/chromeos/chromevox/tools/jsbundler.py |
| @@ -32,6 +32,7 @@ ways: |
| import optparse |
| import os |
| +import re |
| import shutil |
| import sys |
| @@ -171,6 +172,21 @@ def ReadSources(roots=[], source_files=[], need_source_text=False, |
| return sources |
| +def _GetBase(sources): |
| + '''Gets the closure base.js file if present among the sources. |
| + |
| + Args: |
| + sources, dict: Dictionary with SourceWithPath objects as values. |
| + Returns: |
|
David Tseng
2014/06/12 20:23:29
'sources, dict' looks like a pair so perhaps remov
|
| + SourceWithPath: The source file providing the goog namespace. |
| + ''' |
| + for source in sources.itervalues(): |
| + if (os.path.basename(source.GetInPath()) == 'base.js' and |
| + 'goog' in source.provides): |
| + return source |
| + Die('goog.base not provided by any file.') |
| + |
| + |
| def CalcDeps(bundle, sources, top_level): |
| '''Calculates dependencies for a set of top-level files. |
| @@ -180,23 +196,31 @@ def CalcDeps(bundle, sources, top_level): |
| top_level, list: List of top-level input paths to calculate dependencies |
| for. |
| ''' |
| - def GetBase(sources): |
| - for source in sources.itervalues(): |
| - if (os.path.basename(source.GetInPath()) == 'base.js' and |
| - 'goog' in source.provides): |
| - return source |
| - Die('goog.base not provided by any file') |
| - |
| providers = [s for s in sources.itervalues() if len(s.provides) > 0] |
| deps = depstree.DepsTree(providers) |
| namespaces = [] |
| for path in top_level: |
| namespaces.extend(sources[path].requires) |
| # base.js is an implicit dependency that always goes first. |
| - bundle.Add(GetBase(sources)) |
| + bundle.Add(_GetBase(sources)) |
| bundle.Add(deps.GetDependencies(namespaces)) |
| +def _MarkAsCompiled(sources): |
| + '''Sets COMPILED to true in the Closure base.js source.''' |
|
David Tseng
2014/06/12 20:23:29
nit: Args?
|
| + base = _GetBase(sources) |
| + new_content, count = re.subn('^var COMPILED = false;$', |
| + 'var COMPILED = true;', |
| + base.GetSource(), |
| + count=1, |
| + flags=re.MULTILINE) |
| + if count != 1: |
| + Die('COMPILED var assignment not found in %s' % base.GetInPath()) |
|
David Tseng
2014/06/12 20:23:29
Print the count since technically it could be > 1
|
| + sources[base.GetInPath()] = SourceWithPaths( |
| + new_content, |
| + base.GetInPath(), |
| + base.GetOutPath()) |
| + |
| def LinkOrCopyFiles(sources, dest_dir): |
| '''Copies a list of sources to a destination directory.''' |
| @@ -278,11 +302,11 @@ def main(): |
| options, args = CreateOptionParser().parse_args() |
| if len(args) < 1: |
| Die('At least one top-level source file must be specified.') |
| + output_bundle = options.mode in ('bundle', 'compressed_bundle') |
| path_rewriter = PathRewriter(options.prefix_map) |
|
David Tseng
2014/06/12 20:23:29
Maybe call this need_source_text?
|
| - sources = ReadSources(options.roots, |
| - args, |
| - options.mode in ('bundle', 'compressed_bundle'), |
| - path_rewriter) |
| + sources = ReadSources(options.roots, args, output_bundle, path_rewriter) |
| + if output_bundle: |
| + _MarkAsCompiled(sources) |
| bundle = Bundle() |
| if len(options.roots) > 0: |
| CalcDeps(bundle, sources, args) |