mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01: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:
parent
dc616601cd
commit
1b3ae5fa63
@ -31,7 +31,10 @@ import java.util.List;
|
||||
import javax.swing.*;
|
||||
|
||||
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 static processing.app.I18n._;
|
||||
|
||||
@ -90,7 +93,7 @@ public class Base {
|
||||
// found in the sketchbook)
|
||||
static public String librariesClassPath;
|
||||
|
||||
static public Map<String, Target> targetsTable;
|
||||
static public Map<String, TargetPackage> targetsTable;
|
||||
|
||||
// Location for untitled items
|
||||
static File untitledFolder;
|
||||
@ -267,7 +270,7 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
targetsTable = new HashMap<String, Target>();
|
||||
targetsTable = new HashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
|
||||
@ -939,52 +942,51 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
public void rebuildImportMenu(JMenu importMenu) {
|
||||
//System.out.println("rebuilding import menu");
|
||||
importMenu.removeAll();
|
||||
public void rebuildImportMenu(JMenu importMenu) {
|
||||
// System.out.println("rebuilding import menu");
|
||||
importMenu.removeAll();
|
||||
|
||||
// reset the set of libraries
|
||||
libraries = new HashSet<File>();
|
||||
// reset the set of libraries
|
||||
libraries = new HashSet<File>();
|
||||
|
||||
// reset the table mapping imports to libraries
|
||||
importToLibraryTable = new HashMap<String, File>();
|
||||
// reset the table mapping imports to libraries
|
||||
importToLibraryTable = new HashMap<String, File>();
|
||||
|
||||
// Add from the "libraries" subfolder in the Processing directory
|
||||
//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");
|
||||
// Add from the "libraries" subfolder in the Processing directory
|
||||
// Choose which library to add by chip platform
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
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);
|
||||
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) {
|
||||
//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");
|
||||
menu.removeAll();
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
for (Target target : targetsTable.values()) {
|
||||
for (String board : target.getBoards().keySet()) {
|
||||
AbstractAction action =
|
||||
new AbstractAction(target.getBoards().get(board).get("name")) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
//System.out.println("Switching to " + target + ":" + board);
|
||||
Preferences.set("target", (String) getValue("target"));
|
||||
Preferences.set("board", (String) getValue("board"));
|
||||
onBoardOrPortChange();
|
||||
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);
|
||||
if (target.getName().equals(Preferences.get("target")) &&
|
||||
board.equals(Preferences.get("board"))) {
|
||||
item.setSelected(true);
|
||||
}
|
||||
group.add(item);
|
||||
menu.add(item);
|
||||
}
|
||||
}
|
||||
for (TargetPackage targetPackage : targetsTable.values()) {
|
||||
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||
for (String board : targetPlatform.getBoards().keySet()) {
|
||||
AbstractAction action = new AbstractAction(targetPlatform.getBoards().get(
|
||||
board).get("name")) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
// System.out.println("Switching to " + target + ":" + board);
|
||||
Preferences.set("package", (String) getValue("package"));
|
||||
Preferences.set("platform", (String) getValue("platform"));
|
||||
Preferences.set("board", (String) getValue("board"));
|
||||
onBoardOrPortChange();
|
||||
Sketch.buildSettingChanged();
|
||||
// Debug: created new imports menu based on board
|
||||
rebuildImportMenu(activeEditor.importMenu);
|
||||
}
|
||||
};
|
||||
action.putValue("package", targetPackage.getName());
|
||||
action.putValue("platform", targetPlatform.getName());
|
||||
action.putValue("board", board);
|
||||
JMenuItem item = new JRadioButtonMenuItem(action);
|
||||
if (targetPackage.getName().equals(Preferences.get("package"))
|
||||
&& targetPlatform.getName().equals(Preferences.get("platform"))
|
||||
&& 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");
|
||||
menu.removeAll();
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
for (Target target : targetsTable.values()) {
|
||||
for (String programmer : target.getProgrammers().keySet()) {
|
||||
AbstractAction action =
|
||||
new AbstractAction(
|
||||
target.getProgrammers().get(programmer).get("name")) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
Preferences.set("programmer", getValue("target") + ":" +
|
||||
getValue("programmer"));
|
||||
}
|
||||
};
|
||||
action.putValue("target", target.getName());
|
||||
action.putValue("programmer", programmer);
|
||||
JMenuItem item = new JRadioButtonMenuItem(action);
|
||||
if (Preferences.get("programmer").equals(target.getName() + ":" +
|
||||
programmer)) {
|
||||
item.setSelected(true);
|
||||
}
|
||||
group.add(item);
|
||||
menu.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (TargetPackage targetPackage : targetsTable.values()) {
|
||||
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||
for (String programmer : targetPlatform.getProgrammers().keySet()) {
|
||||
String id = targetPackage.getName() + ":" + targetPlatform.getName() + ":"
|
||||
+ programmer;
|
||||
AbstractAction action = new AbstractAction(targetPlatform.getProgrammers()
|
||||
.get(programmer).get("name")) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
Preferences.set("programmer", "" + getValue("id"));
|
||||
}
|
||||
};
|
||||
// action.putValue("package", targetPackage.getName());
|
||||
// action.putValue("platform", targetPlatform.getName());
|
||||
// action.putValue("programmer", programmer);
|
||||
action.putValue("id", id);
|
||||
JMenuItem item = new JRadioButtonMenuItem(action);
|
||||
if (Preferences.get("programmer").equals(id))
|
||||
item.setSelected(true);
|
||||
group.add(item);
|
||||
menu.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -1260,14 +1271,8 @@ public class Base {
|
||||
protected void loadHardware(File folder) {
|
||||
if (!folder.isDirectory()) return;
|
||||
|
||||
String list[] = folder.list(new FilenameFilter() {
|
||||
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());
|
||||
}
|
||||
});
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null) return;
|
||||
|
||||
@ -1277,7 +1282,7 @@ public class Base {
|
||||
|
||||
for (String target : list) {
|
||||
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() {
|
||||
System.out.println("Base.targetsTable.get(Preferences.get(\"target\"))" + Base.targetsTable.get(Preferences.get("target")));
|
||||
System.out.println("Preferences.get(\"target\")" + Preferences.get("target"));
|
||||
Target target = Base.targetsTable.get(Preferences.get("target"));
|
||||
if (target == null) {
|
||||
System.out.println("default target is not in list. Replace with default.");
|
||||
Preferences.set("target", "arduino");
|
||||
target = Base.targetsTable.get(Preferences.get("target"));
|
||||
static public TargetPlatform getTarget() {
|
||||
TargetPackage pack = targetsTable.get(Preferences.get("target_package"));
|
||||
TargetPlatform platform = pack.get(Preferences.get("target_platform"));
|
||||
if (platform == null) {
|
||||
System.out.println("Selected platform is not in list. Replace with default.");
|
||||
Preferences.set("target_platform", "arduino");
|
||||
platform = pack.get(Preferences.get("target_platform"));
|
||||
}
|
||||
return target;
|
||||
return platform;
|
||||
}
|
||||
|
||||
|
||||
static public PreferencesMap getPlatformPreferences() {
|
||||
Target target = getTarget();
|
||||
Map<String, PreferencesMap> platforms = target.getPlatforms();
|
||||
return platforms.get(Preferences.get("platform"));
|
||||
return getTarget().getPlatform();
|
||||
}
|
||||
|
||||
//Get a specific platform
|
||||
static public PreferencesMap getPlatformPreferences(String platformName) {
|
||||
if (platformName == null)
|
||||
platformName = Preferences.get("platform");
|
||||
Target target = getTarget();
|
||||
Map<String, PreferencesMap> platforms = target.getPlatforms();
|
||||
return platforms.get(platformName);
|
||||
// Search for a specific platform
|
||||
static public TargetPlatform getTargetPlatform(String pack, String platform) {
|
||||
return targetsTable.get(pack).get(platform);
|
||||
}
|
||||
|
||||
// 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() {
|
||||
Target target = getTarget();
|
||||
TargetPlatform target = getTarget();
|
||||
if (target != null) {
|
||||
String board = Preferences.get("board");
|
||||
return target.getBoards().get(board);
|
||||
|
@ -30,6 +30,7 @@ import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.syntax.*;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
|
@ -26,34 +26,35 @@
|
||||
|
||||
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.Preferences;
|
||||
import processing.app.SerialException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
public class AvrdudeUploader extends Uploader {
|
||||
public AvrdudeUploader() {
|
||||
}
|
||||
|
||||
public boolean uploadUsingPreferences(String buildPath, String className, boolean usingProgrammer)
|
||||
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
|
||||
// bootloader and upload using the selected programmer.
|
||||
if (usingProgrammer || boardPreferences.get("upload.protocol") == null) {
|
||||
String programmer = Preferences.get("programmer");
|
||||
Target target = Base.getTarget();
|
||||
TargetPlatform targetPlatform = Base.getTarget();
|
||||
|
||||
if (programmer.indexOf(":") != -1) {
|
||||
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
|
||||
programmer = programmer.substring(programmer.indexOf(":") + 1);
|
||||
if (programmer.contains(":")) {
|
||||
String[] split = programmer.split(":");
|
||||
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");
|
||||
return avrdude(params);
|
||||
}
|
||||
@ -63,8 +64,8 @@ public class AvrdudeUploader extends Uploader {
|
||||
|
||||
private boolean uploadViaBootloader(String buildPath, String className)
|
||||
throws RunnerException, SerialException {
|
||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||
List commandDownloader = new ArrayList();
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
List<String> commandDownloader = new ArrayList<String>();
|
||||
String protocol = boardPreferences.get("upload.protocol");
|
||||
|
||||
// avrdude wants "stk500v1" to distinguish it from stk500v2
|
||||
@ -88,17 +89,18 @@ public class AvrdudeUploader extends Uploader {
|
||||
|
||||
public boolean burnBootloader() throws RunnerException {
|
||||
String programmer = Preferences.get("programmer");
|
||||
Target target = Base.getTarget();
|
||||
if (programmer.indexOf(":") != -1) {
|
||||
target = Base.targetsTable.get(programmer.substring(0, programmer.indexOf(":")));
|
||||
programmer = programmer.substring(programmer.indexOf(":") + 1);
|
||||
TargetPlatform targetPlatform = Base.getTarget();
|
||||
if (programmer.contains(":")) {
|
||||
String[] split = programmer.split(":");
|
||||
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) {
|
||||
Map<String, String> programmerPreferences = target.getProgrammers().get(programmer);
|
||||
List params = new ArrayList();
|
||||
private Collection<String> getProgrammerCommands(TargetPlatform target, String programmer) {
|
||||
PreferencesMap programmerPreferences = target.getProgrammers().get(programmer);
|
||||
List<String> params = new ArrayList<String>();
|
||||
params.add("-c" + programmerPreferences.get("protocol"));
|
||||
|
||||
if ("usb".equals(programmerPreferences.get("communication"))) {
|
||||
@ -122,10 +124,10 @@ public class AvrdudeUploader extends Uploader {
|
||||
return params;
|
||||
}
|
||||
|
||||
protected boolean burnBootloader(Collection params)
|
||||
protected boolean burnBootloader(Collection<String> params)
|
||||
throws RunnerException {
|
||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||
List fuses = new ArrayList();
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
List<String> fuses = new ArrayList<String>();
|
||||
fuses.add("-e"); // erase the chip
|
||||
if (boardPreferences.get("bootloader.unlock_bits") != null)
|
||||
fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m");
|
||||
@ -141,26 +143,27 @@ public class AvrdudeUploader extends Uploader {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {}
|
||||
|
||||
Target t;
|
||||
List bootloader = new ArrayList();
|
||||
List<String> bootloader = new ArrayList<String>();
|
||||
String bootloaderPath = boardPreferences.get("bootloader.path");
|
||||
|
||||
if (bootloaderPath != null) {
|
||||
if (bootloaderPath.indexOf(':') == -1) {
|
||||
t = Base.getTarget(); // the current target (associated with the board)
|
||||
} else {
|
||||
String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':'));
|
||||
t = Base.targetsTable.get(targetName);
|
||||
bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1);
|
||||
}
|
||||
|
||||
File bootloadersFile = new File(t.getFolder(), "bootloaders");
|
||||
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
|
||||
bootloaderPath = bootloaderFile.getAbsolutePath();
|
||||
|
||||
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator +
|
||||
boardPreferences.get("bootloader.file") + ":i");
|
||||
}
|
||||
if (bootloaderPath != null) {
|
||||
TargetPlatform targetPlatform;
|
||||
if (bootloaderPath.contains(":")) {
|
||||
// the current target (associated with the board)
|
||||
targetPlatform = Base.getTarget();
|
||||
} else {
|
||||
String[] split = bootloaderPath.split(":", 3);
|
||||
targetPlatform = Base.getTargetPlatform(split[0], split[1]);
|
||||
bootloaderPath = split[2];
|
||||
}
|
||||
|
||||
File bootloadersFile = new File(targetPlatform.getFolder(), "bootloaders");
|
||||
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
|
||||
bootloaderPath = bootloaderFile.getAbsolutePath();
|
||||
|
||||
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator
|
||||
+ boardPreferences.get("bootloader.file") + ":i");
|
||||
}
|
||||
if (boardPreferences.get("bootloader.lock_bits") != null)
|
||||
bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m");
|
||||
|
||||
@ -170,14 +173,14 @@ public class AvrdudeUploader extends Uploader {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean avrdude(Collection p1, Collection p2) throws RunnerException {
|
||||
ArrayList p = new ArrayList(p1);
|
||||
public boolean avrdude(Collection<String> p1, Collection<String> p2) throws RunnerException {
|
||||
List<String> p = new ArrayList<String>(p1);
|
||||
p.addAll(p2);
|
||||
return avrdude(p);
|
||||
}
|
||||
|
||||
public boolean avrdude(Collection params) throws RunnerException {
|
||||
List commandDownloader = new ArrayList();
|
||||
public boolean avrdude(Collection<String> params) throws RunnerException {
|
||||
List<String> commandDownloader = new ArrayList<String>();
|
||||
|
||||
if(Base.isLinux()) {
|
||||
if ((new File(Base.getHardwarePath() + "/tools/" + "avrdude")).exists()) {
|
||||
|
@ -36,11 +36,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.PreferencesMap;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Preferences;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.core.PApplet;
|
||||
|
||||
public class Compiler implements MessageConsumer {
|
||||
@ -82,103 +82,102 @@ public class Compiler implements MessageConsumer {
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
|
||||
// Check for null platform, and use system default if not found
|
||||
PreferencesMap platformPreferences;
|
||||
String platform = boardPreferences.get("platform");
|
||||
if (platform == null)
|
||||
platformPreferences = Base.getPlatformPreferences();
|
||||
else
|
||||
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);
|
||||
String platform = boardPreferences.get("platform");
|
||||
PreferencesMap platformPreferences;
|
||||
if (platform == null)
|
||||
platformPreferences = Base.getPlatformPreferences();
|
||||
else
|
||||
platformPreferences = Base.getPlatformPreferences(platform);
|
||||
|
||||
//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";
|
||||
// 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, "");
|
||||
}
|
||||
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;
|
||||
if (core.indexOf(':') == -1) {
|
||||
Target t = Base.getTarget();
|
||||
File coreFolder = new File(new File(t.getFolder(), "cores"), core);
|
||||
corePath = coreFolder.getAbsolutePath();
|
||||
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
|
||||
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 {
|
||||
Target t = Base.targetsTable.get(core.substring(0, core.indexOf(':')));
|
||||
File coreFolder = new File(t.getFolder(), "cores");
|
||||
coreFolder = new File(coreFolder, core.substring(core.indexOf(':') + 1));
|
||||
corePath = coreFolder.getAbsolutePath();
|
||||
String[] split = core.split(":", 3);
|
||||
TargetPlatform t = Base.getTargetPlatform(split[0], split[1]);
|
||||
coreFolder = new File(t.getFolder(), "cores");
|
||||
coreFolder = new File(coreFolder, split[2]);
|
||||
}
|
||||
String corePath = coreFolder.getAbsolutePath();
|
||||
|
||||
String variant = boardPreferences.get("build.variant");
|
||||
String variantPath = null;
|
||||
if (variant != null) {
|
||||
if (variant.indexOf(':') == -1) {
|
||||
Target t = Base.getTarget();
|
||||
File variantFolder = new File(new File(t.getFolder(), "variants"), variant);
|
||||
variantPath = variantFolder.getAbsolutePath();
|
||||
} else {
|
||||
Target t = Base.targetsTable.get(variant.substring(0, variant.indexOf(':')));
|
||||
File variantFolder = new File(t.getFolder(), "variants");
|
||||
variantFolder = new File(variantFolder, variant.substring(variant.indexOf(':') + 1));
|
||||
variantPath = variantFolder.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
if (variant != null) {
|
||||
File variantFolder;
|
||||
if (!variant.contains(":")) {
|
||||
TargetPlatform t = Base.getTarget();
|
||||
variantFolder = new File(t.getFolder(), "variants");
|
||||
variantFolder = new File(variantFolder, variant);
|
||||
} else {
|
||||
String[] split = variant.split(":");
|
||||
TargetPlatform t = Base.getTargetPlatform(split[0], split[1]);
|
||||
variantFolder = new File(t.getFolder(), "variants");
|
||||
variantFolder = new File(variantFolder, split[2]);
|
||||
}
|
||||
variantPath = variantFolder.getAbsolutePath();
|
||||
}
|
||||
|
||||
// 0. include paths for core + all libraries
|
||||
sketch.setCompilingProgress(20);
|
||||
List<String> includePaths = new ArrayList<String>();
|
||||
includePaths.add(corePath);
|
||||
if (variantPath != null)
|
||||
includePaths.add(variantPath);
|
||||
for (File file : sketch.getImportedLibraries())
|
||||
includePaths.add(file.getPath());
|
||||
// 0. include paths for core + all libraries
|
||||
sketch.setCompilingProgress(20);
|
||||
List<String> includePaths = new ArrayList<String>();
|
||||
includePaths.add(corePath);
|
||||
if (variantPath != null)
|
||||
includePaths.add(variantPath);
|
||||
for (File file : sketch.getImportedLibraries())
|
||||
includePaths.add(file.getPath());
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
System.out.println("1. compileSketch");
|
||||
sketch.setCompilingProgress(30);
|
||||
compileSketch(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
System.out.println("1. compileSketch");
|
||||
sketch.setCompilingProgress(30);
|
||||
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>/
|
||||
//Doesn't really use configPreferences
|
||||
System.out.println("2. compileLibraries");
|
||||
sketch.setCompilingProgress(40);
|
||||
compileLibraries(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
||||
// Doesn't really use configPreferences
|
||||
System.out.println("2. compileLibraries");
|
||||
sketch.setCompilingProgress(40);
|
||||
compileLibraries(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
/*
|
||||
|
||||
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
|
||||
// collecting them into the core.a library file.
|
||||
System.out.println("3. compileCore");
|
||||
System.out.println("corePath: " + corePath);
|
||||
sketch.setCompilingProgress(50);
|
||||
compileCore(avrBasePath, _buildPath, corePath, variant, variantPath, configPreferences);
|
||||
|
||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||
// collecting them into the core.a library file.
|
||||
System.out.println("3. compileCore");
|
||||
System.out.println("corePath: " + corePath);
|
||||
sketch.setCompilingProgress(50);
|
||||
compileCore(avrBasePath, _buildPath, corePath, variant, variantPath,
|
||||
configPreferences);
|
||||
|
||||
/*
|
||||
includePaths.clear();
|
||||
@ -237,10 +236,11 @@ public class Compiler implements MessageConsumer {
|
||||
execAsynchronously(commandAR);
|
||||
}
|
||||
*/
|
||||
// 4. link it all together into the .elf file
|
||||
sketch.setCompilingProgress(60);
|
||||
System.out.println("4. compileLink");
|
||||
compileLink(avrBasePath, _buildPath, corePath, includePaths, configPreferences);
|
||||
// 4. link it all together into the .elf file
|
||||
sketch.setCompilingProgress(60);
|
||||
System.out.println("4. compileLink");
|
||||
compileLink(avrBasePath, _buildPath, corePath, includePaths,
|
||||
configPreferences);
|
||||
|
||||
/*
|
||||
List baseCommandLinker = new ArrayList(Arrays.asList(new String[] {
|
||||
@ -271,8 +271,8 @@ public class Compiler implements MessageConsumer {
|
||||
List commandObjcopy;
|
||||
*/
|
||||
|
||||
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
|
||||
sketch.setCompilingProgress(70);
|
||||
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
|
||||
sketch.setCompilingProgress(70);
|
||||
/*
|
||||
commandObjcopy = new ArrayList(baseCommandObjcopy);
|
||||
commandObjcopy.add(2, "ihex");
|
||||
@ -286,11 +286,11 @@ public class Compiler implements MessageConsumer {
|
||||
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".eep");
|
||||
execAsynchronously(commandObjcopy);
|
||||
*/
|
||||
System.out.println("5. compileEep");
|
||||
compileEep(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
// 6. build the .hex file
|
||||
sketch.setCompilingProgress(80);
|
||||
System.out.println("5. compileEep");
|
||||
compileEep(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
// 6. build the .hex file
|
||||
sketch.setCompilingProgress(80);
|
||||
/*
|
||||
commandObjcopy = new ArrayList(baseCommandObjcopy);
|
||||
commandObjcopy.add(2, "ihex");
|
||||
@ -299,13 +299,12 @@ public class Compiler implements MessageConsumer {
|
||||
commandObjcopy.add(buildPath + File.separator + primaryClassName + ".hex");
|
||||
execAsynchronously(commandObjcopy);
|
||||
*/
|
||||
System.out.println("6. compileHex");
|
||||
compileHex(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
sketch.setCompilingProgress(90);
|
||||
return true;
|
||||
}
|
||||
System.out.println("6. compileHex");
|
||||
compileHex(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
sketch.setCompilingProgress(90);
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<File> compileFiles(String avrBasePath,
|
||||
String buildPath, List<String> includePaths,
|
||||
@ -425,22 +424,20 @@ public class Compiler implements MessageConsumer {
|
||||
*/
|
||||
private void execAsynchronously(String[] command) throws RunnerException {
|
||||
|
||||
//eliminate any empty array entries
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
for(String string : command) {
|
||||
string = string.trim();
|
||||
if(string != null && string.length() > 0) {
|
||||
stringList.add(string);
|
||||
}
|
||||
}
|
||||
command = stringList.toArray(new String[stringList.size()]);
|
||||
// eliminate any empty array entries
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
for (String string : command) {
|
||||
string = string.trim();
|
||||
if (!string.isEmpty())
|
||||
stringList.add(string);
|
||||
}
|
||||
command = stringList.toArray(new String[stringList.size()]);
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (verbose || Preferences.getBoolean("build.verbose")) {
|
||||
for(int j = 0; j < command.length; j++) {
|
||||
System.out.print(command[j] + " ");
|
||||
}
|
||||
for (String c : command)
|
||||
System.out.print(c + " ");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
@ -483,18 +480,18 @@ public class Compiler implements MessageConsumer {
|
||||
//System.out.println("throwing up " + exception);
|
||||
if (exception != null) { throw exception; }
|
||||
|
||||
if (result > 1) {
|
||||
// a failure in the tool (e.g. unable to locate a sub-executable)
|
||||
System.err.println(
|
||||
I18n.format(_("{0} returned {1}"), command[0], result));
|
||||
}
|
||||
if (result > 1) {
|
||||
// a failure in the tool (e.g. unable to locate a sub-executable)
|
||||
System.err
|
||||
.println(I18n.format(_("{0} returned {1}"), command[0], result));
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
RunnerException re = new RunnerException(_("Error compiling."));
|
||||
re.hideStackTrace();
|
||||
throw re;
|
||||
}
|
||||
System.out.println("execAsync: Done.");
|
||||
if (result != 0) {
|
||||
RunnerException re = new RunnerException(_("Error compiling."));
|
||||
re.hideStackTrace();
|
||||
throw re;
|
||||
}
|
||||
System.out.println("execAsync: Done.");
|
||||
}
|
||||
|
||||
|
||||
|
44
app/src/processing/app/debug/TargetPackage.java
Normal file
44
app/src/processing/app/debug/TargetPackage.java
Normal 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;
|
||||
}
|
||||
}
|
@ -29,22 +29,22 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.PreferencesMap;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
public class Target {
|
||||
public class TargetPlatform {
|
||||
private String name;
|
||||
private File folder;
|
||||
private Map<String, PreferencesMap> boards;
|
||||
private Map<String, PreferencesMap> programmers;
|
||||
private Map<String, PreferencesMap> platforms;
|
||||
private PreferencesMap platform;
|
||||
|
||||
public Target(String _name, File _folder) {
|
||||
System.out.println("Target: constructor start, name: " + _name);
|
||||
public TargetPlatform(String _name, File _folder) {
|
||||
System.out.println("TargetPlatform: constructor start, name: " + _name);
|
||||
name = _name;
|
||||
folder = _folder;
|
||||
boards = new HashMap<String, PreferencesMap>();
|
||||
programmers = new HashMap<String, PreferencesMap>();
|
||||
platforms = new HashMap<String, PreferencesMap>();
|
||||
platform = new PreferencesMap();
|
||||
|
||||
try {
|
||||
File boardsFile = new File(_folder, "boards.txt");
|
||||
@ -59,11 +59,8 @@ public class Target {
|
||||
|
||||
try {
|
||||
File platformsFile = new File(_folder, "platforms.txt");
|
||||
if (platformsFile.exists()) {
|
||||
PreferencesMap platformPreferences = new PreferencesMap();
|
||||
platformPreferences.load(platformsFile);
|
||||
platforms = platformPreferences.createFirstLevelMap();
|
||||
}
|
||||
if (platformsFile.exists())
|
||||
platform.load(platformsFile);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading platforms from platform.txt: "
|
||||
+ e);
|
||||
@ -99,7 +96,7 @@ public class Target {
|
||||
return programmers;
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> getPlatforms() {
|
||||
return platforms;
|
||||
public PreferencesMap getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
|
||||
$Id$
|
||||
*/
|
||||
package processing.app;
|
||||
package processing.app.helpers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
43
app/src/processing/app/helpers/filefilters/OnlyDirs.java
Normal file
43
app/src/processing/app/helpers/filefilters/OnlyDirs.java
Normal 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();
|
||||
}
|
||||
}
|
@ -237,9 +237,9 @@ run.present.exclusive = false
|
||||
run.present.exclusive.macosx = true
|
||||
|
||||
# ARDUINO PREFERENCES
|
||||
target_package = arduino
|
||||
target_platform = avr
|
||||
board = uno
|
||||
target = arduino
|
||||
platform = avr
|
||||
software=ARDUINO
|
||||
|
||||
programmer = arduino:avrispmkii
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user