stack: add support for a .zip of symbols.

This is the one remaining feature in vendor/google/tools/stack that
isn't in the "One True" stack script.

Bug: http://b/199390145
Test: manual
Change-Id: I9dd832f6fb5767c3ad3263c1ffc7dfdb0103e535
diff --git a/scripts/stack b/scripts/stack
index aaa32f4..718f49c 100755
--- a/scripts/stack
+++ b/scripts/stack
@@ -17,7 +17,11 @@
 """stack symbolizes native crash dumps."""
 
 import argparse
+import atexit
+import glob
 import sys
+import tempfile
+import zipfile
 
 import stack_core
 import symbol
@@ -25,7 +29,9 @@
 def main():
   parser = argparse.ArgumentParser(description='Parse and symbolize crashes')
   parser.add_argument('--arch', help='the target architecture')
-  parser.add_argument('--syms', '--symdir', help='the symbols directory')
+  group = parser.add_mutually_exclusive_group()
+  group.add_argument('--symbols-dir', '--syms', '--symdir', help='the symbols directory')
+  group.add_argument('--symbols-zip', help='the symbols.zip file from a build')
   parser.add_argument('file',
                       metavar='FILE',
                       default='-',
@@ -36,11 +42,16 @@
                            'or if file is -, it reads from stdin.')
 
   args = parser.parse_args()
-
   if args.arch:
     symbol.ARCH = args.arch
-  if args.syms:
-    symbol.SYMBOLS_DIR = args.syms
+  if args.symbols_dir:
+    symbol.SYMBOLS_DIR = args.symbols_dir
+  if args.symbols_zip:
+    tmp = tempfile.TemporaryDirectory()
+    atexit.register(tmp.cleanup)
+    with zipfile.ZipFile(args.symbols_zip) as zf:
+      zf.extractall(tmp.name)
+    symbol.SYMBOLS_DIR = glob.glob("%s/out/target/product/*/symbols" % tmp.name)[0]
   if args.file == '-':
     print("Reading native crash info from stdin")
     f = sys.stdin