1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Created second level in hardware folder: hardware/PACKAGE/PLATFORM/...

Made some helper class for files filtering.
platforms.txt now contains only one platform at a time.
Some cleanup in Compiler and AvrDudeUploader classes.
This commit is contained in:
Cristian Maglie
2011-12-30 15:46:04 +01:00
parent dc616601cd
commit 1b3ae5fa63
131 changed files with 475 additions and 383 deletions

View File

@ -31,7 +31,10 @@ import java.util.List;
import javax.swing.*; import javax.swing.*;
import processing.app.debug.Compiler; import processing.app.debug.Compiler;
import processing.app.debug.Target; import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.core.*; import processing.core.*;
import static processing.app.I18n._; import static processing.app.I18n._;
@ -90,7 +93,7 @@ public class Base {
// found in the sketchbook) // found in the sketchbook)
static public String librariesClassPath; static public String librariesClassPath;
static public Map<String, Target> targetsTable; static public Map<String, TargetPackage> targetsTable;
// Location for untitled items // Location for untitled items
static File untitledFolder; static File untitledFolder;
@ -267,7 +270,7 @@ public class Base {
} }
} }
targetsTable = new HashMap<String, Target>(); targetsTable = new HashMap<String, TargetPackage>();
loadHardware(getHardwareFolder()); loadHardware(getHardwareFolder());
loadHardware(getSketchbookHardwareFolder()); loadHardware(getSketchbookHardwareFolder());
@ -939,52 +942,51 @@ public class Base {
} }
public void rebuildImportMenu(JMenu importMenu) { public void rebuildImportMenu(JMenu importMenu) {
//System.out.println("rebuilding import menu"); // System.out.println("rebuilding import menu");
importMenu.removeAll(); importMenu.removeAll();
// reset the set of libraries // reset the set of libraries
libraries = new HashSet<File>(); libraries = new HashSet<File>();
// reset the table mapping imports to libraries // reset the table mapping imports to libraries
importToLibraryTable = new HashMap<String, File>(); importToLibraryTable = new HashMap<String, File>();
// Add from the "libraries" subfolder in the Processing directory // Add from the "libraries" subfolder in the Processing directory
//Choose which library to add by chip platform // Choose which library to add by chip platform
try {
// Find the current target. Get the platform, and then select the
// correct name and core path.
String platformname = getBoardPreferences().get("platform");
String targetname = getPlatformPreferences(platformname)
.get("name");
String libraryPath = getPlatformPreferences(platformname).get(
"library.core.path");
JMenuItem platformItem = new JMenuItem(targetname); try {
platformItem.setEnabled(false); // Find the current target. Get the platform, and then select the
importMenu.add(platformItem); // correct name and core path.
importMenu.addSeparator(); String platformname = getBoardPreferences().get("platform");
addLibraries(importMenu, getCoreLibraries(libraryPath)); String targetname = getPlatformPreferences(platformname).get("name");
} catch (IOException e) { String libraryPath = getPlatformPreferences(platformname).get(
e.printStackTrace(); "library.core.path");
}
// Add libraries found in the sketchbook folder
int separatorIndex = importMenu.getItemCount();
try {
File sketchbookLibraries = getSketchbookLibrariesFolder();
boolean found = addLibraries(importMenu, sketchbookLibraries);
if (found) {
JMenuItem contrib = new JMenuItem(_("Contributed"));
contrib.setEnabled(false);
importMenu.insert(contrib, separatorIndex);
importMenu.insertSeparator(separatorIndex);
}
} catch (IOException e) {
e.printStackTrace();
}
}
JMenuItem platformItem = new JMenuItem(targetname);
platformItem.setEnabled(false);
importMenu.add(platformItem);
importMenu.addSeparator();
addLibraries(importMenu, getCoreLibraries(libraryPath));
} catch (IOException e) {
e.printStackTrace();
}
// Add libraries found in the sketchbook folder
int separatorIndex = importMenu.getItemCount();
try {
File sketchbookLibraries = getSketchbookLibrariesFolder();
boolean found = addLibraries(importMenu, sketchbookLibraries);
if (found) {
JMenuItem contrib = new JMenuItem(_("Contributed"));
contrib.setEnabled(false);
importMenu.insert(contrib, separatorIndex);
importMenu.insertSeparator(separatorIndex);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void rebuildExamplesMenu(JMenu menu) { public void rebuildExamplesMenu(JMenu menu) {
//System.out.println("rebuilding examples menu"); //System.out.println("rebuilding examples menu");
@ -1008,64 +1010,73 @@ public class Base {
} }
public void rebuildBoardsMenu(JMenu menu) { @SuppressWarnings("serial")
public void rebuildBoardsMenu(JMenu menu) {
//System.out.println("rebuilding boards menu"); //System.out.println("rebuilding boards menu");
menu.removeAll(); menu.removeAll();
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
for (Target target : targetsTable.values()) { for (TargetPackage targetPackage : targetsTable.values()) {
for (String board : target.getBoards().keySet()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) {
AbstractAction action = for (String board : targetPlatform.getBoards().keySet()) {
new AbstractAction(target.getBoards().get(board).get("name")) { AbstractAction action = new AbstractAction(targetPlatform.getBoards().get(
public void actionPerformed(ActionEvent actionevent) { board).get("name")) {
//System.out.println("Switching to " + target + ":" + board); public void actionPerformed(ActionEvent actionevent) {
Preferences.set("target", (String) getValue("target")); // System.out.println("Switching to " + target + ":" + board);
Preferences.set("board", (String) getValue("board")); Preferences.set("package", (String) getValue("package"));
onBoardOrPortChange(); Preferences.set("platform", (String) getValue("platform"));
Sketch.buildSettingChanged(); Preferences.set("board", (String) getValue("board"));
//Debug: created new imports menu based on board onBoardOrPortChange();
rebuildImportMenu(activeEditor.importMenu); Sketch.buildSettingChanged();
} // Debug: created new imports menu based on board
}; rebuildImportMenu(activeEditor.importMenu);
action.putValue("target", target.getName()); }
action.putValue("board", board); };
JMenuItem item = new JRadioButtonMenuItem(action); action.putValue("package", targetPackage.getName());
if (target.getName().equals(Preferences.get("target")) && action.putValue("platform", targetPlatform.getName());
board.equals(Preferences.get("board"))) { action.putValue("board", board);
item.setSelected(true); JMenuItem item = new JRadioButtonMenuItem(action);
} if (targetPackage.getName().equals(Preferences.get("package"))
group.add(item); && targetPlatform.getName().equals(Preferences.get("platform"))
menu.add(item); && board.equals(Preferences.get("board"))) {
} item.setSelected(true);
} }
group.add(item);
menu.add(item);
}
}
}
} }
public void rebuildProgrammerMenu(JMenu menu) { @SuppressWarnings("serial")
public void rebuildProgrammerMenu(JMenu menu) {
//System.out.println("rebuilding programmer menu"); //System.out.println("rebuilding programmer menu");
menu.removeAll(); menu.removeAll();
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
for (Target target : targetsTable.values()) { for (TargetPackage targetPackage : targetsTable.values()) {
for (String programmer : target.getProgrammers().keySet()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) {
AbstractAction action = for (String programmer : targetPlatform.getProgrammers().keySet()) {
new AbstractAction( String id = targetPackage.getName() + ":" + targetPlatform.getName() + ":"
target.getProgrammers().get(programmer).get("name")) { + programmer;
public void actionPerformed(ActionEvent actionevent) { AbstractAction action = new AbstractAction(targetPlatform.getProgrammers()
Preferences.set("programmer", getValue("target") + ":" + .get(programmer).get("name")) {
getValue("programmer")); public void actionPerformed(ActionEvent actionevent) {
} Preferences.set("programmer", "" + getValue("id"));
}; }
action.putValue("target", target.getName()); };
action.putValue("programmer", programmer); // action.putValue("package", targetPackage.getName());
JMenuItem item = new JRadioButtonMenuItem(action); // action.putValue("platform", targetPlatform.getName());
if (Preferences.get("programmer").equals(target.getName() + ":" + // action.putValue("programmer", programmer);
programmer)) { action.putValue("id", id);
item.setSelected(true); JMenuItem item = new JRadioButtonMenuItem(action);
} if (Preferences.get("programmer").equals(id))
group.add(item); item.setSelected(true);
menu.add(item); group.add(item);
} menu.add(item);
} }
} }
}
}
/** /**
@ -1260,14 +1271,8 @@ public class Base {
protected void loadHardware(File folder) { protected void loadHardware(File folder) {
if (!folder.isDirectory()) return; if (!folder.isDirectory()) return;
String list[] = folder.list(new FilenameFilter() { String list[] = folder.list(new OnlyDirs());
public boolean accept(File dir, String name) {
// skip .DS_Store files, .svn folders, etc
if (name.charAt(0) == '.') return false;
if (name.equals("CVS")) return false;
return (new File(dir, name).isDirectory());
}
});
// if a bad folder or something like that, this might come back null // if a bad folder or something like that, this might come back null
if (list == null) return; if (list == null) return;
@ -1277,7 +1282,7 @@ public class Base {
for (String target : list) { for (String target : list) {
File subfolder = new File(folder, target); File subfolder = new File(folder, target);
targetsTable.put(target, new Target(target, subfolder)); targetsTable.put(target, new TargetPackage(target, subfolder));
} }
} }
@ -1560,36 +1565,38 @@ public class Base {
} }
static public Target getTarget() { static public TargetPlatform getTarget() {
System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target"))); TargetPackage pack = targetsTable.get(Preferences.get("target_package"));
System.out.println("Preferences.get(\"target\")" + Preferences.get("target")); TargetPlatform platform = pack.get(Preferences.get("target_platform"));
Target target = Base.targetsTable.get(Preferences.get("target")); if (platform == null) {
if (target == null) { System.out.println("Selected platform is not in list. Replace with default.");
System.out.println("default target is not in list. Replace with default."); Preferences.set("target_platform", "arduino");
Preferences.set("target", "arduino"); platform = pack.get(Preferences.get("target_platform"));
target = Base.targetsTable.get(Preferences.get("target"));
} }
return target; return platform;
} }
static public PreferencesMap getPlatformPreferences() { static public PreferencesMap getPlatformPreferences() {
Target target = getTarget(); return getTarget().getPlatform();
Map<String, PreferencesMap> platforms = target.getPlatforms();
return platforms.get(Preferences.get("platform"));
} }
//Get a specific platform // Search for a specific platform
static public PreferencesMap getPlatformPreferences(String platformName) { static public TargetPlatform getTargetPlatform(String pack, String platform) {
if (platformName == null) return targetsTable.get(pack).get(platform);
platformName = Preferences.get("platform");
Target target = getTarget();
Map<String, PreferencesMap> platforms = target.getPlatforms();
return platforms.get(platformName);
} }
// Get a specific platform preferences inside actual package
static public PreferencesMap getPlatformPreferences(String platformName) {
if (platformName == null)
platformName = Preferences.get("platform");
TargetPackage pack = targetsTable.get(Preferences.get("target_package"));
TargetPlatform target = pack.get(platformName);
return target.getPlatform();
}
static public PreferencesMap getBoardPreferences() { static public PreferencesMap getBoardPreferences() {
Target target = getTarget(); TargetPlatform target = getTarget();
if (target != null) { if (target != null) {
String board = Preferences.get("board"); String board = Preferences.get("board");
return target.getBoards().get(board); return target.getBoards().get(board);

View File

@ -30,6 +30,7 @@ import java.util.*;
import javax.swing.*; import javax.swing.*;
import processing.app.helpers.PreferencesMap;
import processing.app.syntax.*; import processing.app.syntax.*;
import processing.core.*; import processing.core.*;
import static processing.app.I18n._; import static processing.app.I18n._;

View File

@ -26,34 +26,35 @@
package processing.app.debug; package processing.app.debug;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import processing.app.Base; import processing.app.Base;
import processing.app.Preferences; import processing.app.Preferences;
import processing.app.SerialException; import processing.app.SerialException;
import processing.app.helpers.PreferencesMap;
import java.io.*;
import java.util.*;
public class AvrdudeUploader extends Uploader { public class AvrdudeUploader extends Uploader {
public AvrdudeUploader() {
}
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer) public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
throws RunnerException, SerialException { throws RunnerException, SerialException {
Map<String, String> boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = Base.getBoardPreferences();
// if no protocol is specified for this board, assume it lacks a // if no protocol is specified for this board, assume it lacks a
// bootloader and upload using the selected programmer. // bootloader and upload using the selected programmer.
if (usingProgrammer || boardPreferences.get("upload.protocol") == null) { if (usingProgrammer || boardPreferences.get("upload.protocol") == null) {
String programmer = Preferences.get("programmer"); String programmer = Preferences.get("programmer");
Target target = Base.getTarget(); TargetPlatform targetPlatform = Base.getTarget();
if (programmer.indexOf(":") != -1) { if (programmer.contains(":")) {
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":"))); String[] split = programmer.split(":");
programmer = programmer.substring(programmer.indexOf(":") + 1); targetPlatform = Base.getTargetPlatform(split[0], split[1]);
programmer = split[2];
} }
Collection params = getProgrammerCommands(target, programmer); Collection<String> params = getProgrammerCommands(targetPlatform, programmer);
params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i"); params.add("-Uflash:w:" + buildPath + File.separator + className + ".hex:i");
return avrdude(params); return avrdude(params);
} }
@ -63,8 +64,8 @@ public class AvrdudeUploader extends Uploader {
private boolean uploadViaBootloader(String buildPath, String className) private boolean uploadViaBootloader(String buildPath, String className)
throws RunnerException, SerialException { throws RunnerException, SerialException {
Map<String, String> boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = Base.getBoardPreferences();
List commandDownloader = new ArrayList(); List<String> commandDownloader = new ArrayList<String>();
String protocol = boardPreferences.get("upload.protocol"); String protocol = boardPreferences.get("upload.protocol");
// avrdude wants "stk500v1" to distinguish it from stk500v2 // avrdude wants "stk500v1" to distinguish it from stk500v2
@ -88,17 +89,18 @@ public class AvrdudeUploader extends Uploader {
public boolean burnBootloader() throws RunnerException { public boolean burnBootloader() throws RunnerException {
String programmer = Preferences.get("programmer"); String programmer = Preferences.get("programmer");
Target target = Base.getTarget(); TargetPlatform targetPlatform = Base.getTarget();
if (programmer.indexOf(":") != -1) { if (programmer.contains(":")) {
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":"))); String[] split = programmer.split(":");
programmer = programmer.substring(programmer.indexOf(":") + 1); targetPlatform = Base.getTargetPlatform(split[0], split[1]);
programmer = split[2];
} }
return burnBootloader(getProgrammerCommands(target, programmer)); return burnBootloader(getProgrammerCommands(targetPlatform, programmer));
} }
private Collection getProgrammerCommands(Target target, String programmer) { private Collection<String> getProgrammerCommands(TargetPlatform target, String programmer) {
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer); PreferencesMap programmerPreferences = target.getProgrammers().get(programmer);
List params = new ArrayList(); List<String> params = new ArrayList<String>();
params.add("-c" + programmerPreferences.get("protocol")); params.add("-c" + programmerPreferences.get("protocol"));
if ("usb".equals(programmerPreferences.get("communication"))) { if ("usb".equals(programmerPreferences.get("communication"))) {
@ -122,10 +124,10 @@ public class AvrdudeUploader extends Uploader {
return params; return params;
} }
protected boolean burnBootloader(Collection params) protected boolean burnBootloader(Collection<String> params)
throws RunnerException { throws RunnerException {
Map<String, String> boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = Base.getBoardPreferences();
List fuses = new ArrayList(); List<String> fuses = new ArrayList<String>();
fuses.add("-e"); // erase the chip fuses.add("-e"); // erase the chip
if (boardPreferences.get("bootloader.unlock_bits") != null) if (boardPreferences.get("bootloader.unlock_bits") != null)
fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m"); fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m");
@ -141,26 +143,27 @@ public class AvrdudeUploader extends Uploader {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
Target t; List<String> bootloader = new ArrayList<String>();
List bootloader = new ArrayList();
String bootloaderPath = boardPreferences.get("bootloader.path"); String bootloaderPath = boardPreferences.get("bootloader.path");
if (bootloaderPath != null) { if (bootloaderPath != null) {
if (bootloaderPath.indexOf(':') == -1) { TargetPlatform targetPlatform;
t = Base.getTarget(); // the current target (associated with the board) if (bootloaderPath.contains(":")) {
} else { // the current target (associated with the board)
String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':')); targetPlatform = Base.getTarget();
t = Base.targetsTable.get(targetName); } else {
bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1); String[] split = bootloaderPath.split(":", 3);
} targetPlatform = Base.getTargetPlatform(split[0], split[1]);
bootloaderPath = split[2];
File bootloadersFile = new File(t.getFolder(), "bootloaders"); }
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
bootloaderPath = bootloaderFile.getAbsolutePath(); File bootloadersFile = new File(targetPlatform.getFolder(), "bootloaders");
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator + bootloaderPath = bootloaderFile.getAbsolutePath();
boardPreferences.get("bootloader.file") + ":i");
} bootloader.add("-Uflash:w:" + bootloaderPath + File.separator
+ boardPreferences.get("bootloader.file") + ":i");
}
if (boardPreferences.get("bootloader.lock_bits") != null) if (boardPreferences.get("bootloader.lock_bits") != null)
bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m"); bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m");
@ -170,14 +173,14 @@ public class AvrdudeUploader extends Uploader {
return true; return true;
} }
public boolean avrdude(Collection p1, Collection p2) throws RunnerException { public boolean avrdude(Collection<String> p1, Collection<String> p2) throws RunnerException {
ArrayList p = new ArrayList(p1); List<String> p = new ArrayList<String>(p1);
p.addAll(p2); p.addAll(p2);
return avrdude(p); return avrdude(p);
} }
public boolean avrdude(Collection params) throws RunnerException { public boolean avrdude(Collection<String> params) throws RunnerException {
List commandDownloader = new ArrayList(); List<String> commandDownloader = new ArrayList<String>();
if(Base.isLinux()) { if(Base.isLinux()) {
if ((new File(Base.getHardwarePath() + "/tools/" + "avrdude")).exists()) { if ((new File(Base.getHardwarePath() + "/tools/" + "avrdude")).exists()) {

View File

@ -36,11 +36,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import processing.app.Base; import processing.app.Base;
import processing.app.PreferencesMap;
import processing.app.I18n; import processing.app.I18n;
import processing.app.Preferences; import processing.app.Preferences;
import processing.app.Sketch; import processing.app.Sketch;
import processing.app.SketchCode; import processing.app.SketchCode;
import processing.app.helpers.PreferencesMap;
import processing.core.PApplet; import processing.core.PApplet;
public class Compiler implements MessageConsumer { public class Compiler implements MessageConsumer {
@ -82,103 +82,102 @@ public class Compiler implements MessageConsumer {
PreferencesMap boardPreferences = Base.getBoardPreferences(); PreferencesMap boardPreferences = Base.getBoardPreferences();
// Check for null platform, and use system default if not found // Check for null platform, and use system default if not found
PreferencesMap platformPreferences; String platform = boardPreferences.get("platform");
String platform = boardPreferences.get("platform"); PreferencesMap platformPreferences;
if (platform == null) if (platform == null)
platformPreferences = Base.getPlatformPreferences(); platformPreferences = Base.getPlatformPreferences();
else else
platformPreferences = Base.getPlatformPreferences(platform); platformPreferences = Base.getPlatformPreferences(platform);
// Merge all the global preference configuration
PreferencesMap configPreferences = new PreferencesMap();
configPreferences.putAll(Preferences.getMap());
configPreferences.putAll(platformPreferences);
configPreferences.putAll(boardPreferences);
for (String k : configPreferences.keySet()) {
if (configPreferences.get(k)==null)
configPreferences.put(k, "");
}
String avrBasePath = configPreferences.get("compiler.path");
if (avrBasePath == null)
{
avrBasePath = Base.getAvrBasePath();
System.out.println("avrBasePath: " + avrBasePath);
}
else
{
System.out.println("avrBasePath:exists: " + avrBasePath);
//Put in the system path in the compiler path if available // Merge all the global preference configuration
MessageFormat compileFormat = new MessageFormat(avrBasePath); PreferencesMap configPreferences = new PreferencesMap();
String basePath = System.getProperty("user.dir"); configPreferences.putAll(Preferences.getMap());
if (Base.isMacOS()) { configPreferences.putAll(platformPreferences);
//logger.debug("basePath: " + basePath); configPreferences.putAll(boardPreferences);
basePath += "/Arduino.app/Contents/Resources/Java"; for (String k : configPreferences.keySet()) {
if (configPreferences.get(k) == null)
configPreferences.put(k, "");
} }
Object[] Args = {basePath};
avrBasePath = compileFormat.format( Args );
System.out.println("avrBasePath:new: " + avrBasePath);
}
board = configPreferences.get("board");
if (board == "")
board = "_UNKNOWN";
String core = configPreferences.get("build.core");
if (core == null) {
RunnerException re = new RunnerException(_("No board selected; please choose a board from the Tools > Board menu."));
re.hideStackTrace();
throw re;
}
String corePath; String avrBasePath = configPreferences.get("compiler.path");
if (core.indexOf(':') == -1) { if (avrBasePath == null) {
Target t = Base.getTarget(); avrBasePath = Base.getAvrBasePath();
File coreFolder = new File(new File(t.getFolder(), "cores"), core); System.out.println("avrBasePath: " + avrBasePath);
corePath = coreFolder.getAbsolutePath(); } else {
System.out.println("avrBasePath:exists: " + avrBasePath);
// Put in the system path in the compiler path if available
MessageFormat compileFormat = new MessageFormat(avrBasePath);
String basePath = System.getProperty("user.dir");
if (Base.isMacOS()) {
// logger.debug("basePath: " + basePath);
basePath += "/Arduino.app/Contents/Resources/Java";
}
Object[] Args = { basePath };
avrBasePath = compileFormat.format(Args);
System.out.println("avrBasePath:new: " + avrBasePath);
}
board = configPreferences.get("board");
if (board == "")
board = "_UNKNOWN";
String core = configPreferences.get("build.core");
if (core == null) {
RunnerException re = new RunnerException(
_("No board selected; please choose a board from the Tools > Board menu."));
re.hideStackTrace();
throw re;
}
File coreFolder;
if (!core.contains(":")) {
TargetPlatform t = Base.getTarget();
coreFolder = new File(t.getFolder(), "cores");
coreFolder = new File(coreFolder, core);
} else { } else {
Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':'))); String[] split = core.split(":", 3);
File coreFolder = new File(t.getFolder(), "cores"); TargetPlatform t = Base.getTargetPlatform(split[0], split[1]);
coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1)); coreFolder = new File(t.getFolder(), "cores");
corePath = coreFolder.getAbsolutePath(); coreFolder = new File(coreFolder, split[2]);
} }
String corePath = coreFolder.getAbsolutePath();
String variant = boardPreferences.get("build.variant"); String variant = boardPreferences.get("build.variant");
String variantPath = null; String variantPath = null;
if (variant != null) { if (variant != null) {
if (variant.indexOf(':') == -1) { File variantFolder;
Target t = Base.getTarget(); if (!variant.contains(":")) {
File variantFolder = new File(new File(t.getFolder(), "variants"), variant); TargetPlatform t = Base.getTarget();
variantPath = variantFolder.getAbsolutePath(); variantFolder = new File(t.getFolder(), "variants");
} else { variantFolder = new File(variantFolder, variant);
Target t = Base.targetsTable.get(variant.substring(0, variant.indexOf(':'))); } else {
File variantFolder = new File(t.getFolder(), "variants"); String[] split = variant.split(":");
variantFolder = new File(variantFolder, variant.substring(variant.indexOf(':') + 1)); TargetPlatform t = Base.getTargetPlatform(split[0], split[1]);
variantPath = variantFolder.getAbsolutePath(); variantFolder = new File(t.getFolder(), "variants");
} variantFolder = new File(variantFolder, split[2]);
} }
variantPath = variantFolder.getAbsolutePath();
}
// 0. include paths for core + all libraries // 0. include paths for core + all libraries
sketch.setCompilingProgress(20); sketch.setCompilingProgress(20);
List<String> includePaths = new ArrayList<String>(); List<String> includePaths = new ArrayList<String>();
includePaths.add(corePath); includePaths.add(corePath);
if (variantPath != null) if (variantPath != null)
includePaths.add(variantPath); includePaths.add(variantPath);
for (File file : sketch.getImportedLibraries()) for (File file : sketch.getImportedLibraries())
includePaths.add(file.getPath()); includePaths.add(file.getPath());
// 1. compile the sketch (already in the buildPath) // 1. compile the sketch (already in the buildPath)
System.out.println("1. compileSketch"); System.out.println("1. compileSketch");
sketch.setCompilingProgress(30); sketch.setCompilingProgress(30);
compileSketch(avrBasePath, _buildPath, includePaths, configPreferences); compileSketch(avrBasePath, _buildPath, includePaths, configPreferences);
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/ // 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
// 2. compile the libraries, outputting .o files to: // Doesn't really use configPreferences
// <buildPath>/<library>/ System.out.println("2. compileLibraries");
//Doesn't really use configPreferences sketch.setCompilingProgress(40);
System.out.println("2. compileLibraries"); compileLibraries(avrBasePath, _buildPath, includePaths, configPreferences);
sketch.setCompilingProgress(40);
compileLibraries(avrBasePath, _buildPath, includePaths, configPreferences);
/* /*
for (File libraryFolder : sketch.getImportedLibraries()) { for (File libraryFolder : sketch.getImportedLibraries()) {
@ -206,13 +205,13 @@ public class Compiler implements MessageConsumer {
} }
*/ */
// 3. compile the core, outputting .o files to <buildPath> and then // 3. compile the core, outputting .o files to <buildPath> and then
// collecting them into the core.a library file. // collecting them into the core.a library file.
System.out.println("3. compileCore"); System.out.println("3. compileCore");
System.out.println("corePath: " + corePath); System.out.println("corePath: " + corePath);
sketch.setCompilingProgress(50); sketch.setCompilingProgress(50);
compileCore(avrBasePath, _buildPath, corePath, variant, variantPath, configPreferences); compileCore(avrBasePath, _buildPath, corePath, variant, variantPath,
configPreferences);
/* /*
includePaths.clear(); includePaths.clear();
@ -237,10 +236,11 @@ public class Compiler implements MessageConsumer {
execAsynchronously(commandAR); execAsynchronously(commandAR);
} }
*/ */
// 4. link it all together into the .elf file // 4. link it all together into the .elf file
sketch.setCompilingProgress(60); sketch.setCompilingProgress(60);
System.out.println("4. compileLink"); System.out.println("4. compileLink");
compileLink(avrBasePath, _buildPath, corePath, includePaths, configPreferences); compileLink(avrBasePath, _buildPath, corePath, includePaths,
configPreferences);
/* /*
List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
@ -271,8 +271,8 @@ public class Compiler implements MessageConsumer {
List commandObjcopy; List commandObjcopy;
*/ */
// 5. extract EEPROM data (from EEMEM directive) to .eep file. // 5. extract EEPROM data (from EEMEM directive) to .eep file.
sketch.setCompilingProgress(70); sketch.setCompilingProgress(70);
/* /*
commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy = new ArrayList(baseCommandObjcopy);
commandObjcopy.add(2, "ihex"); commandObjcopy.add(2, "ihex");
@ -286,11 +286,11 @@ public class Compiler implements MessageConsumer {
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep");
execAsynchronously(commandObjcopy); execAsynchronously(commandObjcopy);
*/ */
System.out.println("5. compileEep"); System.out.println("5. compileEep");
compileEep(avrBasePath, _buildPath, includePaths, configPreferences); compileEep(avrBasePath, _buildPath, includePaths, configPreferences);
// 6. build the .hex file // 6. build the .hex file
sketch.setCompilingProgress(80); sketch.setCompilingProgress(80);
/* /*
commandObjcopy = new ArrayList(baseCommandObjcopy); commandObjcopy = new ArrayList(baseCommandObjcopy);
commandObjcopy.add(2, "ihex"); commandObjcopy.add(2, "ihex");
@ -299,13 +299,12 @@ public class Compiler implements MessageConsumer {
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex"); commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex");
execAsynchronously(commandObjcopy); execAsynchronously(commandObjcopy);
*/ */
System.out.println("6. compileHex"); System.out.println("6. compileHex");
compileHex(avrBasePath, _buildPath, includePaths, configPreferences); compileHex(avrBasePath, _buildPath, includePaths, configPreferences);
sketch.setCompilingProgress(90);
return true;
}
sketch.setCompilingProgress(90);
return true;
}
private List<File> compileFiles(String avrBasePath, private List<File> compileFiles(String avrBasePath,
String buildPath, List<String> includePaths, String buildPath, List<String> includePaths,
@ -425,22 +424,20 @@ public class Compiler implements MessageConsumer {
*/ */
private void execAsynchronously(String[] command) throws RunnerException { private void execAsynchronously(String[] command) throws RunnerException {
//eliminate any empty array entries // eliminate any empty array entries
List<String> stringList = new ArrayList<String>(); List<String> stringList = new ArrayList<String>();
for(String string : command) { for (String string : command) {
string = string.trim(); string = string.trim();
if(string != null && string.length() > 0) { if (!string.isEmpty())
stringList.add(string); stringList.add(string);
} }
} command = stringList.toArray(new String[stringList.size()]);
command = stringList.toArray(new String[stringList.size()]);
int result = 0; int result = 0;
if (verbose || Preferences.getBoolean("build.verbose")) { if (verbose || Preferences.getBoolean("build.verbose")) {
for(int j = 0; j < command.length; j++) { for (String c : command)
System.out.print(command[j] + " "); System.out.print(c + " ");
}
System.out.println(); System.out.println();
} }
@ -483,18 +480,18 @@ public class Compiler implements MessageConsumer {
//System.out.println("throwing up " + exception); //System.out.println("throwing up " + exception);
if (exception != null) { throw exception; } if (exception != null) { throw exception; }
if (result > 1) { if (result > 1) {
// a failure in the tool (e.g. unable to locate a sub-executable) // a failure in the tool (e.g. unable to locate a sub-executable)
System.err.println( System.err
I18n.format(_("{0} returned {1}"), command[0], result)); .println(I18n.format(_("{0} returned {1}"), command[0], result));
} }
if (result != 0) { if (result != 0) {
RunnerException re = new RunnerException(_("Error compiling.")); RunnerException re = new RunnerException(_("Error compiling."));
re.hideStackTrace(); re.hideStackTrace();
throw re; throw re;
} }
System.out.println("execAsync: Done."); System.out.println("execAsync: Done.");
} }

View File

@ -0,0 +1,44 @@
package processing.app.debug;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import processing.app.helpers.filefilters.OnlyDirs;
public class TargetPackage {
String name;
File folder;
Map<String, TargetPlatform> platforms = new HashMap<String, TargetPlatform>();
public TargetPackage(String _name, File _folder) {
name = _name;
folder = _folder;
String[] platformsList = folder.list(new OnlyDirs());
for (String platformName : platformsList) {
File platformFolder = new File(folder, platformName);
TargetPlatform platform = new TargetPlatform(platformName, platformFolder);
platforms.put(platformName, platform);
}
}
public Map<String, TargetPlatform> getPlatforms() {
return platforms;
}
public Collection<TargetPlatform> platforms() {
return platforms.values();
}
public TargetPlatform get(String platform) {
return platforms.get(platform);
}
public String getName() {
return name;
}
}

View File

@ -29,22 +29,22 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import processing.app.PreferencesMap; import processing.app.helpers.PreferencesMap;
public class Target { public class TargetPlatform {
private String name; private String name;
private File folder; private File folder;
private Map<String, PreferencesMap> boards; private Map<String, PreferencesMap> boards;
private Map<String, PreferencesMap> programmers; private Map<String, PreferencesMap> programmers;
private Map<String, PreferencesMap> platforms; private PreferencesMap platform;
public Target(String _name, File _folder) { public TargetPlatform(String _name, File _folder) {
System.out.println("Target: constructor start, name: " + _name); System.out.println("TargetPlatform: constructor start, name: " + _name);
name = _name; name = _name;
folder = _folder; folder = _folder;
boards = new HashMap<String, PreferencesMap>(); boards = new HashMap<String, PreferencesMap>();
programmers = new HashMap<String, PreferencesMap>(); programmers = new HashMap<String, PreferencesMap>();
platforms = new HashMap<String, PreferencesMap>(); platform = new PreferencesMap();
try { try {
File boardsFile = new File(_folder, "boards.txt"); File boardsFile = new File(_folder, "boards.txt");
@ -59,11 +59,8 @@ public class Target {
try { try {
File platformsFile = new File(_folder, "platforms.txt"); File platformsFile = new File(_folder, "platforms.txt");
if (platformsFile.exists()) { if (platformsFile.exists())
PreferencesMap platformPreferences = new PreferencesMap(); platform.load(platformsFile);
platformPreferences.load(platformsFile);
platforms = platformPreferences.createFirstLevelMap();
}
} catch (Exception e) { } catch (Exception e) {
System.err.println("Error loading platforms from platform.txt: " System.err.println("Error loading platforms from platform.txt: "
+ e); + e);
@ -99,7 +96,7 @@ public class Target {
return programmers; return programmers;
} }
public Map<String, PreferencesMap> getPlatforms() { public PreferencesMap getPlatform() {
return platforms; return platform;
} }
} }

View File

@ -21,7 +21,7 @@
$Id$ $Id$
*/ */
package processing.app; package processing.app.helpers;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@ -0,0 +1,43 @@
/*
OnlyDirs - FilenameFilter that accepts only directories (CVS, .svn,
.DS_Store files are excluded as well)
Part of the Arduino project - http://www.arduino.cc/
Copyright (c) 2011 Cristian Maglie
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app.helpers.filefilters;
import java.io.File;
import java.io.FilenameFilter;
/**
* This filter accepts only directories (excluding .DS_Store files, .svn
* folders, etc)
*
* @author Cristian Maglie
*/
public class OnlyDirs implements FilenameFilter {
@Override
public boolean accept(File dir, String name) {
if (name.charAt(0) == '.')
return false;
if (name.equals("CVS"))
return false;
return new File(dir, name).isDirectory();
}
}

View File

@ -237,9 +237,9 @@ run.present.exclusive = false
run.present.exclusive.macosx = true run.present.exclusive.macosx = true
# ARDUINO PREFERENCES # ARDUINO PREFERENCES
target_package = arduino
target_platform = avr
board = uno board = uno
target = arduino
platform = avr
software=ARDUINO software=ARDUINO
programmer = arduino:avrispmkii programmer = arduino:avrispmkii

Some files were not shown because too many files have changed in this diff Show More