Skip to content

Commit

Permalink
Add clang version string to clang_delta --version
Browse files Browse the repository at this point in the history
This adds the version of clang currently in use to the output from
clang_delta --version and changes the test script to use this information
instead of looking at the list of dynamic libraries when checking which clang
version is in use. This allows the tests to run when clang_delta is statically
linked against libClang.
  • Loading branch information
mortior committed Jan 2, 2024
1 parent f660442 commit 06a905d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 8 additions & 0 deletions clang_delta/ClangDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cstdlib>

#include "llvm/Support/raw_ostream.h"
#include "clang/Basic/Version.h"
#include "TransformationManager.h"
#include "git_version.h"

Expand All @@ -25,8 +26,15 @@ static int ErrorCode = -1;

static void PrintVersion()
{
// Some versions of the clang library (notably Ubuntu) prefixes its version
// string with uninteresting information. Strip this.
auto version = clang::getClangFullVersion();
auto start = version.find("clang version");
assert(start != version.npos);

llvm::outs() << "clang_delta " << PACKAGE_VERSION << "\n";
llvm::outs() << "Git version: " << git_version << "\n";
llvm::outs() << version.substr(start) << "\n";
// XXX print copyright, contact info, etc.?
}

Expand Down
18 changes: 7 additions & 11 deletions clang_delta/tests/test_clang_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import unittest


def get_llvm_version():
def get_clang_version():
current = os.path.dirname(__file__)
binary = os.path.join(current, '../clang_delta')
output = subprocess.check_output(f'ldd {binary}', shell=True, text=True)
output = subprocess.check_output(f'{binary} --version', shell=True, text=True)
for line in output.splitlines():
part = line.strip().split()[0]
if part.startswith('libLLVM'):
m = re.match(r'libLLVM-(?P<version>[0-9]+)\.so', part)
if m:
return int(m.group('version'))
else:
return int(part.split('.')[-1])
m = re.match(r'clang version (?P<version>[0-9]+)\.', line)
if m:
return int(m.group('version'))

raise AssertionError()

Expand Down Expand Up @@ -378,7 +374,7 @@ def test_rename_class_base_specifier(self):
def test_rename_class_bool(self):
self.check_clang_delta('rename-class/bool.cc', '--transformation=rename-class --counter=1')

@unittest.skipIf(get_llvm_version() >= 16, 'Fails with LLVM >= 16')
@unittest.skipIf(get_clang_version() >= 16, 'Fails with LLVM >= 16')
def test_rename_class_class_template(self):
self.check_clang_delta('rename-class/class_template.cc', '--transformation=rename-class --counter=1')

Expand Down Expand Up @@ -639,7 +635,7 @@ def test_rename_operator_test2(self):
def test_merge_base_class_test1(self):
self.check_clang_delta('merge-base-class/test1.cc', '--transformation=merge-base-class --counter=1')

@unittest.skipIf(get_llvm_version() <= 9, 'Fails with LLVM <= 9')
@unittest.skipIf(get_clang_version() <= 9, 'Fails with LLVM <= 9')
def test_merge_base_class_test2(self):
self.check_clang_delta('merge-base-class/test2.cc', '--transformation=merge-base-class --counter=1')

Expand Down

0 comments on commit 06a905d

Please sign in to comment.