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.
10 DEPS_FILE_URL_SVN = 'https://src.chromium.org/chrome/trunk/src/DEPS?p=%s'
12 'https://chromium.googlesource.com/chromium/src/+/%s/DEPS?format=text')
15 class _VarImpl(object):
17 def __init__(self, local_scope):
18 self._local_scope = local_scope
20 def Lookup(self, var_name):
21 if var_name in self._local_scope.get('vars', {}):
22 return self._local_scope['vars'][var_name]
23 raise Exception('Var is not defined: %s' % var_name)
26 def _ParseDEPS(content):
27 """Parse the DEPS file of chromium."""
29 var = _VarImpl(local_scope)
35 'skip_child_includes': [],
38 exec(content, global_scope, local_scope)
40 local_scope.setdefault('deps', {})
41 local_scope.setdefault('deps_os', {})
43 return (local_scope['deps'], local_scope['deps_os'])
46 def _GetComponentName(path):
47 """Return the component name of a path."""
49 'src/chrome/browser/resources/',
50 'src/chrome/test/data/layout_tests/',
54 'src/third_party/WebKit/',
59 components_renamed = {
63 for host_dir in host_dirs:
64 if path.startswith(host_dir):
65 path = path[len(host_dir):]
66 name = path.split('/')[0].lower()
67 if name in components_renamed:
68 return components_renamed[name].lower()
72 # Unknown path, return the whole path as component name.
73 return '_'.join(path.split('/'))
76 def _GetContentOfDEPS(chromium_revision):
77 if utils.IsGitHash(chromium_revision):
78 url = DEPS_FILE_URL_GIT
80 url = DEPS_FILE_URL_SVN
81 return https.SendRequest(url % chromium_revision)
84 def GetChromiumComponents(chromium_revision,
86 deps_file_downloader=_GetContentOfDEPS):
87 """Return a list of components used by Chrome of the given revision.
90 chromium_revision: The revision of the Chrome build.
91 os_platform: The target platform of the Chrome build, eg. win, mac, etc.
92 deps_file_downloader: A function that takes the chromium_revision as input,
93 and returns the content of the DEPS file. The returned
94 content is assumed to be trusted input and will be
95 evaluated as python code.
98 A map from component path to parsed component name, repository URL,
99 repository type and revision.
101 if os_platform.lower() == 'linux':
104 is_git_hash = utils.IsGitHash(chromium_revision)
106 # Download the content of DEPS file in chromium.
107 deps_content = deps_file_downloader(chromium_revision)
109 # Googlesource git returns text file encoded in base64, so decode it.
111 deps_content = base64.b64decode(deps_content)
115 # Parse the content of DEPS file.
116 deps, deps_os = _ParseDEPS(deps_content)
117 all_deps.update(deps)
118 if os_platform is not None:
119 all_deps.update(deps_os.get(os_platform, {}))
121 # Figure out components based on the dependencies.
123 for component_path in all_deps:
124 name = _GetComponentName(component_path)
125 repository, revision = all_deps[component_path].split('@')
126 is_git_hash = utils.IsGitHash(revision)
127 if repository.startswith('/'):
128 # TODO(stgao): Use git repo after chromium moves to git.
129 repository = 'https://src.chromium.org/chrome%s' % repository
131 repository_type = 'git'
133 repository_type = 'svn'
134 if not component_path.endswith('/'):
135 component_path += '/'
136 components[component_path] = {
137 'path': component_path,
139 'repository': repository,
140 'repository_type': repository_type,
144 # Add chromium as a component, depending on the repository type.
146 repository = 'https://chromium.googlesource.com/chromium/src/'
147 repository_type = 'git'
149 repository = 'https://src.chromium.org/chrome/trunk'
150 repository_type = 'svn'
152 components['src/'] = {
155 'repository': repository,
156 'repository_type': repository_type,
157 'revision': chromium_revision
163 def GetChromiumComponentRange(old_revision,
166 deps_file_downloader=_GetContentOfDEPS):
167 """Return a list of components with their revision ranges.
170 old_revision: The old revision of a Chrome build.
171 new_revision: The new revision of a Chrome build.
172 os_platform: The target platform of the Chrome build, eg. win, mac, etc.
173 deps_file_downloader: A function that takes the chromium_revision as input,
174 and returns the content of the DEPS file. The returned
175 content is assumed to be trusted input and will be
176 evaluated as python code.
179 A map from component path to its parsed regression and other information.
181 # Assume first revision is the old revision.
182 old_components = GetChromiumComponents(old_revision, os_platform,
183 deps_file_downloader)
184 new_components = GetChromiumComponents(new_revision, os_platform,
185 deps_file_downloader)
188 for path in new_components:
189 new_component = new_components[path]
191 if path in old_components:
192 old_component = old_components[path]
193 old_revision = old_component['revision']
196 'rolled': new_component['revision'] != old_revision,
197 'name': new_component['name'],
198 'old_revision': old_revision,
199 'new_revision': new_component['revision'],
200 'repository': new_component['repository'],
201 'repository_type': new_component['repository_type']
207 if __name__ == '__main__':
209 print json.dumps(GetChromiumComponents(
210 'b4b1aea80b25a3b2f7952c9d95585e880421ef2b'), sort_keys=True, indent=2)