Skip to content

Commit

Permalink
Platform.txt in-memory rewrite rules: whenever loaded, if a property …
Browse files Browse the repository at this point in the history
…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 esp8266#2838
  • Loading branch information
Federico Fissore committed Mar 30, 2015
1 parent ea51556 commit ecde17b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
43 changes: 40 additions & 3 deletions arduino-core/src/processing/app/debug/LegacyTargetPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
*/
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;
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 {

Expand Down Expand Up @@ -117,6 +119,12 @@ public LegacyTargetPlatform(String _name, File _folder, TargetPackage parent)
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()) {
Expand All @@ -130,6 +138,35 @@ public LegacyTargetPlatform(String _name, File _folder, TargetPackage parent)
}
}

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;
Expand Down
2 changes: 2 additions & 0 deletions build/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
17 changes: 17 additions & 0 deletions hardware/platform.keys.rewrite.txt
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit ecde17b

Please sign in to comment.