mirror of https://github.com/noisymime/Arduino.git
Recursive properties string-replace
This commit is contained in:
parent
aa3d6cd2ca
commit
0dd5309bc0
|
@ -53,6 +53,8 @@ public class Compiler implements MessageConsumer {
|
||||||
|
|
||||||
private String buildPath;
|
private String buildPath;
|
||||||
private String toolsPath;
|
private String toolsPath;
|
||||||
|
private String corePath;
|
||||||
|
private String variantPath;
|
||||||
private String primaryClassName;
|
private String primaryClassName;
|
||||||
private String board;
|
private String board;
|
||||||
private List<File> objectFiles;
|
private List<File> objectFiles;
|
||||||
|
@ -134,7 +136,7 @@ public class Compiler implements MessageConsumer {
|
||||||
String corePath = coreFolder.getAbsolutePath();
|
String corePath = coreFolder.getAbsolutePath();
|
||||||
|
|
||||||
String variant = boardPreferences.get("build.variant");
|
String variant = boardPreferences.get("build.variant");
|
||||||
String variantPath = null;
|
variantPath = null;
|
||||||
if (variant != null) {
|
if (variant != null) {
|
||||||
File variantFolder;
|
File variantFolder;
|
||||||
if (!variant.contains(":")) {
|
if (!variant.contains(":")) {
|
||||||
|
@ -172,7 +174,7 @@ public class Compiler implements MessageConsumer {
|
||||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||||
// collecting them into the core.a library file.
|
// collecting them into the core.a library file.
|
||||||
sketch.setCompilingProgress(50);
|
sketch.setCompilingProgress(50);
|
||||||
compileCore(corePath, variant, variantPath);
|
compileCore(variant);
|
||||||
|
|
||||||
// 4. link it all together into the .elf file
|
// 4. link it all together into the .elf file
|
||||||
sketch.setCompilingProgress(60);
|
sketch.setCompilingProgress(60);
|
||||||
|
@ -481,7 +483,7 @@ public class Compiler implements MessageConsumer {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String cmd = prefs.get("recipe.S.o.pattern");
|
String cmd = prefs.get("recipe.S.o.pattern");
|
||||||
return StringReplacer.formatAndSplit(cmd, dict);
|
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -501,7 +503,7 @@ public class Compiler implements MessageConsumer {
|
||||||
|
|
||||||
String cmd = prefs.get("recipe.c.o.pattern");
|
String cmd = prefs.get("recipe.c.o.pattern");
|
||||||
try {
|
try {
|
||||||
return StringReplacer.formatAndSplit(cmd, dict);
|
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -521,7 +523,7 @@ public class Compiler implements MessageConsumer {
|
||||||
|
|
||||||
String cmd = prefs.get("recipe.cpp.o.pattern");
|
String cmd = prefs.get("recipe.cpp.o.pattern");
|
||||||
try {
|
try {
|
||||||
return StringReplacer.formatAndSplit(cmd, dict);
|
return StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -588,7 +590,7 @@ public class Compiler implements MessageConsumer {
|
||||||
|
|
||||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||||
// collecting them into the core.a library file.
|
// collecting them into the core.a library file.
|
||||||
void compileCore(String corePath, String variant, String variantPath)
|
void compileCore(String variant)
|
||||||
throws RunnerException {
|
throws RunnerException {
|
||||||
|
|
||||||
List<String> includePaths = new ArrayList<String>();
|
List<String> includePaths = new ArrayList<String>();
|
||||||
|
@ -611,7 +613,7 @@ public class Compiler implements MessageConsumer {
|
||||||
String[] cmdArray;
|
String[] cmdArray;
|
||||||
try {
|
try {
|
||||||
String cmd = prefs.get("recipe.ar.pattern");
|
String cmd = prefs.get("recipe.ar.pattern");
|
||||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict);
|
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -646,11 +648,12 @@ public class Compiler implements MessageConsumer {
|
||||||
dict.put("object_files", objectFileList);
|
dict.put("object_files", objectFileList);
|
||||||
dict.put("ide_version", "" + Base.REVISION);
|
dict.put("ide_version", "" + Base.REVISION);
|
||||||
dict.put("core_path", corePath);
|
dict.put("core_path", corePath);
|
||||||
|
dict.put("variant_path", variantPath + File.separator);
|
||||||
|
|
||||||
String[] cmdArray;
|
String[] cmdArray;
|
||||||
try {
|
try {
|
||||||
String cmd = prefs.get("recipe.c.combine.pattern");
|
String cmd = prefs.get("recipe.c.combine.pattern");
|
||||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict);
|
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -668,7 +671,7 @@ public class Compiler implements MessageConsumer {
|
||||||
String[] cmdArray;
|
String[] cmdArray;
|
||||||
try {
|
try {
|
||||||
String cmd = prefs.get("recipe.objcopy.eep.pattern");
|
String cmd = prefs.get("recipe.objcopy.eep.pattern");
|
||||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict);
|
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
@ -686,7 +689,7 @@ public class Compiler implements MessageConsumer {
|
||||||
String[] cmdArray;
|
String[] cmdArray;
|
||||||
try {
|
try {
|
||||||
String cmd = prefs.get("recipe.objcopy.hex.pattern");
|
String cmd = prefs.get("recipe.objcopy.hex.pattern");
|
||||||
cmdArray = StringReplacer.formatAndSplit(cmd, dict);
|
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,17 +29,28 @@ import java.util.Map;
|
||||||
|
|
||||||
public class StringReplacer {
|
public class StringReplacer {
|
||||||
|
|
||||||
public static String[] formatAndSplit(String src, Map<String, String> dict)
|
public static String[] formatAndSplit(String src, Map<String, String> dict,
|
||||||
throws Exception {
|
boolean recursive) throws Exception {
|
||||||
// Do a replace with dictionary
|
String res;
|
||||||
src = StringReplacer.replaceFromMapping(src, dict);
|
|
||||||
|
// Recursive replace with a max depth of 10 levels.
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
// Do a replace with dictionary
|
||||||
|
res = StringReplacer.replaceFromMapping(src, dict);
|
||||||
|
if (!recursive)
|
||||||
|
break;
|
||||||
|
if (res.equals(src))
|
||||||
|
break;
|
||||||
|
src = res;
|
||||||
|
}
|
||||||
|
|
||||||
// Split the resulting string in arguments
|
// Split the resulting string in arguments
|
||||||
return quotedSplit(src, '"', false);
|
return quotedSplit(src, '"', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String[] quotedSplit(String src, char escapeChar,
|
public static String[] quotedSplit(String src, char escapeChar,
|
||||||
boolean acceptEmptyArguments) throws Exception {
|
boolean acceptEmptyArguments)
|
||||||
|
throws Exception {
|
||||||
String quote = "" + escapeChar;
|
String quote = "" + escapeChar;
|
||||||
List<String> res = new ArrayList<String>();
|
List<String> res = new ArrayList<String>();
|
||||||
String escapedArg = null;
|
String escapedArg = null;
|
||||||
|
@ -68,8 +79,8 @@ public class StringReplacer {
|
||||||
escaping = false;
|
escaping = false;
|
||||||
}
|
}
|
||||||
if (escaping)
|
if (escaping)
|
||||||
throw new Exception("Invalid quoting: no closing '" + escapeChar
|
throw new Exception("Invalid quoting: no closing '" + escapeChar +
|
||||||
+ "' char found.");
|
"' char found.");
|
||||||
return res.toArray(new String[0]);
|
return res.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +89,8 @@ public class StringReplacer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String replaceFromMapping(String src, Map<String, String> map,
|
public static String replaceFromMapping(String src, Map<String, String> map,
|
||||||
String leftDelimiter, String rightDelimiter) {
|
String leftDelimiter,
|
||||||
|
String rightDelimiter) {
|
||||||
for (String k : map.keySet()) {
|
for (String k : map.keySet()) {
|
||||||
String keyword = leftDelimiter + k + rightDelimiter;
|
String keyword = leftDelimiter + k + rightDelimiter;
|
||||||
src = src.replace(keyword, map.get(k));
|
src = src.replace(keyword, map.get(k));
|
||||||
|
|
Loading…
Reference in New Issue