Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import re | 7 import re |
| 8 | 8 |
| 9 from crash.type_enums import CallStackFormatType, CallStackLanguageType | 9 from crash.type_enums import CallStackFormatType, CallStackLanguageType |
| 10 | 10 |
| 11 | 11 |
| 12 GENERATED_CODE_FILE_PATH_PATTERN = re.compile(r'.*out/[^/]+/gen/') | 12 GENERATED_CODE_FILE_PATH_PATTERN = re.compile(r'.*out/[^/]+/gen/') |
| 13 THIRD_PARTY_FILE_PATH_MARKER = 'third_party' | 13 THIRD_PARTY_FILE_PATH_MARKER = 'third_party' |
| 14 CHROMIUM_REPO_URL = 'https://chromium.googlesource.com/chromium/src.git' | |
| 14 | 15 |
| 15 | 16 |
| 16 def GetFullPathForJavaFrame(function): | 17 def GetFullPathForJavaFrame(function): |
| 17 """Uses java function package name to normalize and generate full file path. | 18 """Uses java function package name to normalize and generate full file path. |
| 18 | 19 |
| 19 Args: | 20 Args: |
| 20 function: Java function, for example, 'org.chromium.CrAct.onDestroy'. | 21 function: Java function, for example, 'org.chromium.CrAct.onDestroy'. |
| 21 | 22 |
| 22 Returns: | 23 Returns: |
| 23 A string of normalized full path, for example, org/chromium/CrAct.java | 24 A string of normalized full path, for example, org/chromium/CrAct.java |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 45 | 46 |
| 46 | 47 |
| 47 def GetDepPathAndNormalizedFilePath(path, deps): | 48 def GetDepPathAndNormalizedFilePath(path, deps): |
| 48 """Determines the dep of a file path and normalizes the path. | 49 """Determines the dep of a file path and normalizes the path. |
| 49 | 50 |
| 50 Args: | 51 Args: |
| 51 path (str): Represents a path. | 52 path (str): Represents a path. |
| 52 deps (dict): Map dependency path to its corresponding Dependency. | 53 deps (dict): Map dependency path to its corresponding Dependency. |
| 53 | 54 |
| 54 Returns: | 55 Returns: |
| 55 A tuple - (dep_path, normalized_path), dep_path is the dependency path | 56 A tuple - (dep_path, normalized_path), dep_path is the dependency path |
|
chanli
2016/07/21 21:10:29
This docstring should be updated?
Sharu Jiang
2016/07/21 21:19:32
Done.
| |
| 56 of this path. (e.g 'src/', 'src/v8/' ...etc), '' is no match found. | 57 of this path. (e.g 'src/', 'src/v8/' ...etc), '' is no match found. |
| 57 """ | 58 """ |
| 58 # First normalize the path by retreiving the normalized path. | 59 # First normalize the path by retreiving the normalized path. |
| 59 normalized_path = os.path.normpath(path).replace('\\', '/') | 60 normalized_path = os.path.normpath(path).replace('\\', '/') |
| 60 | 61 |
| 61 if GENERATED_CODE_FILE_PATH_PATTERN.match(normalized_path): | 62 if GENERATED_CODE_FILE_PATH_PATTERN.match(normalized_path): |
| 62 logging.info('Generated code path %s', normalized_path) | 63 logging.info('Generated code path %s', normalized_path) |
| 63 return '', normalized_path | 64 return '', normalized_path, None |
| 64 | 65 |
| 65 # Iterate through all dep paths in the parsed DEPS in an order. | 66 # Iterate through all dep paths in the parsed DEPS in an order. |
| 66 for dep_path in sorted(deps.keys(), key=lambda path: -path.count('/')): | 67 for dep_path in sorted(deps.keys(), key=lambda path: -path.count('/')): |
| 67 # trim the 'src/' in the beginning of the dep_path to match, because there | 68 # trim the 'src/' in the beginning of the dep_path to match, because there |
| 68 # are many cases, especially in linux platform, the file paths are like, | 69 # are many cases, especially in linux platform, the file paths are like, |
| 69 # 'third_party/WebKit/Source/...', or 'v8/...'. | 70 # 'third_party/WebKit/Source/...', or 'v8/...'. |
| 70 trimmed_dep_path = dep_path | 71 trimmed_dep_path = dep_path |
| 71 if trimmed_dep_path.startswith('src/') and trimmed_dep_path != 'src/': | 72 if trimmed_dep_path.startswith('src/') and trimmed_dep_path != 'src/': |
| 72 trimmed_dep_path = trimmed_dep_path[len('src/'):] | 73 trimmed_dep_path = trimmed_dep_path[len('src/'):] |
| 73 | 74 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 97 if dep_path in normalized_path: | 98 if dep_path in normalized_path: |
| 98 current_dep_path = dep_path | 99 current_dep_path = dep_path |
| 99 else: | 100 else: |
| 100 current_dep_path = dep_path_lower | 101 current_dep_path = dep_path_lower |
| 101 | 102 |
| 102 # Normalize the path by stripping everything off the dep's relative | 103 # Normalize the path by stripping everything off the dep's relative |
| 103 # path. | 104 # path. |
| 104 if current_dep_path: | 105 if current_dep_path: |
| 105 normalized_path = normalized_path.split(current_dep_path, 1)[1] | 106 normalized_path = normalized_path.split(current_dep_path, 1)[1] |
| 106 | 107 |
| 107 return (dep_path, normalized_path) | 108 return dep_path, normalized_path, deps[dep_path].repo_url |
| 108 | 109 |
| 109 logging.info( | 110 logging.info( |
| 110 'Cannot find match of dep path for file path %s, Default to src/', | 111 'Cannot find match of dep path for file path %s, Default to src/', |
| 111 normalized_path) | 112 normalized_path) |
| 112 | 113 |
| 113 # For some crashes, the file path looks like this: | 114 # For some crashes, the file path looks like this: |
| 114 # third_party/WebKit/Source/a.cc, the src/ in the beginning is trimmed, so | 115 # third_party/WebKit/Source/a.cc, the src/ in the beginning is trimmed, so |
| 115 # default the dep path to 'src/' if no match found. | 116 # default the dep path to 'src/' if no match found. |
| 116 return 'src/', normalized_path | 117 return 'src/', normalized_path, CHROMIUM_REPO_URL |
| 117 | 118 |
| 118 | 119 |
| 119 def GetLanguageTypeFromFormatType(format_type): | 120 def GetLanguageTypeFromFormatType(format_type): |
| 120 """Gets language type of a callstack from its format type.""" | 121 """Gets language type of a callstack from its format type.""" |
| 121 if format_type == CallStackFormatType.JAVA: | 122 if format_type == CallStackFormatType.JAVA: |
| 122 return CallStackLanguageType.JAVA | 123 return CallStackLanguageType.JAVA |
| 123 | 124 |
| 124 return CallStackLanguageType.CPP | 125 return CallStackLanguageType.CPP |
| OLD | NEW |