Symbol: Python 3 compatibility

Fix some minor issues.

Test: symbol test
Change-Id: Iaa9f304c079abfc26212de8213fba38f4e311ec1
diff --git a/scripts/symbol.py b/scripts/symbol.py
index 5c92ae6..6dbc5c4 100755
--- a/scripts/symbol.py
+++ b/scripts/symbol.py
@@ -28,18 +28,21 @@
 import subprocess
 import unittest
 
-ANDROID_BUILD_TOP = os.environ["ANDROID_BUILD_TOP"]
+ANDROID_BUILD_TOP = str(os.environ["ANDROID_BUILD_TOP"])
 if not ANDROID_BUILD_TOP:
   ANDROID_BUILD_TOP = "."
 
 def FindSymbolsDir():
   saveddir = os.getcwd()
   os.chdir(ANDROID_BUILD_TOP)
+  stream = None
   try:
     cmd = "build/soong/soong_ui.bash --dumpvar-mode --abs TARGET_OUT_UNSTRIPPED"
     stream = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).stdout
-    return os.path.join(ANDROID_BUILD_TOP, stream.read().strip())
+    return os.path.join(ANDROID_BUILD_TOP, str(stream.read().strip()))
   finally:
+    if stream is not None:
+        stream.close()
     os.chdir(saveddir)
 
 SYMBOLS_DIR = FindSymbolsDir()
@@ -166,7 +169,7 @@
 
   _CACHED_TOOLCHAIN = toolchain
   _CACHED_TOOLCHAIN_ARCH = ARCH
-  print "Using %s toolchain from: %s" % (_CACHED_TOOLCHAIN_ARCH, _CACHED_TOOLCHAIN)
+  print("Using %s toolchain from: %s" % (_CACHED_TOOLCHAIN_ARCH, _CACHED_TOOLCHAIN))
   return _CACHED_TOOLCHAIN
 
 
@@ -717,7 +720,13 @@
   def test_no_abi(self):
     global ARCH
 
-    self.assertRaisesRegexp(Exception, "Could not determine arch from input, use --arch=XXX to specify it", SetAbi, [])
+    # Python2 vs Python3 compatibility: Python3 warns on Regexp deprecation, but Regex
+    #                                   does not provide that name.
+    if not hasattr(unittest.TestCase, 'assertRaisesRegex'):
+      unittest.TestCase.assertRaisesRegex = getattr(unittest.TestCase, 'assertRaisesRegexp')
+    self.assertRaisesRegex(Exception,
+                           "Could not determine arch from input, use --arch=XXX to specify it",
+                           SetAbi, [])
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main(verbosity=2)