From 12e2cf72dfe0a9d50419c16fd6b6aa150776deba Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 9 Feb 2024 13:50:35 -0800 Subject: [PATCH] Add soongdbg json to print the json for a module Makes it easier to figure out your jq. Test: soongdbg json SystemUI | jq -r '.source_file + ":" + (.source_line | tostring) + ": " + .name' Change-Id: I3c6eb7fcefa5a27101ea49ddf2dcf59ab24f804b --- bin/soongdbg | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/soongdbg b/bin/soongdbg index c091c972b..024f0fd4a 100755 --- a/bin/soongdbg +++ b/bin/soongdbg @@ -311,6 +311,26 @@ class IdCommand: print(m.id) +class JsonCommand: + help = "Print metadata about modules in json format" + + def args(self, parser): + module_selection_args(parser) + parser.add_argument("--list", action="store_true", + help="Print the results in a json list. If not set and multiple" + + " modules are matched, the output won't be valid json.") + + def run(self, args): + modules = load_and_filter_modules(args) + if args.list: + json.dump([m for m in modules], sys.stdout, indent=4, default=lambda o: o.__dict__) + else: + for m in modules: + json.dump(m, sys.stdout, indent=4, default=lambda o: o.__dict__) + print() + + + class QueryCommand: help = "Query details about modules" @@ -332,6 +352,7 @@ COMMANDS = { "between": BetweenCommand(), "deps": DepsCommand(), "id": IdCommand(), + "json": JsonCommand(), "query": QueryCommand(), }