Skip to content
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

[JENKINS-63580] Update regex for msbuild to recognize linker warnings #952

Merged
merged 2 commits into from
Oct 4, 2023
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: 24 additions & 20 deletions src/main/java/edu/hm/hafner/analysis/parser/MsBuildParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,22 @@ public class MsBuildParser extends LookaheadParser {
private static final long serialVersionUID = -2141974437420906595L;

private static final String MS_BUILD_WARNING_PATTERN
= "(?:^(?:.*)Command line warning ([A-Za-z0-9]+):\\s*(.*)\\s*\\[(.*)\\])|"
+ ANT_TASK + "(?:(?:\\s*(?:\\d+|\\d+:\\d+)>)?(?:(?:(?:(.*?)\\((\\d*)(?:,(\\d+))?[a-zA-Z]*?\\)|.*LINK)\\s*:|"
+ "(.*):)\\s*([A-z-_]*\\s(?:[Nn]ote|[Ii]nfo|[Ww]arning|(?:fatal\\s*)?[Ee]rror))[^A-Za-z0-9]\\s*:?\\s*([A-Za-z0-9\\-_]+)?"
+ "\\s*:\\s(?:\\s*([A-Za-z0-9.]+)\\s*:)?\\s*(.*?)(?: \\[([^\\]]*)[/\\\\][^\\]\\\\]+\\])?"
+ "|(.*)\\s*:.*error\\s*(LNK[0-9]+):\\s*(.*)))$";

private final Pattern ignoredToolsPattern = Pattern.compile("(?!.exe)(\\.[^.]+)$");
= "(?:^(?:.*)Command line warning ([A-Za-z0-9]+):\\s*(.*)\\s*\\[(.*)\\])"
+ "|"
+ ANT_TASK + "(?:"
+ "(?:\\s*(?:\\d+|\\d+:\\d+)>)?(?:(?:(?:(.*?)\\((\\d*)(?:,(\\d+))?[a-zA-Z]*?\\)|.*LINK)"
+ "\\s*:|"
+ "(.*):)\\s*([A-z-_]*\\s(?:[Nn]ote|[Ii]nfo|[Ww]arning|(?:fatal\\s*)?[Ee]rror))[^A-Za-z0-9]\\s*"
pyatizbyantsevia marked this conversation as resolved.
Show resolved Hide resolved
+ ":?"
+ "\\s*([A-Za-z0-9\\-_]+)?"
+ "\\s*:\\s"
+ "(?:\\s*([A-Za-z0-9.]+)\\s*:)?"
+ "\\s*(.*?)"
+ "(?: \\[([^\\]]*)[/\\\\][^\\]\\\\]+\\])?"
+ "))$";

private static final Pattern IGNORED_TOOLS_PATTERN = Pattern.compile("(?!.exe)(\\.[^.]+)$");
private static final Pattern LINKER_CAUSE = Pattern.compile(".*imported by '([A-Za-z0-9\\-_.]+)'.*");

/**
* Creates a new instance of {@link MsBuildParser}.
Expand All @@ -42,7 +51,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
final IssueBuilder builder) {
String fileName = determineFileName(matcher);

Matcher fileExtensionMatcher = ignoredToolsPattern.matcher(fileName);
Matcher fileExtensionMatcher = IGNORED_TOOLS_PATTERN.matcher(fileName);
if (!fileExtensionMatcher.find()) {
return Optional.empty();
}
Expand All @@ -56,14 +65,6 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
.setSeverity(Severity.WARNING_NORMAL)
.buildOptional();
}
if (StringUtils.isNotBlank(matcher.group(13))) {
return builder.setLineStart(0)
.setCategory(matcher.group(14))
.setType(matcher.group(13))
.setMessage(matcher.group(15))
.setSeverity(Severity.guessFromString(matcher.group(8)))
.buildOptional();
}
if (StringUtils.isNotEmpty(matcher.group(10))) {
return builder.setLineStart(matcher.group(5))
.setColumnStart(matcher.group(6))
Expand All @@ -87,7 +88,7 @@ protected Optional<Issue> createIssue(final Matcher matcher, final LookaheadStre
}

/**
* Determines the name of the file that is cause of the warning.
* Determines the name of the file that is the cause of the warning.
*
* @param matcher
* the matcher to get the matches from
Expand All @@ -103,12 +104,15 @@ private String determineFileName(final Matcher matcher) {
else if (StringUtils.isNotBlank(matcher.group(7))) {
fileName = matcher.group(7);
}
else if (StringUtils.isNotBlank(matcher.group(13))) {
fileName = matcher.group(13);
}
else {
fileName = matcher.group(4);
}
if (StringUtils.isBlank(fileName)) {
var linker = LINKER_CAUSE.matcher(matcher.group(11));
if (linker.matches()) {
return linker.group(1);
}
}
if (StringUtils.isBlank(fileName)) {
fileName = StringUtils.substringBetween(matcher.group(11), "'");
}
Expand Down
37 changes: 32 additions & 5 deletions src/test/java/edu/hm/hafner/analysis/parser/MsBuildParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,19 @@ void issue10566() {
}

/**
* Parses a file with warnings of the MS Build tools.
* Parses a file with errors of the MS Build tools.
*
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-3582">Issue 3582</a>
*/
@Test
void issue3582() {
Report warnings = parse("issue3582.txt");
Report errors = parse("issue3582.txt");

assertThat(warnings).hasSize(1);
assertThatReportHasSeverities(warnings, 1, 0, 0, 0);
assertThat(errors).hasSize(1);
assertThatReportHasSeverities(errors, 1, 0, 0, 0);

try (SoftAssertions softly = new SoftAssertions()) {
softly.assertThat(warnings.get(0))
softly.assertThat(errors.get(0))
.hasFileName("TestLib.lib")
.hasCategory("LNK1181")
.hasSeverity(Severity.ERROR)
Expand All @@ -456,6 +456,33 @@ void issue3582() {
}
}

/**
* Parses a file with warnings of the MS Build tools.
*
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-63580">Issue 63580</a>
*/
@Test
void issue63580() {
Report warnings = parse("issue63580.txt");

assertThat(warnings).hasSize(1);
assertThatReportHasSeverities(warnings, 0, 0, 1, 0);

try (SoftAssertions softly = new SoftAssertions()) {
softly.assertThat(warnings.get(0))
.hasFileName("def.obj")
.hasCategory("LNK4217")
.hasSeverity(Severity.WARNING_NORMAL)
.hasMessage("symbol 'XYZ' defined in 'abc.obj' is imported by 'def.obj' in function 'FGH'")
.hasDescription("")
.hasPackageName("-")
.hasLineStart(0)
.hasLineEnd(0)
.hasColumnStart(0)
.hasColumnEnd(0);
}
}

/**
* Parses a file with warnings of Stylecop.
*
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/edu/hm/hafner/analysis/parser/issue63580.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
...
[exec] 23>main.cpp
[exec] 23>Compiling resources...
[exec] 23>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
[exec] 23>Copyright (C) Microsoft Corporation. All rights reserved.
[exec] 23>Linking...
[exec] 23>LINK : warning LNK4217: symbol 'XYZ' defined in 'abc.obj' is imported by 'def.obj' in function 'FGH'
[exec] 23>Build log was saved at "..."
[exec] 23>MyApplication - 0 error(s), 1 warning(s)
[exec] ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========