Skip to content

Commit 015c528

Browse files
tromeyvadimcn
authored andcommitted
Add Rust support to the Python test harness
1 parent 97f0228 commit 015c528

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

632632

633+
def skipUnlessRustInstalled(func):
634+
"""Decorate the item to skip tests when no Rust compiler is available."""
635+
636+
def is_rust_missing(self):
637+
compiler = self.getRustCompilerVersion()
638+
if not compiler:
639+
return "skipping because rust compiler not found"
640+
return None
641+
return skipTestIfFn(is_rust_missing)(func)
642+
643+
633644
def skipIfHostIncompatibleWithRemote(func):
634645
"""Decorate the item to skip tests if binaries built on this host are incompatible."""
635646

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,18 @@ def getDwarfVersion(self):
13111311
pass
13121312
return '0'
13131313

1314+
def getRustCompilerVersion(self):
1315+
""" Returns a string that represents the rust compiler version, or None if rust is not found.
1316+
"""
1317+
compiler = which("rustc")
1318+
if compiler:
1319+
version_output = system([[compiler, "--version"]])[0]
1320+
for line in version_output.split(os.linesep):
1321+
m = re.search('rustc ([0-9\.]+)', line)
1322+
if m:
1323+
return m.group(1)
1324+
return None
1325+
13141326
def platformIsDarwin(self):
13151327
"""Returns true if the OS triple for the selected platform is any valid apple OS"""
13161328
return lldbplatformutil.platformIsDarwin()
@@ -1540,6 +1552,11 @@ def buildProgram(self, sources, exe_name):
15401552
'EXE': exe_name}
15411553
self.build(dictionary=d)
15421554

1555+
def buildRust(self):
1556+
"""Build the default rust binary.
1557+
"""
1558+
system([[which('rustc'), '-g main.rs']])
1559+
15431560
def signBinary(self, binary_path):
15441561
if sys.platform.startswith("darwin"):
15451562
codesign_cmd = "codesign --force --sign \"%s\" %s" % (

0 commit comments

Comments
 (0)