Commit b61d387f authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

gclient: Make GetScmName and CreateSCM abstract methods.

Long term plan is to separate GitDependency and CipdDependency,
where most of the current Dependency code is moved to GitDependency,
since it's not relevant to Cipd anyway.

Bug: 839925
Change-Id: Ic238a24fa7add302704934f79004e8a9ca886895
Reviewed-on: https://chromium-review.googlesource.com/1044651
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarMarc-Antoine Ruel <maruel@chromium.org>
parent afec759d
...@@ -719,17 +719,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -719,17 +719,10 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
self, name, package, cipd_root, self, name, package, cipd_root,
self.custom_vars, should_process, use_relative_paths, self.custom_vars, should_process, use_relative_paths,
condition, condition_value)) condition, condition_value))
elif dep_type == 'git':
url = raw_url.format(**self.get_vars())
deps_to_add.append(
GitDependency(
self, name, raw_url, url, None, None, self.custom_vars, None,
deps_file, should_process, use_relative_paths, condition,
condition_value))
else: else:
url = raw_url.format(**self.get_vars()) if raw_url else None url = raw_url.format(**self.get_vars()) if raw_url else None
deps_to_add.append( deps_to_add.append(
Dependency( GitDependency(
self, name, raw_url, url, None, None, self.custom_vars, None, self, name, raw_url, url, None, None, self.custom_vars, None,
deps_file, should_process, use_relative_paths, condition, deps_file, should_process, use_relative_paths, condition,
condition_value)) condition_value))
...@@ -1097,38 +1090,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): ...@@ -1097,38 +1090,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
print('Skipped missing %s' % cwd, file=sys.stderr) print('Skipped missing %s' % cwd, file=sys.stderr)
def GetScmName(self, url): def GetScmName(self, url):
"""Get the name of the SCM for the given URL. raise NotImplementedError()
While we currently support both git and cipd as SCM implementations,
this currently cannot return 'cipd', regardless of the URL, as CIPD
has no canonical URL format. If you want to use CIPD as an SCM, you
must currently do so by explicitly using a CipdDependency.
"""
if not url:
return None
url, _ = gclient_utils.SplitUrlRevision(url)
if url.endswith('.git'):
return 'git'
protocol = url.split('://')[0]
if protocol in (
'file', 'git', 'git+http', 'git+https', 'http', 'https', 'ssh', 'sso'):
return 'git'
return None
def CreateSCM(self, url, root_dir=None, relpath=None, out_fh=None, def CreateSCM(self, url, root_dir=None, relpath=None, out_fh=None,
out_cb=None): out_cb=None):
SCM_MAP = { raise NotImplementedError()
'cipd': gclient_scm.CipdWrapper,
'git': gclient_scm.GitWrapper,
}
scm_name = self.GetScmName(url)
if not scm_name in SCM_MAP:
raise gclient_utils.Error('No SCM found for url %s' % url)
scm_class = SCM_MAP[scm_name]
if not scm_class.BinaryExists():
raise gclient_utils.Error('%s command not found' % scm_name)
return scm_class(url, root_dir, relpath, out_fh, out_cb, self.print_outbuf)
def HasGNArgsFile(self): def HasGNArgsFile(self):
return self._gn_args_file is not None return self._gn_args_file is not None
...@@ -1399,7 +1365,24 @@ def _detect_host_os(): ...@@ -1399,7 +1365,24 @@ def _detect_host_os():
return _PLATFORM_MAPPING[sys.platform] return _PLATFORM_MAPPING[sys.platform]
class GClient(Dependency): class GitDependency(Dependency):
"""A Dependency object that represents a single git checkout."""
#override
def GetScmName(self, url):
"""Always 'git'."""
del url
return 'git'
#override
def CreateSCM(self, url, root_dir=None, relpath=None, out_fh=None,
out_cb=None):
"""Create a Wrapper instance suitable for handling this git dependency."""
return gclient_scm.GitWrapper(url, root_dir, relpath, out_fh, out_cb,
print_outbuf=self.print_outbuf)
class GClient(GitDependency):
"""Object that represent a gclient checkout. A tree of Dependency(), one per """Object that represent a gclient checkout. A tree of Dependency(), one per
solution or DEPS entry.""" solution or DEPS entry."""
...@@ -1441,8 +1424,8 @@ solutions = %(solution_list)s ...@@ -1441,8 +1424,8 @@ solutions = %(solution_list)s
# Do not change previous behavior. Only solution level and immediate DEPS # Do not change previous behavior. Only solution level and immediate DEPS
# are processed. # are processed.
self._recursion_limit = 2 self._recursion_limit = 2
Dependency.__init__(self, None, None, None, None, True, None, None, None, GitDependency.__init__(self, None, None, None, None, True, None, None, None,
'unused', True, None, None, True) 'unused', True, None, None, True)
self._options = options self._options = options
if options.deps_os: if options.deps_os:
enforced_os = options.deps_os.split(',') enforced_os = options.deps_os.split(',')
...@@ -1461,7 +1444,7 @@ solutions = %(solution_list)s ...@@ -1461,7 +1444,7 @@ solutions = %(solution_list)s
solutions.""" solutions."""
for dep in self.dependencies: for dep in self.dependencies:
if dep.managed and dep.url: if dep.managed and dep.url:
scm = self.CreateSCM( scm = dep.CreateSCM(
dep.url, self.root_dir, dep.name, self.outbuf) dep.url, self.root_dir, dep.name, self.outbuf)
actual_url = scm.GetActualRemoteURL(self._options) actual_url = scm.GetActualRemoteURL(self._options)
if actual_url and not scm.DoesRemoteURLMatch(self._options): if actual_url and not scm.DoesRemoteURLMatch(self._options):
...@@ -1533,7 +1516,7 @@ it or fix the checkout. ...@@ -1533,7 +1516,7 @@ it or fix the checkout.
deps_to_add = [] deps_to_add = []
for s in config_dict.get('solutions', []): for s in config_dict.get('solutions', []):
try: try:
deps_to_add.append(Dependency( deps_to_add.append(GitDependency(
self, s['name'], s['url'], s['url'], self, s['name'], s['url'], s['url'],
s.get('managed', True), s.get('managed', True),
s.get('custom_deps', {}), s.get('custom_deps', {}),
...@@ -1757,8 +1740,8 @@ it or fix the checkout. ...@@ -1757,8 +1740,8 @@ it or fix the checkout.
(not any(path.startswith(entry + '/') for path in entries)) and (not any(path.startswith(entry + '/') for path in entries)) and
os.path.exists(e_dir)): os.path.exists(e_dir)):
# The entry has been removed from DEPS. # The entry has been removed from DEPS.
scm = self.CreateSCM( scm = GitDependency.CreateSCM(
prev_url, self.root_dir, entry_fixed, self.outbuf) self, prev_url, self.root_dir, entry_fixed, self.outbuf)
# Check to see if this directory is now part of a higher-up checkout. # Check to see if this directory is now part of a higher-up checkout.
scm_root = None scm_root = None
...@@ -1965,22 +1948,6 @@ it or fix the checkout. ...@@ -1965,22 +1948,6 @@ it or fix the checkout.
return self._enforced_cpu return self._enforced_cpu
class GitDependency(Dependency):
"""A Dependency object that represents a single git checkout."""
#override
def GetScmName(self, url):
"""Always 'git'."""
del url
return 'git'
#override
def CreateSCM(self, url, root_dir=None, relpath=None, out_fh=None,
out_cb=None):
"""Create a Wrapper instance suitable for handling this git dependency."""
return gclient_scm.GitWrapper(url, root_dir, relpath, out_fh, out_cb)
class CipdDependency(Dependency): class CipdDependency(Dependency):
"""A Dependency object that represents a single CIPD package.""" """A Dependency object that represents a single CIPD package."""
......
...@@ -61,15 +61,15 @@ class GclientTest(trial_dir.TestCase): ...@@ -61,15 +61,15 @@ class GclientTest(trial_dir.TestCase):
self.previous_dir = os.getcwd() self.previous_dir = os.getcwd()
os.chdir(self.root_dir) os.chdir(self.root_dir)
# Manual mocks. # Manual mocks.
self._old_createscm = gclient.Dependency.CreateSCM self._old_createscm = gclient.GitDependency.CreateSCM
gclient.Dependency.CreateSCM = self._createscm gclient.GitDependency.CreateSCM = self._createscm
self._old_sys_stdout = sys.stdout self._old_sys_stdout = sys.stdout
sys.stdout = gclient.gclient_utils.MakeFileAutoFlush(sys.stdout) sys.stdout = gclient.gclient_utils.MakeFileAutoFlush(sys.stdout)
sys.stdout = gclient.gclient_utils.MakeFileAnnotated(sys.stdout) sys.stdout = gclient.gclient_utils.MakeFileAnnotated(sys.stdout)
def tearDown(self): def tearDown(self):
self.assertEquals([], self._get_processed()) self.assertEquals([], self._get_processed())
gclient.Dependency.CreateSCM = self._old_createscm gclient.GitDependency.CreateSCM = self._old_createscm
sys.stdout = self._old_sys_stdout sys.stdout = self._old_sys_stdout
os.chdir(self.previous_dir) os.chdir(self.previous_dir)
super(GclientTest, self).tearDown() super(GclientTest, self).tearDown()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment