diff --git a/scripts/symbol.py b/scripts/symbol.py index d74d5065a..5ec4e483e 100755 --- a/scripts/symbol.py +++ b/scripts/symbol.py @@ -31,6 +31,18 @@ import unittest 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 @@ def CallCppFilt(mangled_symbol): 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 @@ class FindToolchainTests(unittest.TestCase): 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