From 1474741435774f15923967e50bf7531a3cc9d4f7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 27 Apr 2016 16:10:38 -0700 Subject: Move shell and python scripts to scripts/ directory Change-Id: Icdff44a54d14ddfc2266d99cf0578a8105716918 --- bootstrap.bash | 4 ++-- cc/builder.go | 2 +- copygcclib.sh | 7 ------- reverse_path.py | 40 ------------------------------------- reverse_path_test.py | 45 ------------------------------------------ scripts/copygcclib.sh | 7 +++++++ scripts/reverse_path.py | 40 +++++++++++++++++++++++++++++++++++++ scripts/reverse_path_test.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 97 insertions(+), 95 deletions(-) delete mode 100755 copygcclib.sh delete mode 100755 reverse_path.py delete mode 100644 reverse_path_test.py create mode 100755 scripts/copygcclib.sh create mode 100755 scripts/reverse_path.py create mode 100755 scripts/reverse_path_test.py diff --git a/bootstrap.bash b/bootstrap.bash index 62c429c5..e48f4803 100755 --- a/bootstrap.bash +++ b/bootstrap.bash @@ -8,7 +8,7 @@ if [[ "$ORIG_SRCDIR" != "." ]]; then echo "error: To use BUILDDIR, run from the source directory" exit 1 fi - export BUILDDIR=$("${ORIG_SRCDIR}/build/soong/reverse_path.py" "$ORIG_SRCDIR") + export BUILDDIR=$("${ORIG_SRCDIR}/build/soong/scripts/reverse_path.py" "$ORIG_SRCDIR") cd $ORIG_SRCDIR fi if [[ -z "$BUILDDIR" ]]; then @@ -45,7 +45,7 @@ if [[ $# -eq 0 ]]; then exit 1 fi - export SRCDIR_FROM_BUILDDIR=$(build/soong/reverse_path.py "$BUILDDIR") + export SRCDIR_FROM_BUILDDIR=$(build/soong/scripts/reverse_path.py "$BUILDDIR") sed -e "s|@@BuildDir@@|${BUILDDIR}|" \ -e "s|@@SrcDirFromBuildDir@@|${SRCDIR_FROM_BUILDDIR}|" \ diff --git a/cc/builder.go b/cc/builder.go index f67f9bd3..ca8bc750 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -101,7 +101,7 @@ var ( }, "objcopyCmd", "prefix") - copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/copygcclib.sh") + copyGccLibPath = pctx.SourcePathVariable("copyGccLibPath", "build/soong/scripts/copygcclib.sh") copyGccLib = pctx.StaticRule("copyGccLib", blueprint.RuleParams{ diff --git a/copygcclib.sh b/copygcclib.sh deleted file mode 100755 index 93c52cc5..00000000 --- a/copygcclib.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - -OUT=$1 -shift -LIBPATH=$($@) -cp -f $LIBPATH $OUT -echo "$OUT: $LIBPATH" > ${OUT}.d diff --git a/reverse_path.py b/reverse_path.py deleted file mode 100755 index 7b7d6217..00000000 --- a/reverse_path.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/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/reverse_path_test.py b/reverse_path_test.py deleted file mode 100644 index c5bb8e69..00000000 --- a/reverse_path_test.py +++ /dev/null @@ -1,45 +0,0 @@ -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() 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() -- cgit v1.2.3