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() |
| 43 content = None | |
| 44 | |
| 45 if IsChromeVersion(revision): | |
| 46 repo = git_repository.GitRepository(_BUILDSPEC_REPO, http_client) | |
|
stgao
2016/05/05 21:02:47
Can we handled both in the same way?
In abstract,
Sharu Jiang
2016/05/05 23:03:45
Done.
| |
| 47 url = '%s/+/master/releases/%s/%s' % (_BUILDSPEC_REPO, revision, | |
|
stgao
2016/05/05 21:02:46
Why can't we use the repo_url passed in here?
Sharu Jiang
2016/05/05 23:03:45
Done.
| |
| 48 deps_file) | |
| 49 # The buildspec/ is a chrome internal repo, add header to verify the | |
| 50 # identity of the appengine app based on the service account. | |
| 51 headers = {'Authorization': 'Bearer ' + auth_util.GetAuthToken()} | |
| 52 content = repo._SendRequestForTextResponse(url, headers=headers) | |
|
stgao
2016/05/05 21:02:47
Class-internal functions like this are not suppose
Sharu Jiang
2016/05/05 23:03:45
Done.
| |
| 53 | |
| 54 if content is None: | |
| 55 raise Exception( | |
| 56 'Failed to pull %s file from buildspec/ for version %s.' % ( | |
| 57 deps_file, revision)) | |
| 58 | |
| 59 return content | |
| 60 | |
| 26 repo = git_repository.GitRepository(repo_url, http_client) | 61 repo = git_repository.GitRepository(repo_url, http_client) |
| 27 | 62 |
| 28 content = None | |
| 29 | |
| 30 if self.check_deps_git_first and deps_file == 'DEPS': | 63 if self.check_deps_git_first and deps_file == 'DEPS': |
| 31 # When the given deps_file is "DEPS" and .DEPS.git should be checked | 64 # When the given deps_file is "DEPS" and .DEPS.git should be checked |
| 32 # first, it's because before migration from SVN to Git, .DEPS.git contains | 65 # first, it's because before migration from SVN to Git, .DEPS.git contains |
| 33 # dependencies hosted in Git while DEPS contains those in SVN. | 66 # dependencies hosted in Git while DEPS contains those in SVN. |
| 34 # If .DEPS.git is not found, fallback to the given deps_file. Assume it is | 67 # If .DEPS.git is not found, fallback to the given deps_file. Assume it is |
| 35 # a commit after migration from SVN to Git. | 68 # a commit after migration from SVN to Git. |
| 36 content = repo.GetSource('.DEPS.git', revision) | 69 content = repo.GetSource('.DEPS.git', revision) |
| 37 | 70 |
| 38 if content is None: | 71 if content is None: |
| 39 content = repo.GetSource(deps_file, revision) | 72 content = repo.GetSource(deps_file, revision) |
| 40 | 73 |
| 41 if content is None: | 74 if content is None: |
| 42 raise Exception( | 75 raise Exception( |
| 43 'Failed to pull %s file from %s, at revision %s.' % ( | 76 'Failed to pull %s file from %s, at revision %s.' % ( |
| 44 deps_file, repo_url, revision)) | 77 deps_file, repo_url, revision)) |
| 45 | 78 |
| 46 return content | 79 return content |
| 47 | 80 |
| 48 | 81 |
| 49 def GetChromeDependency(revision, platform, check_deps_git_first=False): | 82 def GetChromeDependency(revision, platform, check_deps_git_first=False): |
| 50 """Returns all dependencies of Chrome as a dict for the given revision and OS. | 83 """Returns all dependencies of Chrome as a dict for the given revision and OS. |
| 51 | 84 |
| 52 Args: | 85 Args: |
| 53 revision (str): The revision of a Chrome build. | 86 revision (str): The revision of a Chrome build, it can be a githash or a |
| 87 chrome version for a official build. | |
| 54 platform (str): The target platform of the Chrome build, should be one of | 88 platform (str): The target platform of the Chrome build, should be one of |
| 55 'win', 'ios', 'mac', 'unix', 'android', or 'all'. | 89 'win', 'ios', 'mac', 'unix', 'android', or 'all'. |
| 56 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. | 90 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. |
| 57 | 91 |
| 58 Returns: | 92 Returns: |
| 59 A map from dependency path to the dependency info. | 93 A map from dependency path to the dependency info. |
| 60 """ | 94 """ |
| 61 root_dep = dependency.Dependency( | 95 root_dep = dependency.Dependency( |
| 62 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS') | 96 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS') |
| 63 | 97 |
| 64 deps_parser.UpdateDependencyTree( | 98 deps_parser.UpdateDependencyTree(root_dep, [platform], |
| 65 root_dep, [platform], DEPSDownloader(check_deps_git_first)) | 99 DEPSDownloader(check_deps_git_first)) |
| 100 | |
| 101 if IsChromeVersion(root_dep.revision): | |
| 102 http_client = http_client_appengine.HttpClientAppengine() | |
| 103 repo = git_repository.GitRepository(_CHROMIUM_REPO_MASTER, http_client) | |
| 104 # Convert chrome version to githash revision to be consistent. | |
| 105 root_dep.revision = repo.GetRevisionForChromeVersion(root_dep.revision) | |
| 66 | 106 |
| 67 dependencies = {} | 107 dependencies = {} |
| 68 | 108 |
| 69 # Flatten the dependency tree into a one-level dict. | 109 # Flatten the dependency tree into a one-level dict. |
| 70 def FlattenDepTree(dep): | 110 def FlattenDepTree(dep): |
| 71 dependencies[dep.path] = dep | 111 dependencies[dep.path] = dep |
| 72 for child in dep.children.values(): | 112 for child in dep.children.values(): |
| 73 FlattenDepTree(child) | 113 FlattenDepTree(child) |
| 74 | 114 |
| 75 FlattenDepTree(root_dep) | 115 FlattenDepTree(root_dep) |
| 76 | 116 |
| 77 return dependencies | 117 return dependencies |
| 78 | 118 |
| 79 | 119 |
| 80 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, | 120 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, |
| 81 check_deps_git_first=False): | 121 check_deps_git_first=False, skip_chromium_roll=True): |
| 82 """Returns a list of dependency rolls between the given Chromium revisions. | 122 """Returns a list of dependency rolls between the given Chromium revisions. |
| 83 | 123 |
| 84 Args: | 124 Args: |
| 85 old_cr_revision (str): The Git commit hash for the old Chromium revision. | 125 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. | 126 chrome version for a official build. |
| 127 new_cr_revision (str): The new Chromium revision, it can be a githash or a | |
| 128 chrome version for a official build. | |
| 87 platform (str): The target OS platform of the Chrome or test binary. | 129 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. | 130 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. |
| 131 skip_chromium_roll (bool): If False, chromium roll will be contained in | |
| 132 the return. | |
| 133 | |
| 134 Returns: | |
| 135 A list of DependencyRoll objects in the revision range. | |
| 89 """ | 136 """ |
| 90 old_deps = GetChromeDependency( | 137 old_deps = GetChromeDependency( |
| 91 old_cr_revision, platform, check_deps_git_first) | 138 old_cr_revision, platform, check_deps_git_first) |
| 92 new_deps = GetChromeDependency( | 139 new_deps = GetChromeDependency( |
| 93 new_cr_revision, platform, check_deps_git_first) | 140 new_cr_revision, platform, check_deps_git_first) |
| 94 | 141 |
| 95 rolls = [] | 142 rolls = [] |
| 96 | 143 |
| 97 for path, new_dep in new_deps.iteritems(): | 144 for path, new_dep in new_deps.iteritems(): |
| 98 if path == _CHROMIUM_ROOT_DIR: # Skip the root dependency -- chromium. | 145 if skip_chromium_roll and path == _CHROMIUM_ROOT_DIR: |
| 99 continue | 146 continue |
| 100 | 147 |
| 101 old_revision = None | 148 old_revision = None |
| 102 if path in old_deps: | 149 if path in old_deps: |
| 103 old_revision = old_deps[path].revision | 150 old_revision = old_deps[path].revision |
| 104 | 151 |
| 105 if old_revision != new_dep.revision: | 152 if old_revision != new_dep.revision: |
| 106 rolls.append( | 153 rolls.append( |
| 107 dependency.DependencyRoll( | 154 dependency.DependencyRoll( |
| 108 path, new_dep.repo_url, old_revision, new_dep.revision)) | 155 path, new_dep.repo_url, old_revision, new_dep.revision)) |
| 109 | 156 |
| 110 for path, old_dep in old_deps.iteritems(): | 157 for path, old_dep in old_deps.iteritems(): |
| 111 if path not in new_deps: | 158 if path not in new_deps: |
| 112 rolls.append( | 159 rolls.append( |
| 113 dependency.DependencyRoll( | 160 dependency.DependencyRoll( |
| 114 path, old_dep.repo_url, old_dep.revision, None)) | 161 path, old_dep.repo_url, old_dep.revision, None)) |
| 115 | 162 |
| 116 return rolls | 163 return rolls |
| 117 | 164 |
| 118 | 165 |
| 119 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform): | 166 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform): |
| 120 """Gets dep_path to DependencyRoll dictionary for deps in | 167 """Gets dep_path to DependencyRoll dictionary for deps between revisions. |
| 121 (old_cr_revision, new_cr_revision]. | |
| 122 | 168 |
| 123 Args: | 169 Args: |
| 124 old_cr_revision (str): The Git commit hash for the old Chromium revision. | 170 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. | 171 chrome version for a official build. |
| 172 new_cr_revision (str): The new Chromium revision, it can be a githash or a | |
| 173 chrome version for a official build. | |
| 126 platform (str): The target OS platform of the Chrome or test binary. | 174 platform (str): The target OS platform of the Chrome or test binary. |
| 127 | 175 |
| 128 Returns: | 176 Returns: |
| 129 A dict, mapping dep path to DependencyRoll. | 177 A dict, mapping dep path to its DependencyRoll. |
| 130 """ | 178 """ |
| 131 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform) | 179 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, |
| 132 # Add chromium as dependency roll. | 180 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 | 181 |
| 137 deps_rolls_dict = {} | 182 deps_rolls_dict = {} |
| 138 for dep_roll in deps_rolls: | 183 for dep_roll in deps_rolls: |
| 139 deps_rolls_dict[dep_roll.path] = dep_roll | 184 deps_rolls_dict[dep_roll.path] = dep_roll |
| 140 | 185 |
| 141 return deps_rolls_dict | 186 return deps_rolls_dict |
| OLD | NEW |