OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] | 81 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] |
82 | 82 |
83 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) | 83 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) |
84 | 84 |
85 # Basic regex for invalid JsDoc types: an object type name ([A-Z][A-Za-z0-9.]+[A
-Za-z0-9]) not preceded by '!', '?', ':' (this, new), or '.' (object property). | 85 # Basic regex for invalid JsDoc types: an object type name ([A-Z][A-Za-z0-9.]+[A
-Za-z0-9]) not preceded by '!', '?', ':' (this, new), or '.' (object property). |
86 invalid_type_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*\{.
*(?<![!?:.A-Za-z0-9])([A-Z][A-Za-z0-9.]+[A-Za-z0-9])[^/]*\}") | 86 invalid_type_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*\{.
*(?<![!?:.A-Za-z0-9])([A-Z][A-Za-z0-9.]+[A-Za-z0-9])[^/]*\}") |
87 | 87 |
88 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or
+ r")\s*.*(?<![{: ])([?!])=?\}") | 88 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or
+ r")\s*.*(?<![{: ])([?!])=?\}") |
89 | 89 |
90 importscript_regex = re.compile(r"importScript\(\s*[\"']") | |
91 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") | 90 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") |
92 | 91 |
93 errors_found = False | 92 errors_found = False |
94 | 93 |
95 | 94 |
96 def run_in_shell(command_line): | 95 def run_in_shell(command_line): |
97 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc
ess.STDOUT, shell=True) | 96 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc
ess.STDOUT, shell=True) |
98 | 97 |
99 | 98 |
100 def hasErrors(output): | 99 def hasErrors(output): |
101 return re.search(error_warning_regex, output) != None | 100 return re.search(error_warning_regex, output) != None |
102 | 101 |
103 | 102 |
104 def verify_importScript_usage(): | |
105 errors_found = False | |
106 for module in modules: | |
107 for file_name in module["sources"]: | |
108 if path.basename(file_name) == module_initializer_name: | |
109 log_error("Module initializer (%s) may not be listed among modul
e's scripts; found in '%s'" % (module_initializer_name, module["name"])) | |
110 errors_found = True | |
111 continue | |
112 try: | |
113 with open(path.join(devtools_frontend_path, file_name), "r") as
sourceFile: | |
114 source = sourceFile.read() | |
115 if re.search(importscript_regex, source): | |
116 log_error("importScript() call only allowed in module in
itializers (%s); found in %s" % (module_initializer_name, file_name)) | |
117 errors_found = True | |
118 except: | |
119 log_error("Failed to access %s" % file_name) | |
120 raise | |
121 return errors_found | |
122 | |
123 | |
124 def dump_all_checked_files(): | 103 def dump_all_checked_files(): |
125 files = {} | 104 files = {} |
126 for module in modules: | 105 for module in modules: |
127 for source in module["sources"]: | 106 for source in module["sources"]: |
128 files[path.join(devtools_frontend_path, source)] = True | 107 files[path.join(devtools_frontend_path, source)] = True |
129 return files.keys() | 108 return files.keys() |
130 | 109 |
131 | 110 |
132 def verify_jsdoc_extra(additional_files): | 111 def verify_jsdoc_extra(additional_files): |
133 return run_in_shell("%s -jar %s %s" % (java_exec, jsdoc_validator_jar, " ".j
oin(dump_all_checked_files() + additional_files))) | 112 return run_in_shell("%s -jar %s %s" % (java_exec, jsdoc_validator_jar, " ".j
oin(dump_all_checked_files() + additional_files))) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 proc = subprocess.Popen("which java", stdout=subprocess.PIPE, shell=True) | 157 proc = subprocess.Popen("which java", stdout=subprocess.PIPE, shell=True) |
179 (javaPath, _) = proc.communicate() | 158 (javaPath, _) = proc.communicate() |
180 | 159 |
181 if proc.returncode != 0: | 160 if proc.returncode != 0: |
182 print "Cannot find java ('which java' return code = %d, should be 0)" %
proc.returncode | 161 print "Cannot find java ('which java' return code = %d, should be 0)" %
proc.returncode |
183 sys.exit(1) | 162 sys.exit(1) |
184 print "Java executable: " + re.sub(r"\n$", "", javaPath) | 163 print "Java executable: " + re.sub(r"\n$", "", javaPath) |
185 | 164 |
186 check_java_path() | 165 check_java_path() |
187 | 166 |
188 print "Verifying 'importScript' function usage..." | |
189 errors_found |= verify_importScript_usage() | |
190 | |
191 modules_dir = tempfile.mkdtemp() | 167 modules_dir = tempfile.mkdtemp() |
192 common_closure_args = " --summary_detail_level 3 --jscomp_error visibility --com
pilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASC
RIPT5 --accept_const_keyword --module_output_path_prefix %s/" % modules_dir | 168 common_closure_args = " --summary_detail_level 3 --jscomp_error visibility --com
pilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in ECMASC
RIPT5 --accept_const_keyword --module_output_path_prefix %s/" % modules_dir |
193 | 169 |
194 spawned_compiler_command = "%s -jar %s %s \\\n" % (java_exec, closure_compiler_j
ar, common_closure_args) | 170 spawned_compiler_command = "%s -jar %s %s \\\n" % (java_exec, closure_compiler_j
ar, common_closure_args) |
195 | 171 |
196 modules_by_name = {} | 172 modules_by_name = {} |
197 standalone_modules_by_name = {} | 173 standalone_modules_by_name = {} |
198 dependents_by_module_name = {} | 174 dependents_by_module_name = {} |
199 | 175 |
200 for module in modules: | 176 for module in modules: |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 errors_found |= hasErrors(validateInjectedScriptOut) | 382 errors_found |= hasErrors(validateInjectedScriptOut) |
407 | 383 |
408 if errors_found: | 384 if errors_found: |
409 print "ERRORS DETECTED" | 385 print "ERRORS DETECTED" |
410 | 386 |
411 os.remove(injectedScriptSourceTmpFile) | 387 os.remove(injectedScriptSourceTmpFile) |
412 os.remove(injectedScriptCanvasModuleSourceTmpFile) | 388 os.remove(injectedScriptCanvasModuleSourceTmpFile) |
413 os.remove(compiler_args_file.name) | 389 os.remove(compiler_args_file.name) |
414 os.remove(protocol_externs_file) | 390 os.remove(protocol_externs_file) |
415 shutil.rmtree(modules_dir, True) | 391 shutil.rmtree(modules_dir, True) |
OLD | NEW |