[scripts] Remove hard-coded clang version
Bug: http://b/187231324
Instead,
- For local development, invoke build/soong/scripts/get_clang_version.py
to find the current clang version.
- In CI, find llvm-cxxfilt using glob expansion.
Test: development/scripts/symbol.py unittest for local development
python-stack_core_test on presubmit
Change-Id: Id4258dd791626508520b6a478b8a1b54495ebb11
diff --git a/scripts/symbol.py b/scripts/symbol.py
index d74d506..5ec4e48 100755
--- a/scripts/symbol.py
+++ b/scripts/symbol.py
@@ -31,6 +31,18 @@
ANDROID_BUILD_TOP = os.environ.get("ANDROID_BUILD_TOP", ".")
+
+def FindClangDir():
+ get_clang_version = ANDROID_BUILD_TOP + "/build/soong/scripts/get_clang_version.py"
+ if os.path.exists(get_clang_version):
+ # We want the script to fail if get_clang_version.py exists but is unable
+ # to find the clang version.
+ version_output = subprocess.check_output(get_clang_version, text=True)
+ return ANDROID_BUILD_TOP + "/prebuilts/clang/host/linux-x86/" + version_output.strip()
+ else:
+ return None
+
+
def FindSymbolsDir():
saveddir = os.getcwd()
os.chdir(ANDROID_BUILD_TOP)
@@ -437,9 +449,19 @@
global _CACHED_CXX_FILT
if not _CACHED_CXX_FILT:
toolchains = None
- # TODO(b/187231324) do not hard-code prebuilt version number below
- if os.path.exists('./clang-r416183b1/bin/llvm-cxxfilt'):
- toolchains = ["./clang-r416183b1/bin/llvm-cxxfilt"]
+ clang_dir = FindClangDir()
+ if clang_dir:
+ if os.path.exists(clang_dir + "/bin/llvm-cxxfilt"):
+ toolchains = [clang_dir + "/bin/llvm-cxxfilt"]
+ else:
+ raise Exception("bin/llvm-cxxfilt missing from " + clang_dir)
+ else:
+ # When run in CI, we don't have a way to find the clang version. But
+ # llvm-cxxfilt should be available in the following relative path.
+ toolchains = glob.glob("./clang-r*/bin/llvm-cxxfilt")
+ if toolchains and len(toolchains) != 1:
+ raise Exception("Expected one llvm-cxxfilt but found many: " + \
+ ", ".join(toolchains))
if not toolchains:
raise Exception("Could not find llvm-cxxfilt tool")
_CACHED_CXX_FILT = sorted(toolchains)[-1]
@@ -550,6 +572,11 @@
self.assert_toolchain_found("x86")
self.assert_toolchain_found("x86_64")
+class FindClangDirTests(unittest.TestCase):
+ @unittest.skipIf(ANDROID_BUILD_TOP == '.', 'Test only supported in an Android tree.')
+ def test_clang_dir_found(self):
+ self.assertIsNotNone(FindClangDir())
+
class SetArchTests(unittest.TestCase):
def test_abi_check(self):
global ARCH