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

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

Issue 2605943002: Removing the mutation in the factories for getting dep repositories (Closed)
Patch Set: Added the Factory method to CachedGitilesRepository Created 3 years, 11 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 re 5 import re
6 6
7 from common import dependency 7 from common import dependency
8 from common import deps_parser 8 from common import deps_parser
9 9
10 _CHROMIUM_ROOT_DIR = 'src/' 10 _CHROMIUM_ROOT_DIR = 'src/'
11 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git' 11 _CHROMIUM_REPO_MASTER = 'https://chromium.googlesource.com/chromium/src.git'
12 12
13 _CHROME_VERSION_PATTERN = re.compile(r'^\d+\.\d+\.\d+\.\d+$') 13 _CHROME_VERSION_PATTERN = re.compile(r'^\d+\.\d+\.\d+\.\d+$')
14 14
15 _BUILDSPEC_REPO = ('https://chrome-internal.googlesource.com/chrome/tools/' 15 _BUILDSPEC_REPO = ('https://chrome-internal.googlesource.com/chrome/tools/'
16 'buildspec.git/') 16 'buildspec.git/')
17 17
18 18
19 def IsChromeVersion(revision): 19 def IsChromeVersion(revision):
20 """Determines if a revision is a chrome version.""" 20 """Determines if a revision is a chrome version."""
21 if _CHROME_VERSION_PATTERN.match(revision): 21 return bool(_CHROME_VERSION_PATTERN.match(revision))
22 return True
23
24 return False
25 22
26 23
27 class DEPSDownloader(deps_parser.DEPSLoader): 24 class DEPSDownloader(deps_parser.DEPSLoader):
28 """Downloads DEPS from remote Git repo.""" 25 """Downloads DEPS from remote Git repo."""
29 26
30 def __init__(self, repository): 27 def __init__(self, get_repository):
31 self.repository = repository 28 assert callable(get_repository), (
29 'The ``get_repository`` argument must be callable.')
30 self._get_repository = get_repository
32 31
33 def Load(self, repo_url, revision, deps_file): 32 def Load(self, repo_url, revision, deps_file):
34 self.repository.repo_url = repo_url 33 repository = self._get_repository(repo_url)
35 content = None 34 content = None
36 if deps_file == 'DEPS' and repo_url == _CHROMIUM_REPO_MASTER: 35 if deps_file == 'DEPS' and repo_url == _CHROMIUM_REPO_MASTER:
37 # Try .DEPS.git instead of DEPS first, for commits during the Git chaos. 36 # Try .DEPS.git instead of DEPS first, for commits during the Git chaos.
38 content = self.repository.GetSource('.DEPS.git', revision) 37 content = repository.GetSource('.DEPS.git', revision)
39 38
40 if content is None: 39 if content is None:
41 content = self.repository.GetSource(deps_file, revision) 40 content = repository.GetSource(deps_file, revision)
42 41
43 if content is None and deps_file != 'DEPS': 42 if content is None and deps_file != 'DEPS':
44 # Like gclient, fall back to raw 'DEPS' when all else fails. 43 # Like gclient, fall back to raw 'DEPS' when all else fails.
45 content = self.repository.GetSource('DEPS', revision) 44 content = repository.GetSource('DEPS', revision)
46 45
47 if content is None: 46 if content is None:
48 raise Exception( 47 raise Exception(
49 'Failed to pull %s file from %s, at revision %s.' % ( 48 'Failed to pull %s file from %s, at revision %s.' % (
50 deps_file, repo_url, revision)) 49 deps_file, repo_url, revision))
51 50
52 return content 51 return content
53 52
54 53
55 class ChromeDependencyFetcher(object): 54 class ChromeDependencyFetcher(object):
56 55
57 def __init__(self, repository): 56 def __init__(self, get_repository):
58 self.repository = repository 57 assert callable(get_repository), (
58 'The ``get_repository`` argument must be callable.')
59 self._get_repository = get_repository
59 60
60 def GetDependency(self, revision, platform): 61 def GetDependency(self, revision, platform):
61 """Returns all dependencies of Chrome as a dict for given revision and OS. 62 """Returns all dependencies of Chrome as a dict for given revision and OS.
62 63
63 Args: 64 Args:
64 revision (str): The revision of a Chrome build, it can be a githash or a 65 revision (str): The revision of a Chrome build, it can be a githash or a
65 chrome version for a official build. 66 chrome version for a official build.
66 platform (str): The target platform of the Chrome build, should be one of 67 platform (str): The target platform of the Chrome build, should be one of
67 'win', 'ios', 'mac', 'unix', 'android', or 'all'. 68 'win', 'ios', 'mac', 'unix', 'android', or 'all'.
68 69
69 Returns: 70 Returns:
70 A map from dependency path to the dependency info. 71 A map from dependency path to the dependency info.
71 """ 72 """
72 deps_repo_info = {'deps_file': 'DEPS'} 73 deps_repo_info = {'deps_file': 'DEPS'}
73 74
74 if IsChromeVersion(revision): 75 if IsChromeVersion(revision):
75 # For chrome version, get the DEPS file from internal buildspec/ repo 76 # For chrome version, get the DEPS file from internal buildspec/ repo
76 # instead of chromium trunk. 77 # instead of chromium trunk.
77 deps_repo_info['deps_repo_url'] = _BUILDSPEC_REPO 78 deps_repo_info['deps_repo_url'] = _BUILDSPEC_REPO
78 deps_repo_info['deps_repo_revision'] = 'master' 79 deps_repo_info['deps_repo_revision'] = 'master'
79 deps_repo_info['deps_file'] = 'releases/%s/DEPS' % revision 80 deps_repo_info['deps_file'] = 'releases/%s/DEPS' % revision
80 81
81 root_dep = dependency.Dependency( 82 root_dep = dependency.Dependency(
82 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, **deps_repo_info) 83 _CHROMIUM_ROOT_DIR, _CHROMIUM_REPO_MASTER, revision, **deps_repo_info)
83 84
84 deps_parser.UpdateDependencyTree( 85 deps_parser.UpdateDependencyTree(
85 root_dep, [platform], DEPSDownloader(self.repository)) 86 root_dep, [platform], DEPSDownloader(self._get_repository))
86 87
87 dependencies = {} 88 dependencies = {}
88 89
89 # Flatten the dependency tree into a one-level dict. 90 # Flatten the dependency tree into a one-level dict.
90 def FlattenDepTree(dep): 91 def FlattenDepTree(dep):
91 dependencies[dep.path] = dep 92 dependencies[dep.path] = dep
92 for child in dep.children.values(): 93 for child in dep.children.values():
93 FlattenDepTree(child) 94 FlattenDepTree(child)
94 95
95 FlattenDepTree(root_dep) 96 FlattenDepTree(root_dep)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 """ 159 """
159 deps_rolls = self.GetDependencyRolls(old_cr_revision, new_cr_revision, 160 deps_rolls = self.GetDependencyRolls(old_cr_revision, new_cr_revision,
160 platform, skip_chromium_roll=False) 161 platform, skip_chromium_roll=False)
161 162
162 deps_rolls_dict = {} 163 deps_rolls_dict = {}
163 164
164 for dep_roll in deps_rolls: 165 for dep_roll in deps_rolls:
165 deps_rolls_dict[dep_roll.path] = dep_roll 166 deps_rolls_dict[dep_roll.path] = dep_roll
166 167
167 return deps_rolls_dict 168 return deps_rolls_dict
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698