Skip to content

Commit 0171000

Browse files
tromeyvadimcn
authored andcommitted
Add Rust support to the Python test harness
1 parent 7b6c40a commit 0171000

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
@@ -719,6 +719,17 @@ def skipUnlessTargetAndroid(func):
719719
)(func)
720720

721721

722+
def skipUnlessRustInstalled(func):
723+
"""Decorate the item to skip tests when no Rust compiler is available."""
724+
725+
def is_rust_missing(self):
726+
compiler = self.getRustCompilerVersion()
727+
if not compiler:
728+
return "skipping because rust compiler not found"
729+
return None
730+
return skipTestIfFn(is_rust_missing)(func)
731+
732+
722733
def skipIfHostIncompatibleWithRemote(func):
723734
"""Decorate the item to skip tests if binaries built on this host are incompatible."""
724735

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,18 @@ def getDwarfVersion(self):
13681368
pass
13691369
return "0"
13701370

1371+
def getRustCompilerVersion(self):
1372+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1373+
"""
1374+
compiler = which("rustc")
1375+
if compiler:
1376+
version_output = system([[compiler, "--version"]])[0]
1377+
for line in version_output.split(os.linesep):
1378+
m = re.search('rustc ([0-9\.]+)', line)
1379+
if m:
1380+
return m.group(1)
1381+
return None
1382+
13711383
def platformIsDarwin(self):
13721384
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
13731385
return lldbplatformutil.platformIsDarwin()
@@ -1609,6 +1621,11 @@ def buildProgram(self, sources, exe_name):
16091621
d = {"CXX_SOURCES": sources, "EXE": exe_name}
16101622
self.build(dictionary=d)
16111623

1624+
def buildRust(self):
1625+
"""Build the default rust binary.
1626+
"""
1627+
system([[which('rustc'), '-g main.rs']])
1628+
16121629
def signBinary(self, binary_path):
16131630
if sys.platform.startswith("darwin"):
16141631
codesign_cmd = 'codesign --force --sign "%s" %s' % (

0 commit comments

Comments
 (0)