Skip to content

Commit 1d89e86

Browse files
committed
"build.core" property can now be used inside custom menus.
Fixes #1304
1 parent c1c87a1 commit 1d89e86

File tree

5 files changed

+35
-87
lines changed

5 files changed

+35
-87
lines changed

app/src/processing/app/Base.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ public Base(String[] args) throws Exception {
294294
System.out.println(_("No valid configured cores found! Exiting..."));
295295
System.exit(3);
296296
}
297-
for (TargetPackage pack : packages.values())
298-
pack.resolveReferencedPlatforms(packages);
299297

300298
// Setup board-dependent variables.
301299
onBoardOrPortChange();
@@ -1087,19 +1085,23 @@ public void actionPerformed(ActionEvent e) {
10871085
importMenu.add(addLibraryMenuItem);
10881086

10891087
// Split between user supplied libraries and IDE libraries
1090-
TargetBoard board = getTargetBoard();
1088+
TargetPlatform targetPlatform = getTargetPlatform();
10911089

1092-
if (board != null) {
1090+
if (targetPlatform != null) {
10931091
LibraryList ideLibs = getIDELibs();
10941092
LibraryList userLibs = getUserLibs();
10951093
try {
10961094
// Find the current target. Get the platform, and then select the
10971095
// correct name and core path.
1098-
PreferencesMap prefs = board.getMergedPlatformPreferences();
1099-
String platformName = prefs.get("name");
1100-
JMenuItem platformItem = new JMenuItem(_(platformName));
1101-
platformItem.setEnabled(false);
1102-
importMenu.add(platformItem);
1096+
PreferencesMap prefs = targetPlatform.getPreferences();
1097+
if (prefs != null) {
1098+
String platformName = prefs.get("name");
1099+
if (platformName != null) {
1100+
JMenuItem platformItem = new JMenuItem(_(platformName));
1101+
platformItem.setEnabled(false);
1102+
importMenu.add(platformItem);
1103+
}
1104+
}
11031105
if (ideLibs.size() > 0) {
11041106
importMenu.addSeparator();
11051107
addLibraries(importMenu, ideLibs);

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,30 @@ private PreferencesMap createBuildPreferences(String _buildPath,
132132
throw re;
133133
}
134134

135-
TargetBoard targetBoard = Base.getTargetBoard();
136-
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
135+
// Check if the board needs a platform from another package
136+
TargetPlatform targetPlatform = Base.getTargetPlatform();
137+
TargetPlatform corePlatform = null;
138+
PreferencesMap boardPreferences = Base.getBoardPreferences();
139+
String core = boardPreferences.get("build.core");
140+
if (core.contains(":")) {
141+
String[] split = core.split(":");
142+
core = split[1];
143+
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
144+
if (corePlatform == null) {
145+
RunnerException re = new RunnerException(I18n
146+
.format(_("Selected board depends on '{0}' core (not installed)."),
147+
split[0]));
148+
re.hideStackTrace();
149+
throw re;
150+
}
151+
}
137152

138153
// Merge all the global preference configuration in order of priority
139154
PreferencesMap p = new PreferencesMap();
140155
p.putAll(Preferences.getMap());
141-
p.putAll(targetBoard.getMergedPlatformPreferences());
156+
if (corePlatform != null)
157+
p.putAll(corePlatform.getPreferences());
158+
p.putAll(targetPlatform.getPreferences());
142159
p.putAll(Base.getBoardPreferences());
143160
for (String k : p.keySet()) {
144161
if (p.get(k) == null)
@@ -154,12 +171,12 @@ private PreferencesMap createBuildPreferences(String _buildPath,
154171
p.put("compiler.path", Base.getAvrBasePath());
155172

156173
// Core folder
157-
TargetPlatform tp = targetBoard.getReferencedPlatform();
174+
TargetPlatform tp = corePlatform;
158175
if (tp == null)
159-
tp = targetBoard.getContainerPlatform();
176+
tp = targetPlatform;
160177
File coreFolder = new File(tp.getFolder(), "cores");
161-
String core = p.get("build.core");
162178
coreFolder = new File(coreFolder, core);
179+
p.put("build.core", core);
163180
p.put("build.core.path", coreFolder.getAbsolutePath());
164181

165182
// System Folder
@@ -175,8 +192,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
175192
t = targetPlatform;
176193
} else {
177194
String[] split = variant.split(":", 2);
178-
t = Base
179-
.getTargetPlatform(split[0], Preferences.get("target_platform"));
195+
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
180196
variant = split[1];
181197
}
182198
File variantFolder = new File(t.getFolder(), "variants");

app/src/processing/app/debug/TargetBoard.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package processing.app.debug;
22

3-
import static processing.app.I18n._;
4-
import static processing.app.I18n.format;
5-
63
import java.util.LinkedHashMap;
74
import java.util.Map;
85
import java.util.Set;
@@ -16,10 +13,6 @@ public class TargetBoard {
1613
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
1714
private TargetPlatform containerPlatform;
1815

19-
private String referencedPackageId;
20-
private TargetPlatform referencedPlatform;
21-
private TargetPackage referencedPackage;
22-
2316
/**
2417
* Create a TargetBoard based on preferences passed as argument.
2518
*
@@ -35,14 +28,6 @@ public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
3528
PreferencesMap menus = prefs.firstLevelMap().get("menu");
3629
if (menus != null)
3730
menuOptions = menus.firstLevelMap();
38-
39-
// Setup referenced platform
40-
String core = prefs.get("build.core");
41-
if (core.contains(":")) {
42-
String[] split = core.split(":");
43-
referencedPackageId = split[0];
44-
prefs.put("build.core", split[1]);
45-
}
4631
}
4732

4833
/**
@@ -63,15 +48,6 @@ public String getId() {
6348
return id;
6449
}
6550

66-
/**
67-
* Get the package this board refers to
68-
*
69-
* @return
70-
*/
71-
public String getReferencedPackageId() {
72-
return referencedPackageId;
73-
}
74-
7551
/**
7652
* Get the full preferences map of the board with a given identifier
7753
*
@@ -138,38 +114,4 @@ public TargetPlatform getContainerPlatform() {
138114
return containerPlatform;
139115
}
140116

141-
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
142-
throws Exception {
143-
if (referencedPackageId == null)
144-
return;
145-
146-
if (!packages.containsKey(referencedPackageId))
147-
throw new Exception(
148-
format(_("Can't find referenced package ({1}) for board {0}"), id,
149-
referencedPackageId));
150-
referencedPackage = packages.get(referencedPackageId);
151-
152-
Map<String, TargetPlatform> platforms = referencedPackage.getPlatforms();
153-
154-
String ourPlatformId = getContainerPlatform().getId();
155-
if (!platforms.containsKey(ourPlatformId))
156-
throw new Exception(
157-
format(_("Can't find referenced package ({1}) for board {0}"), id,
158-
referencedPackageId));
159-
referencedPlatform = platforms.get(ourPlatformId);
160-
}
161-
162-
public TargetPlatform getReferencedPlatform() {
163-
return referencedPlatform;
164-
}
165-
166-
public PreferencesMap getMergedPlatformPreferences() {
167-
PreferencesMap res = new PreferencesMap();
168-
if (referencedPlatform != null)
169-
res.putAll(referencedPlatform.getPreferences());
170-
if (containerPlatform.getPreferences() != null)
171-
res.putAll(containerPlatform.getPreferences());
172-
return res;
173-
}
174-
175117
}

app/src/processing/app/debug/TargetPackage.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ public TargetPlatform get(String platform) {
6464
return platforms.get(platform);
6565
}
6666

67-
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
68-
throws Exception {
69-
for (TargetPlatform platform : getPlatforms().values())
70-
platform.resolveReferencedPlatforms(packages);
71-
}
72-
7367
public String getId() {
7468
return id;
7569
}

app/src/processing/app/debug/TargetPlatform.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ public TargetPackage getContainerPackage() {
163163
return containerPackage;
164164
}
165165

166-
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
167-
throws Exception {
168-
for (TargetBoard board : getBoards().values())
169-
board.resolveReferencedPlatforms(packages);
170-
}
171-
172166
@Override
173167
public String toString() {
174168
String res = "TargetPlatform: name=" + id + " boards={\n";

0 commit comments

Comments
 (0)