bug 632616 - fix symbolstore.py's handling of relative paths. r=catlee

This commit is contained in:
Ted Mielczarek 2012-05-24 11:58:35 -04:00
parent e41e79984f
commit 7aefe2bf5b
3 changed files with 46 additions and 3 deletions

View File

@ -98,3 +98,6 @@ endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk
check::
$(PYTHON) $(srcdir)/tools/unit-symbolstore.py

View File

@ -286,9 +286,9 @@ class HGFileInfo(VCSFileInfo):
if self.revision and self.clean_root:
if self.srcdir:
# strip the base path off
file = os.path.normpath(file)
if IsInDir(file, self.srcdir):
file = file[len(self.srcdir):]
abs_file = os.path.abspath(file)
if IsInDir(abs_file, self.srcdir):
file = abs_file[len(self.srcdir):]
if file.startswith('/') or file.startswith('\\'):
file = file[1:]
return "hg:%s:%s:%s" % (self.clean_root, file, self.revision)

View File

@ -0,0 +1,40 @@
#!/usr/bin/env python
import os, tempfile, unittest, shutil
import symbolstore
class TestGetVCSFilename(unittest.TestCase):
"""
Unit tests for GetVCSFilename
"""
def setUp(self):
self.srcdir = tempfile.mkdtemp()
# make it look vaguely like a hg repo
os.mkdir(os.path.join(self.srcdir, ".hg"))
# and force-feed it to the symbolstore cache
symbolstore.HGRepoInfo.repos[self.srcdir] = \
symbolstore.HGRepoInfo("http://example.com/repo",
"abcd",
'example.com/repo')
objdir = os.path.join(self.srcdir, "obj")
os.mkdir(objdir)
self.oldcwd = os.getcwd()
os.chdir(objdir)
def tearDown(self):
os.chdir(self.oldcwd)
shutil.rmtree(self.srcdir)
def testRelativePath(self):
"""
Test that a relative path doesn't get
removed.
"""
vcsfile, root = symbolstore.GetVCSFilename("../foo.h", [self.srcdir])
vcs,location,filename,rev = vcsfile.split(":")
self.assertEqual(filename, "foo.h")
if __name__ == '__main__':
unittest.main()