Index: tools/findit/chromium_deps.py |
diff --git a/tools/findit/chromium_deps.py b/tools/findit/chromium_deps.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..79acbb74a7dbe8a133ca845ee3a5694194f07997 |
--- /dev/null |
+++ b/tools/findit/chromium_deps.py |
@@ -0,0 +1,165 @@ |
+# Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import sys |
+import urllib2 |
+ |
+import utils |
+ |
+ |
+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.
|
+ |
+ |
+class _VarImpl(object): |
+ def __init__(self, local_scope): |
+ self._local_scope = local_scope |
+ |
+ def Lookup(self, var_name): |
+ if var_name in self._local_scope.get('vars', {}): |
+ return self._local_scope['vars'][var_name] |
+ raise Exception('Var is not defined: %s' % var_name) |
+ |
+ |
+def _ParseDEPS(content): |
+ """Parse the DEPS file of chromium.""" |
+ local_scope = {} |
+ var = _VarImpl(local_scope) |
+ global_scope = { |
+ 'Var': var.Lookup, |
+ 'deps': {}, |
+ 'deps_os': {}, |
+ 'include_rules': [], |
+ 'skip_child_includes': [], |
+ 'hooks': [], |
+ } |
+ 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
|
+ |
+ local_scope.setdefault('deps', {}) |
+ local_scope.setdefault('deps_os', {}) |
+ local_scope.setdefault('include_rules', []) |
+ local_scope.setdefault('skip_child_includes', []) |
+ local_scope.setdefault('hooks', []) |
+ |
+ return (local_scope['deps'], local_scope['deps_os'], |
+ local_scope['include_rules'], local_scope['skip_child_includes'], |
+ local_scope['hooks']) |
+ |
+ |
+def _GetComponentName(path): |
+ """Return the component name of a path.""" |
+ host_dirs = [ |
+ 'src/chrome/browser/resources/', |
+ 'src/media/', |
+ 'src/third_party/', |
+ 'src/tools/', |
+ 'src/', |
+ ] |
+ components_renamed = { |
+ 'webkit': 'blink', |
+ } |
+ |
+ for host_dir in host_dirs: |
+ if path.startswith(host_dir): |
+ name = path[len(host_dir):].split('/')[0].lower() |
+ if name in components_renamed: |
+ return components_renamed[name].lower() |
+ else: |
+ return name.lower() |
+ |
+ # Unknown path, return the whole path as component name. |
+ return path |
+ |
+ |
+def _GetContentOfDEPS(chromium_revision): |
+ 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.
|
+ |
+ |
+def GetChromiumComponents(chromium_revision, |
+ os_platform='unix', |
+ deps_file_downloader=_GetContentOfDEPS): |
+ """Return a list of components used by Chrome of the given revision.""" |
+ if os_platform.lower() == 'linux': |
+ os_platform = 'unix' |
+ |
+ # Download the content of DEPS file in chromium. |
+ deps_content = deps_file_downloader(chromium_revision) |
+ |
+ all_deps = {} |
+ |
+ # Parse the content of DEPS file. |
+ deps, deps_os, _, _, _ = _ParseDEPS(deps_content) |
+ all_deps.update(deps) |
+ if os_platform is not None: |
+ all_deps.update(deps_os.get(os_platform, {})) |
+ |
+ # Figure out components based on the dependencies. |
+ components = {} |
+ for component_path in all_deps.keys(): |
+ name = _GetComponentName(component_path) |
+ repository, revision = all_deps[component_path].split('@') |
+ is_svn = utils.IsSvnRevision(revision) |
+ if repository.startswith('/'): |
+ # TODO(stgao): Use git repo after chromium moves to git. |
+ repository = 'http://src.chromium.org/chrome%s' % repository |
+ if is_svn: |
+ repository_type = 'svn' |
+ else: |
+ repository_type = 'git' |
+ if not component_path.endswith('/'): |
+ component_path += '/' |
+ components[component_path] = { |
+ 'path': component_path, |
+ 'name': name, |
+ 'repository': repository, |
+ 'repository_type': repository_type, |
+ 'revision': revision |
+ } |
+ |
+ # Add chromium as a component. |
+ # TODO(stgao): Move to git. |
+ components['src/'] = { |
+ 'path': 'src/', |
+ 'name': 'chromium', |
+ 'repository': 'http://src.chromium.org/chrome/trunk', |
+ 'repository_type': 'svn', |
+ 'revision': chromium_revision |
+ } |
+ |
+ return components |
+ |
+ |
+def GetChromiumComponentRange(cr_revision1, |
+ cr_revision2, |
+ os_platform='unix', |
+ deps_file_downloader=_GetContentOfDEPS): |
+ """Return a list of components with their revision ranges.""" |
+ # TODO(stgao): support git. |
+ cr_revision1 = int(cr_revision1) |
+ cr_revision2 = int(cr_revision2) |
+ old_revision = str(min(cr_revision1, cr_revision2)) |
+ new_revision = str(max(cr_revision1, cr_revision2)) |
+ |
+ old_components = GetChromiumComponents(old_revision, os_platform, |
+ deps_file_downloader) |
+ new_components = GetChromiumComponents(new_revision, os_platform, |
+ deps_file_downloader) |
+ |
+ components = {} |
+ for path in new_components.keys(): |
+ new_component = new_components[path] |
+ old_revision = None |
+ if path in old_components: |
+ old_component = old_components[path] |
+ old_revision = old_component['revision'] |
+ components[path] = { |
+ 'path': path, |
+ 'rolled': new_component['revision'] != old_revision, |
+ 'name': new_component['name'], |
+ 'old_revision': old_revision, |
+ 'new_revision': new_component['revision'], |
+ 'repository': new_component['repository'], |
+ 'repository_type': new_component['repository_type'] |
+ } |
+ |
+ return components |