Moving libraries out of arduino platform / core directory and to top-level.

This commit is contained in:
David A. Mellis 2009-11-07 17:54:56 +00:00
parent ff0336a3b6
commit 3075c8e4fd
90 changed files with 91 additions and 48 deletions

View File

@ -85,6 +85,8 @@ public class Base {
// found in the sketchbook)
static public String librariesClassPath;
static HashMap<String, File> platformsTable;
// Location for untitled items
static File untitledFolder;
@ -276,6 +278,9 @@ public class Base {
}
}
loadHardware(getHardwareFolder());
loadHardware(getSketchbookHardwareFolder());
// Check if there were previously opened sketches to be restored
boolean opened = restoreSketches();
@ -987,6 +992,31 @@ public class Base {
}
public void rebuildBoardsMenu(JMenu menu) {
//System.out.println("rebuilding boards menu");
try {
menu.removeAll();
ButtonGroup group = new ButtonGroup();
for (String board : Preferences.getSubKeys("boards")) {
JMenu item =
new JRadioButtonMenuItem(
new AbstractAction(Preferences.get("boards", "board", "name")) {
{ putValue("board", board); }
public void actionPerformed(ActionEvent actionevent) {
//System.out.println("Switching to " + board);
Preferences.set("board", getValue("board"));
}
}));
if (board.equals(Preferences.get("board"))) item.setSelected(true);
group.add(item);
menu.add(item);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Scan a folder recursively, and add any sketches found to the menu
* specified. Set the openReplaces parameter to true when opening the sketch
@ -1138,7 +1168,8 @@ public class Base {
// String packages[] =
// Compiler.packageListFromClassPath(libraryClassPath);
libraries.add(subfolder);
String packages[] = Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
String packages[] =
Compiler.headerListFromIncludePath(subfolder.getAbsolutePath());
for (String pkg : packages) {
importToLibraryTable.put(pkg, subfolder);
}
@ -1164,6 +1195,42 @@ public class Base {
}
protected boolean loadHardware(File folder) {
if (!folder.isDirectory()) return false;
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());
}
});
// if a bad folder or something like that, this might come back null
if (list == null) return false;
// alphabetize list, since it's not always alpha order
// replaced hella slow bubble sort with this feller for 0093
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
for (String platform : list) {
File subfolder = new File(folder, platform);
File boardsFile = new File(subfolder, "boards.txt");
if (boardsFile.exists()) {
Preferences.load(new FileInputStream(boardsFile), "boards");
}
File programmersFile = new File(subfolder, "programmers.txt");
if (programmersFile.exists()) {
Preferences.load(new FileInputStream(programmersFile), "programmers");
}
platformsTable.put(platform, subfolder);
}
}
// .................................................................

View File

@ -1842,10 +1842,7 @@ public class Editor extends JFrame implements RunnerListener {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
sketch.compile(new Target(
Base.getHardwarePath() + File.separator + "cores",
Preferences.get("boards." + Preferences.get("board") + ".build.core")),
verbose);
sketch.compile(verbose);
statusNotice("Done compiling.");
} catch (RunnerException e) {
//statusError("Error compiling...");
@ -2257,10 +2254,7 @@ public class Editor extends JFrame implements RunnerListener {
uploading = true;
boolean success = sketch.exportApplet(new Target(
Base.getHardwarePath() + File.separator + "cores",
Preferences.get("boards." + Preferences.get("board") + ".build.core")),
verbose);
boolean success = sketch.exportApplet(verbose);
if (success) {
statusNotice("Done uploading.");
} else {

View File

@ -199,25 +199,6 @@ public class Preferences {
}
}
}
try {
load(new FileInputStream(new File(Base.getHardwareFolder(), "boards.txt")),
"boards");
} catch (Exception ex) {
Base.showError("Error reading board definitions",
"Error reading the board definitions file (" +
new File(Base.getHardwareFolder(), "boards.txt").getAbsolutePath() + "). " +
"Please re-download or re-unzip Arduino.\n", ex);
}
try {
load(new FileInputStream(new File(Base.getHardwareFolder(), "programmers.txt")),
"programmers");
} catch (Exception ex) {
Base.showError("Error reading programmers definitions",
"Error reading the programmers definitions file. " +
"Please re-download or re-unzip Arduino.\n", ex);
}
}
@ -570,9 +551,8 @@ public class Preferences {
}
static protected void load(InputStream input, String prefix) throws IOException {
LinkedHashMap table = new LinkedHashMap();
prefixes.put(prefix, table);
load(input, table);
if (!prefixes.containsKey(prefix)) prefixes.put(prefix, new LinkedHashMap());
load(input, (Map) prefixes.get(prefix));
}
static protected void load(InputStream input, Map table) throws IOException {
@ -629,6 +609,11 @@ public class Preferences {
//return get(attribute, null);
//}
static public String get(String prefix, String selector, String suffix) {
if (get(selector) == null) return null;
return get(prefix + "." + get(selector) + "." + suffix);
}
static public String get(String attribute /*, String defaultValue */) {
// if the attribute starts with a prefix used by one of our subsidiary
// preference files, look up the attribute in that file's Hashtable

View File

@ -27,7 +27,6 @@ import processing.app.debug.AvrdudeUploader;
import processing.app.debug.Compiler;
import processing.app.debug.RunnerException;
import processing.app.debug.Sizer;
import processing.app.debug.Target;
import processing.app.debug.Uploader;
import processing.app.preproc.*;
import processing.core.*;
@ -1142,7 +1141,7 @@ public class Sketch {
* X. afterwards, some of these steps need a cleanup function
* </PRE>
*/
protected String compile(Target target, boolean verbose)
protected String compile(boolean verbose)
throws RunnerException {
String name;
@ -1177,7 +1176,7 @@ public class Sketch {
cleanup();
// handle preprocessing the main file's code
name = build(tempBuildFolder.getAbsolutePath(), target, verbose);
name = build(tempBuildFolder.getAbsolutePath(), verbose);
size(tempBuildFolder.getAbsolutePath(), name);
return name;
@ -1199,11 +1198,11 @@ public class Sketch {
* @param buildPath Location to copy all the .java files
* @return null if compilation failed, main class name if not
*/
public String preprocess(String buildPath, Target target) throws RunnerException {
return preprocess(buildPath, new PdePreprocessor(), target);
public String preprocess(String buildPath) throws RunnerException {
return preprocess(buildPath, new PdePreprocessor());
}
public String preprocess(String buildPath, PdePreprocessor preprocessor, Target target) throws RunnerException {
public String preprocess(String buildPath, PdePreprocessor preprocessor) throws RunnerException {
// make sure the user didn't hide the sketch folder
ensureExistence();
@ -1279,8 +1278,7 @@ public class Sketch {
headerOffset = preprocessor.writePrefix(bigCode.toString(),
buildPath,
name,
codeFolderPackages,
target);
codeFolderPackages);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = "Build folder disappeared or could not be written";
@ -1378,31 +1376,31 @@ public class Sketch {
*
* @return null if compilation failed, main class name if not
*/
public String build(String buildPath, Target target, boolean verbose)
public String build(String buildPath, boolean verbose)
throws RunnerException {
// run the preprocessor
String primaryClassName = preprocess(buildPath, target);
String primaryClassName = preprocess(buildPath);
// compile the program. errors will happen as a RunnerException
// that will bubble up to whomever called build().
Compiler compiler = new Compiler();
if (compiler.compile(this, buildPath, primaryClassName, target, verbose)) {
if (compiler.compile(this, buildPath, primaryClassName, verbose)) {
return primaryClassName;
}
return null;
}
protected boolean exportApplet(Target target, boolean verbose) throws Exception {
return exportApplet(new File(folder, "applet").getAbsolutePath(), target, verbose);
protected boolean exportApplet(boolean verbose) throws Exception {
return exportApplet(new File(folder, "applet").getAbsolutePath(), verbose);
}
/**
* Handle export to applet.
*/
public boolean exportApplet(String appletPath, Target target, boolean verbose)
public boolean exportApplet(String appletPath, boolean verbose)
throws RunnerException, IOException {
// Make sure the user didn't hide the sketch folder
@ -1426,7 +1424,7 @@ public class Sketch {
appletFolder.mkdirs();
// build the sketch
String foundName = build(appletFolder.getPath(), target, false);
String foundName = build(appletFolder.getPath(), false);
// (already reported) error during export, exit this function
if (foundName == null) return false;

View File

@ -55,14 +55,12 @@ public class Compiler implements MessageConsumer {
* @param sketch Sketch object to be compiled.
* @param buildPath Where the temporary files live and will be built from.
* @param primaryClassName the name of the combined sketch file w/ extension
* @param target the target (core) to build against
* @return true if successful.
* @throws RunnerException Only if there's a problem. Only then.
*/
public boolean compile(Sketch sketch,
String buildPath,
String primaryClassName,
Target target,
boolean verbose) throws RunnerException {
this.sketch = sketch;
this.buildPath = buildPath;
@ -73,6 +71,7 @@ public class Compiler implements MessageConsumer {
MessageStream pms = new MessageStream(this);
String avrBasePath = Base.getAvrBasePath();
String corePath = Preferences.get("boards", "board", "build.core");
List<File> objectFiles = new ArrayList<File>();