aboutsummaryrefslogtreecommitdiffstats
path: root/tools/findleaves.py
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2016-05-27 15:20:31 -0700
committerColin Cross <ccross@android.com>2016-05-27 16:05:10 -0700
commit9808645cd9800a7bf7afeb208f3f25c208c64c20 (patch)
treee6e3653630386adb55e1e5d63cbc8b10834fa012 /tools/findleaves.py
parent8ed91b66240d3071a42365737f4cd5c7dbe601e1 (diff)
downloadplatform_build-9808645cd9800a7bf7afeb208f3f25c208c64c20.tar.gz
platform_build-9808645cd9800a7bf7afeb208f3f25c208c64c20.tar.bz2
platform_build-9808645cd9800a7bf7afeb208f3f25c208c64c20.zip
Add --dir option to findleaves.py
findleaves.py needs to be able to search multiple directories for multiple filenames (Android.bp and Android.mk). Add support for a new --dir= option to specify one or more directories to search, and then treat any remaining options as filenames. If no directories are specified, fall back to treating only the last option as a filename and the rest as directories. Change-Id: Ie879facd49192c6b4fafae070ad00eb21b1faa32
Diffstat (limited to 'tools/findleaves.py')
-rwxr-xr-xtools/findleaves.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/tools/findleaves.py b/tools/findleaves.py
index 3a9e5084e2..72cc02456b 100755
--- a/tools/findleaves.py
+++ b/tools/findleaves.py
@@ -23,7 +23,7 @@
import os
import sys
-def perform_find(mindepth, prune, dirlist, filename):
+def perform_find(mindepth, prune, dirlist, filenames):
result = []
pruneleaves = set(map(lambda x: os.path.split(x)[1], prune))
for rootdir in dirlist:
@@ -48,19 +48,24 @@ def perform_find(mindepth, prune, dirlist, filename):
if depth < mindepth:
continue
# match
- if filename in files:
- result.append(os.path.join(root, filename))
- del dirs[:]
+ for filename in filenames:
+ if filename in files:
+ result.append(os.path.join(root, filename))
+ del dirs[:]
return result
def usage():
- sys.stderr.write("""Usage: %(progName)s [<options>] <dirlist> <filename>
+ sys.stderr.write("""Usage: %(progName)s [<options>] [--dir=<dir>] <filenames>
Options:
--mindepth=<mindepth>
Both behave in the same way as their find(1) equivalents.
--prune=<dirname>
Avoids returning results from inside any directory called <dirname>
(e.g., "*/out/*"). May be used multiple times.
+ --dir=<dir>
+ Add a directory to search. May be repeated multiple times. For backwards
+ compatibility, if no --dir argument is provided then all but the last entry
+ in <filenames> are treated as directories.
""" % {
"progName": os.path.split(sys.argv[0])[1],
})
@@ -69,6 +74,7 @@ Options:
def main(argv):
mindepth = -1
prune = []
+ dirlist = []
i=1
while i<len(argv) and len(argv[i])>2 and argv[i][0:2] == "--":
arg = argv[i]
@@ -82,14 +88,24 @@ def main(argv):
if len(p) == 0:
usage()
prune.append(p)
+ elif arg.startswith("--dir="):
+ d = arg[len("--dir="):]
+ if len(p) == 0:
+ usage()
+ dirlist.append(d)
else:
usage()
i += 1
- if len(argv)-i < 2: # need both <dirlist> and <filename>
- usage()
- dirlist = argv[i:-1]
- filename = argv[-1]
- results = list(set(perform_find(mindepth, prune, dirlist, filename)))
+ if len(dirlist) == 0: # backwards compatibility
+ if len(argv)-i < 2: # need both <dirlist> and <filename>
+ usage()
+ dirlist = argv[i:-1]
+ filenames = [argv[-1]]
+ else:
+ if len(argv)-i < 1: # need <filename>
+ usage()
+ filenames = argv[i:]
+ results = list(set(perform_find(mindepth, prune, dirlist, filenames)))
results.sort()
for r in results:
print r