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

Side by Side Diff: third_party/closure_compiler/js_binary.py

Issue 2800833004: Create js_library and js_binary templates for closure compiling. (Closed)
Patch Set: update comments Created 3 years, 8 months 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
« no previous file with comments | « third_party/closure_compiler/compile_js.gni ('k') | third_party/closure_compiler/js_library.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """Used by a js_binary action to compile javascript files.
5
6 This script takes in a list of sources and dependencies and compiles them all
7 together into a single compiled .js file. The dependencies are ordered in a
8 post-order, left-to-right traversal order. If multiple instances of the same
9 source file are read, only the first is kept. The script can also take in
10 optional --flags argument which will add custom flags to the compiler. Any
11 extern files can also be passed in using the --extern flag.
12 """
13
14 from argparse import ArgumentParser
15 import os
16 import compile2
17
18
19 def ParseDepList(dep):
20 """Parses a depenency list, returns |sources, deps|."""
21 assert os.path.isfile(dep), (os.path.splitext(dep) +
22 ' is not a js_library target')
23 with open(dep, 'r') as dep_list:
24 lines = dep_list.read().splitlines()
25 assert 'deps:' in lines, dep + ' is not formated correctly, missing "deps:"'
26 split = lines.index('deps:')
27 return lines[1:split], lines[split+1:]
28
29
30 def CrawlDepsTree(deps, sources):
31 """Parses the dependency tree creating a post-order listing of sources."""
32 for dep in deps:
33 new_sources, new_deps = ParseDepList(dep)
34
35 sources = CrawlDepsTree(new_deps, sources)
36 sources += [source for source in new_sources if source not in sources]
37 return sources
38
39
40 def main():
41 parser = ArgumentParser()
42 parser.add_argument('-c', '--compiler', required=True,
43 help='Path to compiler')
44 parser.add_argument('-s', '--sources', nargs='*', default=[],
45 help='List of js source files')
46 parser.add_argument('-o', '--output', required=True,
47 help='Compile to output')
48 parser.add_argument('-d', '--deps', nargs='*', default=[],
49 help='List of js_libarary dependencies')
50 parser.add_argument('-b', '--bootstrap',
51 help='A file to include before all others')
52 parser.add_argument('-cf', '--config', nargs='*', default=[],
53 help='A list of files to include after bootstrap and '
54 'before all others')
55 parser.add_argument('-f', '--flags', nargs='*', default=[],
56 help='A list of custom flags to pass to the compiler. '
57 'Do not include leading dashes')
58 parser.add_argument('-e', '--externs', nargs='*', default=[],
59 help='A list of extern files to pass to the compiler')
60
61 args = parser.parse_args()
62 sources = CrawlDepsTree(args.deps, []) + args.sources
63
64 compiler_args = ['--%s' % flag for flag in args.flags]
65 compiler_args += ['--externs=%s' % e for e in args.externs]
66 compiler_args += [
67 '--js_output_file',
68 args.output,
69 '--js',
70 ]
71 if args.bootstrap:
72 compiler_args += [args.bootstrap]
73 compiler_args += args.config
74 compiler_args += sources
75
76 compile2.Checker().run_jar(args.compiler, compiler_args)
77
78
79 if __name__ == '__main__':
80 main()
OLDNEW
« no previous file with comments | « third_party/closure_compiler/compile_js.gni ('k') | third_party/closure_compiler/js_library.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698