Skip to content

Fixed parsing of dependency files (.d) to improve sketch build speed #2395

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 1 commit into from
Oct 31, 2014
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
21 changes: 18 additions & 3 deletions app/src/processing/app/debug/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ private List<File> compileFiles(File outputPath, File sourcePath,
return objectPaths;
}

/**
* Strip escape sequences used in makefile dependency files (.d)
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
*
* @param dep
* @return
*/
protected static String unescapeDepFile(String line) {
// Replaces: "\\" -> "\"
// Replaces: "\ " -> " "
// Replaces: "\#" -> "#"
line = line.replaceAll("\\\\([ #\\\\])", "$1");
// Replaces: "$$" -> "$"
line = line.replace("$$", "$");
return line;
}

private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) {
boolean ret=true;
try {
Expand All @@ -293,9 +310,7 @@ private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, Stri
line = line.substring(0, line.length() - 1);
}
line = line.trim();
// Strip backslash escape sequences. This replaces \\ with \ and
// removes all other backslashes
line = line.replaceAll("\\\\(.)", "$1");
line = unescapeDepFile(line);
if (line.length() == 0) continue; // ignore blank lines
if (need_obj_parse) {
// line is supposed to be the object file - make sure it really is!
Expand Down
22 changes: 22 additions & 0 deletions app/test/processing/app/debug/CompilerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package processing.app.debug;

import static org.junit.Assert.assertEquals;
import static processing.app.debug.Compiler.unescapeDepFile;

import org.junit.Test;

import processing.app.AbstractWithPreferencesTest;

public class CompilerTest extends AbstractWithPreferencesTest {

@Test
public void makeDepUnescapeTest() throws Exception {
assertEquals("C:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
unescapeDepFile("C:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
assertEquals("C:\\Arduino 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
unescapeDepFile("C:\\Arduino\\ 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
assertEquals("C:\\Ard$ui#\\\\ no 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
unescapeDepFile("C:\\Ard$$ui\\#\\\\\\\\\\ no 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
}

}