clean_header: Run outside of $ANDROID_BUILD_TOP
Enable the use case where we run clean_header.py from outside of
$ANDROID_BUILD_TOP. Previously, this script required the current working
directory to be under $ANDROID_BUILD_TOP. Running it from a different
directory resulted in the following error message:
clean_header.py: error: Not in android tree pointed at by ANDROID_BUILD_TOP (....)
Change-Id: I48210ea1a0033228a9aaa4124d28247b07cee6d4
diff --git a/libc/kernel/tools/clean_header.py b/libc/kernel/tools/clean_header.py
index 88b2ae0..92a2139 100755
--- a/libc/kernel/tools/clean_header.py
+++ b/libc/kernel/tools/clean_header.py
@@ -152,8 +152,8 @@
usage()
no_update = True
- dst_dir = get_kernel_dir()
- src_dir = get_kernel_headers_original_dir()
+ dst_dir = None
+ src_dir = None
for opt, arg in optlist:
if opt == '-u':
no_update = False
@@ -163,6 +163,15 @@
src_dir = arg
elif opt == '-d':
dst_dir = arg
+ # get_kernel_dir() and get_kernel_headers_original_dir() require the current
+ # working directory to be a direct or indirect subdirectory of
+ # ANDROID_BUILD_TOP. Otherwise, these functions print an error message and
+ # exit. Let's allow the user to run this program from an unrelated
+ # directory, if they specify src_dir and dst_dir on the command line.
+ if dst_dir is None:
+ dst_dir = get_kernel_dir()
+ if src_dir is None:
+ src_dir = get_kernel_headers_original_dir()
if len(args) == 0:
usage()