Commit c532e17e authored by msb@chromium.org's avatar msb@chromium.org

gclient: implement a less hacky relative URL implementation

Doing something like basename when concatenating base_url with
relative url.

Added use_relative_urls2 to enable switching between old
implementation and new implementation. Once the old implementation
is deprecated we can remove the use_relative_urls2.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@34563 0039d316-1c4b-4281-b951-d872f2087c98
parent 4c317183
......@@ -518,6 +518,11 @@ class GClient(object):
solution_deps_content[solution["name"]],
custom_vars)
local_scope = {}
var = self._VarImpl(custom_vars, local_scope)
global_scope = {"From": self.FromImpl, "Var": var.Lookup, "deps_os": {}}
exec(solution_deps_content[solution["name"]], global_scope, local_scope)
# If a line is in custom_deps, but not in the solution, we want to append
# this line to the solution.
if "custom_deps" in solution:
......@@ -555,10 +560,10 @@ class GClient(object):
if path[0] != "/":
raise gclient_utils.Error(
"relative DEPS entry \"%s\" must begin with a slash" % d)
# Create a scm just to query the full url.
scm = gclient_scm.CreateSCM(solution["url"], self._root_dir,
None)
url = scm.FullUrlForRelativeUrl(url)
if local_scope.get('use_relative_urls2'):
url = gclient_utils.FullUrlFromRelative2(solution["url"], url)
else:
url = gclient_utils.FullUrlFromRelative(solution["url"], url)
if d in deps and deps[d] != url:
raise gclient_utils.Error(
"Solutions have conflicting versions of dependency \"%s\"" % d)
......
......@@ -57,10 +57,6 @@ class SCMWrapper(object):
if self.relpath and self._root_dir:
self.checkout_path = os.path.join(self._root_dir, self.relpath)
def FullUrlForRelativeUrl(self, url):
# Find the forth '/' and strip from there. A bit hackish.
return '/'.join(self.url.split('/')[:4]) + url
def RunCommand(self, command, options, args, file_list=None):
# file_list will have all files that are modified appended to it.
if file_list is None:
......
......@@ -38,6 +38,17 @@ def SplitUrlRevision(url):
return tuple(components)
def FullUrlFromRelative(base_url, url):
# Find the forth '/' and strip from there. A bit hackish.
return '/'.join(base_url.split('/')[:4]) + url
def FullUrlFromRelative2(base_url, url):
# Strip from last '/'
# Equivalent to unix basename
return base_url[:base_url.rfind('/')] + url
def ParseXML(output):
try:
return xml.dom.minidom.parseString(output)
......
......@@ -65,7 +65,7 @@ class SVNWrapperTestCase(BaseTestCase):
def testDir(self):
members = [
'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo',
'CaptureStatus', 'DiffItem', 'FullUrlForRelativeUrl', 'GetEmail',
'CaptureStatus', 'DiffItem', 'GetEmail',
'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run',
'RunAndFilterOutput', 'RunAndGetFileList',
'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert',
......@@ -81,14 +81,6 @@ class SVNWrapperTestCase(BaseTestCase):
exception_msg = 'Unsupported scm %(scm_name)s' % kwargs
self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs)
def testFullUrlForRelativeUrl(self):
self.url = 'svn://a/b/c/d'
self.mox.ReplayAll()
scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir,
relpath=self.relpath)
self.assertEqual(scm.FullUrlForRelativeUrl('/crap'), 'svn://a/b/crap')
def testRunCommandException(self):
options = self.Options(verbose=False)
file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git')
......@@ -367,8 +359,7 @@ from :3
def testDir(self):
members = [
'COMMAND', 'Capture', 'CaptureStatus', 'FullUrlForRelativeUrl',
'GetEmail',
'COMMAND', 'Capture', 'CaptureStatus', 'GetEmail',
'RunCommand', 'cleanup', 'diff', 'export', 'relpath', 'revert',
'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url',
]
......
......@@ -47,6 +47,7 @@ class GClientBaseTestCase(BaseTestCase):
self.mox.StubOutWithMock(gclient.gclient_utils, 'FileWrite')
self.mox.StubOutWithMock(gclient.gclient_utils, 'SubprocessCall')
self.mox.StubOutWithMock(gclient.gclient_utils, 'RemoveDirectory')
self.mox.StubOutWithMock(gclient.gclient_utils, 'FullUrlFromRelative')
# Mock them to be sure nothing bad happens.
self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'Capture')
self.mox.StubOutWithMock(gclient.gclient_scm.scm.SVN, 'CaptureInfo')
......@@ -797,15 +798,13 @@ deps_os = {
scm_wrapper_src)
scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, [])
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src2)
scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/cygwin@3248'
).AndReturn(cygwin_path)
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/deps/third_party/cygwin@3248'
).AndReturn(cygwin_path)
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src2)
scm_wrapper_src2.FullUrlForRelativeUrl('/trunk/deps/third_party/WebKit'
).AndReturn(webkit_path)
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/deps/third_party/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(
webkit_path, self.root_dir, 'foo/third_party/WebKit'
......@@ -913,10 +912,9 @@ deps = {
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_scm.CreateSCM(self.url, self.root_dir, None
).AndReturn(scm_wrapper_src)
scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar/WebKit'
).AndReturn(webkit_path)
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/bar/WebKit',
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(
webkit_path, self.root_dir, 'foo/third_party/WebKit'
......@@ -977,10 +975,9 @@ deps = {
gclient.gclient_scm.CreateSCM)
gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, [])
gclient.gclient_scm.CreateSCM(self.url, self.root_dir,
None).AndReturn(scm_wrapper_src)
scm_wrapper_src.FullUrlForRelativeUrl('/trunk/bar_custom/WebKit'
).AndReturn(webkit_path)
gclient.gclient_utils.FullUrlFromRelative(self.url,
'/trunk/bar_custom/WebKit'
).AndReturn(webkit_path)
gclient.gclient_scm.CreateSCM(webkit_path, self.root_dir,
'foo/third_party/WebKit').AndReturn(gclient.gclient_scm.CreateSCM)
......
......@@ -86,6 +86,18 @@ class SplitUrlRevisionTestCase(SuperMoxTestBase):
self.assertEquals(out_url, url)
class FullUrlFromRelative(SuperMoxTestBase):
def testFullUrlFromRelative(self):
base_url = 'svn://a/b/c/d'
full_url = gclient_utils.FullUrlFromRelative(base_url, '/crap')
self.assertEqual(full_url, 'svn://a/b/crap')
def testFullUrlFromRelative2(self):
base_url = 'svn://a/b/c/d'
full_url = gclient_utils.FullUrlFromRelative2(base_url, '/crap')
self.assertEqual(full_url, 'svn://a/b/c/crap')
if __name__ == '__main__':
import unittest
unittest.main()
......
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