Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: appengine/findit/common/chromium_deps.py

Issue 1950123003: [Findit] Fetch DEPS from buildspec/ instead of trunk for chrome official builds. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Address comments. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 functools
7 import re
8
9 from common import auth_util
10 from common import dependency
11 from common import deps_parser
5 from common import git_repository 12 from common import git_repository
6 from common import http_client_appengine 13 from common import http_client_appengine
7 from common import dependency
8 from common import deps_parser
9
10 14
11 _CHROMIUM_ROOT_DIR = 'src/' 15 _CHROMIUM_ROOT_DIR = 'src/'
12 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git' 16 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git'
13 17
18 _CHROME_VERSION_PATTERN = re.compile(r'^\d+\.\d+\.\d+\.\d+$')
19
20 _BUILDSPEC_REPO = ('https://chrome-internal.googlesource.com/chrome/tools/'
21 'buildspec.git/')
22
23
24 def IsChromeVersion(revision):
25 """Determines if a revision is a chrome version."""
26 if _CHROME_VERSION_PATTERN.match(revision):
27 return True
28
29 return False
30
14 31
15 class DEPSDownloader(deps_parser.DEPSLoader): 32 class DEPSDownloader(deps_parser.DEPSLoader):
16 """Downloads DEPS from remote Git repo.""" 33 """Downloads DEPS from remote Git repo."""
34
17 def __init__(self, check_deps_git_first=False): 35 def __init__(self, check_deps_git_first=False):
18 """ 36 """
19 Args: 37 Args:
20 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. 38 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS.
21 """ 39 """
22 self.check_deps_git_first = check_deps_git_first 40 self.check_deps_git_first = check_deps_git_first
23 41
24 def Load(self, repo_url, revision, deps_file): 42 def Load(self, repo_url, revision, deps_file):
25 http_client = http_client_appengine.HttpClientAppengine() 43 http_client = http_client_appengine.HttpClientAppengine()
44 content = None
45
46 if IsChromeVersion(revision):
47 # The buildspec/ is a chrome internal repo, add header to verify the
48 # identity of the appengine app based on the service account.
49 headers = {'Authorization': 'Bearer ' + auth_util.GetAuthToken()}
50 http_client.Get = functools.partial(http_client.Get, headers=headers)
stgao 2016/05/06 00:15:53 This seems a little hacky to me. An alternative i
Sharu Jiang 2016/05/06 18:35:28 Done.
51
52 repo = git_repository.GitRepository(_BUILDSPEC_REPO, http_client)
stgao 2016/05/06 00:15:53 Can we unify this with the code below?
Sharu Jiang 2016/05/06 18:35:28 Done.
53 content = repo.GetSource('releases/%s/%s' % (revision, deps_file),
54 'master')
55
56 if content is None:
57 raise Exception(
58 'Failed to pull %s file from buildspec/ for version %s.' % (
59 deps_file, revision))
60
61 return content
62
26 repo = git_repository.GitRepository(repo_url, http_client) 63 repo = git_repository.GitRepository(repo_url, http_client)
27 64
28 content = None
29
30 if self.check_deps_git_first and deps_file == 'DEPS': 65 if self.check_deps_git_first and deps_file == 'DEPS':
31 # When the given deps_file is "DEPS" and .DEPS.git should be checked 66 # 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 67 # first, it's because before migration from SVN to Git, .DEPS.git contains
33 # dependencies hosted in Git while DEPS contains those in SVN. 68 # 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 69 # If .DEPS.git is not found, fallback to the given deps_file. Assume it is
35 # a commit after migration from SVN to Git. 70 # a commit after migration from SVN to Git.
36 content = repo.GetSource('.DEPS.git', revision) 71 content = repo.GetSource('.DEPS.git', revision)
37 72
38 if content is None: 73 if content is None:
39 content = repo.GetSource(deps_file, revision) 74 content = repo.GetSource(deps_file, revision)
40 75
41 if content is None: 76 if content is None:
42 raise Exception( 77 raise Exception(
43 'Failed to pull %s file from %s, at revision %s.' % ( 78 'Failed to pull %s file from %s, at revision %s.' % (
44 deps_file, repo_url, revision)) 79 deps_file, repo_url, revision))
45 80
46 return content 81 return content
47 82
48 83
49 def GetChromeDependency(revision, platform, check_deps_git_first=False): 84 def GetChromeDependency(revision, platform, check_deps_git_first=False):
50 """Returns all dependencies of Chrome as a dict for the given revision and OS. 85 """Returns all dependencies of Chrome as a dict for the given revision and OS.
51 86
52 Args: 87 Args:
53 revision (str): The revision of a Chrome build. 88 revision (str): The revision of a Chrome build, it can be a githash or a
89 chrome version for a official build.
54 platform (str): The target platform of the Chrome build, should be one of 90 platform (str): The target platform of the Chrome build, should be one of
55 'win', 'ios', 'mac', 'unix', 'android', or 'all'. 91 'win', 'ios', 'mac', 'unix', 'android', or 'all'.
56 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS. 92 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS.
57 93
58 Returns: 94 Returns:
59 A map from dependency path to the dependency info. 95 A map from dependency path to the dependency info.
60 """ 96 """
61 root_dep = dependency.Dependency( 97 root_dep = dependency.Dependency(
62 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS') 98 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, 'DEPS')
63 99
64 deps_parser.UpdateDependencyTree( 100 deps_parser.UpdateDependencyTree(root_dep, [platform],
65 root_dep, [platform], DEPSDownloader(check_deps_git_first)) 101 DEPSDownloader(check_deps_git_first))
66 102
67 dependencies = {} 103 dependencies = {}
68 104
69 # Flatten the dependency tree into a one-level dict. 105 # Flatten the dependency tree into a one-level dict.
70 def FlattenDepTree(dep): 106 def FlattenDepTree(dep):
71 dependencies[dep.path] = dep 107 dependencies[dep.path] = dep
72 for child in dep.children.values(): 108 for child in dep.children.values():
73 FlattenDepTree(child) 109 FlattenDepTree(child)
74 110
75 FlattenDepTree(root_dep) 111 FlattenDepTree(root_dep)
76 112
77 return dependencies 113 return dependencies
78 114
79 115
80 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform, 116 def GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform,
81 check_deps_git_first=False): 117 check_deps_git_first=False, skip_chromium_roll=True):
82 """Returns a list of dependency rolls between the given Chromium revisions. 118 """Returns a list of dependency rolls between the given Chromium revisions.
83 119
84 Args: 120 Args:
85 old_cr_revision (str): The Git commit hash for the old Chromium revision. 121 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. 122 chrome version for a official build.
123 new_cr_revision (str): The new Chromium revision, it can be a githash or a
124 chrome version for a official build.
87 platform (str): The target OS platform of the Chrome or test binary. 125 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. 126 check_deps_git_first (bool): If True, use .DEPS.git instead of DEPS.
127 skip_chromium_roll (bool): If False, chromium roll will be contained in
128 the return.
129
130 Returns:
131 A list of DependencyRoll objects in the revision range.
89 """ 132 """
90 old_deps = GetChromeDependency( 133 old_deps = GetChromeDependency(
91 old_cr_revision, platform, check_deps_git_first) 134 old_cr_revision, platform, check_deps_git_first)
92 new_deps = GetChromeDependency( 135 new_deps = GetChromeDependency(
93 new_cr_revision, platform, check_deps_git_first) 136 new_cr_revision, platform, check_deps_git_first)
94 137
95 rolls = [] 138 rolls = []
96 139
97 for path, new_dep in new_deps.iteritems(): 140 for path, new_dep in new_deps.iteritems():
98 if path == _CHROMIUM_ROOT_DIR: # Skip the root dependency -- chromium. 141 if skip_chromium_roll and path == _CHROMIUM_ROOT_DIR:
99 continue 142 continue
100 143
101 old_revision = None 144 old_revision = None
102 if path in old_deps: 145 if path in old_deps:
103 old_revision = old_deps[path].revision 146 old_revision = old_deps[path].revision
104 147
105 if old_revision != new_dep.revision: 148 if old_revision != new_dep.revision:
106 rolls.append( 149 rolls.append(
107 dependency.DependencyRoll( 150 dependency.DependencyRoll(
108 path, new_dep.repo_url, old_revision, new_dep.revision)) 151 path, new_dep.repo_url, old_revision, new_dep.revision))
109 152
110 for path, old_dep in old_deps.iteritems(): 153 for path, old_dep in old_deps.iteritems():
111 if path not in new_deps: 154 if path not in new_deps:
112 rolls.append( 155 rolls.append(
113 dependency.DependencyRoll( 156 dependency.DependencyRoll(
114 path, old_dep.repo_url, old_dep.revision, None)) 157 path, old_dep.repo_url, old_dep.revision, None))
115 158
116 return rolls 159 return rolls
117 160
118 161
119 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform): 162 def GetDEPSRollsDict(old_cr_revision, new_cr_revision, platform):
120 """Gets dep_path to DependencyRoll dictionary for deps in 163 """Gets dep_path to DependencyRoll dictionary for deps between revisions.
121 (old_cr_revision, new_cr_revision].
122 164
123 Args: 165 Args:
124 old_cr_revision (str): The Git commit hash for the old Chromium revision. 166 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. 167 chrome version for a official build.
168 new_cr_revision (str): The new Chromium revision, it can be a githash or a
169 chrome version for a official build.
126 platform (str): The target OS platform of the Chrome or test binary. 170 platform (str): The target OS platform of the Chrome or test binary.
127 171
128 Returns: 172 Returns:
129 A dict, mapping dep path to DependencyRoll. 173 A dict, mapping dep path to its DependencyRoll.
130 """ 174 """
131 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform) 175 deps_rolls = GetChromiumDEPSRolls(old_cr_revision, new_cr_revision, platform,
132 # Add chromium as dependency roll. 176 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 177
137 deps_rolls_dict = {} 178 deps_rolls_dict = {}
138 for dep_roll in deps_rolls: 179 for dep_roll in deps_rolls:
139 deps_rolls_dict[dep_roll.path] = dep_roll 180 deps_rolls_dict[dep_roll.path] = dep_roll
140 181
141 return deps_rolls_dict 182 return deps_rolls_dict
OLDNEW
« no previous file with comments | « no previous file | appengine/findit/common/git_repository.py » ('j') | appengine/findit/common/git_repository.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698