Commit 30ef9ae3 authored by tony@chromium.org's avatar tony@chromium.org

Extend From() to allow importing from different mappings. Also

allow From() to import when the URL is relative.

For example, if src/DEPS is:
deps = {
  'base' = 'svn://svn/base@123',
  'main' = From('base', 'src/main'),
}
and base/DEPS is:
deps = {
  'src/main': '/main@100',
}

This will checkout svn://svn/main@100 in main.

Review URL: http://codereview.chromium.org/1547026

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@44044 0039d316-1c4b-4281-b951-d872f2087c98
parent 1edec4dc
......@@ -428,11 +428,34 @@ class GClient(object):
class FromImpl:
"""Used to implement the From syntax."""
def __init__(self, module_name):
def __init__(self, module_name, sub_target_name=None):
"""module_name is the dep module we want to include from. It can also be
the name of a subdirectory to include from.
sub_target_name is an optional parameter if the module name in the other
DEPS file is different. E.g., you might want to map src/net to net."""
self.module_name = module_name
self.sub_target_name = sub_target_name
def __str__(self):
return 'From("%s")' % self.module_name
return 'From(%s, %s)' % (repr(self.module_name),
repr(self.sub_target_name))
def GetUrl(self, target_name, sub_deps_base_url, root_dir, sub_deps):
"""Resolve the URL for this From entry."""
sub_deps_target_name = target_name
if self.sub_target_name:
sub_deps_target_name = self.sub_target_name
url = sub_deps[sub_deps_target_name]
if url.startswith('/'):
# If it's a relative URL, we need to resolve the URL relative to the
# sub deps base URL.
if not isinstance(sub_deps_base_url, basestring):
sub_deps_base_url = sub_deps_base_url.GetPath()
scm = gclient_scm.CreateSCM(sub_deps_base_url, root_dir,
None)
url = scm.FullUrlForRelativeUrl(url)
return url
class FileImpl:
"""Used to implement the File('') syntax which lets you sync a single file
......@@ -471,7 +494,7 @@ class GClient(object):
raise gclient_utils.Error("Var is not defined: %s" % var_name)
def _ParseSolutionDeps(self, solution_name, solution_deps_content,
custom_vars):
custom_vars, parse_hooks):
"""Parses the DEPS file for the specified solution.
Args:
......@@ -531,7 +554,7 @@ class GClient(object):
else:
deps.update(os_deps)
if 'hooks' in local_scope:
if 'hooks' in local_scope and parse_hooks:
self._deps_hooks.extend(local_scope['hooks'])
# If use_relative_paths is set in the DEPS file, regenerate
......@@ -570,7 +593,8 @@ class GClient(object):
solution_deps = self._ParseSolutionDeps(
solution["name"],
solution_deps_content[solution["name"]],
custom_vars)
custom_vars,
True)
# If a line is in custom_deps, but not in the solution, we want to append
# this line to the solution.
......@@ -779,8 +803,13 @@ class GClient(object):
deps[d].module_name,
self._options.deps_file)
content = gclient_utils.FileRead(filename)
sub_deps = self._ParseSolutionDeps(deps[d].module_name, content, {})
url = sub_deps[d]
sub_deps = self._ParseSolutionDeps(deps[d].module_name, content, {},
False)
# Getting the URL from the sub_deps file can involve having to resolve
# a File() or having to resolve a relative URL. To resolve relative
# URLs, we need to pass in the orignal sub deps URL.
sub_deps_base_url = deps[deps[d].module_name]
url = deps[d].GetUrl(d, sub_deps_base_url, self._root_dir, sub_deps)
entries[d] = url
if run_scm:
self._options.revision = revision_overrides.get(d)
......
......@@ -1017,9 +1017,198 @@ deps = {
self.assertRaisesError(exception, self._gclient_gclient.RunOnDeps, client,
'update', self.args)
def testFromImpl(self):
# TODO(maruel): Test me!
pass
def testFromImplOne(self):
base_url = 'svn://base@123'
deps_content = (
"deps = {\n"
" 'base': '%s',\n"
" 'main': From('base'),\n"
"}\n" % base_url
)
main_url = 'svn://main@456'
base_deps_content = (
"deps = {\n"
" 'main': '%s',\n"
"}\n" % main_url
)
# Fake .gclient file.
name = 'testFromImplOne_solution_name'
gclient_config = (
"solutions = [ {\n"
"'name': '%s',\n"
"'url': '%s',\n"
"'custom_deps': {},\n"
"}, ]" % (name, self.url))
options = self.Options()
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
).AndReturn(False)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, name, options.deps_file)
).AndReturn(deps_content)
# base gets updated.
gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, 'base', options.deps_file)
).AndReturn(base_deps_content)
# main gets updated.
gclient.gclient_scm.CreateSCM(main_url, self.root_dir, 'main').AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
# Process is done and will write an .gclient_entries.
gclient.os.path.exists(
gclient.os.path.join(self.root_dir, options.entries_filename)
).AndReturn(False)
gclient.gclient_utils.FileWrite(
gclient.os.path.join(self.root_dir, options.entries_filename),
mox.IgnoreArg())
self.mox.ReplayAll()
client = self._gclient_gclient(self.root_dir, options)
client.SetConfig(gclient_config)
client.RunOnDeps('update', self.args)
def testFromImplTwo(self):
base_url = 'svn://base@123'
deps_content = (
"deps = {\n"
" 'base': '%s',\n"
" 'main': From('base', 'src/main'),\n"
"}\n" % base_url
)
main_url = 'svn://main@456'
base_deps_content = (
"deps = {\n"
" 'src/main': '%s',\n"
"}\n" % main_url
)
# Fake .gclient file.
name = 'testFromImplTwo_solution_name'
gclient_config = (
"solutions = [ {\n"
"'name': '%s',\n"
"'url': '%s',\n"
"'custom_deps': {},\n"
"}, ]" % (name, self.url))
options = self.Options()
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
).AndReturn(False)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, name, options.deps_file)
).AndReturn(deps_content)
# base gets updated.
gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, 'base', options.deps_file)
).AndReturn(base_deps_content)
# main gets updated.
gclient.gclient_scm.CreateSCM(main_url, self.root_dir, 'main').AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
# Process is done and will write an .gclient_entries.
gclient.os.path.exists(
gclient.os.path.join(self.root_dir, options.entries_filename)
).AndReturn(False)
gclient.gclient_utils.FileWrite(
gclient.os.path.join(self.root_dir, options.entries_filename),
mox.IgnoreArg())
self.mox.ReplayAll()
client = self._gclient_gclient(self.root_dir, options)
client.SetConfig(gclient_config)
client.RunOnDeps('update', self.args)
def testFromImplTwoRelatvie(self):
base_url = 'svn://base@123'
deps_content = (
"deps = {\n"
" 'base': '%s',\n"
" 'main': From('base', 'src/main'),\n"
"}\n" % base_url
)
main_url = '/relative@456'
base_deps_content = (
"deps = {\n"
" 'src/main': '%s',\n"
"}\n" % main_url
)
# Fake .gclient file.
name = 'testFromImplTwo_solution_name'
gclient_config = (
"solutions = [ {\n"
"'name': '%s',\n"
"'url': '%s',\n"
"'custom_deps': {},\n"
"}, ]" % (name, self.url))
options = self.Options()
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'main', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, 'base', '.git')
).AndReturn(False)
gclient.os.path.exists(gclient.os.path.join(self.root_dir, name, '.git')
).AndReturn(False)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir, name).AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, name, options.deps_file)
).AndReturn(deps_content)
# base gets updated.
gclient.gclient_scm.CreateSCM(base_url, self.root_dir, 'base').AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_utils.FileRead(
gclient.os.path.join(self.root_dir, 'base', options.deps_file)
).AndReturn(base_deps_content)
# main gets updated after resolving the relative url.
gclient.gclient_scm.CreateSCM(base_url, self.root_dir, None).AndReturn(
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.FullUrlForRelativeUrl(main_url
).AndReturn('svn://base' + main_url)
gclient.gclient_scm.CreateSCM('svn://base' + main_url, self.root_dir,
'main').AndReturn(gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
# Process is done and will write an .gclient_entries.
gclient.os.path.exists(
gclient.os.path.join(self.root_dir, options.entries_filename)
).AndReturn(False)
gclient.gclient_utils.FileWrite(
gclient.os.path.join(self.root_dir, options.entries_filename),
mox.IgnoreArg())
self.mox.ReplayAll()
client = self._gclient_gclient(self.root_dir, options)
client.SetConfig(gclient_config)
client.RunOnDeps('update', self.args)
def testFileImpl(self):
# Fake .gclient file.
......
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