Skip to content

Commit 98afe72

Browse files
tromeyvadimcn
authored andcommitted
Add Rust support to the Python test harness
1 parent 6274f86 commit 98afe72

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
@@ -626,6 +626,17 @@ def skipUnlessTargetAndroid(func):
626626
"requires target to be Android")(func)
627627

628628

629+
def skipUnlessRustInstalled(func):
630+
"""Decorate the item to skip tests when no Rust compiler is available."""
631+
632+
def is_rust_missing(self):
633+
compiler = self.getRustCompilerVersion()
634+
if not compiler:
635+
return "skipping because rust compiler not found"
636+
return None
637+
return skipTestIfFn(is_rust_missing)(func)
638+
639+
629640
def skipIfHostIncompatibleWithRemote(func):
630641
"""Decorate the item to skip tests if binaries built on this host are incompatible."""
631642

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,18 @@ def getDwarfVersion(self):
13311331
except: pass
13321332
return '0'
13331333

1334+
def getRustCompilerVersion(self):
1335+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1336+
"""
1337+
compiler = which("rustc")
1338+
if compiler:
1339+
version_output = system([[compiler, "--version"]])[0]
1340+
for line in version_output.split(os.linesep):
1341+
m = re.search('rustc ([0-9\.]+)', line)
1342+
if m:
1343+
return m.group(1)
1344+
return None
1345+
13341346
def platformIsDarwin(self):
13351347
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
13361348
return lldbplatformutil.platformIsDarwin()
@@ -1599,6 +1611,11 @@ def buildGModules(
15991611
dictionary, testdir, testname):
16001612
raise Exception("Don't know how to build binary with gmodules")
16011613

1614+
def buildRust(self):
1615+
"""Build the default rust binary.
1616+
"""
1617+
system([[which('rustc'), '-g main.rs']])
1618+
16021619
def signBinary(self, binary_path):
16031620
if sys.platform.startswith("darwin"):
16041621
codesign_cmd = "codesign --force --sign \"%s\" %s" % (

0 commit comments

Comments
 (0)