OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import https |
| 6 import utils |
| 7 |
| 8 |
| 9 DEPS_FILE_URL = 'https://src.chromium.org/chrome/trunk/src/DEPS?p=%s' |
| 10 |
| 11 |
| 12 class _VarImpl(object): |
| 13 def __init__(self, local_scope): |
| 14 self._local_scope = local_scope |
| 15 |
| 16 def Lookup(self, var_name): |
| 17 if var_name in self._local_scope.get('vars', {}): |
| 18 return self._local_scope['vars'][var_name] |
| 19 raise Exception('Var is not defined: %s' % var_name) |
| 20 |
| 21 |
| 22 def _ParseDEPS(content): |
| 23 """Parse the DEPS file of chromium.""" |
| 24 local_scope = {} |
| 25 var = _VarImpl(local_scope) |
| 26 global_scope = { |
| 27 'Var': var.Lookup, |
| 28 'deps': {}, |
| 29 'deps_os': {}, |
| 30 'include_rules': [], |
| 31 'skip_child_includes': [], |
| 32 'hooks': [], |
| 33 } |
| 34 exec(content, global_scope, local_scope) |
| 35 |
| 36 local_scope.setdefault('deps', {}) |
| 37 local_scope.setdefault('deps_os', {}) |
| 38 |
| 39 return (local_scope['deps'], local_scope['deps_os']) |
| 40 |
| 41 |
| 42 def _GetComponentName(path): |
| 43 """Return the component name of a path.""" |
| 44 host_dirs = [ |
| 45 'src/chrome/browser/resources/', |
| 46 'src/chrome/test/data/layout_tests/', |
| 47 'src/media/', |
| 48 'src/sdch/', |
| 49 'src/testing/', |
| 50 'src/third_party/WebKit/', |
| 51 'src/third_party/', |
| 52 'src/tools/', |
| 53 'src/', |
| 54 ] |
| 55 components_renamed = { |
| 56 'webkit': 'blink', |
| 57 } |
| 58 |
| 59 for host_dir in host_dirs: |
| 60 if path.startswith(host_dir): |
| 61 path = path[len(host_dir):] |
| 62 name = path.split('/')[0].lower() |
| 63 if name in components_renamed: |
| 64 return components_renamed[name].lower() |
| 65 else: |
| 66 return name.lower() |
| 67 |
| 68 # Unknown path, return the whole path as component name. |
| 69 return '_'.join(path.split('/')) |
| 70 |
| 71 |
| 72 def _GetContentOfDEPS(chromium_revision): |
| 73 return https.SendRequest(DEPS_FILE_URL % chromium_revision) |
| 74 |
| 75 |
| 76 def GetChromiumComponents(chromium_revision, |
| 77 os_platform='unix', |
| 78 deps_file_downloader=_GetContentOfDEPS): |
| 79 """Return a list of components used by Chrome of the given revision. |
| 80 |
| 81 Args: |
| 82 chromium_revision: The revision of the Chrome build. |
| 83 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
| 84 deps_file_downloader: A function that takes the chromium_revision as input, |
| 85 and returns the content of the DEPS file. The returned |
| 86 content is assumed to be trusted input and will be |
| 87 evaluated as python code. |
| 88 """ |
| 89 if os_platform.lower() == 'linux': |
| 90 os_platform = 'unix' |
| 91 |
| 92 # Download the content of DEPS file in chromium. |
| 93 deps_content = deps_file_downloader(chromium_revision) |
| 94 |
| 95 all_deps = {} |
| 96 |
| 97 # Parse the content of DEPS file. |
| 98 deps, deps_os = _ParseDEPS(deps_content) |
| 99 all_deps.update(deps) |
| 100 if os_platform is not None: |
| 101 all_deps.update(deps_os.get(os_platform, {})) |
| 102 |
| 103 # Figure out components based on the dependencies. |
| 104 components = {} |
| 105 for component_path in all_deps.keys(): |
| 106 name = _GetComponentName(component_path) |
| 107 repository, revision = all_deps[component_path].split('@') |
| 108 is_git_hash = utils.IsGitHash(revision) |
| 109 if repository.startswith('/'): |
| 110 # TODO(stgao): Use git repo after chromium moves to git. |
| 111 repository = 'https://src.chromium.org/chrome%s' % repository |
| 112 if is_git_hash: |
| 113 repository_type = 'git' |
| 114 else: |
| 115 repository_type = 'svn' |
| 116 if not component_path.endswith('/'): |
| 117 component_path += '/' |
| 118 components[component_path] = { |
| 119 'path': component_path, |
| 120 'name': name, |
| 121 'repository': repository, |
| 122 'repository_type': repository_type, |
| 123 'revision': revision |
| 124 } |
| 125 |
| 126 # Add chromium as a component. |
| 127 # TODO(stgao): Move to git. |
| 128 components['src/'] = { |
| 129 'path': 'src/', |
| 130 'name': 'chromium', |
| 131 'repository': 'https://src.chromium.org/chrome/trunk', |
| 132 'repository_type': 'svn', |
| 133 'revision': chromium_revision |
| 134 } |
| 135 |
| 136 return components |
| 137 |
| 138 |
| 139 def GetChromiumComponentRange(chromium_revision1, |
| 140 chromium_revision2, |
| 141 os_platform='unix', |
| 142 deps_file_downloader=_GetContentOfDEPS): |
| 143 """Return a list of components with their revision ranges. |
| 144 |
| 145 Args: |
| 146 chromium_revision1: The revision of a Chrome build. |
| 147 chromium_revision2: The revision of another Chrome build. |
| 148 os_platform: The target platform of the Chrome build, eg. win, mac, etc. |
| 149 deps_file_downloader: A function that takes the chromium_revision as input, |
| 150 and returns the content of the DEPS file. The returned |
| 151 content is assumed to be trusted input and will be |
| 152 evaluated as python code. |
| 153 """ |
| 154 # TODO(stgao): support git. |
| 155 chromium_revision1 = int(chromium_revision1) |
| 156 chromium_revision2 = int(chromium_revision2) |
| 157 old_revision = str(min(chromium_revision1, chromium_revision2)) |
| 158 new_revision = str(max(chromium_revision1, chromium_revision2)) |
| 159 |
| 160 old_components = GetChromiumComponents(old_revision, os_platform, |
| 161 deps_file_downloader) |
| 162 new_components = GetChromiumComponents(new_revision, os_platform, |
| 163 deps_file_downloader) |
| 164 |
| 165 components = {} |
| 166 for path in new_components.keys(): |
| 167 new_component = new_components[path] |
| 168 old_revision = None |
| 169 if path in old_components: |
| 170 old_component = old_components[path] |
| 171 old_revision = old_component['revision'] |
| 172 components[path] = { |
| 173 'path': path, |
| 174 'rolled': new_component['revision'] != old_revision, |
| 175 'name': new_component['name'], |
| 176 'old_revision': old_revision, |
| 177 'new_revision': new_component['revision'], |
| 178 'repository': new_component['repository'], |
| 179 'repository_type': new_component['repository_type'] |
| 180 } |
| 181 |
| 182 return components |
| 183 |
| 184 |
| 185 if __name__ == '__main__': |
| 186 import json |
| 187 print json.dumps(GetChromiumComponents(284750), sort_keys=True, indent=2) |
OLD | NEW |