Skip to content

Commit

Permalink
Fixed parsing of dependency files (.d) to improve sketch build speed
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Oct 31, 2014
1 parent b032f74 commit e76de57
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
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"));
}

}

0 comments on commit e76de57

Please sign in to comment.