[Lldb-commits] [lldb] [lldb][test] Improve toolchain detection in Makefile.rules (PR #102185)

Vladislav Dzhidzhoev via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 2 06:07:01 PDT 2024


================
@@ -96,16 +98,119 @@ def getArchSpec(self, architecture):
         """
         return ["ARCH=" + architecture] if architecture else []
 
-    def getCCSpec(self, compiler):
+    def getToolchainSpec(self, compiler):
         """
-        Helper function to return the key-value string to specify the compiler
+        Helper function to return the key-value strings to specify the toolchain
         used for the make system.
         """
         cc = compiler if compiler else None
         if not cc and configuration.compiler:
             cc = configuration.compiler
+
         if cc:
-            return ['CC="%s"' % cc]
+            exe_ext = ""
+            if lldbplatformutil.getHostPlatform() == "windows":
+                exe_ext = ".exe"
+
+            cc = cc.strip()
+            cc_path = pathlib.Path(cc)
+
+            # We can get CC compiler string in the following formats:
+            #  [<tool>] <compiler>    - such as 'xrun clang', 'xrun /usr/bin/clang' & etc
+            #
+            # Where <compiler> could contain the following parts:
+            #   <simple-name>[.<exe-ext>]                           - sucn as 'clang', 'clang.exe' ('clang-cl.exe'?)
+            #   <target-triple>-<simple-name>[.<exe-ext>]           - such as 'armv7-linux-gnueabi-gcc'
+            #   <path>/<simple-name>[.<exe-ext>]                    - such as '/usr/bin/clang', 'c:\path\to\compiler\clang,exe'
+            #   <path>/<target-triple>-<simple-name>[.<exe-ext>]    - such as '/usr/bin/clang', 'c:\path\to\compiler\clang,exe'
+
+            cc_ext = cc_path.suffix
+            # Compiler name without extension
+            cc_name = cc_path.stem.split(" ")[-1]
+
+            # A kind of compiler (canonical name): clang, gcc, cc & etc.
+            cc_type = cc_name
+            # A triple prefix of compiler name: <armv7-none-linux-gnu->gcc
+            cc_prefix = ""
+            if not "clang-cl" in cc_name and not "llvm-gcc" in cc_name:
+                cc_name_parts = cc_name.split("-")
+                cc_type = cc_name_parts[-1]
+                if len(cc_name_parts) > 1:
+                    cc_prefix = "-".join(cc_name_parts[:-1]) + "-"
+
+            # A kind of C++ compiler.
+            cxx_types = {
+                "icc": "icpc",
+                "llvm-gcc": "llvm-g++",
+                "gcc": "g++",
+                "cc": "c++",
+                "clang": "clang++",
+            }
+            cxx_type = cxx_types.get(cc_type, cc_type)
+
+            cc_dir = cc_path.parent
+
+            def getLlvmUtil(util_name):
+                llvm_tools_dir = os.getenv("LLVM_TOOLS_DIR", cc_dir)
+                return os.path.join(llvm_tools_dir, util_name + exe_ext)
+
+            def getToolchainUtil(util_name):
+                return cc_dir / (cc_prefix + util_name + cc_ext)
+
+            cxx = getToolchainUtil(cxx_type)
+
+            util_names = {
+                "OBJCOPY": "objcopy",
+                "STRIP": "objcopy",
----------------
dzhidzhoev wrote:

Sorry, it was just a copy-paste typo.

https://github.com/llvm/llvm-project/pull/102185


More information about the lldb-commits mailing list