Runs checkdeps on #include statements added in this change. Breaking - rules is an error, breaking ! rules is a warning.
(input_api, output_api)
| 163 | |
| 164 | |
| 165 | def _CheckUnwantedDependencies(input_api, output_api): |
| 166 | """Runs checkdeps on #include statements added in this |
| 167 | change. Breaking - rules is an error, breaking ! rules is a |
| 168 | warning. |
| 169 | """ |
| 170 | # We need to wait until we have an input_api object and use this |
| 171 | # roundabout construct to import checkdeps because this file is |
| 172 | # eval-ed and thus doesn't have __file__. |
| 173 | original_sys_path = sys.path |
| 174 | try: |
| 175 | root = input_api.PresubmitLocalPath() |
| 176 | if not os.path.exists(os.path.join(root, 'buildtools')): |
| 177 | root = os.path.dirname(root) |
| 178 | if not os.path.exists(os.path.join(root, 'buildtools')): |
| 179 | raise RuntimeError( |
| 180 | "Failed to find //buildtools directory for checkdeps") |
| 181 | sys.path = sys.path + [ |
| 182 | input_api.os_path.join(root, 'buildtools', 'checkdeps') |
| 183 | ] |
| 184 | import checkdeps |
| 185 | from cpp_checker import CppChecker |
| 186 | from rules import Rule |
| 187 | finally: |
| 188 | # Restore sys.path to what it was before. |
| 189 | sys.path = original_sys_path |
| 190 | |
| 191 | def _FilesImpactedByDepsChange(files): |
| 192 | all_files = [f.AbsoluteLocalPath() for f in files] |
| 193 | deps_files = [p for p in all_files if IsDepsFile(p)] |
| 194 | impacted_files = union([_CollectImpactedFiles(path) for path in deps_files]) |
| 195 | impacted_file_objs = [ImpactedFile(path) for path in impacted_files] |
| 196 | return impacted_file_objs |
| 197 | |
| 198 | def IsDepsFile(p): |
| 199 | return os.path.isfile(p) and os.path.basename(p) == 'DEPS' |
| 200 | |
| 201 | def union(list_of_lists): |
| 202 | """Ensure no duplicates""" |
| 203 | return set(sum(list_of_lists, [])) |
| 204 | |
| 205 | def _CollectImpactedFiles(deps_file): |
| 206 | # TODO(liviurau): Do not walk paths twice. Then we have no duplicates. |
| 207 | # Higher level DEPS changes may dominate lower level DEPS changes. |
| 208 | # TODO(liviurau): Check if DEPS changed in the right way. |
| 209 | # 'include_rules' impact c++ files but 'vars' or 'deps' do not. |
| 210 | # Maybe we just eval both old and new DEPS content and check |
| 211 | # if the list are the same. |
| 212 | result = [] |
| 213 | parent_dir = os.path.dirname(deps_file) |
| 214 | for relative_f in input_api.change.AllFiles(parent_dir): |
| 215 | abs_f = os.path.join(parent_dir, relative_f) |
| 216 | if CppChecker.IsCppFile(abs_f): |
| 217 | result.append(abs_f) |
| 218 | return result |
| 219 | |
| 220 | class ImpactedFile(object): |
| 221 | """Duck type version of AffectedFile needed to check files under directories |
| 222 | where a DEPS file changed. Extend the interface along the line of |
nothing calls this directly
no test coverage detected
searching dependent graphs…