| 1 |
import os |
| 2 |
import platform |
| 3 |
import subprocess |
| 4 |
import sys |
| 5 |
import itertools |
| 6 |
|
| 7 |
import lldbsuite.test.lldbtest as lldbtest |
| 8 |
import lldbsuite.test.lldbutil as lldbutil |
| 9 |
from lldbsuite.test import configuration |
| 10 |
from lldbsuite.test_event import build_exception |
| 11 |
|
| 12 |
|
| 13 |
class Builder: |
| 14 |
def getArchitecture(self): |
| 15 |
"""Returns the architecture in effect the test suite is running with.""" |
| 16 |
return configuration.arch if configuration.arch else "" |
| 17 |
|
| 18 |
def getCompiler(self): |
| 19 |
"""Returns the compiler in effect the test suite is running with.""" |
| 20 |
compiler = configuration.compiler if configuration.compiler else "clang" |
| 21 |
compiler = lldbutil.which(compiler) |
| 22 |
return os.path.abspath(compiler) |
| 23 |
|
| 24 |
def getTriple(self, arch): |
| 25 |
"""Returns the triple for the given architecture or None.""" |
| 26 |
return None |
| 27 |
|
| 28 |
def getExtraMakeArgs(self): |
| 29 |
""" |
| 30 |
Helper function to return extra argumentsfor the make system. This |
| 31 |
method is meant to be overridden by platform specific builders. |
| 32 |
""" |
| 33 |
return [] |
| 34 |
|
| 35 |
def getArchCFlags(self, architecture): |
| 36 |
"""Returns the ARCH_CFLAGS for the make system.""" |
| 37 |
return [] |
| 38 |
|
| 39 |
def getMake(self, test_subdir, test_name): |
| 40 |
"""Returns the invocation for GNU make. |
| 41 |
The first argument is a tuple of the relative path to the testcase |
| 42 |
and its filename stem.""" |
| 43 |
# Construct the base make invocation. |
| 44 |
lldb_test = os.environ["LLDB_TEST"] |
| 45 |
if not ( |
| 46 |
lldb_test |
| 47 |
and configuration.test_build_dir |
| 48 |
and test_subdir |
| 49 |
and test_name |
| 50 |
and (not os.path.isabs(test_subdir)) |
| 51 |
): |
| 52 |
raise Exception("Could not derive test directories") |
| 53 |
build_dir = os.path.join(configuration.test_build_dir, test_subdir, test_name) |
| 54 |
src_dir = os.path.join(configuration.test_src_root, test_subdir) |
| 55 |
# This is a bit of a hack to make inline testcases work. |
| 56 |
makefile = os.path.join(src_dir, "Makefile") |
| 57 |
if not os.path.isfile(makefile): |
| 58 |
makefile = os.path.join(build_dir, "Makefile") |
| 59 |
return [ |
| 60 |
configuration.make_path, |
| 61 |
"VPATH=" + src_dir, |
| 62 |
"-C", |
| 63 |
build_dir, |
| 64 |
"-I", |
| 65 |
src_dir, |
| 66 |
"-I", |
| 67 |
os.path.join(lldb_test, "make"), |
| 68 |
"-f", |
| 69 |
makefile, |
| 70 |
] |
| 71 |
|
| 72 |
def getCmdLine(self, d): |
| 73 |
""" |
| 74 |
Helper function to return a command line argument string used for the |
| 75 |
make system. |
| 76 |
""" |
| 77 |
|
| 78 |
# If d is None or an empty mapping, just return an empty list. |
| 79 |
if not d: |
| 80 |
return [] |
| 81 |
|
| 82 |
def setOrAppendVariable(k, v): |
| 83 |
append_vars = ["CFLAGS", "CFLAGS_EXTRAS", "LD_EXTRAS"] |
| 84 |
if k in append_vars and k in os.environ: |
| 85 |
v = os.environ[k] + " " + v |
| 86 |
return "%s=%s" % (k, v) |
| 87 |
|
| 88 |
cmdline = [setOrAppendVariable(k, v) for k, v in list(d.items())] |
| 89 |
|
| 90 |
return cmdline |
| 91 |
|
| 92 |
def getArchSpec(self, architecture): |
| 93 |
""" |
| 94 |
Helper function to return the key-value string to specify the architecture |
| 95 |
used for the make system. |
| 96 |
""" |
| 97 |
return ["ARCH=" + architecture] if architecture else [] |
| 98 |
|
| 99 |
def getCCSpec(self, compiler): |
| 100 |
""" |
| 101 |
Helper function to return the key-value string to specify the compiler |
| 102 |
used for the make system. |
| 103 |
""" |
| 104 |
cc = compiler if compiler else None |
| 105 |
if not cc and configuration.compiler: |
| 106 |
cc = configuration.compiler |
| 107 |
if cc: |
| 108 |
return ['CC="%s"' % cc] |
| 109 |
return [] |
| 110 |
|
| 111 |
def getSDKRootSpec(self): |
| 112 |
""" |
| 113 |
Helper function to return the key-value string to specify the SDK root |
| 114 |
used for the make system. |
| 115 |
""" |
| 116 |
if configuration.sdkroot: |
| 117 |
return ["SDKROOT={}".format(configuration.sdkroot)] |
| 118 |
return [] |
| 119 |
|
| 120 |
def getModuleCacheSpec(self): |
| 121 |
""" |
| 122 |
Helper function to return the key-value string to specify the clang |
| 123 |
module cache used for the make system. |
| 124 |
""" |
| 125 |
if configuration.clang_module_cache_dir: |
| 126 |
return [ |
| 127 |
"CLANG_MODULE_CACHE_DIR={}".format(configuration.clang_module_cache_dir) |
| 128 |
] |
| 129 |
return [] |
| 130 |
|
| 131 |
def getLibCxxArgs(self): |
| 132 |
if configuration.libcxx_include_dir and configuration.libcxx_library_dir: |
| 133 |
libcpp_args = [ |
| 134 |
"LIBCPP_INCLUDE_DIR={}".format(configuration.libcxx_include_dir), |
| 135 |
"LIBCPP_LIBRARY_DIR={}".format(configuration.libcxx_library_dir), |
| 136 |
] |
| 137 |
if configuration.libcxx_include_target_dir: |
| 138 |
libcpp_args.append( |
| 139 |
"LIBCPP_INCLUDE_TARGET_DIR={}".format( |
| 140 |
configuration.libcxx_include_target_dir |
| 141 |
) |
| 142 |
) |
| 143 |
return libcpp_args |
| 144 |
return [] |
| 145 |
|
| 146 |
def getLLDBObjRoot(self): |
| 147 |
return ["LLDB_OBJ_ROOT={}".format(configuration.lldb_obj_root)] |
| 148 |
|
| 149 |
def _getDebugInfoArgs(self, debug_info): |
| 150 |
if debug_info is None: |
| 151 |
return [] |
| 152 |
if debug_info == "dwarf": |
| 153 |
return ["MAKE_DSYM=NO"] |
| 154 |
if debug_info == "dwo": |
| 155 |
return ["MAKE_DSYM=NO", "MAKE_DWO=YES"] |
| 156 |
if debug_info == "gmodules": |
| 157 |
return ["MAKE_DSYM=NO", "MAKE_GMODULES=YES"] |
| 158 |
return None |
| 159 |
|
| 160 |
def getBuildCommand( |
| 161 |
self, |
| 162 |
debug_info, |
| 163 |
architecture=None, |
| 164 |
compiler=None, |
| 165 |
dictionary=None, |
| 166 |
testdir=None, |
| 167 |
testname=None, |
| 168 |
make_targets=None, |
| 169 |
): |
| 170 |
debug_info_args = self._getDebugInfoArgs(debug_info) |
| 171 |
if debug_info_args is None: |
| 172 |
return None |
| 173 |
if make_targets is None: |
| 174 |
make_targets = ["all"] |
| 175 |
command_parts = [ |
| 176 |
self.getMake(testdir, testname), |
| 177 |
debug_info_args, |
| 178 |
make_targets, |
| 179 |
self.getArchCFlags(architecture), |
| 180 |
self.getArchSpec(architecture), |
| 181 |
self.getCCSpec(compiler), |
| 182 |
self.getExtraMakeArgs(), |
| 183 |
self.getSDKRootSpec(), |
| 184 |
self.getModuleCacheSpec(), |
| 185 |
self.getLibCxxArgs(), |
| 186 |
self.getLLDBObjRoot(), |
| 187 |
self.getCmdLine(dictionary), |
| 188 |
] |
| 189 |
command = list(itertools.chain(*command_parts)) |
| 190 |
|
| 191 |
return command |
| 192 |
|
| 193 |
def cleanup(self, dictionary=None): |
| 194 |
"""Perform a platform-specific cleanup after the test.""" |
| 195 |
return True |