Skip to content

msg-filter: adapt paths from llvm-17 source tree #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/lib/msg-filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ struct MsgFilter::Private {
TMsgReplaceList repList;
TSubstMap fileSubsts;

const std::string strKrn = "^[a-zA-Z+]+";
const RE reKrn = RE(strKrn + /* convert el8_9 -> el8 */ "|_[0-9]+$");
const RE reDir = RE("^([^:]*/)");
const RE reFile = RE("[^/]+$");
const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+)/(.*)(\\.[ly])?$");
const RE rePyBuild = RE("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$");
const RE reTmpPath = RE("^(/var)?/tmp/(.*)$");
const RE reTmpCleaner = RE("(.*)");

void addMsgFilter(
const std::string &checker,
const std::string &regexp,
Expand Down Expand Up @@ -247,47 +238,62 @@ std::string MsgFilter::filterPath(
{
std::string path = origPath;

static const RE reDir("^([^:]*/)");

TSubstMap &substMap = d->fileSubsts;
if (!substMap.empty()) {
std::string base = regexReplaceWrap(origPath, d->reDir, "");
std::string dir = regexReplaceWrap(origPath, d->reFile, "");
std::string base = regexReplaceWrap(origPath, reDir, "");
static const RE reFile("[^/]+$");
std::string dir = regexReplaceWrap(origPath, reFile, "");
if (substMap.find(base) != substMap.end()) {
const std::string &substWith = substMap[base];
path = dir + substWith;
}
}

if (!forceFullPath && d->ignorePath)
return regexReplaceWrap(path, d->reDir, "");
return regexReplaceWrap(path, reDir, "");

// adapt paths from llvm-17 source tree to match the llvm-19 source tree
static const RE reLLVM17("^(llvm-17\\.[^/]*)"
"((?:/redhat-linux-build)?)/"
"(include|lib|tools|unittests|utils)");
path = boost::regex_replace(path, reLLVM17, "\\1/llvm\\2/\\3");

if (boost::regex_match(path, d->reTmpPath)) {
static const RE reTmpPath("^(/var)?/tmp/(.*)$");
if (boost::regex_match(path, reTmpPath)) {
// filter random numbers in names of temporary generated files
std::string tmpPath = boost::regex_replace(path, d->reTmpCleaner, "/tmp/tmp.c");
static const RE reTmpCleaner("(.*)");
std::string tmpPath = boost::regex_replace(path, reTmpCleaner, "/tmp/tmp.c");
return tmpPath;
}

// "/usr/src/kernels/4.18.0-552.el8.x86_64+debug/..."
// -> "/usr/src/kernels/VERSION-RELEASE+debug/..."
const RE reKrnUsrSrc("^(/usr/src/kernels/)[^/-]+-[^/-]+((?:\\+debug)?/.*)$");
static const RE reKrnUsrSrc("^(/usr/src/kernels/)[^/-]+-[^/-]+((?:\\+debug)?/.*)$");
path = regexReplaceWrap(path, reKrnUsrSrc, "\\1VERSION-RELEASE\\2");

boost::smatch sm;
if (boost::regex_match(path, sm, d->rePyBuild)) {
static const RE rePyBuild("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$");
if (boost::regex_match(path, sm, rePyBuild)) {
// %{_builddir}/build/lib/setuptools/glob.py ->
// %{_builddir}/setuptools/glob.py
path = sm[1] + sm[2];
}

if (!boost::regex_match(path, sm, d->rePath))
static const RE rePath("^(?:/builddir/build/BUILD/)?([^/]+)/(.*)(\\.[ly])?$");
if (!boost::regex_match(path, sm, rePath))
// no match
return path;

const std::string nvr = sm[/* NVR */ 1];
path = sm[/* core */ 2];

// try to kill the multiple version strings in paths (kernel, OpenLDAP, ...)
const std::string ver = boost::regex_replace(nvr, d->reKrn, "");
const std::string krnPattern = d->strKrn + ver + "[^/]*/";
static const std::string strKrn = "^[a-zA-Z+]+";
static const RE reKrn(strKrn + /* convert el8_9 -> el8 */ "|_[0-9]+$");
const std::string ver = boost::regex_replace(nvr, reKrn, "");
const std::string krnPattern = strKrn + ver + "[^/]*/";

#if DEBUG_SUBST > 2
std::cerr << "nvr: " << nvr << "\n";
Expand Down
1 change: 1 addition & 0 deletions tests/csdiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,6 @@ test_csdiff(diff-misc 21-kernel-shell-code)
test_csdiff(diff-misc 22-kernel-zstream-path)
test_csdiff(diff-misc 23-cov-parser-key-event)
test_csdiff(diff-misc 24-shellcheck-line-content)
test_csdiff(diff-misc 25-llvm-17-path-filter)

add_subdirectory(filter-file)
17,092 changes: 17,092 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-add-z.err

Large diffs are not rendered by default.

17,178 changes: 17,178 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-add.err

Large diffs are not rendered by default.

9,498 changes: 9,498 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-fix-z.err

Large diffs are not rendered by default.

9,584 changes: 9,584 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-fix.err

Large diffs are not rendered by default.

30,492 changes: 30,492 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-new.err

Large diffs are not rendered by default.

22,898 changes: 22,898 additions & 0 deletions tests/csdiff/diff-misc/25-llvm-17-path-filter-old.err

Large diffs are not rendered by default.