Skip to content

Commit 194e015

Browse files
tromeynikic
authored andcommitted
Add Rust support to the Python test harness
1 parent 465bcdd commit 194e015

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 skipUnlessDarwin(func):
607607
return skipUnlessPlatform(lldbplatformutil.getDarwinOSTriples())(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
@@ -1300,6 +1300,18 @@ def getDwarfVersion(self):
13001300
except: pass
13011301
return '0'
13021302

1303+
def getRustCompilerVersion(self):
1304+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1305+
"""
1306+
compiler = which("rustc")
1307+
if compiler:
1308+
version_output = system([[compiler, "--version"]])[0]
1309+
for line in version_output.split(os.linesep):
1310+
m = re.search('rustc ([0-9\.]+)', line)
1311+
if m:
1312+
return m.group(1)
1313+
return None
1314+
13031315
def platformIsDarwin(self):
13041316
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
13051317
return lldbplatformutil.platformIsDarwin()
@@ -1568,6 +1580,11 @@ def buildGModules(
15681580
dictionary, testdir, testname):
15691581
raise Exception("Don't know how to build binary with gmodules")
15701582

1583+
def buildRust(self):
1584+
"""Build the default rust binary.
1585+
"""
1586+
system([[which('rustc'), '-g main.rs']])
1587+
15711588
def signBinary(self, binary_path):
15721589
if sys.platform.startswith("darwin"):
15731590
codesign_cmd = "codesign --force --sign \"%s\" %s" % (

0 commit comments

Comments
 (0)