Skip to content

Commit ecde17b

Browse files
author
Federico Fissore
committed
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 esp8266#2838
1 parent ea51556 commit ecde17b

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

arduino-core/src/processing/app/debug/LegacyTargetPlatform.java

+40-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@
2020
*/
2121
package processing.app.debug;
2222

23-
import static processing.app.I18n._;
24-
import static processing.app.I18n.format;
23+
import processing.app.BaseNoGui;
24+
import processing.app.I18n;
25+
import processing.app.helpers.PreferencesMap;
2526

2627
import java.io.File;
2728
import java.io.IOException;
2829
import java.util.LinkedHashMap;
2930
import java.util.Map;
3031
import java.util.Set;
3132

32-
import processing.app.helpers.PreferencesMap;
33+
import static processing.app.I18n._;
34+
import static processing.app.I18n.format;
3335

3436
public class LegacyTargetPlatform implements TargetPlatform {
3537

@@ -117,6 +119,12 @@ public LegacyTargetPlatform(String _name, File _folder, TargetPackage parent)
117119
format(_("Error loading {0}"), localPlatformsFile.getAbsolutePath()), e);
118120
}
119121

122+
try {
123+
rewriteKeysOfOldPlatformsTxtAndWarnAboutIt();
124+
} catch (IOException e) {
125+
throw new TargetPlatformException(e);
126+
}
127+
120128
File progFile = new File(folder, "programmers.txt");
121129
try {
122130
if (progFile.exists() && progFile.canRead()) {
@@ -130,6 +138,35 @@ public LegacyTargetPlatform(String _name, File _folder, TargetPackage parent)
130138
}
131139
}
132140

141+
private void rewriteKeysOfOldPlatformsTxtAndWarnAboutIt() throws IOException {
142+
File platformRewrite = new File(BaseNoGui.getHardwareFolder(), "platform.keys.rewrite.txt");
143+
PreferencesMap platformRewriteProps = new PreferencesMap(platformRewrite);
144+
145+
PreferencesMap oldProps = platformRewriteProps.subTree("old");
146+
PreferencesMap newProps = platformRewriteProps.subTree("new");
147+
148+
String platformName = preferences.get("name");
149+
if (platformName == null) {
150+
platformName = folder.getAbsolutePath();
151+
}
152+
153+
for (Map.Entry<String, String> entry : oldProps.entrySet()) {
154+
String preferencesKey = entry.getKey().substring(entry.getKey().indexOf(".") + 1);
155+
if (preferences.containsKey(preferencesKey) && entry.getValue().equals(preferences.get(preferencesKey))) {
156+
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())));
157+
preferences.put(preferencesKey, newProps.get(entry.getKey()));
158+
}
159+
}
160+
161+
PreferencesMap addedProps = platformRewriteProps.subTree("added");
162+
for (Map.Entry<String, String> entry : addedProps.entrySet()) {
163+
if (!preferences.containsKey(entry.getKey())) {
164+
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()));
165+
preferences.put(entry.getKey(), entry.getValue());
166+
}
167+
}
168+
}
169+
133170
@Override
134171
public String getId() {
135172
return id;

build/build.xml

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113

114114
<antcall target="assemble-hardware" />
115115

116+
<copy file="../hardware/platform.keys.rewrite.txt" todir="${staging_folder}/work/${staging_hardware_folder}"/>
117+
116118
<!-- copy shared examples folder -->
117119
<copy todir="${target.path}/examples">
118120
<fileset dir="shared/examples" />

hardware/platform.keys.rewrite.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
old.0.compiler.path={runtime.ide.path}/hardware/tools/avr/bin/
2+
new.0.compiler.path={runtime.tools.avr-gcc.path}/bin/
3+
4+
added.tools.avrdude.path={runtime.tools.avrdude.path}
5+
6+
old.1.tools.avrdude.cmd.path={runtime.ide.path}/hardware/tools/avr/bin/avrdude
7+
new.1.tools.avrdude.cmd.path={path}/bin/avrdude
8+
9+
old.2.tools.avrdude.config.path={runtime.ide.path}/hardware/tools/avr/etc/avrdude.conf
10+
new.2.tools.avrdude.config.path={path}/etc/avrdude.conf
11+
12+
old.3.compiler.path={runtime.ide.path}/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/
13+
new.3.compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
14+
15+
old.4.tools.bossac.path={runtime.ide.path}/hardware/tools
16+
new.4.tools.bossac.path={runtime.tools.bossac.path}
17+

0 commit comments

Comments
 (0)