Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 base64 | |
| 6 import re | |
| 7 | |
| 8 from common import auth_util | |
| 9 from common import dependency | |
| 10 from common import deps_parser | |
| 5 from common import git_repository | 11 from common import git_repository |
| 6 from common import http_client_appengine | 12 from common import http_client_appengine |
| 7 from common import dependency | |
| 8 from common import deps_parser | |
| 9 | |
| 10 | 13 |
| 11 _CHROMIUM_ROOT_DIR = 'src/' | 14 _CHROMIUM_ROOT_DIR = 'src/' |
| 12 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git' | 15 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git' |
| 13 | 16 |
| 17 _CHROME_VERSION_PATTERN = re.compile(r'^\d+\.\d+\.\d+\.\d+$') | |
| 18 | |
| 19 _BUILDSPEC_REPO = ('https://chrome-internal.googlesource.com/chrome/tools/' | |
| 20 'buildspec.git/') | |
| 21 | |
| 22 | |
| 23 def IsChromeVersion(revision): | |
| 24 """Determines if a revision is a chrome version.""" | |
| 25 if _CHROME_VERSION_PATTERN.match(revision): | |
| 26 return True | |
| 27 | |
| 28 return False | |
| 29 | |
| 14 | 30 |
| 15 class DEPSDownloader(deps_parser.DEPSLoader): | 31 class DEPSDownloader(deps_parser.DEPSLoader): |
| 16 """Downloads DEPS from remote Git repo.""" | 32 """Downloads DEPS from remote Git repo.""" |
| 33 | |
| 17 def __init__(self, check_deps_git_first=False): | 34 def __init__(self, check_deps_git_first=False): |
| 18 """ | 35 """ |
| 19 Args: | 36 Args: |
| 20 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. | 37 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. |
| 21 """ | 38 """ |
| 22 self.check_deps_git_first = check_deps_git_first | 39 self.check_deps_git_first = check_deps_git_first |
| 23 | 40 |
| 24 def Load(self, repo_url, revision, deps_file): | 41 def Load(self, repo_url, revision, deps_file): |
| 25 http_client = http_client_appengine.HttpClientAppengine() | 42 http_client = http_client_appengine.HttpClientAppengine() |
| 26 repo = git_repository.GitRepository(repo_url, http_client) | 43 repo = git_repository.GitRepository(repo_url, http_client) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 39 content = repo.GetSource(deps_file, revision) | 56 content = repo.GetSource(deps_file, revision) |
| 40 | 57 |
| 41 if content is None: | 58 if content is None: |
| 42 raise Exception( | 59 raise Exception( |
| 43 'Failed to pull %s file from %s, at revision %s.' % ( | 60 'Failed to pull %s file from %s, at revision %s.' % ( |
| 44 deps_file, repo_url, revision)) | 61 deps_file, repo_url, revision)) |
| 45 | 62 |
| 46 return content | 63 return content |
| 47 | 64 |
| 48 | 65 |
| 66 class DEPSDownloaderForChromeVersion(deps_parser.DEPSLoader): | |
|
stgao
2016/05/05 17:32:28
Can we just reuse DEPSDownloader above with some s
Sharu Jiang
2016/05/05 20:26:45
Done.
| |
| 67 | |
| 68 def Load(self, _, version, deps_file): | |
|
Martin Barbella
2016/05/05 16:37:37
Is there any way to refactor DEPSLoader such that
stgao
2016/05/05 17:32:28
This breaks the API expected by deps_parser.
Sharu Jiang
2016/05/05 20:26:45
Done.
| |
| 69 http_client = http_client_appengine.HttpClientAppengine() | |
| 70 url = '%s/+/master/releases/%s/%s' % (_BUILDSPEC_REPO, version, deps_file) | |
| 71 headers = {'Authorization': 'Bearer ' + auth_util.GetAuthToken()} | |
| 72 | |
| 73 status_code, content = http_client.Get(url, headers=headers) | |
| 74 if status_code != 200: | |
| 75 return None | |
| 76 return base64.b64decode(content) | |
| 77 | |
|
Martin Barbella
2016/05/05 16:37:37
Additional blank line here.
Sharu Jiang
2016/05/05 20:26:45
Done.
| |
| 49 def GetChromeDependency(revision, platform, check_deps_git_first=False): | 78 def GetChromeDependency(revision, platform, check_deps_git_first=False): |
| 50 """Returns all dependencies of Chrome as a dict for the given revision and OS. | 79 """Returns all dependencies of Chrome as a dict for the given revision and OS. |
| 51 | 80 |
| 52 Args: | 81 Args: |
| 53 revision (str): The revision of a Chrome build. | 82 revision (str): The revision of a Chrome build, it can be a githash or a |
| 83 chrome version for a official build. | |
| 54 platform (str): The target platform of the Chrome build, should be one of | 84 platform (str): The target platform of the Chrome build, should be one of |
| 55 'win', 'ios', 'mac', 'unix', 'android', or 'all'. | 85 'win', 'ios', 'mac', 'unix', 'android', or 'all'. |
| 56 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. | 86 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. |
| 57 | 87 |
| 58 Returns: | 88 Returns: |
| 59 A map from dependency path to the dependency info. | 89 A map from dependency path to the dependency info. |
| 60 """ | 90 """ |
| 61 root_dep = dependency.Dependency( | 91 root_dep = dependency.Dependency( |
|
Martin Barbella
2016/05/05 16:37:37
Would it be possible or cleaner to use the convert
Sharu Jiang
2016/05/05 20:26:45
I have to keep it as a version until we call deps_
| |
| 62 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS') | 92 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS') |
|
stgao
2016/05/05 17:32:28
When reusing DEPSDownloader above, this might need
Sharu Jiang
2016/05/05 20:26:45
It seems no change is needed.
| |
| 63 | 93 |
| 64 deps_parser.UpdateDependencyTree( | 94 root_is_chrome_version = IsChromeVersion(root_dep.revision) |
| 65 root_dep, [platform], DEPSDownloader(check_deps_git_first)) | 95 |
| 96 if root_is_chrome_version: | |
| 97 deps_loader = DEPSDownloaderForChromeVersion() | |
| 98 else: | |
| 99 # For official chrome release build, fetch the DEPS generated by buildspec. | |
| 100 deps_loader = DEPSDownloader(check_deps_git_first) | |
| 101 | |
| 102 deps_parser.UpdateDependencyTree(root_dep, [platform], deps_loader) | |
| 103 | |
| 104 if root_is_chrome_version: | |
| 105 http_client = http_client_appengine.HttpClientAppengine() | |
| 106 repo = git_repository.GitRepository(_CHROMIUM_REPO_MASTER, http_client) | |
| 107 # Convert chrome version revision to githash revision to be consistent. | |
|
stgao
2016/05/05 17:32:28
"version revision" seems a bit confusing.
Sharu Jiang
2016/05/05 20:26:45
Done.
| |
| 108 root_dep.revision = repo.GetRevisionForChromeVersion(root_dep.revision) | |
|
stgao
2016/05/05 17:32:28
If we convert the version to git-hash here, will t
Sharu Jiang
2016/05/05 20:26:45
No, after this, pulling changelogs would be exactl
stgao
2016/05/05 21:02:46
What if there are patch cherrypick in the Chrome b
Sharu Jiang
2016/05/05 23:03:45
Hm... I see, in this case, we shouldn't do the con
| |
| 66 | 109 |
| 67 dependencies = {} | 110 dependencies = {} |
| 68 | 111 |
| 69 # Flatten the dependency tree into a one-level dict. | 112 # Flatten the dependency tree into a one-level dict. |
| 70 def FlattenDepTree(dep): | 113 def FlattenDepTree(dep): |
| 71 dependencies[dep.path] = dep | 114 dependencies[dep.path] = dep |
| 72 for child in dep.children.values(): | 115 for child in dep.children.values(): |
| 73 FlattenDepTree(child) | 116 FlattenDepTree(child) |
| 74 | 117 |
| 75 FlattenDepTree(root_dep) | 118 FlattenDepTree(root_dep) |
| 76 | 119 |
| 77 return dependencies | 120 return dependencies |
| 78 | 121 |
| 79 | 122 |
| 80 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, | 123 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, |
| 81 check_deps_git_first=False): | 124 check_deps_git_first=False, skip_chromium_roll=True): |
| 82 """Returns a list of dependency rolls between the given Chromium revisions. | 125 """Returns a list of dependency rolls between the given Chromium revisions. |
| 83 | 126 |
| 84 Args: | 127 Args: |
| 85 old_cr_revision (str): The Git commit hash for the old Chromium revision. | 128 old_cr_revision (str): The old Chromium revision, it can be a githash or a |
| 86 new_cr_revision (str): The Git commit hash for the new Chromium revision. | 129 chrome version for a official build. |
| 130 new_cr_revision (str): The new Chromium revision, it can be a githash or a | |
| 131 chrome version for a official build. | |
| 87 platform (str): The target OS platform of the Chrome or test binary. | 132 platform (str): The target OS platform of the Chrome or test binary. |
| 88 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. | 133 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. |
| 134 skip_chromium_roll (bool): If False, chromium roll will be contained in | |
| 135 the return. | |
| 136 | |
| 137 Returns: | |
| 138 A list of DependencyRoll objects in the revision range. | |
| 89 """ | 139 """ |
| 90 old_deps = GetChromeDependency( | 140 old_deps = GetChromeDependency( |
| 91 old_cr_revision, platform, check_deps_git_first) | 141 old_cr_revision, platform, check_deps_git_first) |
| 92 new_deps = GetChromeDependency( | 142 new_deps = GetChromeDependency( |
| 93 new_cr_revision, platform, check_deps_git_first) | 143 new_cr_revision, platform, check_deps_git_first) |
| 94 | 144 |
| 95 rolls = [] | 145 rolls = [] |
| 96 | 146 |
| 97 for path, new_dep in new_deps.iteritems(): | 147 for path, new_dep in new_deps.iteritems(): |
| 98 if path == _CHROMIUM_ROOT_DIR: # Skip the root dependency -- chromium. | 148 if skip_chromium_roll and path == _CHROMIUM_ROOT_DIR: |
| 99 continue | 149 continue |
| 100 | 150 |
| 101 old_revision = None | 151 old_revision = None |
| 102 if path in old_deps: | 152 if path in old_deps: |
| 103 old_revision = old_deps[path].revision | 153 old_revision = old_deps[path].revision |
| 104 | 154 |
| 105 if old_revision != new_dep.revision: | 155 if old_revision != new_dep.revision: |
| 106 rolls.append( | 156 rolls.append( |
| 107 dependency.DependencyRoll( | 157 dependency.DependencyRoll( |
| 108 path, new_dep.repo_url, old_revision, new_dep.revision)) | 158 path, new_dep.repo_url, old_revision, new_dep.revision)) |
| 109 | 159 |
| 110 for path, old_dep in old_deps.iteritems(): | 160 for path, old_dep in old_deps.iteritems(): |
| 111 if path not in new_deps: | 161 if path not in new_deps: |
| 112 rolls.append( | 162 rolls.append( |
| 113 dependency.DependencyRoll( | 163 dependency.DependencyRoll( |
| 114 path, old_dep.repo_url, old_dep.revision, None)) | 164 path, old_dep.repo_url, old_dep.revision, None)) |
| 115 | 165 |
| 116 return rolls | 166 return rolls |
| 117 | 167 |
| 118 | 168 |
| 119 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform): | 169 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform): |
| 120 """Gets dep_path to DependencyRoll dictionary for deps in | 170 """Gets dep_path to DependencyRoll dictionary for deps between revisions. |
| 121 (old_cr_revision, new_cr_revision]. | |
| 122 | 171 |
| 123 Args: | 172 Args: |
| 124 old_cr_revision (str): The Git commit hash for the old Chromium revision. | 173 old_cr_revision (str): The old Chromium revision, it can be a githash or a |
| 125 new_cr_revision (str): The Git commit hash for the new Chromium revision. | 174 chrome version for a official build. |
| 175 new_cr_revision (str): The new Chromium revision, it can be a githash or a | |
| 176 chrome version for a official build. | |
| 126 platform (str): The target OS platform of the Chrome or test binary. | 177 platform (str): The target OS platform of the Chrome or test binary. |
| 127 | 178 |
| 128 Returns: | 179 Returns: |
| 129 A dict, mapping dep path to DependencyRoll. | 180 A dict, mapping dep path to its DependencyRoll. |
| 130 """ | 181 """ |
| 131 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform) | 182 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, |
| 132 # Add chromium as dependency roll. | 183 skip_chromium_roll=False) |
| 133 deps_rolls.append(dependency.DependencyRoll( | |
| 134 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, | |
| 135 old_cr_revision, new_cr_revision)) | |
| 136 | 184 |
| 137 deps_rolls_dict = {} | 185 deps_rolls_dict = {} |
| 138 for dep_roll in deps_rolls: | 186 for dep_roll in deps_rolls: |
| 139 deps_rolls_dict[dep_roll.path] = dep_roll | 187 deps_rolls_dict[dep_roll.path] = dep_roll |
| 140 | 188 |
| 141 return deps_rolls_dict | 189 return deps_rolls_dict |
| OLD | NEW |