diff options
author | Dan Willemsen <dwillemsen@google.com> | 2016-03-22 14:08:17 -0700 |
---|---|---|
committer | Dan Willemsen <dwillemsen@google.com> | 2016-03-22 19:53:36 -0700 |
commit | 6ac18ecb84332b6e84f498434812541f58a64ed4 (patch) | |
tree | af18bd7447c199f1c99fe0dc9b880aeb30dc8b3a /reverse_path_test.py | |
parent | 7253e0b8a486797347b8bdec43aa98ce135f3ad7 (diff) | |
download | build_soong-6ac18ecb84332b6e84f498434812541f58a64ed4.tar.gz build_soong-6ac18ecb84332b6e84f498434812541f58a64ed4.tar.bz2 build_soong-6ac18ecb84332b6e84f498434812541f58a64ed4.zip |
Improve BUILDDIR handling with symlinks
If BUILDDIR is a local symlink to another directory in the same parent
directory (out -> out.angler), then using out and .. as relative paths
to get back and forth work.
But if BUILDDIR is a symlink to another directory altogether (out ->
/mnt/sdd/out.master), then we shouldn't be relying on relative paths (so
that the source directory can still be moved).
Change-Id: I946c8116090410ab2b935eafba9b6e96f5f2f1dd
Diffstat (limited to 'reverse_path_test.py')
-rw-r--r-- | reverse_path_test.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/reverse_path_test.py b/reverse_path_test.py new file mode 100644 index 00000000..c5bb8e69 --- /dev/null +++ b/reverse_path_test.py @@ -0,0 +1,45 @@ +from __future__ import print_function + +import os +import shutil +import tempfile +import unittest + +from reverse_path import reverse_path + +class TestReversePath(unittest.TestCase): + def setUp(self): + self.tmpdir = tempfile.mkdtemp() + os.chdir(self.tmpdir) + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + def test_absolute(self): + self.assertEqual(self.tmpdir, reverse_path('/out')) + + def test_relative(self): + os.mkdir('a') + os.mkdir('b') + + self.assertEqual('..', reverse_path('a')) + + os.chdir('a') + self.assertEqual('a', reverse_path('..')) + self.assertEqual('.', reverse_path('../a')) + self.assertEqual('../a', reverse_path('../b')) + + def test_symlink(self): + os.mkdir('b') + os.symlink('b', 'a') + os.mkdir('b/d') + os.symlink('b/d', 'c') + + self.assertEqual('..', reverse_path('a')) + self.assertEqual('..', reverse_path('b')) + self.assertEqual(self.tmpdir, reverse_path('c')) + self.assertEqual('../..', reverse_path('b/d')) + + +if __name__ == '__main__': + unittest.main() |