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

Side by Side Diff: Source/devtools/PRESUBMIT.py

Issue 662393004: DevTools: scripts: remove manual path concatenation / splitting (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 | « no previous file | Source/devtools/scripts/devtools_file_hashes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2014 Google Inc. All rights reserved. 1 # Copyright (C) 2014 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 14 matching lines...) Expand all
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 """DevTools JSDoc validator presubmit script 29 """DevTools JSDoc validator presubmit script
30 30
31 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 31 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
32 for more details about the presubmit API built into gcl. 32 for more details about the presubmit API built into gcl.
33 """ 33 """
34 34
35 import os
36 import re
37 import sys 35 import sys
38 36
39 37
40 def _CompileDevtoolsFrontend(input_api, output_api): 38 def _CompileDevtoolsFrontend(input_api, output_api):
41 # FIXME: Make this run on other platforms as well. 39 # FIXME: Make this run on other platforms as well.
42 if not input_api.platform.startswith('linux'): 40 if not input_api.platform.startswith('linux'):
43 return [] 41 return []
44 local_paths = [f.LocalPath() for f in input_api.AffectedFiles()] 42 local_paths = [f.LocalPath() for f in input_api.AffectedFiles()]
45 43
46 # FIXME: The compilation does not actually run if injected script-related fi les 44 # FIXME: The compilation does not actually run if injected script-related fi les
47 # have changed, as they reside in core/inspector, which is not affected 45 # have changed, as they reside in core/inspector, which is not affected
48 # by this presubmit. 46 # by this presubmit.
49 # Once this is fixed, InjectedScriptHost.idl and JavaScriptCallFrame.idl 47 # Once this is fixed, InjectedScriptHost.idl and JavaScriptCallFrame.idl
50 # should be added to the list of triggers. 48 # should be added to the list of triggers.
51 if (any("devtools/front_end" in path for path in local_paths) or 49 devtools_front_end = input_api.os_path.join("devtools", "front_end")
50 if (any(devtools_front_end in path for path in local_paths) or
52 any("protocol.json" in path for path in local_paths) or 51 any("protocol.json" in path for path in local_paths) or
53 any("InjectedScriptSource.js" in path for path in local_paths) or 52 any("InjectedScriptSource.js" in path for path in local_paths) or
54 any("InjectedScriptCanvasModuleSource.js" in path for path in local_path s)): 53 any("InjectedScriptCanvasModuleSource.js" in path for path in local_path s)):
55 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 54 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
56 "scripts", "compile_frontend.py") 55 "scripts", "compile_frontend.py")
57 out, _ = input_api.subprocess.Popen( 56 out, _ = input_api.subprocess.Popen(
58 [input_api.python_executable, lint_path], 57 [input_api.python_executable, lint_path],
59 stdout=input_api.subprocess.PIPE, 58 stdout=input_api.subprocess.PIPE,
60 stderr=input_api.subprocess.STDOUT).communicate() 59 stderr=input_api.subprocess.STDOUT).communicate()
61 if "WARNING" in out or "ERROR" in out: 60 if "WARNING" in out or "ERROR" in out:
62 return [output_api.PresubmitError(out)] 61 return [output_api.PresubmitError(out)]
63 return [] 62 return []
64 63
65 64
66 def _CheckConvertSVGToPNGHashes(input_api, output_api): 65 def _CheckConvertSVGToPNGHashes(input_api, output_api):
67 if not input_api.platform.startswith('linux'): 66 if not input_api.platform.startswith('linux'):
68 return [] 67 return []
69 68
70 original_sys_path = sys.path 69 original_sys_path = sys.path
71 try: 70 try:
72 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')] 71 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')]
73 import devtools_file_hashes 72 import devtools_file_hashes
74 finally: 73 finally:
75 sys.path = original_sys_path 74 sys.path = original_sys_path
76 75
77 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)] 76 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)]
78 image_source_file_paths = [path for path in absolute_local_paths if "devtool s/front_end/Images/src" in path and path.endswith(".svg")] 77 images_src_path = input_api.os_path.join("devtools", "front_end", "Images", "src")
78 image_source_file_paths = [path for path in absolute_local_paths if images_s rc_path in path and path.endswith(".svg")]
79 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src") 79 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
80 hashes_file_name = "svg2png.hashes" 80 hashes_file_name = "svg2png.hashes"
81 hashes_file_path = image_sources_path + "/" + hashes_file_name 81 hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_na me)
82 invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(has hes_file_path, image_source_file_paths) 82 invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(has hes_file_path, image_source_file_paths)
83 if len(invalid_hash_file_paths) == 0: 83 if len(invalid_hash_file_paths) == 0:
84 return [] 84 return []
85 invalid_hash_file_names = [re.sub(".*/", "", file_path) for file_path in inv alid_hash_file_paths] 85 invalid_hash_file_names = [input_api.os_path.basename(file_path) for file_pa th in invalid_hash_file_paths]
86 file_paths_str = ", ".join(invalid_hash_file_names) 86 file_paths_str = ", ".join(invalid_hash_file_names)
87 error_message = "The following SVG files should be converted to PNG using co nvert_svg_images_png.py script before uploading: \n - %s" % file_paths_str 87 error_message = "The following SVG files should be converted to PNG using co nvert_svg_images_png.py script before uploading: \n - %s" % file_paths_str
88 return [output_api.PresubmitError(error_message)] 88 return [output_api.PresubmitError(error_message)]
89 89
90 90
91 def _CheckOptimizePNGHashes(input_api, output_api): 91 def _CheckOptimizePNGHashes(input_api, output_api):
92 if not input_api.platform.startswith('linux'): 92 if not input_api.platform.startswith('linux'):
93 return [] 93 return []
94 94
95 original_sys_path = sys.path 95 original_sys_path = sys.path
96 try: 96 try:
97 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')] 97 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')]
98 import devtools_file_hashes 98 import devtools_file_hashes
99 finally: 99 finally:
100 sys.path = original_sys_path 100 sys.path = original_sys_path
101 101
102 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)] 102 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)]
103 image_source_file_paths = [path for path in absolute_local_paths if "devtool s/front_end/Images/src" in path and path.endswith(".svg")] 103 images_src_path = input_api.os_path.join("devtools", "front_end", "Images", "src")
104 image_source_file_paths = [path for path in absolute_local_paths if images_s rc_path in path and path.endswith(".svg")]
104 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src") 105 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
105 hashes_file_name = "optimize_png.hashes" 106 hashes_file_name = "optimize_png.hashes"
106 hashes_file_path = image_sources_path + "/" + hashes_file_name 107 hashes_file_path = input_api.os_path.join(image_sources_path, hashes_file_na me)
107 invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(has hes_file_path, image_source_file_paths) 108 invalid_hash_file_paths = devtools_file_hashes.files_with_invalid_hashes(has hes_file_path, image_source_file_paths)
108 if len(invalid_hash_file_paths) == 0: 109 if len(invalid_hash_file_paths) == 0:
109 return [] 110 return []
110 invalid_hash_file_names = [re.sub(".*/", "", file_path) for file_path in inv alid_hash_file_paths] 111 invalid_hash_file_names = [input_api.os_path.basename(file_path) for file_pa th in invalid_hash_file_paths]
111 file_paths_str = ", ".join(invalid_hash_file_names) 112 file_paths_str = ", ".join(invalid_hash_file_names)
112 error_message = "The following PNG files should be optimized using optimize_ png_images.py script before uploading: \n - %s" % file_paths_str 113 error_message = "The following PNG files should be optimized using optimize_ png_images.py script before uploading: \n - %s" % file_paths_str
113 return [output_api.PresubmitError(error_message)] 114 return [output_api.PresubmitError(error_message)]
114 115
115 116
116 def CheckChangeOnUpload(input_api, output_api): 117 def CheckChangeOnUpload(input_api, output_api):
117 results = [] 118 results = []
118 results.extend(_CompileDevtoolsFrontend(input_api, output_api)) 119 results.extend(_CompileDevtoolsFrontend(input_api, output_api))
119 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api)) 120 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api))
120 results.extend(_CheckOptimizePNGHashes(input_api, output_api)) 121 results.extend(_CheckOptimizePNGHashes(input_api, output_api))
121 return results 122 return results
122 123
123 124
124 def CheckChangeOnCommit(input_api, output_api): 125 def CheckChangeOnCommit(input_api, output_api):
125 return [] 126 return []
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/scripts/devtools_file_hashes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698