From 97ea68aea6d274fb9135df927fde53fcfb1c81d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Ca=C3=B1as?= Date: Tue, 23 Apr 2024 20:36:14 -0400 Subject: [PATCH] Add --unused parameter to whichgit The --unused parameter inverts the output of whichgit, reporting which git projects are not used for a given build target. Test: build/make/tools/whichgit --unused Test: build/make/tools/whichgit --unused --modules framework Existing use-cases should remain unchanged: Test: build/make/tools/whichgit --modules framework Change-Id: Ia4e55a5cb0331d522fed76821fe813ef98c25a67 --- tools/whichgit | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tools/whichgit b/tools/whichgit index b0bf2e42f8..8cf84f5629 100755 --- a/tools/whichgit +++ b/tools/whichgit @@ -50,7 +50,7 @@ def get_referenced_projects(git_dirs, files): referenced_dirs.add(d) prev_dir = d break - return [d[0:-1] for d in referenced_dirs] + return referenced_dirs def main(argv): @@ -63,9 +63,11 @@ def main(argv): help="The TARGET_BUILD_VARIANTS to check. If not provided just uses whatever has" + " already been built, or eng if --products is supplied") ap.add_argument("--modules", nargs="*", - help="The build modules to check, or droid it not supplied") + help="The build modules to check, or droid if not supplied") ap.add_argument("--why", nargs="*", help="Also print the input files used in these projects, or \"*\" for all") + ap.add_argument("--unused", help="List the unused git projects for the given modules rather than" + + "the used ones. Ignores --why", action="store_true") args = ap.parse_args(argv[1:]) modules = args.modules if args.modules else ["droid"] @@ -92,15 +94,21 @@ def main(argv): sources = sorted(sources) - # Print the list of git directories that has one or more of the sources in it - for project in sorted(get_referenced_projects(get_git_dirs(), sources)): - print(project) - if args.why: - if "*" in args.why or project in args.why: - prefix = project + "/" - for f in sources: - if f.startswith(prefix): - print(" " + f) + if args.unused: + # Print the list of git directories that don't contain sources + used_git_dirs = set(get_git_dirs()) + for project in sorted(used_git_dirs.difference(set(get_referenced_projects(used_git_dirs, sources)))): + print(project[0:-1]) + else: + # Print the list of git directories that has one or more of the sources in it + for project in sorted(get_referenced_projects(get_git_dirs(), sources)): + print(project[0:-1]) + if args.why: + if "*" in args.why or project[0:-1] in args.why: + prefix = project + for f in sources: + if f.startswith(prefix): + print(" " + f) if __name__ == "__main__":