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

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 | no next file » | 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 30 matching lines...) Expand all
41 # FIXME: Make this run on other platforms as well. 41 # FIXME: Make this run on other platforms as well.
42 if not input_api.platform.startswith('linux'): 42 if not input_api.platform.startswith('linux'):
43 return [] 43 return []
44 local_paths = [f.LocalPath() for f in input_api.AffectedFiles()] 44 local_paths = [f.LocalPath() for f in input_api.AffectedFiles()]
45 45
46 # FIXME: The compilation does not actually run if injected script-related fi les 46 # 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 47 # have changed, as they reside in core/inspector, which is not affected
48 # by this presubmit. 48 # by this presubmit.
49 # Once this is fixed, InjectedScriptHost.idl and JavaScriptCallFrame.idl 49 # Once this is fixed, InjectedScriptHost.idl and JavaScriptCallFrame.idl
50 # should be added to the list of triggers. 50 # should be added to the list of triggers.
51 if (any("devtools/front_end" in path for path in local_paths) or 51 devtools_front_end = input_api.os_path.join("devtools", "front_end")
52 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 53 any("protocol.json" in path for path in local_paths) or
53 any("InjectedScriptSource.js" in path for path in local_paths) or 54 any("InjectedScriptSource.js" in path for path in local_paths) or
54 any("InjectedScriptCanvasModuleSource.js" in path for path in local_path s)): 55 any("InjectedScriptCanvasModuleSource.js" in path for path in local_path s)):
55 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 56 lint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
56 "scripts", "compile_frontend.py") 57 "scripts", "compile_frontend.py")
57 out, _ = input_api.subprocess.Popen( 58 out, _ = input_api.subprocess.Popen(
58 [input_api.python_executable, lint_path], 59 [input_api.python_executable, lint_path],
59 stdout=input_api.subprocess.PIPE, 60 stdout=input_api.subprocess.PIPE,
60 stderr=input_api.subprocess.STDOUT).communicate() 61 stderr=input_api.subprocess.STDOUT).communicate()
61 if "WARNING" in out or "ERROR" in out: 62 if "WARNING" in out or "ERROR" in out:
62 return [output_api.PresubmitError(out)] 63 return [output_api.PresubmitError(out)]
63 return [] 64 return []
64 65
65 66
66 def _CheckConvertSVGToPNGHashes(input_api, output_api): 67 def _CheckConvertSVGToPNGHashes(input_api, output_api):
67 if not input_api.platform.startswith('linux'): 68 if not input_api.platform.startswith('linux'):
68 return [] 69 return []
69 70
70 original_sys_path = sys.path 71 original_sys_path = sys.path
71 try: 72 try:
72 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')] 73 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')]
73 import devtools_file_hashes 74 import devtools_file_hashes
74 finally: 75 finally:
75 sys.path = original_sys_path 76 sys.path = original_sys_path
76 77
77 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)] 78 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")] 79 images_src_path = input_api.os_path.join("devtools", "front_end", "Images", "src")
apavlov 2014/10/21 14:13:49 You can declare devtools_front_end at the top leve
80 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") 81 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
80 hashes_file_name = "svg2png.hashes" 82 hashes_file_name = "svg2png.hashes"
81 hashes_file_path = image_sources_path + "/" + hashes_file_name 83 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) 84 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: 85 if len(invalid_hash_file_paths) == 0:
84 return [] 86 return []
85 invalid_hash_file_names = [re.sub(".*/", "", file_path) for file_path in inv alid_hash_file_paths] 87 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) 88 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 89 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)] 90 return [output_api.PresubmitError(error_message)]
89 91
90 92
91 def _CheckOptimizePNGHashes(input_api, output_api): 93 def _CheckOptimizePNGHashes(input_api, output_api):
92 if not input_api.platform.startswith('linux'): 94 if not input_api.platform.startswith('linux'):
93 return [] 95 return []
94 96
95 original_sys_path = sys.path 97 original_sys_path = sys.path
96 try: 98 try:
97 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')] 99 sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPa th(), 'scripts')]
98 import devtools_file_hashes 100 import devtools_file_hashes
99 finally: 101 finally:
100 sys.path = original_sys_path 102 sys.path = original_sys_path
101 103
102 absolute_local_paths = [af.AbsoluteLocalPath() for af in input_api.AffectedF iles(include_deletes=False)] 104 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")] 105 images_src_path = input_api.os_path.join("devtools", "front_end", "Images", "src")
apavlov 2014/10/21 14:13:49 ditto
106 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") 107 image_sources_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "front_end", "Images", "src")
105 hashes_file_name = "optimize_png.hashes" 108 hashes_file_name = "optimize_png.hashes"
106 hashes_file_path = image_sources_path + "/" + hashes_file_name 109 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) 110 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: 111 if len(invalid_hash_file_paths) == 0:
109 return [] 112 return []
110 invalid_hash_file_names = [re.sub(".*/", "", file_path) for file_path in inv alid_hash_file_paths] 113 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) 114 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 115 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)] 116 return [output_api.PresubmitError(error_message)]
114 117
115 118
116 def CheckChangeOnUpload(input_api, output_api): 119 def CheckChangeOnUpload(input_api, output_api):
117 results = [] 120 results = []
118 results.extend(_CompileDevtoolsFrontend(input_api, output_api)) 121 results.extend(_CompileDevtoolsFrontend(input_api, output_api))
119 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api)) 122 results.extend(_CheckConvertSVGToPNGHashes(input_api, output_api))
120 results.extend(_CheckOptimizePNGHashes(input_api, output_api)) 123 results.extend(_CheckOptimizePNGHashes(input_api, output_api))
121 return results 124 return results
122 125
123 126
124 def CheckChangeOnCommit(input_api, output_api): 127 def CheckChangeOnCommit(input_api, output_api):
125 return [] 128 return []
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698