Platform.txt in-memory rewrite rules: whenever loaded, if a property is set to a value known to be wrong/old, that property is replaced with the current/right value.

This happens in-memory, no platform.txt file were harmed during rewriting
Mitigate #2838
This commit is contained in:
Federico Fissore 2015-03-30 16:18:08 +02:00
parent ea5155656a
commit ecde17b6e2
3 changed files with 59 additions and 3 deletions

View File

@ -20,8 +20,9 @@
*/
package processing.app.debug;
import static processing.app.I18n._;
import static processing.app.I18n.format;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.helpers.PreferencesMap;
import java.io.File;
import java.io.IOException;
@ -29,7 +30,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import processing.app.helpers.PreferencesMap;
import static processing.app.I18n._;
import static processing.app.I18n.format;
public class LegacyTargetPlatform implements TargetPlatform {
@ -117,6 +119,12 @@ public class LegacyTargetPlatform implements TargetPlatform {
format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e);
}
try {
rewriteKeysOfOldPlatformsTxtAndWarnAboutIt();
} catch (IOException e) {
throw new TargetPlatformException(e);
}
File progFile = new File(folder, "programmers.txt");
try {
if (progFile.exists() && progFile.canRead()) {
@ -130,6 +138,35 @@ public class LegacyTargetPlatform implements TargetPlatform {
}
}
private void rewriteKeysOfOldPlatformsTxtAndWarnAboutIt() throws IOException {
File platformRewrite = new File(BaseNoGui.getHardwareFolder(), "platform.keys.rewrite.txt");
PreferencesMap platformRewriteProps = new PreferencesMap(platformRewrite);
PreferencesMap oldProps = platformRewriteProps.subTree("old");
PreferencesMap newProps = platformRewriteProps.subTree("new");
String platformName = preferences.get("name");
if (platformName == null) {
platformName = folder.getAbsolutePath();
}
for (Map.Entry<String, String> entry : oldProps.entrySet()) {
String preferencesKey = entry.getKey().substring(entry.getKey().indexOf(".") + 1);
if (preferences.containsKey(preferencesKey) && entry.getValue().equals(preferences.get(preferencesKey))) {
System.err.println(I18n.format(_("Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core."), platformName, preferencesKey + "=" + entry.getValue(), preferencesKey + "=" + newProps.get(entry.getKey())));
preferences.put(preferencesKey, newProps.get(entry.getKey()));
}
}
PreferencesMap addedProps = platformRewriteProps.subTree("added");
for (Map.Entry<String, String> entry : addedProps.entrySet()) {
if (!preferences.containsKey(entry.getKey())) {
System.err.println(I18n.format(_("Warning: platform.txt from core '{0}' misses property {1}, automatically set to {2}. Consider upgrading this core."), platformName, entry.getKey(), entry.getValue()));
preferences.put(entry.getKey(), entry.getValue());
}
}
}
@Override
public String getId() {
return id;

View File

@ -113,6 +113,8 @@
<antcall target="assemble-hardware" />
<copy file="../hardware/platform.keys.rewrite.txt" todir="${staging_folder}/work/${staging_hardware_folder}"/>
<!-- copy shared examples folder -->
<copy todir="${target.path}/examples">
<fileset dir="shared/examples" />

View File

@ -0,0 +1,17 @@
old.0.compiler.path={runtime.ide.path}/hardware/tools/avr/bin/
new.0.compiler.path={runtime.tools.avr-gcc.path}/bin/
added.tools.avrdude.path={runtime.tools.avrdude.path}
old.1.tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude
new.1.tools.avrdude.cmd.path={path}/bin/avrdude
old.2.tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf
new.2.tools.avrdude.config.path={path}/etc/avrdude.conf
old.3.compiler.path={runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/
new.3.compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
old.4.tools.bossac.path={runtime.ide.path}/hardware/tools
new.4.tools.bossac.path={runtime.tools.bossac.path}