Chromium Code Reviews| 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 sys | |
| 6 import urllib2 | |
| 7 | |
| 8 import utils | |
| 9 | |
| 10 | |
| 11 DEPS_FILE_URL = 'http://src.chromium.org/chrome/trunk/src/DEPS?p=%s' | |
|
Martin Barbella
2014/07/16 20:50:49
Definitely don't download this over HTTP.
stgao
2014/07/22 00:35:46
Done.
| |
| 12 | |
| 13 | |
| 14 class _VarImpl(object): | |
| 15 def __init__(self, local_scope): | |
| 16 self._local_scope = local_scope | |
| 17 | |
| 18 def Lookup(self, var_name): | |
| 19 if var_name in self._local_scope.get('vars', {}): | |
| 20 return self._local_scope['vars'][var_name] | |
| 21 raise Exception('Var is not defined: %s' % var_name) | |
| 22 | |
| 23 | |
| 24 def _ParseDEPS(content): | |
| 25 """Parse the DEPS file of chromium.""" | |
| 26 local_scope = {} | |
| 27 var = _VarImpl(local_scope) | |
| 28 global_scope = { | |
| 29 'Var': var.Lookup, | |
| 30 'deps': {}, | |
| 31 'deps_os': {}, | |
| 32 'include_rules': [], | |
| 33 'skip_child_includes': [], | |
| 34 'hooks': [], | |
| 35 } | |
| 36 exec(content, global_scope, local_scope) | |
|
Martin Barbella
2014/07/16 20:50:49
This really shouldn't be done with exec if possibl
stgao
2014/07/22 00:35:46
This is how chromium parses the DEPS file. As disc
| |
| 37 | |
| 38 local_scope.setdefault('deps', {}) | |
| 39 local_scope.setdefault('deps_os', {}) | |
| 40 local_scope.setdefault('include_rules', []) | |
| 41 local_scope.setdefault('skip_child_includes', []) | |
| 42 local_scope.setdefault('hooks', []) | |
| 43 | |
| 44 return (local_scope['deps'], local_scope['deps_os'], | |
| 45 local_scope['include_rules'], local_scope['skip_child_includes'], | |
| 46 local_scope['hooks']) | |
| 47 | |
| 48 | |
| 49 def _GetComponentName(path): | |
| 50 """Return the component name of a path.""" | |
| 51 host_dirs = [ | |
| 52 'src/chrome/browser/resources/', | |
| 53 'src/media/', | |
| 54 'src/third_party/', | |
| 55 'src/tools/', | |
| 56 'src/', | |
| 57 ] | |
| 58 components_renamed = { | |
| 59 'webkit': 'blink', | |
| 60 } | |
| 61 | |
| 62 for host_dir in host_dirs: | |
| 63 if path.startswith(host_dir): | |
| 64 name = path[len(host_dir):].split('/')[0].lower() | |
| 65 if name in components_renamed: | |
| 66 return components_renamed[name].lower() | |
| 67 else: | |
| 68 return name.lower() | |
| 69 | |
| 70 # Unknown path, return the whole path as component name. | |
| 71 return path | |
| 72 | |
| 73 | |
| 74 def _GetContentOfDEPS(chromium_revision): | |
| 75 return urllib2.urlopen(DEPS_FILE_URL % chromium_revision).read() | |
|
Martin Barbella
2014/07/16 20:50:49
What other sources would this come from? We need t
stgao
2014/07/22 00:35:46
Good catch.
| |
| 76 | |
| 77 | |
| 78 def GetChromiumComponents(chromium_revision, | |
| 79 os_platform='unix', | |
| 80 deps_file_downloader=_GetContentOfDEPS): | |
| 81 """Return a list of components used by Chrome of the given revision.""" | |
| 82 if os_platform.lower() == 'linux': | |
| 83 os_platform = 'unix' | |
| 84 | |
| 85 # Download the content of DEPS file in chromium. | |
| 86 deps_content = deps_file_downloader(chromium_revision) | |
| 87 | |
| 88 all_deps = {} | |
| 89 | |
| 90 # Parse the content of DEPS file. | |
| 91 deps, deps_os, _, _, _ = _ParseDEPS(deps_content) | |
| 92 all_deps.update(deps) | |
| 93 if os_platform is not None: | |
| 94 all_deps.update(deps_os.get(os_platform, {})) | |
| 95 | |
| 96 # Figure out components based on the dependencies. | |
| 97 components = {} | |
| 98 for component_path in all_deps.keys(): | |
| 99 name = _GetComponentName(component_path) | |
| 100 repository, revision = all_deps[component_path].split('@') | |
| 101 is_svn = utils.IsSvnRevision(revision) | |
| 102 if repository.startswith('/'): | |
| 103 # TODO(stgao): Use git repo after chromium moves to git. | |
| 104 repository = 'http://src.chromium.org/chrome%s' % repository | |
| 105 if is_svn: | |
| 106 repository_type = 'svn' | |
| 107 else: | |
| 108 repository_type = 'git' | |
| 109 if not component_path.endswith('/'): | |
| 110 component_path += '/' | |
| 111 components[component_path] = { | |
| 112 'path': component_path, | |
| 113 'name': name, | |
| 114 'repository': repository, | |
| 115 'repository_type': repository_type, | |
| 116 'revision': revision | |
| 117 } | |
| 118 | |
| 119 # Add chromium as a component. | |
| 120 # TODO(stgao): Move to git. | |
| 121 components['src/'] = { | |
| 122 'path': 'src/', | |
| 123 'name': 'chromium', | |
| 124 'repository': 'http://src.chromium.org/chrome/trunk', | |
| 125 'repository_type': 'svn', | |
| 126 'revision': chromium_revision | |
| 127 } | |
| 128 | |
| 129 return components | |
| 130 | |
| 131 | |
| 132 def GetChromiumComponentRange(cr_revision1, | |
| 133 cr_revision2, | |
| 134 os_platform='unix', | |
| 135 deps_file_downloader=_GetContentOfDEPS): | |
| 136 """Return a list of components with their revision ranges.""" | |
| 137 # TODO(stgao): support git. | |
| 138 cr_revision1 = int(cr_revision1) | |
| 139 cr_revision2 = int(cr_revision2) | |
| 140 old_revision = str(min(cr_revision1, cr_revision2)) | |
| 141 new_revision = str(max(cr_revision1, cr_revision2)) | |
| 142 | |
| 143 old_components = GetChromiumComponents(old_revision, os_platform, | |
| 144 deps_file_downloader) | |
| 145 new_components = GetChromiumComponents(new_revision, os_platform, | |
| 146 deps_file_downloader) | |
| 147 | |
| 148 components = {} | |
| 149 for path in new_components.keys(): | |
| 150 new_component = new_components[path] | |
| 151 old_revision = None | |
| 152 if path in old_components: | |
| 153 old_component = old_components[path] | |
| 154 old_revision = old_component['revision'] | |
| 155 components[path] = { | |
| 156 'path': path, | |
| 157 'rolled': new_component['revision'] != old_revision, | |
| 158 'name': new_component['name'], | |
| 159 'old_revision': old_revision, | |
| 160 'new_revision': new_component['revision'], | |
| 161 'repository': new_component['repository'], | |
| 162 'repository_type': new_component['repository_type'] | |
| 163 } | |
| 164 | |
| 165 return components | |
| OLD | NEW |