[Lldb-commits] [lldb] [lldb][test] Toolchain detection rewrite in Python (PR #102185)

Vladislav Dzhidzhoev via lldb-commits lldb-commits at lists.llvm.org
Wed Sep 11 05:29:21 PDT 2024


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

>From b3fb433811a0f072823f03de7814cbc574c18dec Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Sat, 27 Jul 2024 02:39:32 +0200
Subject: [PATCH 01/15] [lldb][test] Improve toolchain detection in
 Makefile.rules

This fix is based on a problem with cxx_compiler and cxx_linker macros
on Windows.
There was an issue with compiler detection in paths containing "icc". In
such case, Makefile.rules thought it was provided with icc compiler.

To solve that, utilities detection has been rewritten in Python.
The last element of compiler's path is separated, taking into account
platform path delimiter, and compiler type is extracted, with regard
of possible cross-toolchain prefix.  Paths for additional tools,
like OBJCOPY, are initialized with tools built with LLVM if USE_LLVM_TOOLS
is on, to achieve better portability for Windows.
Quotes from paths are removed in Makefile.rules, that may be added when
arguments are passed from Python to make.
---
 .../Python/lldbsuite/test/builders/builder.py | 114 +++++++++++++++++-
 .../Python/lldbsuite/test/make/Makefile.rules | 103 +++++-----------
 .../breakpoint/breakpoint_ids/Makefile        |   2 +-
 .../breakpoint/breakpoint_locations/Makefile  |   2 +-
 .../consecutive_breakpoints/Makefile          |   2 +-
 .../functionalities/breakpoint/cpp/Makefile   |   2 +-
 .../dummy_target_breakpoints/Makefile         |   2 +-
 .../require_hw_breakpoints/Makefile           |   2 +-
 .../breakpoint/step_over_breakpoint/Makefile  |   2 +-
 .../thread_plan_user_breakpoint/Makefile      |   2 +-
 .../ObjCDataFormatterTestCase.py              |   4 +-
 .../TestNSDictionarySynthetic.py              |   4 +-
 .../nssetsynth/TestNSSetSynthetic.py          |   4 +-
 .../poarray/TestPrintObjectArray.py           |   4 +-
 .../functionalities/inline-stepping/Makefile  |   2 +-
 .../postmortem/minidump-new/makefile.txt      |   1 +
 .../lang/objc/orderedset/TestOrderedSet.py    |   4 +-
 .../TestObjCSingleEntryDictionary.py          |   4 +-
 lldb/test/API/macosx/macCatalyst/Makefile     |   1 +
 .../macCatalystAppMacOSFramework/Makefile     |   1 +
 .../macosx/simulator/TestSimulatorPlatform.py |   4 +-
 .../API/python_api/frame/inlines/Makefile     |   2 +-
 .../lldb-server/TestAppleSimulatorOSType.py   |   4 +-
 23 files changed, 168 insertions(+), 104 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 4ea9a86c1d5fc9..ca91684ca065d6 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -1,10 +1,12 @@
 import os
+import pathlib
 import platform
 import subprocess
 import sys
 import itertools
 
 import lldbsuite.test.lldbtest as lldbtest
+import lldbsuite.test.lldbplatformutil as lldbplatformutil
 import lldbsuite.test.lldbutil as lldbutil
 from lldbsuite.test import configuration
 from lldbsuite.test_event import build_exception
@@ -96,16 +98,120 @@ 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)
+            cc = cc_path.as_posix()
+
+            # 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' ('clamg-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.as_posix())
+                return llvm_tools_dir + "/" + util_name + exe_ext
+
+            def getToolchainUtil(util_name):
+                return (cc_dir / (cc_prefix + util_name + cc_ext)).as_posix()
+
+            cxx = getToolchainUtil(cxx_type)
+
+            util_names = {
+                "OBJCOPY": "objcopy",
+                "STRIP": "objcopy",
+                "ARCHIVER": "ar",
+                "DWP": "dwp",
+            }
+            utils = []
+
+            # Note: LLVM_AR is currently required by API TestBSDArchives.py tests.
+            # Assembly a full path to llvm-ar for given LLVM_TOOLS_DIR;
+            # otherwise assume we have llvm-ar at the same place where is CC specified.
+            if not os.getenv("LLVM_AR"):
+                llvm_ar = getLlvmUtil("llvm-ar")
+                utils.extend(['LLVM_AR="%s"' % llvm_ar])
+
+            if not lldbplatformutil.platformIsDarwin():
+                if os.getenv("USE_LLVM_TOOLS"):
+                    # Use the llvm project tool instead of the system defaults.
+                    # Note: do not override explicity specified tool from the cmd line.
+                    for var, name in util_names.items():
+                        utils.append('%s="%s"' % (var, getLlvmUtil("llvm-" + name)))
+                    utils.extend(['AR="%s"' % llvm_ar])
+                elif cc_type in ["clang", "cc", "gcc"]:
+                    util_paths = {}
+                    # Assembly a toolchain side tool cmd based on passed CC.
+                    for var, name in util_names.items():
+                        if not os.getenv(var):
+                            util_paths[var] = getToolchainUtil(name)
+                        else:
+                            util_paths[var] = os.getenv(var)
+                    utils.extend(['AR="%s"' % util_paths["ARCHIVER"]])
+
+                    # Look for llvm-dwp or gnu dwp
+                    if not lldbutil.which(util_paths["DWP"]):
+                        util_paths["DWP"] = getToolchainUtil("llvm-dwp")
+                    if not lldbutil.which(util_paths["DWP"]):
+                        util_paths["DWP"] = lldbutil.which("llvm-dwp")
+                    if not util_paths["DWP"]:
+                        util_paths["DWP"] = lldbutil.which("dwp")
+                        if not util_paths["DWP"]:
+                            del util_paths["DWP"]
+
+                    for var, path in util_paths.items():
+                        utils.append('%s="%s"' % (var, path))
+            else:
+                utils.extend(['AR="%slibtool"' % os.getenv("CROSS_COMPILE", "")])
+
+            return [
+                'CC="%s"' % cc,
+                'CCC="%s"' % cc_type,
+                'CXX="%s"' % cxx,
+            ] + utils
         return []
 
     def getSDKRootSpec(self):
@@ -178,7 +284,7 @@ def getBuildCommand(
             make_targets,
             self.getArchCFlags(architecture),
             self.getArchSpec(architecture),
-            self.getCCSpec(compiler),
+            self.getToolchainSpec(compiler),
             self.getExtraMakeArgs(),
             self.getSDKRootSpec(),
             self.getModuleCacheSpec(),
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index 1ba3f843e87cf3..a1bb3f4c17e59b 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -102,15 +102,33 @@ endif
 # If you change the defaults of CC, be sure to also change it in the file
 # test/builders/builder_base.py, which provides a Python way to return the
 # value of the make variable CC -- getCompiler().
-#
-# See also these functions:
-#   o cxx_compiler
-#   o cxx_linker
 #----------------------------------------------------------------------
 ifeq "$(CC)" ""
 $(error "C compiler is not specified. Please run tests through lldb-dotest or lit")
 endif
 
+# Remove all " and ' characters from the path. Also remove surrounding space chars.
+cstrip = $(strip $(subst ",,$(subst ',,$(1))))
+override CC := $(call cstrip,$(CC))
+override CCC := $(call cstrip,$(CCC))
+override CXX := $(call cstrip,$(CXX))
+# Always override the linker. Assign already normalized CC.
+override LD := $(call cstrip,$(CC))
+# A kind of linker. It always gets retrieved from CC.
+override LDC := $(call cstrip,$(CCC))
+override OBJCOPY := $(call cstrip,$(OBJCOPY))
+override STRIP := $(call cstrip,$(STRIP))
+override ARCHIVER := $(call cstrip,$(ARCHIVER))
+override AR := $(call cstrip,$(AR))
+override DWP := $(call cstrip,$(DWP))
+override LLVM_AR := $(call cstrip,$(LLVM_AR))
+
+ifeq "$(HOST_OS)" "Windows_NT"
+       # This function enframes the full path with the platform specific quotes. This is necessary to run the c++ executable
+       # properly under 'sh' on Windows host (prevent the path breakage because of Windows style path separators).
+       override CXX := $(QUOTE)$(CXX)$(QUOTE)
+endif
+
 #----------------------------------------------------------------------
 # Handle SDKROOT for the cross platform builds.
 #----------------------------------------------------------------------
@@ -147,10 +165,8 @@ ifeq "$(OS)" "Darwin"
 	DS := $(DSYMUTIL)
 	DSFLAGS := $(DSFLAGS_EXTRAS)
 	DSYM = $(EXE).dSYM
-	AR := $(CROSS_COMPILE)libtool
 	ARFLAGS := -static -o
 else
-	AR := $(CROSS_COMPILE)ar
 	# On non-Apple platforms, -arch becomes -m
 	ARCHFLAG := -m
 
@@ -213,7 +229,7 @@ endif
 LIMIT_DEBUG_INFO_FLAGS =
 NO_LIMIT_DEBUG_INFO_FLAGS =
 MODULE_DEBUG_INFO_FLAGS =
-ifneq (,$(findstring clang,$(CC)))
+ifeq ($(CCC), clang)
    LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
    NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info
    MODULE_DEBUG_INFO_FLAGS += -gmodules
@@ -279,7 +295,6 @@ endif
 
 CFLAGS += $(CFLAGS_EXTRAS)
 CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
-LD = $(CC)
 # Copy common options to the linker flags (dwarf, arch. & etc).
 # Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc).
 LDFLAGS += $(CFLAGS)
@@ -312,61 +327,6 @@ ifneq "$(DYLIB_NAME)" ""
 	endif
 endif
 
-# Function that returns the counterpart C++ compiler, given $(CC) as arg.
-cxx_compiler_notdir = $(if $(findstring icc,$(1)), \
-			$(subst icc,icpc,$(1)), \
-			$(if $(findstring llvm-gcc,$(1)), \
-				$(subst llvm-gcc,llvm-g++,$(1)), \
-				$(if $(findstring gcc,$(1)), \
-					$(subst gcc,g++,$(1)), \
-					$(subst cc,c++,$(1)))))
-cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
-
-# Function that returns the C++ linker, given $(CC) as arg.
-cxx_linker_notdir = $(if $(findstring icc,$(1)), \
-			$(subst icc,icpc,$(1)), \
-			$(if $(findstring llvm-gcc,$(1)), \
-				$(subst llvm-gcc,llvm-g++,$(1)), \
-				$(if $(findstring gcc,$(1)), \
-					$(subst gcc,g++,$(1)), \
-					$(subst cc,c++,$(1)))))
-cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
-
-ifneq "$(OS)" "Darwin"
-	CLANG_OR_GCC := $(strip $(if $(findstring clang,$(CC)), \
-				$(findstring clang,$(CC)), \
-				$(if $(findstring gcc,$(CC)), \
-					$(findstring gcc,$(CC)), \
-					cc)))
-
-	CC_LASTWORD := $(strip $(lastword $(subst -, ,$(CC))))
-
-	replace_with = $(strip $(if $(findstring $(3),$(CC_LASTWORD)), \
-			$(subst $(3),$(1),$(2)), \
-			$(subst $(3),$(1),$(subst -$(CC_LASTWORD),,$(2)))))
-
-	ifeq "$(notdir $(CC))" "$(CC)"
-		replace_cc_with = $(call replace_with,$(1),$(CC),$(CLANG_OR_GCC))
-	else
-		replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(1),$(notdir $(CC)),$(CLANG_OR_GCC)))
-	endif
-
-	OBJCOPY ?= $(call replace_cc_with,objcopy)
-	ARCHIVER ?= $(call replace_cc_with,ar)
-	# Look for llvm-dwp or gnu dwp
-	DWP ?= $(call replace_cc_with,llvm-dwp)
-	ifeq ($(wildcard $(DWP)),)
-		DWP = $(call replace_cc_with,dwp)
-		ifeq ($(wildcard $(DWP)),)
-			DWP = $(shell command -v llvm-dwp 2> /dev/null)
-			ifeq ($(wildcard $(DWP)),)
-				DWP = $(shell command -v dwp 2> /dev/null)
-			endif
-		endif
-	endif
-	override AR = $(ARCHIVER)
-endif
-
 ifdef PIE
 	LDFLAGS += -pie
 endif
@@ -375,7 +335,7 @@ endif
 # Windows specific options
 #----------------------------------------------------------------------
 ifeq "$(OS)" "Windows_NT"
-	ifneq (,$(findstring clang,$(CC)))
+	ifeq ($(CCC), clang)
 		# Clang for Windows doesn't support C++ Exceptions
 		CXXFLAGS += -fno-exceptions
 		CXXFLAGS += -D_HAS_EXCEPTIONS=0
@@ -420,7 +380,7 @@ endif
 
 ifeq (1,$(USE_LIBSTDCPP))
 	# Clang requires an extra flag: -stdlib=libstdc++
-	ifneq (,$(findstring clang,$(CC)))
+	ifeq ($(CCC), clang)
 		# Force clang looking for the gcc's headers at specific rootfs folder.
 		CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
 		LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
@@ -458,7 +418,7 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
         CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
         LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
     else
-        ifneq (,$(findstring clang,$(CC)))
+        ifeq ($(CCC), clang)
             # Force clang looking for the gcc's headers at specific rootfs folder.
             CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS)
             LDFLAGS += $(GCC_TOOLCHAIN_FLAGS)
@@ -485,8 +445,6 @@ DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
 DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
 ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
 	DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o)))
-	CXX = $(call cxx_compiler,$(CC))
-	LD = $(call cxx_linker,$(CC))
 endif
 
 #----------------------------------------------------------------------
@@ -509,8 +467,6 @@ endif
 #----------------------------------------------------------------------
 ifneq "$(strip $(CXX_SOURCES))" ""
 	OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
-	CXX = $(call cxx_compiler,$(CC))
-	LD = $(call cxx_linker,$(CC))
 endif
 
 #----------------------------------------------------------------------
@@ -526,19 +482,18 @@ endif
 #----------------------------------------------------------------------
 ifneq "$(strip $(OBJCXX_SOURCES))" ""
 	OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
-	CXX = $(call cxx_compiler,$(CC))
-	LD = $(call cxx_linker,$(CC))
 	ifeq "$(findstring lobjc,$(LDFLAGS))" ""
 		LDFLAGS +=-lobjc
 	endif
 endif
 
-ifeq ($(findstring clang, $(CXX)), clang)
+ifeq ($(CCC), clang)
 	CXXFLAGS += --driver-mode=g++
 endif
 
 ifneq "$(CXX)" ""
-	ifeq ($(findstring clang, $(LD)), clang)
+	# Specify the driver mode parameter if we use clang as the linker.
+	ifeq ($(LDC), clang)
 		LDFLAGS += --driver-mode=g++
 	endif
 endif
diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile b/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
index 2c00681fa22804..b1c02b64971dc1 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
index 9645fd9cc8dfbc..4e16ab79ad53a1 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
index 2c00681fa22804..b1c02b64971dc1 100644
--- a/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/cpp/Makefile b/lldb/test/API/functionalities/breakpoint/cpp/Makefile
index 66108b79e7fe0b..77435bfadab82f 100644
--- a/lldb/test/API/functionalities/breakpoint/cpp/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/cpp/Makefile
@@ -1,7 +1,7 @@
 CXX_SOURCES := main.cpp
 CXXFLAGS_EXTRAS := -std=c++14
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
index 9645fd9cc8dfbc..4e16ab79ad53a1 100644
--- a/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
index 9645fd9cc8dfbc..4e16ab79ad53a1 100644
--- a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
index 2c00681fa22804..b1c02b64971dc1 100644
--- a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
index 2c00681fa22804..b1c02b64971dc1 100644
--- a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py
index a0d6802b3a506a..c1cd9556c5ef3f 100644
--- a/lldb/test/API/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py
+++ b/lldb/test/API/functionalities/data-formatter/data-formatter-objc/ObjCDataFormatterTestCase.py
@@ -16,12 +16,12 @@ def appkit_tester_impl(self, commands, use_constant_classes):
             self.build()
         else:
             disable_constant_classes = {
-                "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
                 "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
                 + "-fno-constant-nsarray-literals "
                 + "-fno-constant-nsdictionary-literals",
             }
-            self.build(dictionary=disable_constant_classes)
+            # FIXME: Remove compiler when flags are available upstream.
+            self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.appkit_common_data_formatters_command()
         commands()
 
diff --git a/lldb/test/API/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py b/lldb/test/API/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py
index 9ac41d67eb9ab3..e1d7e42bdd1a99 100644
--- a/lldb/test/API/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py
+++ b/lldb/test/API/functionalities/data-formatter/nsdictionarysynth/TestNSDictionarySynthetic.py
@@ -26,12 +26,12 @@ def test_rdar11988289_with_run_command(self):
     def test_rdar11988289_with_run_command_no_const(self):
         """Test that NSDictionary reports its synthetic children properly."""
         disable_constant_classes = {
-            "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
             "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
             + "-fno-constant-nsarray-literals "
             + "-fno-constant-nsdictionary-literals",
         }
-        self.build(dictionary=disable_constant_classes)
+        # FIXME: Remove when flags are available upstream.
+        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.run_tests()
 
     def run_tests(self):
diff --git a/lldb/test/API/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py b/lldb/test/API/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py
index 053ec0ee9757e0..1037e75c17eb34 100644
--- a/lldb/test/API/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py
+++ b/lldb/test/API/functionalities/data-formatter/nssetsynth/TestNSSetSynthetic.py
@@ -26,12 +26,12 @@ def test_rdar12529957_with_run_command(self):
     def test_rdar12529957_with_run_command_no_const(self):
         """Test that NSSet reports its synthetic children properly."""
         disable_constant_classes = {
-            "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
             "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
             + "-fno-constant-nsarray-literals "
             + "-fno-constant-nsdictionary-literals",
         }
-        self.build(dictionary=disable_constant_classes)
+        # FIXME: Remove compiler when flags are available upstream.
+        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.run_tests()
 
     def run_tests(self):
diff --git a/lldb/test/API/functionalities/data-formatter/poarray/TestPrintObjectArray.py b/lldb/test/API/functionalities/data-formatter/poarray/TestPrintObjectArray.py
index fff37829cd20dc..db86f48f8ec1fe 100644
--- a/lldb/test/API/functionalities/data-formatter/poarray/TestPrintObjectArray.py
+++ b/lldb/test/API/functionalities/data-formatter/poarray/TestPrintObjectArray.py
@@ -20,13 +20,13 @@ def test_print_array(self):
     def test_print_array_no_const(self):
         """Test that expr -O -Z works"""
         disable_constant_classes = {
-            "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
             "USE_SYSTEM_STDLIB": "1",  # See above.
             "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
             + "-fno-constant-nsarray-literals "
             + "-fno-constant-nsdictionary-literals",
         }
-        self.build(dictionary=disable_constant_classes)
+        # FIXME: Remove compiler when flags are available upstream.
+        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.printarray_data_formatter_commands()
 
     def setUp(self):
diff --git a/lldb/test/API/functionalities/inline-stepping/Makefile b/lldb/test/API/functionalities/inline-stepping/Makefile
index 362b89d7f995b3..61f65c489ffec1 100644
--- a/lldb/test/API/functionalities/inline-stepping/Makefile
+++ b/lldb/test/API/functionalities/inline-stepping/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := calling.cpp
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt b/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
index 7096efabdcfe1e..980a17d07c3089 100644
--- a/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
+++ b/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
@@ -19,6 +19,7 @@
 # to generate a Minidump when the binary crashes/requests such.
 #
 CC=g++
+CCC=gcc
 FLAGS=-g --std=c++11
 INCLUDE=-I$HOME/breakpad/src/src/
 LINK=-L. -lbreakpad -lpthread -nostdlib -lc -lstdc++ -lgcc_s -fno-exceptions
diff --git a/lldb/test/API/lang/objc/orderedset/TestOrderedSet.py b/lldb/test/API/lang/objc/orderedset/TestOrderedSet.py
index 14bfc322979b37..a7d6d9d155efca 100644
--- a/lldb/test/API/lang/objc/orderedset/TestOrderedSet.py
+++ b/lldb/test/API/lang/objc/orderedset/TestOrderedSet.py
@@ -12,12 +12,12 @@ def test_ordered_set(self):
     @skipUnlessDarwin
     def test_ordered_set_no_const(self):
         disable_constant_classes = {
-            "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
             "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
             + "-fno-constant-nsarray-literals "
             + "-fno-constant-nsdictionary-literals",
         }
-        self.build(dictionary=disable_constant_classes)
+        # FIXME: Remove when flags are available upstream.
+        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.run_tests()
 
     def run_tests(self):
diff --git a/lldb/test/API/lang/objc/single-entry-dictionary/TestObjCSingleEntryDictionary.py b/lldb/test/API/lang/objc/single-entry-dictionary/TestObjCSingleEntryDictionary.py
index 68c0af76b8e3b8..8debe731dfe1af 100644
--- a/lldb/test/API/lang/objc/single-entry-dictionary/TestObjCSingleEntryDictionary.py
+++ b/lldb/test/API/lang/objc/single-entry-dictionary/TestObjCSingleEntryDictionary.py
@@ -28,12 +28,12 @@ def test_single_entry_dict(self):
     )  # bug in NSDictionary formatting on watchos
     def test_single_entry_dict_no_const(self):
         disable_constant_classes = {
-            "CC": "xcrun clang",  # FIXME: Remove when flags are available upstream.
             "CFLAGS_EXTRAS": "-fno-constant-nsnumber-literals "
             + "-fno-constant-nsarray-literals "
             + "-fno-constant-nsdictionary-literals",
         }
-        self.build(dictionary=disable_constant_classes)
+        # FIXME: Remove compiler when flags are available upstream.
+        self.build(dictionary=disable_constant_classes, compiler="xcrun clang")
         self.run_tests()
 
     def run_tests(self):
diff --git a/lldb/test/API/macosx/macCatalyst/Makefile b/lldb/test/API/macosx/macCatalyst/Makefile
index 3f084968a2d57b..dd64a7b0682a8c 100644
--- a/lldb/test/API/macosx/macCatalyst/Makefile
+++ b/lldb/test/API/macosx/macCatalyst/Makefile
@@ -7,6 +7,7 @@ USE_SYSTEM_STDLIB := 1
 
 # FIXME: rdar://problem/54986190
 # There is a Clang driver change missing on llvm.org.
+override CCC=clang
 override CC=xcrun clang
 
 include Makefile.rules
diff --git a/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile b/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
index b24fe3f574ccfc..8fb3c66232a1e0 100644
--- a/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
+++ b/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
@@ -5,6 +5,7 @@ override TRIPLE := $(ARCH)-apple-ios13.0-macabi
 CFLAGS_EXTRAS := -target $(TRIPLE)
 
 # FIXME: rdar://problem/54986190
+override CCC=clang
 override CC=xcrun clang
 
 all: libfoo.dylib a.out
diff --git a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
index b712afdd7560a7..3f5645a486bcb4 100644
--- a/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
+++ b/lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
@@ -59,10 +59,10 @@ def run_with(self, arch, os, vers, env, expected_load_command):
         self.build(
             dictionary={
                 "ARCH": arch,
-                "CC": clang,
                 "ARCH_CFLAGS": "-target {} {}".format(triple, version_min),
                 "SDKROOT": sdk_root,
-            }
+            },
+            compiler=clang,
         )
 
         self.check_load_commands(expected_load_command)
diff --git a/lldb/test/API/python_api/frame/inlines/Makefile b/lldb/test/API/python_api/frame/inlines/Makefile
index e6d9d8310a0fa8..da37368a041a34 100644
--- a/lldb/test/API/python_api/frame/inlines/Makefile
+++ b/lldb/test/API/python_api/frame/inlines/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := inlines.c
 
-ifneq (,$(findstring icc,$(CC)))
+ifeq ($(CCC), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
index 16297efe14372a..ed47f94e9492be 100644
--- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -71,12 +71,12 @@ def check_simulator_ostype(self, sdk, platform_name, arch=platform.machine()):
         self.build(
             dictionary={
                 "EXE": exe_name,
-                "CC": clang,
                 "SDKROOT": sdkroot.strip(),
                 "ARCH": arch,
                 "ARCH_CFLAGS": "-target {} {}".format(triple, version_min),
                 "USE_SYSTEM_STDLIB": 1,
-            }
+            },
+            compiler=clang,
         )
         exe_path = os.path.realpath(self.getBuildArtifact(exe_name))
         cmd = [

>From ef9aef9e3770de488acf29e398299751f8d26ed2 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Fri, 16 Aug 2024 23:07:50 +0200
Subject: [PATCH 02/15] Fix comment

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index ca91684ca065d6..14fcee2f28cc18 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -178,7 +178,6 @@ def getToolchainUtil(util_name):
             if not lldbplatformutil.platformIsDarwin():
                 if os.getenv("USE_LLVM_TOOLS"):
                     # Use the llvm project tool instead of the system defaults.
-                    # Note: do not override explicity specified tool from the cmd line.
                     for var, name in util_names.items():
                         utils.append('%s="%s"' % (var, getLlvmUtil("llvm-" + name)))
                     utils.extend(['AR="%s"' % llvm_ar])
@@ -186,6 +185,7 @@ def getToolchainUtil(util_name):
                     util_paths = {}
                     # Assembly a toolchain side tool cmd based on passed CC.
                     for var, name in util_names.items():
+                        # Do not override explicity specified tool from the cmd line.
                         if not os.getenv(var):
                             util_paths[var] = getToolchainUtil(name)
                         else:

>From 7a8a1c7a30b3e5415b939fb3c81e2c1d851d4573 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <dzhidzhoev at gmail.com>
Date: Mon, 26 Aug 2024 19:07:12 +0200
Subject: [PATCH 03/15] Typo fix

Co-authored-by: Pavel Labath <pavel at labath.sk>
---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 14fcee2f28cc18..5d191993afd138 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -120,7 +120,7 @@ def getToolchainSpec(self, compiler):
             #  [<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' ('clamg-cl.exe'?)
+            #   <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'

>From 52b420b458aee5b21746a2de1cd7c3dffbe1b7fb Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 26 Aug 2024 20:22:16 +0200
Subject: [PATCH 04/15] Don't quote paths

---
 .../Python/lldbsuite/test/builders/builder.py  | 18 +++++++++---------
 .../Python/lldbsuite/test/make/Makefile.rules  | 15 ++-------------
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 5d191993afd138..1d90d07de2a7d3 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -173,14 +173,14 @@ def getToolchainUtil(util_name):
             # otherwise assume we have llvm-ar at the same place where is CC specified.
             if not os.getenv("LLVM_AR"):
                 llvm_ar = getLlvmUtil("llvm-ar")
-                utils.extend(['LLVM_AR="%s"' % llvm_ar])
+                utils.extend(['LLVM_AR=%s' % llvm_ar])
 
             if not lldbplatformutil.platformIsDarwin():
                 if os.getenv("USE_LLVM_TOOLS"):
                     # Use the llvm project tool instead of the system defaults.
                     for var, name in util_names.items():
-                        utils.append('%s="%s"' % (var, getLlvmUtil("llvm-" + name)))
-                    utils.extend(['AR="%s"' % llvm_ar])
+                        utils.append('%s=%s' % (var, getLlvmUtil("llvm-" + name)))
+                    utils.extend(['AR=%s' % llvm_ar])
                 elif cc_type in ["clang", "cc", "gcc"]:
                     util_paths = {}
                     # Assembly a toolchain side tool cmd based on passed CC.
@@ -190,7 +190,7 @@ def getToolchainUtil(util_name):
                             util_paths[var] = getToolchainUtil(name)
                         else:
                             util_paths[var] = os.getenv(var)
-                    utils.extend(['AR="%s"' % util_paths["ARCHIVER"]])
+                    utils.extend(['AR=%s' % util_paths["ARCHIVER"]])
 
                     # Look for llvm-dwp or gnu dwp
                     if not lldbutil.which(util_paths["DWP"]):
@@ -203,14 +203,14 @@ def getToolchainUtil(util_name):
                             del util_paths["DWP"]
 
                     for var, path in util_paths.items():
-                        utils.append('%s="%s"' % (var, path))
+                        utils.append('%s=%s' % (var, path))
             else:
-                utils.extend(['AR="%slibtool"' % os.getenv("CROSS_COMPILE", "")])
+                utils.extend(['AR=%slibtool' % os.getenv("CROSS_COMPILE", "")])
 
             return [
-                'CC="%s"' % cc,
-                'CCC="%s"' % cc_type,
-                'CXX="%s"' % cxx,
+                'CC=%s' % cc,
+                'CCC=%s' % cc_type,
+                'CXX=%s' % cxx,
             ] + utils
         return []
 
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index a1bb3f4c17e59b..2fb115eaefc447 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -107,21 +107,10 @@ ifeq "$(CC)" ""
 $(error "C compiler is not specified. Please run tests through lldb-dotest or lit")
 endif
 
-# Remove all " and ' characters from the path. Also remove surrounding space chars.
-cstrip = $(strip $(subst ",,$(subst ',,$(1))))
-override CC := $(call cstrip,$(CC))
-override CCC := $(call cstrip,$(CCC))
-override CXX := $(call cstrip,$(CXX))
 # Always override the linker. Assign already normalized CC.
-override LD := $(call cstrip,$(CC))
+override LD := $(CC)
 # A kind of linker. It always gets retrieved from CC.
-override LDC := $(call cstrip,$(CCC))
-override OBJCOPY := $(call cstrip,$(OBJCOPY))
-override STRIP := $(call cstrip,$(STRIP))
-override ARCHIVER := $(call cstrip,$(ARCHIVER))
-override AR := $(call cstrip,$(AR))
-override DWP := $(call cstrip,$(DWP))
-override LLVM_AR := $(call cstrip,$(LLVM_AR))
+override LDC := $(CCC)
 
 ifeq "$(HOST_OS)" "Windows_NT"
        # This function enframes the full path with the platform specific quotes. This is necessary to run the c++ executable

>From 94c71b74817a7961fcb7cda0157c6161abb5df5e Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Wed, 28 Aug 2024 15:02:22 +0200
Subject: [PATCH 05/15] Join paths with os.path.join

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 1d90d07de2a7d3..54996550c04813 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -153,7 +153,7 @@ def getToolchainSpec(self, compiler):
 
             def getLlvmUtil(util_name):
                 llvm_tools_dir = os.getenv("LLVM_TOOLS_DIR", cc_dir.as_posix())
-                return llvm_tools_dir + "/" + util_name + exe_ext
+                return os.path.join(llvm_tools_dir, util_name + exe_ext)
 
             def getToolchainUtil(util_name):
                 return (cc_dir / (cc_prefix + util_name + cc_ext)).as_posix()

>From e41da92267d56fb62f6cb342e7f3341842bfc4bd Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Wed, 28 Aug 2024 20:53:25 +0200
Subject: [PATCH 06/15] Use native paths

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 54996550c04813..2ee98ae1caf6cd 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -114,7 +114,6 @@ def getToolchainSpec(self, compiler):
 
             cc = cc.strip()
             cc_path = pathlib.Path(cc)
-            cc = cc_path.as_posix()
 
             # We can get CC compiler string in the following formats:
             #  [<tool>] <compiler>    - such as 'xrun clang', 'xrun /usr/bin/clang' & etc
@@ -152,11 +151,11 @@ def getToolchainSpec(self, compiler):
             cc_dir = cc_path.parent
 
             def getLlvmUtil(util_name):
-                llvm_tools_dir = os.getenv("LLVM_TOOLS_DIR", cc_dir.as_posix())
+                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)).as_posix()
+                return cc_dir / (cc_prefix + util_name + cc_ext)
 
             cxx = getToolchainUtil(cxx_type)
 

>From 9ea46fe4341ea0a150a51487ec162d9658e08767 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Fri, 30 Aug 2024 14:21:07 +0200
Subject: [PATCH 07/15] Use cmd arguments instead of env variables in builder

---
 .../packages/Python/lldbsuite/test/builders/builder.py |  5 ++---
 lldb/packages/Python/lldbsuite/test/configuration.py   |  5 +++++
 lldb/packages/Python/lldbsuite/test/dotest.py          |  4 ++++
 lldb/packages/Python/lldbsuite/test/dotest_args.py     | 10 +++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 2ee98ae1caf6cd..f65b64da7c0d0f 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -151,8 +151,7 @@ def getToolchainSpec(self, compiler):
             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)
+                return os.path.join(configuration.llvm_tools_dir, util_name + exe_ext)
 
             def getToolchainUtil(util_name):
                 return cc_dir / (cc_prefix + util_name + cc_ext)
@@ -175,7 +174,7 @@ def getToolchainUtil(util_name):
                 utils.extend(['LLVM_AR=%s' % llvm_ar])
 
             if not lldbplatformutil.platformIsDarwin():
-                if os.getenv("USE_LLVM_TOOLS"):
+                if configuration.use_llvm_tools:
                     # Use the llvm project tool instead of the system defaults.
                     for var, name in util_names.items():
                         utils.append('%s=%s' % (var, getLlvmUtil("llvm-" + name)))
diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py
index 27eef040497d13..75b7c04ad2b793 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -118,6 +118,11 @@
 # same base name.
 all_tests = set()
 
+# Force use llvm tools in API tests
+use_llvm_tools = False
+# Path to LLVM tools to be used by tests.
+llvm_tools_dir = None
+
 # LLDB library directory.
 lldb_libs_dir = None
 lldb_obj_root = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index f14a00a2394b0b..52e35d320c1d1b 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -279,7 +279,11 @@ def parseOptionsAndInitTestdirs():
         configuration.dsymutil = seven.get_command_output(
             "xcrun -find -toolchain default dsymutil"
         )
+
+    if args.use_llvm_tools:
+        configuration.use_llvm_tools = True
     if args.llvm_tools_dir:
+        configuration.llvm_tools_dir = args.llvm_tools_dir
         configuration.filecheck = shutil.which("FileCheck", path=args.llvm_tools_dir)
         configuration.yaml2obj = shutil.which("yaml2obj", path=args.llvm_tools_dir)
 
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec5891..aaff9adb9fb447 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -108,12 +108,20 @@ def create_parser():
         dest="dsymutil",
         help=textwrap.dedent("Specify which dsymutil to use."),
     )
+    group.add_argument(
+        "--use-llvm-tools",
+        dest="use_llvm_tools",
+        action="store_true",
+        help=textwrap.dedent(
+            "Force use LLVM tools for testing (llvm-ar, llvm-objcopy, etc.)."
+        ),
+    )
     group.add_argument(
         "--llvm-tools-dir",
         metavar="dir",
         dest="llvm_tools_dir",
         help=textwrap.dedent(
-            "The location of llvm tools used for testing (yaml2obj, FileCheck, etc.)."
+            "The location of llvm tools used for testing (llvm-ar, yaml2obj, FileCheck, etc.)."
         ),
     )
 

>From 5b2661d4856b1d76fd6ca46052ad794f81aba5b4 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Sep 2024 13:55:51 +0200
Subject: [PATCH 08/15] Rename CCC to CC_TYPE

---
 .../Python/lldbsuite/test/builders/builder.py        |  2 +-
 .../Python/lldbsuite/test/make/Makefile.rules        | 12 ++++++------
 .../breakpoint/breakpoint_ids/Makefile               |  2 +-
 .../breakpoint/breakpoint_locations/Makefile         |  2 +-
 .../breakpoint/consecutive_breakpoints/Makefile      |  2 +-
 .../test/API/functionalities/breakpoint/cpp/Makefile |  2 +-
 .../breakpoint/dummy_target_breakpoints/Makefile     |  2 +-
 .../require_hw_breakpoints/Makefile                  |  2 +-
 .../breakpoint/step_over_breakpoint/Makefile         |  2 +-
 .../breakpoint/thread_plan_user_breakpoint/Makefile  |  2 +-
 .../API/functionalities/inline-stepping/Makefile     |  2 +-
 .../postmortem/minidump-new/makefile.txt             |  2 +-
 lldb/test/API/macosx/macCatalyst/Makefile            |  2 +-
 .../API/macosx/macCatalystAppMacOSFramework/Makefile |  2 +-
 lldb/test/API/python_api/frame/inlines/Makefile      |  2 +-
 15 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index f65b64da7c0d0f..790ac826404923 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -207,7 +207,7 @@ def getToolchainUtil(util_name):
 
             return [
                 'CC=%s' % cc,
-                'CCC=%s' % cc_type,
+                'CC_TYPE=%s' % cc_type,
                 'CXX=%s' % cxx,
             ] + utils
         return []
diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
index 2fb115eaefc447..f81db9bc06d8a8 100644
--- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
+++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules
@@ -110,7 +110,7 @@ endif
 # Always override the linker. Assign already normalized CC.
 override LD := $(CC)
 # A kind of linker. It always gets retrieved from CC.
-override LDC := $(CCC)
+override LDC := $(CC_TYPE)
 
 ifeq "$(HOST_OS)" "Windows_NT"
        # This function enframes the full path with the platform specific quotes. This is necessary to run the c++ executable
@@ -218,7 +218,7 @@ endif
 LIMIT_DEBUG_INFO_FLAGS =
 NO_LIMIT_DEBUG_INFO_FLAGS =
 MODULE_DEBUG_INFO_FLAGS =
-ifeq ($(CCC), clang)
+ifeq ($(CC_TYPE), clang)
    LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
    NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info
    MODULE_DEBUG_INFO_FLAGS += -gmodules
@@ -324,7 +324,7 @@ endif
 # Windows specific options
 #----------------------------------------------------------------------
 ifeq "$(OS)" "Windows_NT"
-	ifeq ($(CCC), clang)
+	ifeq ($(CC_TYPE), clang)
 		# Clang for Windows doesn't support C++ Exceptions
 		CXXFLAGS += -fno-exceptions
 		CXXFLAGS += -D_HAS_EXCEPTIONS=0
@@ -369,7 +369,7 @@ endif
 
 ifeq (1,$(USE_LIBSTDCPP))
 	# Clang requires an extra flag: -stdlib=libstdc++
-	ifeq ($(CCC), clang)
+	ifeq ($(CC_TYPE), clang)
 		# Force clang looking for the gcc's headers at specific rootfs folder.
 		CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
 		LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
@@ -407,7 +407,7 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
         CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
         LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
     else
-        ifeq ($(CCC), clang)
+        ifeq ($(CC_TYPE),clang)
             # Force clang looking for the gcc's headers at specific rootfs folder.
             CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS)
             LDFLAGS += $(GCC_TOOLCHAIN_FLAGS)
@@ -476,7 +476,7 @@ ifneq "$(strip $(OBJCXX_SOURCES))" ""
 	endif
 endif
 
-ifeq ($(CCC), clang)
+ifeq ($(CC_TYPE), clang)
 	CXXFLAGS += --driver-mode=g++
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile b/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
index b1c02b64971dc1..778d3e58ab56fa 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_ids/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
index 4e16ab79ad53a1..304633c2dca1f2 100644
--- a/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/breakpoint_locations/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
index b1c02b64971dc1..778d3e58ab56fa 100644
--- a/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/consecutive_breakpoints/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/cpp/Makefile b/lldb/test/API/functionalities/breakpoint/cpp/Makefile
index 77435bfadab82f..3b4be01d551f46 100644
--- a/lldb/test/API/functionalities/breakpoint/cpp/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/cpp/Makefile
@@ -1,7 +1,7 @@
 CXX_SOURCES := main.cpp
 CXXFLAGS_EXTRAS := -std=c++14
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
index 4e16ab79ad53a1..304633c2dca1f2 100644
--- a/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/dummy_target_breakpoints/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
index 4e16ab79ad53a1..304633c2dca1f2 100644
--- a/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/hardware_breakpoints/require_hw_breakpoints/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := main.c
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
index b1c02b64971dc1..778d3e58ab56fa 100644
--- a/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/step_over_breakpoint/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
index b1c02b64971dc1..778d3e58ab56fa 100644
--- a/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
+++ b/lldb/test/API/functionalities/breakpoint/thread_plan_user_breakpoint/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := main.cpp
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/inline-stepping/Makefile b/lldb/test/API/functionalities/inline-stepping/Makefile
index 61f65c489ffec1..bf646c7b7db33f 100644
--- a/lldb/test/API/functionalities/inline-stepping/Makefile
+++ b/lldb/test/API/functionalities/inline-stepping/Makefile
@@ -1,6 +1,6 @@
 CXX_SOURCES := calling.cpp
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CXXFLAGS_EXTRAS := -debug inline-debug-info
 endif
 
diff --git a/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt b/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
index 980a17d07c3089..d594b585b2d5ff 100644
--- a/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
+++ b/lldb/test/API/functionalities/postmortem/minidump-new/makefile.txt
@@ -19,7 +19,7 @@
 # to generate a Minidump when the binary crashes/requests such.
 #
 CC=g++
-CCC=gcc
+CC_TYPE=gcc
 FLAGS=-g --std=c++11
 INCLUDE=-I$HOME/breakpad/src/src/
 LINK=-L. -lbreakpad -lpthread -nostdlib -lc -lstdc++ -lgcc_s -fno-exceptions
diff --git a/lldb/test/API/macosx/macCatalyst/Makefile b/lldb/test/API/macosx/macCatalyst/Makefile
index dd64a7b0682a8c..ef17d89d2372c5 100644
--- a/lldb/test/API/macosx/macCatalyst/Makefile
+++ b/lldb/test/API/macosx/macCatalyst/Makefile
@@ -7,7 +7,7 @@ USE_SYSTEM_STDLIB := 1
 
 # FIXME: rdar://problem/54986190
 # There is a Clang driver change missing on llvm.org.
-override CCC=clang
+override CC_TYPE=clang
 override CC=xcrun clang
 
 include Makefile.rules
diff --git a/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile b/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
index 8fb3c66232a1e0..c77a186724fda1 100644
--- a/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
+++ b/lldb/test/API/macosx/macCatalystAppMacOSFramework/Makefile
@@ -5,7 +5,7 @@ override TRIPLE := $(ARCH)-apple-ios13.0-macabi
 CFLAGS_EXTRAS := -target $(TRIPLE)
 
 # FIXME: rdar://problem/54986190
-override CCC=clang
+override CC_TYPE=clang
 override CC=xcrun clang
 
 all: libfoo.dylib a.out
diff --git a/lldb/test/API/python_api/frame/inlines/Makefile b/lldb/test/API/python_api/frame/inlines/Makefile
index da37368a041a34..cf17569a5e351a 100644
--- a/lldb/test/API/python_api/frame/inlines/Makefile
+++ b/lldb/test/API/python_api/frame/inlines/Makefile
@@ -1,6 +1,6 @@
 C_SOURCES := inlines.c
 
-ifeq ($(CCC), icc)
+ifeq ($(CC_TYPE), icc)
     CFLAGS_EXTRAS := -debug inline-debug-info
 endif
 

>From 09a197b62fbc962778f8ed6c6fb03ccf75e660cd Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Sep 2024 13:58:11 +0200
Subject: [PATCH 09/15] Fix typo

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 790ac826404923..b67f2be1674806 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -167,7 +167,7 @@ def getToolchainUtil(util_name):
             utils = []
 
             # Note: LLVM_AR is currently required by API TestBSDArchives.py tests.
-            # Assembly a full path to llvm-ar for given LLVM_TOOLS_DIR;
+            # Assemble a full path to llvm-ar for given LLVM_TOOLS_DIR;
             # otherwise assume we have llvm-ar at the same place where is CC specified.
             if not os.getenv("LLVM_AR"):
                 llvm_ar = getLlvmUtil("llvm-ar")

>From 7152e2eef3825031862a912894bddfcfed29ea55 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Sep 2024 13:58:36 +0200
Subject: [PATCH 10/15] Fix wrong utility for STRIP

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index b67f2be1674806..9de420cb6ab945 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -160,7 +160,7 @@ def getToolchainUtil(util_name):
 
             util_names = {
                 "OBJCOPY": "objcopy",
-                "STRIP": "objcopy",
+                "STRIP": "strip",
                 "ARCHIVER": "ar",
                 "DWP": "dwp",
             }

>From 0cd89700319367e1b4e4451994017ff1d67e918c Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Sep 2024 15:05:49 +0200
Subject: [PATCH 11/15] Reformat condition

---
 .../Python/lldbsuite/test/builders/builder.py | 203 +++++++++---------
 1 file changed, 102 insertions(+), 101 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 9de420cb6ab945..6aa4e45c086738 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -107,110 +107,111 @@ def getToolchainSpec(self, compiler):
         if not cc and configuration.compiler:
             cc = configuration.compiler
 
-        if 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):
-                return os.path.join(configuration.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": "strip",
-                "ARCHIVER": "ar",
-                "DWP": "dwp",
-            }
-            utils = []
-
-            # Note: LLVM_AR is currently required by API TestBSDArchives.py tests.
-            # Assemble a full path to llvm-ar for given LLVM_TOOLS_DIR;
-            # otherwise assume we have llvm-ar at the same place where is CC specified.
-            if not os.getenv("LLVM_AR"):
-                llvm_ar = getLlvmUtil("llvm-ar")
-                utils.extend(['LLVM_AR=%s' % llvm_ar])
-
-            if not lldbplatformutil.platformIsDarwin():
-                if configuration.use_llvm_tools:
-                    # Use the llvm project tool instead of the system defaults.
-                    for var, name in util_names.items():
-                        utils.append('%s=%s' % (var, getLlvmUtil("llvm-" + name)))
-                    utils.extend(['AR=%s' % llvm_ar])
-                elif cc_type in ["clang", "cc", "gcc"]:
-                    util_paths = {}
-                    # Assembly a toolchain side tool cmd based on passed CC.
-                    for var, name in util_names.items():
-                        # Do not override explicity specified tool from the cmd line.
-                        if not os.getenv(var):
-                            util_paths[var] = getToolchainUtil(name)
-                        else:
-                            util_paths[var] = os.getenv(var)
-                    utils.extend(['AR=%s' % util_paths["ARCHIVER"]])
-
-                    # Look for llvm-dwp or gnu dwp
-                    if not lldbutil.which(util_paths["DWP"]):
-                        util_paths["DWP"] = getToolchainUtil("llvm-dwp")
-                    if not lldbutil.which(util_paths["DWP"]):
-                        util_paths["DWP"] = lldbutil.which("llvm-dwp")
+        if not cc:
+            return []
+
+        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):
+            return os.path.join(configuration.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": "strip",
+            "ARCHIVER": "ar",
+            "DWP": "dwp",
+        }
+        utils = []
+
+        # Note: LLVM_AR is currently required by API TestBSDArchives.py tests.
+        # Assemble a full path to llvm-ar for given LLVM_TOOLS_DIR;
+        # otherwise assume we have llvm-ar at the same place where is CC specified.
+        if not os.getenv("LLVM_AR"):
+            llvm_ar = getLlvmUtil("llvm-ar")
+            utils.extend(['LLVM_AR=%s' % llvm_ar])
+
+        if not lldbplatformutil.platformIsDarwin():
+            if configuration.use_llvm_tools:
+                # Use the llvm project tool instead of the system defaults.
+                for var, name in util_names.items():
+                    utils.append('%s=%s' % (var, getLlvmUtil("llvm-" + name)))
+                utils.extend(['AR=%s' % llvm_ar])
+            elif cc_type in ["clang", "cc", "gcc"]:
+                util_paths = {}
+                # Assembly a toolchain side tool cmd based on passed CC.
+                for var, name in util_names.items():
+                    # Do not override explicity specified tool from the cmd line.
+                    if not os.getenv(var):
+                        util_paths[var] = getToolchainUtil(name)
+                    else:
+                        util_paths[var] = os.getenv(var)
+                utils.extend(['AR=%s' % util_paths["ARCHIVER"]])
+
+                # Look for llvm-dwp or gnu dwp
+                if not lldbutil.which(util_paths["DWP"]):
+                    util_paths["DWP"] = getToolchainUtil("llvm-dwp")
+                if not lldbutil.which(util_paths["DWP"]):
+                    util_paths["DWP"] = lldbutil.which("llvm-dwp")
+                if not util_paths["DWP"]:
+                    util_paths["DWP"] = lldbutil.which("dwp")
                     if not util_paths["DWP"]:
-                        util_paths["DWP"] = lldbutil.which("dwp")
-                        if not util_paths["DWP"]:
-                            del util_paths["DWP"]
+                        del util_paths["DWP"]
 
-                    for var, path in util_paths.items():
-                        utils.append('%s=%s' % (var, path))
-            else:
-                utils.extend(['AR=%slibtool' % os.getenv("CROSS_COMPILE", "")])
+                for var, path in util_paths.items():
+                    utils.append('%s=%s' % (var, path))
+        else:
+            utils.extend(['AR=%slibtool' % os.getenv("CROSS_COMPILE", "")])
 
-            return [
-                'CC=%s' % cc,
-                'CC_TYPE=%s' % cc_type,
-                'CXX=%s' % cxx,
-            ] + utils
-        return []
+        return [
+            'CC=%s' % cc,
+            'CC_TYPE=%s' % cc_type,
+            'CXX=%s' % cxx,
+        ] + utils
 
     def getSDKRootSpec(self):
         """

>From 0086b9b23b311343df5517f0c00064a17a9c9aa3 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Mon, 2 Sep 2024 15:23:45 +0200
Subject: [PATCH 12/15] Formatting fixed

---
 .../Python/lldbsuite/test/builders/builder.py  | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 6aa4e45c086738..b0605729906316 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -173,14 +173,14 @@ def getToolchainUtil(util_name):
         # otherwise assume we have llvm-ar at the same place where is CC specified.
         if not os.getenv("LLVM_AR"):
             llvm_ar = getLlvmUtil("llvm-ar")
-            utils.extend(['LLVM_AR=%s' % llvm_ar])
+            utils.extend(["LLVM_AR=%s" % llvm_ar])
 
         if not lldbplatformutil.platformIsDarwin():
             if configuration.use_llvm_tools:
                 # Use the llvm project tool instead of the system defaults.
                 for var, name in util_names.items():
-                    utils.append('%s=%s' % (var, getLlvmUtil("llvm-" + name)))
-                utils.extend(['AR=%s' % llvm_ar])
+                    utils.append("%s=%s" % (var, getLlvmUtil("llvm-" + name)))
+                utils.extend(["AR=%s" % llvm_ar])
             elif cc_type in ["clang", "cc", "gcc"]:
                 util_paths = {}
                 # Assembly a toolchain side tool cmd based on passed CC.
@@ -190,7 +190,7 @@ def getToolchainUtil(util_name):
                         util_paths[var] = getToolchainUtil(name)
                     else:
                         util_paths[var] = os.getenv(var)
-                utils.extend(['AR=%s' % util_paths["ARCHIVER"]])
+                utils.extend(["AR=%s" % util_paths["ARCHIVER"]])
 
                 # Look for llvm-dwp or gnu dwp
                 if not lldbutil.which(util_paths["DWP"]):
@@ -203,14 +203,14 @@ def getToolchainUtil(util_name):
                         del util_paths["DWP"]
 
                 for var, path in util_paths.items():
-                    utils.append('%s=%s' % (var, path))
+                    utils.append("%s=%s" % (var, path))
         else:
-            utils.extend(['AR=%slibtool' % os.getenv("CROSS_COMPILE", "")])
+            utils.extend(["AR=%slibtool" % os.getenv("CROSS_COMPILE", "")])
 
         return [
-            'CC=%s' % cc,
-            'CC_TYPE=%s' % cc_type,
-            'CXX=%s' % cxx,
+            "CC=%s" % cc,
+            "CC_TYPE=%s" % cc_type,
+            "CXX=%s" % cxx,
         ] + utils
 
     def getSDKRootSpec(self):

>From 646e41fedd627201ed3f9389ca8befc3e0c83126 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 3 Sep 2024 23:05:45 +0200
Subject: [PATCH 13/15] Revert "Use cmd arguments instead of env variables in
 builder"

This reverts commit 55b981cb0fcb4c2d3b62d8412b507afedd8801da.
---
 .../packages/Python/lldbsuite/test/builders/builder.py |  5 +++--
 lldb/packages/Python/lldbsuite/test/configuration.py   |  5 -----
 lldb/packages/Python/lldbsuite/test/dotest.py          |  4 ----
 lldb/packages/Python/lldbsuite/test/dotest_args.py     | 10 +---------
 4 files changed, 4 insertions(+), 20 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index b0605729906316..fa22f94343d0f1 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -153,7 +153,8 @@ def getToolchainSpec(self, compiler):
         cc_dir = cc_path.parent
 
         def getLlvmUtil(util_name):
-            return os.path.join(configuration.llvm_tools_dir, util_name + exe_ext)
+            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)
@@ -176,7 +177,7 @@ def getToolchainUtil(util_name):
             utils.extend(["LLVM_AR=%s" % llvm_ar])
 
         if not lldbplatformutil.platformIsDarwin():
-            if configuration.use_llvm_tools:
+            if os.getenv("USE_LLVM_TOOLS"):
                 # Use the llvm project tool instead of the system defaults.
                 for var, name in util_names.items():
                     utils.append("%s=%s" % (var, getLlvmUtil("llvm-" + name)))
diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py
index 75b7c04ad2b793..27eef040497d13 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -118,11 +118,6 @@
 # same base name.
 all_tests = set()
 
-# Force use llvm tools in API tests
-use_llvm_tools = False
-# Path to LLVM tools to be used by tests.
-llvm_tools_dir = None
-
 # LLDB library directory.
 lldb_libs_dir = None
 lldb_obj_root = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 52e35d320c1d1b..f14a00a2394b0b 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -279,11 +279,7 @@ def parseOptionsAndInitTestdirs():
         configuration.dsymutil = seven.get_command_output(
             "xcrun -find -toolchain default dsymutil"
         )
-
-    if args.use_llvm_tools:
-        configuration.use_llvm_tools = True
     if args.llvm_tools_dir:
-        configuration.llvm_tools_dir = args.llvm_tools_dir
         configuration.filecheck = shutil.which("FileCheck", path=args.llvm_tools_dir)
         configuration.yaml2obj = shutil.which("yaml2obj", path=args.llvm_tools_dir)
 
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index aaff9adb9fb447..a80428ebec5891 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -108,20 +108,12 @@ def create_parser():
         dest="dsymutil",
         help=textwrap.dedent("Specify which dsymutil to use."),
     )
-    group.add_argument(
-        "--use-llvm-tools",
-        dest="use_llvm_tools",
-        action="store_true",
-        help=textwrap.dedent(
-            "Force use LLVM tools for testing (llvm-ar, llvm-objcopy, etc.)."
-        ),
-    )
     group.add_argument(
         "--llvm-tools-dir",
         metavar="dir",
         dest="llvm_tools_dir",
         help=textwrap.dedent(
-            "The location of llvm tools used for testing (llvm-ar, yaml2obj, FileCheck, etc.)."
+            "The location of llvm tools used for testing (yaml2obj, FileCheck, etc.)."
         ),
     )
 

>From ae96df6d7f67210abc348ff5055e84e0976675f9 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 3 Sep 2024 23:12:18 +0200
Subject: [PATCH 14/15] Remove USE_LLVM_TOOLS usage

---
 .../Python/lldbsuite/test/builders/builder.py  | 18 +-----------------
 1 file changed, 1 insertion(+), 17 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index fa22f94343d0f1..dc75dd7b1d4c5f 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -152,10 +152,6 @@ def getToolchainSpec(self, compiler):
 
         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)
 
@@ -169,20 +165,8 @@ def getToolchainUtil(util_name):
         }
         utils = []
 
-        # Note: LLVM_AR is currently required by API TestBSDArchives.py tests.
-        # Assemble a full path to llvm-ar for given LLVM_TOOLS_DIR;
-        # otherwise assume we have llvm-ar at the same place where is CC specified.
-        if not os.getenv("LLVM_AR"):
-            llvm_ar = getLlvmUtil("llvm-ar")
-            utils.extend(["LLVM_AR=%s" % llvm_ar])
-
         if not lldbplatformutil.platformIsDarwin():
-            if os.getenv("USE_LLVM_TOOLS"):
-                # Use the llvm project tool instead of the system defaults.
-                for var, name in util_names.items():
-                    utils.append("%s=%s" % (var, getLlvmUtil("llvm-" + name)))
-                utils.extend(["AR=%s" % llvm_ar])
-            elif cc_type in ["clang", "cc", "gcc"]:
+            if cc_type in ["clang", "cc", "gcc"]:
                 util_paths = {}
                 # Assembly a toolchain side tool cmd based on passed CC.
                 for var, name in util_names.items():

>From f1e4f5fe06fc2c3bd48653ec7760ac7e3a0a76e5 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Wed, 11 Sep 2024 15:28:56 +0300
Subject: [PATCH 15/15] Removed unused exe_ext variable

---
 lldb/packages/Python/lldbsuite/test/builders/builder.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index dc75dd7b1d4c5f..564918c58b6dd2 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -110,10 +110,6 @@ def getToolchainSpec(self, compiler):
         if not cc:
             return []
 
-        exe_ext = ""
-        if lldbplatformutil.getHostPlatform() == "windows":
-            exe_ext = ".exe"
-
         cc = cc.strip()
         cc_path = pathlib.Path(cc)
 



More information about the lldb-commits mailing list