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

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

Issue 421253006: Add ChromeCodingConvention.java to Closure Compiler to preserve getInstance() type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@A_typechecking_about
Patch Set: rebase onto master Created 6 years, 4 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 from checker import Checker as Checker 7 from checker import Checker as Checker
8 import os 8 import os
9 import sys
10
9 try: 11 try:
10 import json 12 import json
11 except: 13 except:
12 import simplejson as json 14 import simplejson as json
13 15
14 16
15 class Module(object): 17 class Module(object):
16 def __init__(self, name, sources, depends=[], externs=[]): 18 def __init__(self, name, sources, depends=[], externs=[]):
17 self.name = name 19 self.name = name
18 self.sources = sources 20 self.sources = sources
(...skipping 19 matching lines...) Expand all
38 # TODO(dbeam): should ModuleParser be internal to ModuleCompiler or should we 40 # TODO(dbeam): should ModuleParser be internal to ModuleCompiler or should we
39 # pass Modules into ModuleCompiler.compile()? Maybe this is fine? 41 # pass Modules into ModuleCompiler.compile()? Maybe this is fine?
40 class ModuleParser(object): 42 class ModuleParser(object):
41 _cache = {} 43 _cache = {}
42 44
43 def __init__(self, verbose=False): 45 def __init__(self, verbose=False):
44 self._verbose = verbose 46 self._verbose = verbose
45 47
46 def parse(self, file_path): 48 def parse(self, file_path):
47 if file_path in self._cache: 49 if file_path in self._cache:
48 print "(INFO) Found module file %s in the cache" % file_path 50 print "(INFO) Found module file %s in the cache" % file_path
49 return self._cache[file_path] 51 return self._cache[file_path]
50 52
51 file = open(file_path, "r") 53 file = open(file_path, "r")
52 data = json.load(file) 54 data = json.load(file)
53 file.close() 55 file.close()
54 56
55 if self._verbose: 57 if self._verbose:
56 pretty_json = json.dumps(data, indent=2, separators=(',', ': ')).strip() 58 pretty_json = json.dumps(data, indent=2, separators=(',', ': ')).strip()
57 print "(INFO) Layout: " + os.linesep + pretty_json + os.linesep 59 print "(INFO) Layout: " + os.linesep + pretty_json + os.linesep
58 60
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 rel_path = lambda f: os.path.join(here_to_module_dir, f) 92 rel_path = lambda f: os.path.join(here_to_module_dir, f)
91 93
92 modules = self._parser.parse(module_file) 94 modules = self._parser.parse(module_file)
93 95
94 for m in modules: 96 for m in modules:
95 self._debug("MODULE: " + m.name, prefix="", suffix=os.linesep) 97 self._debug("MODULE: " + m.name, prefix="", suffix=os.linesep)
96 98
97 for s in m.sources: 99 for s in m.sources:
98 depends = [rel_path(d) for d in m.depends] 100 depends = [rel_path(d) for d in m.depends]
99 externs = [rel_path(e) for e in m.externs] 101 externs = [rel_path(e) for e in m.externs]
100 self._checker.check(rel_path(s), depends=depends, externs=externs) 102 exit_code, _ = self._checker.check(rel_path(s), depends=depends,
103 externs=externs)
104 if exit_code:
105 sys.exit(exit_code)
101 106
102 if s != m.sources[-1]: 107 if s != m.sources[-1]:
103 self._debug(os.linesep, prefix="") 108 self._debug(os.linesep, prefix="")
104 109
105 if m != modules[-1]: 110 if m != modules[-1]:
106 self._debug(os.linesep, prefix="") 111 self._debug(os.linesep, prefix="")
107 112
108 113
109 def main(opts): 114 def main(opts):
110 module_compiler = ModuleCompiler(verbose=opts.verbose) 115 module_compiler = ModuleCompiler(verbose=opts.verbose)
111 for module_file in opts.module_file: 116 for module_file in opts.module_file:
112 module_compiler.compile(module_file) 117 module_compiler.compile(module_file)
113 118
114 119
115 if __name__ == "__main__": 120 if __name__ == "__main__":
116 parser = argparse.ArgumentParser( 121 parser = argparse.ArgumentParser(
117 description="Typecheck JavaScript using Closure compiler") 122 description="Typecheck JavaScript using Closure compiler")
118 parser.add_argument("-v", "--verbose", action="store_true", 123 parser.add_argument("-v", "--verbose", action="store_true",
119 help="Show more information as this script runs") 124 help="Show more information as this script runs")
120 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE, 125 parser.add_argument("module_file", nargs=argparse.ONE_OR_MORE,
121 help="Path to a modules file to check") 126 help="Path to a modules file to check")
122 main(parser.parse_args()) 127 main(parser.parse_args())
OLDNEW
« no previous file with comments | « third_party/closure_compiler/coding_conventions_test.py ('k') | third_party/closure_compiler/runner/build_runner_jar.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698