diff --git a/gclient.py b/gclient.py index e6a6432f9..fa86f2130 100755 --- a/gclient.py +++ b/gclient.py @@ -518,11 +518,6 @@ 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: @@ -560,10 +555,10 @@ class GClient(object): if path[0] != "/": raise gclient_utils.Error( "relative DEPS entry \"%s\" must begin with a slash" % d) - if local_scope.get('use_relative_urls2'): - url = gclient_utils.FullUrlFromRelative2(solution["url"], url) - else: - url = gclient_utils.FullUrlFromRelative(solution["url"], url) + # Create a scm just to query the full url. + scm = gclient_scm.CreateSCM(solution["url"], self._root_dir, + None) + url = scm.FullUrlForRelativeUrl(url) if d in deps and deps[d] != url: raise gclient_utils.Error( "Solutions have conflicting versions of dependency \"%s\"" % d) diff --git a/gclient_scm.py b/gclient_scm.py index 9aa0f0609..b564ed48e 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -249,6 +249,12 @@ class GitWrapper(SCMWrapper, scm.GIT): files = self._Run(['diff', '--name-only', merge_base]).split() file_list.extend([os.path.join(self.checkout_path, f) for f in files]) + def FullUrlForRelativeUrl(self, url): + # Strip from last '/' + # Equivalent to unix basename + base_url = self.url + return base_url[:base_url.rfind('/')] + url + def _CheckMinVersion(self, min_version): def only_int(val): if val.isdigit(): @@ -528,3 +534,7 @@ class SVNWrapper(SCMWrapper, scm.SVN): # There's no file list to retrieve. else: self.RunAndGetFileList(options, command, path, file_list) + + def FullUrlForRelativeUrl(self, url): + # Find the forth '/' and strip from there. A bit hackish. + return '/'.join(self.url.split('/')[:4]) + url diff --git a/gclient_utils.py b/gclient_utils.py index 5068563e9..3c62afb99 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -71,17 +71,6 @@ 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) diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 9794b51a7..66c1f5e3b 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -66,8 +66,8 @@ class SVNWrapperTestCase(BaseTestCase): members = [ 'COMMAND', 'Capture', 'CaptureHeadRevision', 'CaptureInfo', 'CaptureStatus', 'DiffItem', 'GenerateDiff', 'GetCheckoutRoot', - 'GetEmail', 'GetFileProperty', 'IsMoved', 'ReadSimpleAuth', 'Run', - 'RunAndFilterOutput', 'RunAndGetFileList', + 'GetEmail', 'GetFileProperty', 'FullUrlForRelativeUrl', 'IsMoved', + 'ReadSimpleAuth', 'Run', 'RunAndFilterOutput', 'RunAndGetFileList', 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', ] @@ -81,6 +81,22 @@ class SVNWrapperTestCase(BaseTestCase): exception_msg = 'Unsupported scm %(scm_name)s' % kwargs self.assertRaisesError(exception_msg, self._scm_wrapper, *args, **kwargs) + def testSVNFullUrlForRelativeUrl(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 testGITFullUrlForRelativeUrl(self): + self.url = 'git://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'), 'git://a/b/c/crap') + def testRunCommandException(self): options = self.Options(verbose=False) file_path = gclient_scm.os.path.join(self.root_dir, self.relpath, '.git') @@ -361,10 +377,11 @@ from :3 def testDir(self): members = [ 'COMMAND', 'Capture', 'CaptureStatus', 'FetchUpstreamTuple', - 'GenerateDiff', 'GetBranch', 'GetBranchRef', 'GetCheckoutRoot', - 'GetDifferentFiles', 'GetEmail', 'GetPatchName', 'GetSVNBranch', - 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', 'ShortBranchName', - 'RunCommand', 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', + 'FullUrlForRelativeUrl', 'GenerateDiff', 'GetBranch', 'GetBranchRef', + 'GetCheckoutRoot', 'GetDifferentFiles', 'GetEmail', 'GetPatchName', + 'GetSVNBranch', 'GetUpstream', 'IsGitSvn', 'RunAndFilterOutput', + 'ShortBranchName', 'RunCommand', + 'cleanup', 'diff', 'export', 'pack', 'relpath', 'revert', 'revinfo', 'runhooks', 'scm_name', 'status', 'update', 'url', ] diff --git a/tests/gclient_test.py b/tests/gclient_test.py index aaa007c3e..e21c20ae7 100755 --- a/tests/gclient_test.py +++ b/tests/gclient_test.py @@ -47,7 +47,6 @@ 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') @@ -798,13 +797,15 @@ deps_os = { scm_wrapper_src) scm_wrapper_src.RunCommand('update', mox.Func(OptIsRev123), self.args, []) - 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/cygwin@3248' + ).AndReturn(cygwin_path) - gclient.gclient_utils.FullUrlFromRelative(self.url, - '/trunk/deps/third_party/WebKit' - ).AndReturn(webkit_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_scm.CreateSCM( webkit_path, self.root_dir, 'foo/third_party/WebKit' @@ -912,9 +913,10 @@ deps = { gclient.gclient_scm.CreateSCM) gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) - gclient.gclient_utils.FullUrlFromRelative(self.url, - '/trunk/bar/WebKit', - ).AndReturn(webkit_path) + 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_scm.CreateSCM( webkit_path, self.root_dir, 'foo/third_party/WebKit' @@ -975,9 +977,10 @@ deps = { gclient.gclient_scm.CreateSCM) gclient.gclient_scm.CreateSCM.RunCommand('update', options, self.args, []) - gclient.gclient_utils.FullUrlFromRelative(self.url, - '/trunk/bar_custom/WebKit' - ).AndReturn(webkit_path) + 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_scm.CreateSCM(webkit_path, self.root_dir, 'foo/third_party/WebKit').AndReturn(gclient.gclient_scm.CreateSCM) diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py index 5e509ea24..4bbc0b9f6 100644 --- a/tests/gclient_utils_test.py +++ b/tests/gclient_utils_test.py @@ -15,8 +15,7 @@ class GclientUtilsUnittest(SuperMoxTestBase): def testMembersChanged(self): members = [ 'CheckCall', 'CheckCallError', 'Error', 'FileRead', 'FileWrite', - 'FindGclientRoot', - 'FullUrlFromRelative', 'FullUrlFromRelative2', 'GetNamedNodeText', + 'FindGclientRoot', 'GetNamedNodeText', 'GetNodeNamedAttributeText', 'IsUsingGit', 'PathDifference', 'ParseXML', 'PrintableObject', 'RemoveDirectory', 'SplitUrlRevision', 'SubprocessCall', 'SubprocessCallAndFilter', 'errno', 'logging', 'os', @@ -138,18 +137,6 @@ 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()