diff options
author | David Ferguson <ferguson.david@gmail.com> | 2013-06-05 11:32:00 -0400 |
---|---|---|
committer | David Ferguson <ferguson.david@gmail.com> | 2013-06-05 11:58:08 -0400 |
commit | fc54d9eb229b44249aa580b43a6c581283d6577f (patch) | |
tree | ac26abfb0075cbf9eaec73e7a0444164cdfc168b | |
parent | af7aa23ce01fc8e1af0ac5f66bd575f3e5f8f32c (diff) | |
download | build-fc54d9eb229b44249aa580b43a6c581283d6577f.zip build-fc54d9eb229b44249aa580b43a6c581283d6577f.tar.gz build-fc54d9eb229b44249aa580b43a6c581283d6577f.tar.bz2 |
repopick: allow running from a subdir of ANDROID_BUILD_TOP
Change-Id: I6dfcd5dfe700174ed87dc8627b23519c62b4cb27
-rwxr-xr-x | tools/repopick.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/repopick.py b/tools/repopick.py index 039f122..8210e6b 100755 --- a/tools/repopick.py +++ b/tools/repopick.py @@ -109,6 +109,12 @@ def execute_cmd(cmd): print('\nCommand that failed:\n%s' % cmd) sys.exit(1) +# Verifies whether pathA is a subdirectory (or the same) as pathB +def is_pathA_subdir_of_pathB(pathA, pathB): + pathA = os.path.realpath(pathA) + '/' + pathB = os.path.realpath(pathB) + '/' + return(pathB == pathA[:len(pathB)]) + # Find the necessary bins - repo repo_bin = which('repo') if repo_bin == None: @@ -123,6 +129,19 @@ if not is_exe(git_bin): sys.stderr.write('ERROR: Could not find the git program in $PATH\n') sys.exit(1) +# Change current directory to the top of the tree +if 'ANDROID_BUILD_TOP' in os.environ: + top = os.environ['ANDROID_BUILD_TOP'] + if not is_pathA_subdir_of_pathB(os.getcwd(), top): + sys.stderr.write('ERROR: You must run this tool from within $ANDROID_BUILD_TOP!\n') + sys.exit(1) + os.chdir(os.environ['ANDROID_BUILD_TOP']) + +# Sanity check that we are being run from the top level of the tree +if not os.path.isdir('.repo'): + sys.stderr.write('ERROR: No .repo directory found. Please run this from the top of your tree.\n') + sys.exit(1) + # If --abandon-first is given, abandon the branch before starting if args.abandon_first: # Determine if the branch already exists; skip the abandon if it does not |