Skip to content

Commit 841b264

Browse files
committed
Merge pull request arduino#2395 from cmaglie/fix-makedep-unescape
Fixed parsing of dependency files (.d) to improve sketch build speed
2 parents b032f74 + e76de57 commit 841b264

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

app/src/processing/app/debug/Compiler.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,23 @@ private List<File> compileFiles(File outputPath, File sourcePath,
275275
return objectPaths;
276276
}
277277

278+
/**
279+
* Strip escape sequences used in makefile dependency files (.d)
280+
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
281+
*
282+
* @param dep
283+
* @return
284+
*/
285+
protected static String unescapeDepFile(String line) {
286+
// Replaces: "\\" -> "\"
287+
// Replaces: "\ " -> " "
288+
// Replaces: "\#" -> "#"
289+
line = line.replaceAll("\\\\([ #\\\\])", "$1");
290+
// Replaces: "$$" -> "$"
291+
line = line.replace("$$", "$");
292+
return line;
293+
}
294+
278295
private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) {
279296
boolean ret=true;
280297
try {
@@ -293,9 +310,7 @@ private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, Stri
293310
line = line.substring(0, line.length() - 1);
294311
}
295312
line = line.trim();
296-
// Strip backslash escape sequences. This replaces \\ with \ and
297-
// removes all other backslashes
298-
line = line.replaceAll("\\\\(.)", "$1");
313+
line = unescapeDepFile(line);
299314
if (line.length() == 0) continue; // ignore blank lines
300315
if (need_obj_parse) {
301316
// line is supposed to be the object file - make sure it really is!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package processing.app.debug;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static processing.app.debug.Compiler.unescapeDepFile;
5+
6+
import org.junit.Test;
7+
8+
import processing.app.AbstractWithPreferencesTest;
9+
10+
public class CompilerTest extends AbstractWithPreferencesTest {
11+
12+
@Test
13+
public void makeDepUnescapeTest() throws Exception {
14+
assertEquals("C:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
15+
unescapeDepFile("C:\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
16+
assertEquals("C:\\Arduino 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
17+
unescapeDepFile("C:\\Arduino\\ 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
18+
assertEquals("C:\\Ard$ui#\\\\ no 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp",
19+
unescapeDepFile("C:\\Ard$$ui\\#\\\\\\\\\\ no 1.5.3\\hardware\\arduino\\avr\\cores\\arduino\\Stream.cpp"));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)