diff options
author | Colin Cross <ccross@android.com> | 2016-04-27 16:10:38 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2016-04-29 13:59:56 -0700 |
commit | 1474741435774f15923967e50bf7531a3cc9d4f7 (patch) | |
tree | ca23ce8c26f725a5394ff44d5c27a461131a26ee /scripts | |
parent | 369f01315a669f32f741659ae9a5f5c4fb7b7fad (diff) | |
download | build_soong-1474741435774f15923967e50bf7531a3cc9d4f7.tar.gz build_soong-1474741435774f15923967e50bf7531a3cc9d4f7.tar.bz2 build_soong-1474741435774f15923967e50bf7531a3cc9d4f7.zip |
Move shell and python scripts to scripts/ directory
Change-Id: Icdff44a54d14ddfc2266d99cf0578a8105716918
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/copygcclib.sh | 7 | ||||
-rwxr-xr-x | scripts/reverse_path.py | 40 | ||||
-rwxr-xr-x | scripts/reverse_path_test.py | 47 |
3 files changed, 94 insertions, 0 deletions
diff --git a/scripts/copygcclib.sh b/scripts/copygcclib.sh new file mode 100755 index 00000000..93c52cc5 --- /dev/null +++ b/scripts/copygcclib.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +OUT=$1 +shift +LIBPATH=$($@) +cp -f $LIBPATH $OUT +echo "$OUT: $LIBPATH" > ${OUT}.d diff --git a/scripts/reverse_path.py b/scripts/reverse_path.py new file mode 100755 index 00000000..7b7d6217 --- /dev/null +++ b/scripts/reverse_path.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import os +import sys + +# Find the best reverse path to reference the current directory from another +# directory. We use this to find relative paths to and from the source and build +# directories. +# +# If the directory is given as an absolute path, return an absolute path to the +# current directory. +# +# If there's a symlink involved, and the same relative path would not work if +# the symlink was replace with a regular directory, then return an absolute +# path. This handles paths like out -> /mnt/ssd/out +# +# For symlinks that can use the same relative path (out -> out.1), just return +# the relative path. That way out.1 can be renamed as long as the symlink is +# updated. +# +# For everything else, just return the relative path. That allows the source and +# output directories to be moved as long as they stay in the same position +# relative to each other. +def reverse_path(path): + if path.startswith("/"): + return os.path.abspath('.') + + realpath = os.path.relpath(os.path.realpath('.'), os.path.realpath(path)) + relpath = os.path.relpath('.', path) + + if realpath != relpath: + return os.path.abspath('.') + + return relpath + + +if __name__ == '__main__': + print(reverse_path(sys.argv[1])) diff --git a/scripts/reverse_path_test.py b/scripts/reverse_path_test.py new file mode 100755 index 00000000..55776935 --- /dev/null +++ b/scripts/reverse_path_test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +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() |