Skip to content

Commit eb46b32

Browse files
tromeycuviper
authored andcommitted
Add Rust support to the Python test harness
1 parent 62d2c8a commit eb46b32

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
@@ -595,6 +595,17 @@ def skipUnlessDarwin(func):
595595
return skipUnlessPlatform(lldbplatformutil.getDarwinOSTriples())(func)
596596

597597

598+
def skipUnlessRustInstalled(func):
599+
"""Decorate the item to skip tests when no Rust compiler is available."""
600+
601+
def is_rust_missing(self):
602+
compiler = self.getRustCompilerVersion()
603+
if not compiler:
604+
return "skipping because rust compiler not found"
605+
return None
606+
return skipTestIfFn(is_rust_missing)(func)
607+
608+
598609
def skipIfHostIncompatibleWithRemote(func):
599610
"""Decorate the item to skip tests if binaries built on this host are incompatible."""
600611

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,18 @@ def getCompilerVersion(self):
13091309
version = m.group(1)
13101310
return version
13111311

1312+
def getRustCompilerVersion(self):
1313+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1314+
"""
1315+
compiler = which("rustc")
1316+
if compiler:
1317+
version_output = system([[compiler, "--version"]])[0]
1318+
for line in version_output.split(os.linesep):
1319+
m = re.search('rustc ([0-9\.]+)', line)
1320+
if m:
1321+
return m.group(1)
1322+
return None
1323+
13121324
def platformIsDarwin(self):
13131325
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
13141326
return lldbplatformutil.platformIsDarwin()
@@ -1577,6 +1589,11 @@ def buildGModules(
15771589
dictionary, testdir, testname):
15781590
raise Exception("Don't know how to build binary with gmodules")
15791591

1592+
def buildRust(self):
1593+
"""Build the default rust binary.
1594+
"""
1595+
system([[which('rustc'), '-g main.rs']])
1596+
15801597
def signBinary(self, binary_path):
15811598
if sys.platform.startswith("darwin"):
15821599
codesign_cmd = "codesign --force --sign \"%s\" %s" % (

0 commit comments

Comments
 (0)