Skip to content

Commit ececf5e

Browse files
tromeyvadimcn
authored andcommitted
Add Rust support to the Python test harness
1 parent 46ca593 commit ececf5e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,17 @@ def skipUnlessTargetAndroid(func):
607607
"requires target to be Android")(func)
608608

609609

610+
def skipUnlessRustInstalled(func):
611+
"""Decorate the item to skip tests when no Rust compiler is available."""
612+
613+
def is_rust_missing(self):
614+
compiler = self.getRustCompilerVersion()
615+
if not compiler:
616+
return "skipping because rust compiler not found"
617+
return None
618+
return skipTestIfFn(is_rust_missing)(func)
619+
620+
610621
def skipIfHostIncompatibleWithRemote(func):
611622
"""Decorate the item to skip tests if binaries built on this host are incompatible."""
612623

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,18 @@ def getDwarfVersion(self):
12941294
except: pass
12951295
return '0'
12961296

1297+
def getRustCompilerVersion(self):
1298+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1299+
"""
1300+
compiler = which("rustc")
1301+
if compiler:
1302+
version_output = system([[compiler, "--version"]])[0]
1303+
for line in version_output.split(os.linesep):
1304+
m = re.search('rustc ([0-9\.]+)', line)
1305+
if m:
1306+
return m.group(1)
1307+
return None
1308+
12971309
def platformIsDarwin(self):
12981310
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
12991311
return lldbplatformutil.platformIsDarwin()
@@ -1562,6 +1574,11 @@ def buildGModules(
15621574
dictionary, testdir, testname):
15631575
raise Exception("Don't know how to build binary with gmodules")
15641576

1577+
def buildRust(self):
1578+
"""Build the default rust binary.
1579+
"""
1580+
system([[which('rustc'), '-g main.rs']])
1581+
15651582
def signBinary(self, binary_path):
15661583
if sys.platform.startswith("darwin"):
15671584
codesign_cmd = "codesign --force --sign \"%s\" %s" % (

0 commit comments

Comments
 (0)