2 If the build* function is passed the compiler argument, for example, 'llvm-gcc',
3 it is passed as a make variable to the make command. Otherwise, we check the
4 LLDB_CC environment variable; if it is defined, it is passed as a make variable
7 If neither the compiler keyword argument nor the LLDB_CC environment variable is
8 specified, no CC make variable is passed to the make command. The Makefile gets
9 to define the default CC being used.
11 Same idea holds for LLDB_ARCH environment variable, which maps to the ARCH make
22 import lldbsuite.test.lldbtest as lldbtest
23 import lldbsuite.test.lldbutil as lldbutil
24 from lldbsuite.test_event import build_exception
26 def getArchitecture():
27 """Returns the architecture in effect the test suite is running with."""
28 return os.environ["ARCH"] if "ARCH" in os.environ else ""
31 """Returns the compiler in effect the test suite is running with."""
32 compiler = os.environ.get("CC", "clang")
33 compiler = lldbutil.which(compiler)
34 return os.path.realpath(compiler)
37 """Returns the flag required to specify the arch"""
38 compiler = getCompiler()
41 elif "gcc" in compiler:
43 elif "clang" in compiler:
48 return ("ARCHFLAG=" + archflag) if archflag else ""
51 """Returns the name for GNU make"""
52 if platform.system() == "FreeBSD" or platform.system() == "NetBSD":
57 def getArchSpec(architecture):
59 Helper function to return the key-value string to specify the architecture
60 used for the make system.
62 arch = architecture if architecture else None
63 if not arch and "ARCH" in os.environ:
64 arch = os.environ["ARCH"]
66 return ("ARCH=" + arch) if arch else ""
68 def getCCSpec(compiler):
70 Helper function to return the key-value string to specify the compiler
71 used for the make system.
73 cc = compiler if compiler else None
74 if not cc and "CC" in os.environ:
77 return "CC=\"%s\"" % cc
83 Helper function to return a properly formatted command line argument(s)
84 string used for the make system.
87 # If d is None or an empty mapping, just return an empty string.
90 pattern = '%s="%s"' if "win32" in sys.platform else "%s='%s'"
92 def setOrAppendVariable(k, v):
93 append_vars = ["CFLAGS_EXTRAS", "LD_EXTRAS"]
94 if k in append_vars and k in os.environ:
95 v = os.environ[k] + " " + v
96 return pattern % (k, v)
97 cmdline = " ".join([setOrAppendVariable(k, v) for k, v in list(d.items())])
102 def runBuildCommands(commands, sender):
104 lldbtest.system(commands, sender=sender)
105 except subprocess.CalledProcessError as called_process_error:
106 # Convert to a build-specific error.
107 # We don't do that in lldbtest.system() since that
108 # is more general purpose.
109 raise build_exception.BuildError(called_process_error)
112 def buildDefault(sender=None, architecture=None, compiler=None, dictionary=None, clean=True):
113 """Build the binaries the default way."""
116 commands.append([getMake(), "clean", getCmdLine(dictionary)])
117 commands.append([getMake(), getArchSpec(architecture), getCCSpec(compiler), getCmdLine(dictionary)])
119 runBuildCommands(commands, sender=sender)
121 # True signifies that we can handle building default.
124 def buildDwarf(sender=None, architecture=None, compiler=None, dictionary=None, clean=True):
125 """Build the binaries with dwarf debug info."""
128 commands.append([getMake(), "clean", getCmdLine(dictionary)])
129 commands.append([getMake(), "MAKE_DSYM=NO", getArchSpec(architecture), getCCSpec(compiler), getCmdLine(dictionary)])
131 runBuildCommands(commands, sender=sender)
132 # True signifies that we can handle building dwarf.
135 def buildDwo(sender=None, architecture=None, compiler=None, dictionary=None, clean=True):
136 """Build the binaries with dwarf debug info."""
139 commands.append([getMake(), "clean", getCmdLine(dictionary)])
140 commands.append([getMake(), "MAKE_DSYM=NO", "MAKE_DWO=YES", getArchSpec(architecture), getCCSpec(compiler), getCmdLine(dictionary)])
142 runBuildCommands(commands, sender=sender)
143 # True signifies that we can handle building dwo.
146 def buildGModules(sender=None, architecture=None, compiler=None, dictionary=None, clean=True):
147 """Build the binaries with dwarf debug info."""
150 commands.append([getMake(), "clean", getCmdLine(dictionary)])
151 commands.append([getMake(), "MAKE_DSYM=NO", "MAKE_GMODULES=YES", getArchSpec(architecture), getCCSpec(compiler), getCmdLine(dictionary)])
153 lldbtest.system(commands, sender=sender)
154 # True signifies that we can handle building with gmodules.
157 def cleanup(sender=None, dictionary=None):
158 """Perform a platform-specific cleanup after the test."""
160 #traceback.print_stack()
162 if os.path.isfile("Makefile"):
163 commands.append([getMake(), "clean", getCmdLine(dictionary)])
165 runBuildCommands(commands, sender=sender)
166 # True signifies that we can handle cleanup.