Skip to content

Commit

Permalink
Merge pull request #695 from w-gates/JENKINS-66923
Browse files Browse the repository at this point in the history
[JENKINS-66923] Do not stop processing when parsing "entering directory" or "leaving directory" message from tools other than make
  • Loading branch information
uhafner authored Oct 19, 2021
2 parents c159311 + cbf5144 commit acac97f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/main/java/edu/hm/hafner/analysis/LookaheadParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public abstract class LookaheadParser extends IssueParser {

private static final String ENTERING_DIRECTORY = "Entering directory";
private static final String LEAVING_DIRECTORY = "Leaving directory";
private static final Pattern MAKE_PATH
= Pattern.compile(".*make(?:\\[\\d+])?: " + ENTERING_DIRECTORY + " [`'](?<dir>.*)['`]");
private static final Pattern ENTERING_DIRECTORY_PATH
= Pattern.compile(".*" + ENTERING_DIRECTORY + " [`'](?<dir>.*)['`]");
private static final String CMAKE_PREFIX = "-- Build files have";
private static final Pattern CMAKE_PATH = Pattern.compile(CMAKE_PREFIX + " been written to: (?<dir>.*)");

private static final int MAX_LINE_LENGTH = 4000; // see JENKINS-55805

private final Pattern pattern;

private final Stack<String> recursiveMakeDirectories;
private final Stack<String> recursiveDirectories;

/**
* Creates a new instance of {@link LookaheadParser}.
Expand All @@ -46,7 +46,7 @@ protected LookaheadParser(final String pattern) {
super();

this.pattern = Pattern.compile(pattern);
this.recursiveMakeDirectories = new Stack<>();
this.recursiveDirectories = new Stack<>();
}

@Override
Expand Down Expand Up @@ -80,36 +80,38 @@ private void parse(final Report report, final LookaheadStream lookahead) {
}

/**
* When changing directories using Make output, save new directory to our stack for later use, then return it for
* use now.
* When changing directories using 'Entering directory' output, save new directory to our stack for later use, then
* return it for use now.
*
* @param line
* the line to parse
* *
* @return The new directory to change to
*/
private String newMakeDirectory(final String line) {
recursiveMakeDirectories.push(extractDirectory(line, MAKE_PATH));
return recursiveMakeDirectories.peek();
private String enterDirectory(final String line) {
recursiveDirectories.push(extractDirectory(line, ENTERING_DIRECTORY_PATH));
return recursiveDirectories.peek();
}

/**
* When changing directories using Make output, set our stack to the last directory seen, and return that directory.
* When changing directories using 'Leaving directory' output, set our stack to the last directory seen, and return
* that directory.
*
* @return The last directory seen, or an empty String if we have returned to the beginning
*/
private String lastMakeDirectory() {
if (!recursiveMakeDirectories.empty()) {
recursiveMakeDirectories.pop();
if (!recursiveMakeDirectories.empty()) {
return recursiveMakeDirectories.peek();
private String leaveDirectory() {
if (!recursiveDirectories.empty()) {
recursiveDirectories.pop();
if (!recursiveDirectories.empty()) {
return recursiveDirectories.peek();
}
}
return "";
}

/**
* Uses Make and CMake output to track directory structure as the compiler moves between source locations.
* Uses Make-like ("Entering directory" and "Leaving directory") and CMake-like ("Build files have been written to")
* output to track directory structure as the compiler moves between source locations.
*
* @param builder
* {@link IssueBuilder} to set directory for
Expand All @@ -118,10 +120,10 @@ private String lastMakeDirectory() {
*/
private void handleDirectoryChanges(final IssueBuilder builder, final String line) {
if (line.contains(ENTERING_DIRECTORY)) {
builder.setDirectory(newMakeDirectory(line));
builder.setDirectory(enterDirectory(line));
}
else if (line.contains(LEAVING_DIRECTORY)) {
builder.setDirectory(lastMakeDirectory());
builder.setDirectory(leaveDirectory());
}
else if (line.contains(CMAKE_PREFIX)) {
builder.setDirectory(extractDirectory(line, CMAKE_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ void issue66835() {
"/path/to/workspace/libraries/this-library-workspace/sublibrary/src/OtherProblemFile.cpp");
}

/**
* Parser should not throw errors when Entering directory and Leaving directory if not from make.
*
* @see <a href="https://issues.jenkins-ci.org/browse/JENKINS-66923">Issue 66923</a>
*/
@Test
void issue66923() {
Report warnings = createParser().parse(createReaderFactory("issue66923.txt"));

assertThat(warnings).hasSize(0);
assertThat(warnings).doesNotHaveErrors();
}

/**
* Parser should make relative paths absolute if cmake/ninja is used.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ninja: Entering directory `bin/example_project'
ninja: Leaving directory `bin/example_project'
Waf: Entering directory `/home/jenkins/workspace/ndn-cxx/OS/Ubuntu-20.04/build'
Waf: Leaving directory `/home/jenkins/workspace/ndn-cxx/OS/Ubuntu-20.04/build'

0 comments on commit acac97f

Please sign in to comment.