"build.core" property can now be used inside custom menus.

Fixes #1304
This commit is contained in:
Cristian Maglie 2013-03-05 20:18:46 +01:00
parent c1c87a1642
commit 1d89e86b62
5 changed files with 35 additions and 87 deletions

View File

@ -294,8 +294,6 @@ public class Base {
System.out.println(_("No valid configured cores found! Exiting..."));
System.exit(3);
}
for (TargetPackage pack : packages.values())
pack.resolveReferencedPlatforms(packages);
// Setup board-dependent variables.
onBoardOrPortChange();
@ -1087,19 +1085,23 @@ public class Base {
importMenu.add(addLibraryMenuItem);
// Split between user supplied libraries and IDE libraries
TargetBoard board = getTargetBoard();
TargetPlatform targetPlatform = getTargetPlatform();
if (board != null) {
if (targetPlatform != null) {
LibraryList ideLibs = getIDELibs();
LibraryList userLibs = getUserLibs();
try {
// Find the current target. Get the platform, and then select the
// correct name and core path.
PreferencesMap prefs = board.getMergedPlatformPreferences();
String platformName = prefs.get("name");
JMenuItem platformItem = new JMenuItem(_(platformName));
platformItem.setEnabled(false);
importMenu.add(platformItem);
PreferencesMap prefs = targetPlatform.getPreferences();
if (prefs != null) {
String platformName = prefs.get("name");
if (platformName != null) {
JMenuItem platformItem = new JMenuItem(_(platformName));
platformItem.setEnabled(false);
importMenu.add(platformItem);
}
}
if (ideLibs.size() > 0) {
importMenu.addSeparator();
addLibraries(importMenu, ideLibs);

View File

@ -132,13 +132,30 @@ public class Compiler implements MessageConsumer {
throw re;
}
TargetBoard targetBoard = Base.getTargetBoard();
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
// Check if the board needs a platform from another package
TargetPlatform targetPlatform = Base.getTargetPlatform();
TargetPlatform corePlatform = null;
PreferencesMap boardPreferences = Base.getBoardPreferences();
String core = boardPreferences.get("build.core");
if (core.contains(":")) {
String[] split = core.split(":");
core = split[1];
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
if (corePlatform == null) {
RunnerException re = new RunnerException(I18n
.format(_("Selected board depends on '{0}' core (not installed)."),
split[0]));
re.hideStackTrace();
throw re;
}
}
// Merge all the global preference configuration in order of priority
PreferencesMap p = new PreferencesMap();
p.putAll(Preferences.getMap());
p.putAll(targetBoard.getMergedPlatformPreferences());
if (corePlatform != null)
p.putAll(corePlatform.getPreferences());
p.putAll(targetPlatform.getPreferences());
p.putAll(Base.getBoardPreferences());
for (String k : p.keySet()) {
if (p.get(k) == null)
@ -154,12 +171,12 @@ public class Compiler implements MessageConsumer {
p.put("compiler.path", Base.getAvrBasePath());
// Core folder
TargetPlatform tp = targetBoard.getReferencedPlatform();
TargetPlatform tp = corePlatform;
if (tp == null)
tp = targetBoard.getContainerPlatform();
tp = targetPlatform;
File coreFolder = new File(tp.getFolder(), "cores");
String core = p.get("build.core");
coreFolder = new File(coreFolder, core);
p.put("build.core", core);
p.put("build.core.path", coreFolder.getAbsolutePath());
// System Folder
@ -175,8 +192,7 @@ public class Compiler implements MessageConsumer {
t = targetPlatform;
} else {
String[] split = variant.split(":", 2);
t = Base
.getTargetPlatform(split[0], Preferences.get("target_platform"));
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
variant = split[1];
}
File variantFolder = new File(t.getFolder(), "variants");

View File

@ -1,8 +1,5 @@
package processing.app.debug;
import static processing.app.I18n._;
import static processing.app.I18n.format;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@ -16,10 +13,6 @@ public class TargetBoard {
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
private TargetPlatform containerPlatform;
private String referencedPackageId;
private TargetPlatform referencedPlatform;
private TargetPackage referencedPackage;
/**
* Create a TargetBoard based on preferences passed as argument.
*
@ -35,14 +28,6 @@ public class TargetBoard {
PreferencesMap menus = prefs.firstLevelMap().get("menu");
if (menus != null)
menuOptions = menus.firstLevelMap();
// Setup referenced platform
String core = prefs.get("build.core");
if (core.contains(":")) {
String[] split = core.split(":");
referencedPackageId = split[0];
prefs.put("build.core", split[1]);
}
}
/**
@ -63,15 +48,6 @@ public class TargetBoard {
return id;
}
/**
* Get the package this board refers to
*
* @return
*/
public String getReferencedPackageId() {
return referencedPackageId;
}
/**
* Get the full preferences map of the board with a given identifier
*
@ -138,38 +114,4 @@ public class TargetBoard {
return containerPlatform;
}
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
throws Exception {
if (referencedPackageId == null)
return;
if (!packages.containsKey(referencedPackageId))
throw new Exception(
format(_("Can't find referenced package ({1}) for board {0}"), id,
referencedPackageId));
referencedPackage = packages.get(referencedPackageId);
Map<String, TargetPlatform> platforms = referencedPackage.getPlatforms();
String ourPlatformId = getContainerPlatform().getId();
if (!platforms.containsKey(ourPlatformId))
throw new Exception(
format(_("Can't find referenced package ({1}) for board {0}"), id,
referencedPackageId));
referencedPlatform = platforms.get(ourPlatformId);
}
public TargetPlatform getReferencedPlatform() {
return referencedPlatform;
}
public PreferencesMap getMergedPlatformPreferences() {
PreferencesMap res = new PreferencesMap();
if (referencedPlatform != null)
res.putAll(referencedPlatform.getPreferences());
if (containerPlatform.getPreferences() != null)
res.putAll(containerPlatform.getPreferences());
return res;
}
}

View File

@ -64,12 +64,6 @@ public class TargetPackage {
return platforms.get(platform);
}
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
throws Exception {
for (TargetPlatform platform : getPlatforms().values())
platform.resolveReferencedPlatforms(packages);
}
public String getId() {
return id;
}

View File

@ -163,12 +163,6 @@ public class TargetPlatform {
return containerPackage;
}
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
throws Exception {
for (TargetBoard board : getBoards().values())
board.resolveReferencedPlatforms(packages);
}
@Override
public String toString() {
String res = "TargetPlatform: name=" + id + " boards={\n";