mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Various cleanups. Introduced class PreferencesMap to replace/simplify Map<String, String>.
This commit is contained in:
parent
e63c2d1429
commit
dc616601cd
@ -26,6 +26,7 @@ import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@ -48,7 +49,7 @@ public class Base {
|
||||
/** Set true if this a proper release rather than a numbered revision. */
|
||||
static public boolean RELEASE = false;
|
||||
|
||||
static HashMap<Integer, String> platformNames = new HashMap<Integer, String>();
|
||||
static Map<Integer, String> platformNames = new HashMap<Integer, String>();
|
||||
static {
|
||||
platformNames.put(PConstants.WINDOWS, "windows");
|
||||
platformNames.put(PConstants.MACOSX, "macosx");
|
||||
@ -78,19 +79,18 @@ public class Base {
|
||||
static private File examplesFolder;
|
||||
static private File librariesFolder;
|
||||
static private File toolsFolder;
|
||||
static private File hardwareFolder;
|
||||
|
||||
static HashSet<File> libraries;
|
||||
static Set<File> libraries;
|
||||
|
||||
// maps imported packages to their library folder
|
||||
static HashMap<String, File> importToLibraryTable;
|
||||
static Map<String, File> importToLibraryTable;
|
||||
|
||||
// classpath for all known libraries for p5
|
||||
// (both those in the p5/libs folder and those with lib subfolders
|
||||
// found in the sketchbook)
|
||||
static public String librariesClassPath;
|
||||
|
||||
static public HashMap<String, Target> targetsTable;
|
||||
static public Map<String, Target> targetsTable;
|
||||
|
||||
// Location for untitled items
|
||||
static File untitledFolder;
|
||||
@ -99,10 +99,7 @@ public class Base {
|
||||
// static Image icon;
|
||||
|
||||
// int editorCount;
|
||||
// Editor[] editors;
|
||||
java.util.List<Editor> editors =
|
||||
Collections.synchronizedList(new ArrayList<Editor>());
|
||||
// ArrayList editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||
Editor activeEditor;
|
||||
|
||||
|
||||
@ -956,17 +953,19 @@ public class Base {
|
||||
//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 = this.getBoardPreferences().get("platform");
|
||||
String targetname = this.getPlatformPreferences(platformname).get("name");
|
||||
String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path");
|
||||
// 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();
|
||||
}
|
||||
@ -1574,91 +1573,28 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
static public Map<String, String> getPlatformPreferences() {
|
||||
System.out.println("getPlatformPreferences() no arguments: start");
|
||||
static public PreferencesMap getPlatformPreferences() {
|
||||
Target target = getTarget();
|
||||
//if (target == null) return new LinkedHashMap();
|
||||
Map map = target.getPlatforms();
|
||||
/*
|
||||
if (map == null)
|
||||
{
|
||||
System.err.println("Error loading platforms preference from Target");
|
||||
System.exit(0);
|
||||
}
|
||||
*/
|
||||
//if (map == null) return new LinkedHashMap();
|
||||
map = (Map) map.get(Preferences.get("platform"));
|
||||
//if (map == null) return new LinkedHashMap();
|
||||
return map;
|
||||
Map<String, PreferencesMap> platforms = target.getPlatforms();
|
||||
return platforms.get(Preferences.get("platform"));
|
||||
}
|
||||
|
||||
//Get a specific platform
|
||||
static public Map<String, String> getPlatformPreferences(String platformname) {
|
||||
if (platformname == null) {
|
||||
platformname = Preferences.get("platform");
|
||||
|
||||
}
|
||||
System.out.println("getlatformPreferences(String platformname)): start: platformname = " + platformname );
|
||||
static public PreferencesMap getPlatformPreferences(String platformName) {
|
||||
if (platformName == null)
|
||||
platformName = Preferences.get("platform");
|
||||
Target target = getTarget();
|
||||
if (target == null ) {
|
||||
System.out.println("get target is null. trouble! ");
|
||||
}
|
||||
Map map = target.getPlatforms();
|
||||
map = (Map) map.get(platformname);
|
||||
|
||||
//What if null or defaults to nonexisent platform
|
||||
System.out.println("PlatformName: " + platformname);
|
||||
if (map == null)
|
||||
{
|
||||
System.err.println("Error loading platforms preference from Target");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
return map;
|
||||
Map<String, PreferencesMap> platforms = target.getPlatforms();
|
||||
return platforms.get(platformName);
|
||||
}
|
||||
|
||||
static public Map<String, String> bogusgetBoardPreferences() {
|
||||
System.out.println("getBoardPrefences method: start");
|
||||
Target target = getTarget();
|
||||
if (target == null) {
|
||||
System.out.println("getBoardPrefereces method: target == null");
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
Map map = target.getBoards();
|
||||
if (map == null) {
|
||||
System.out.println("getBoardPrefereces method: target.getBoards() == null");
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
map = (Map) map.get(Preferences.get("board"));
|
||||
if (map == null) {
|
||||
System.out.println("getBoardPrefereces method: Preferences.get(board) == null");
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
//Debug iterate the map
|
||||
Iterator iterator = map.entrySet().iterator();
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Map.Entry pair = (Map.Entry)iterator.next();
|
||||
if (pair.getValue() == null)
|
||||
{
|
||||
System.out.println("KeyName: " + pair.getKey() + " val: null");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("KeyName: " + pair.getKey() + " val" + pair.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
static public Map<String, String> getBoardPreferences() {
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
Target target = getTarget();
|
||||
if (target != null) {
|
||||
String board = Preferences.get("board");
|
||||
return target.getBoards().get(board);
|
||||
}
|
||||
return new HashMap<String, String>();
|
||||
return new PreferencesMap();
|
||||
}
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
|
@ -782,17 +782,16 @@ public class Preferences {
|
||||
}
|
||||
|
||||
//get a Map of the Preferences
|
||||
static public Map<String, String> getMap()
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
Map globalpreferences = new LinkedHashMap();
|
||||
Enumeration e = table.keys();
|
||||
PreferencesMap globalpreferences = new PreferencesMap();
|
||||
Enumeration<String> e = table.keys();
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
String key = (String) e.nextElement();
|
||||
//System.out.println("Key: " + key + "Val: " + table.get(key));
|
||||
String value = (String) table.get(key);
|
||||
globalpreferences.put(key, value );
|
||||
globalpreferences.put(key, value);
|
||||
}
|
||||
|
||||
return globalpreferences;
|
||||
|
88
app/src/processing/app/PreferencesMap.java
Normal file
88
app/src/processing/app/PreferencesMap.java
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
PreferencesMap - A Map<String, String> with some useful features
|
||||
to handle preferences.
|
||||
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
|
||||
|
||||
$Id$
|
||||
*/
|
||||
package processing.app;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.core.PApplet;
|
||||
|
||||
public class PreferencesMap extends HashMap<String, String> {
|
||||
|
||||
/**
|
||||
* Parse a property list file and put kev/value pairs into the Map
|
||||
*
|
||||
* @param file
|
||||
* @throws FileNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(File file) throws FileNotFoundException, IOException {
|
||||
load(new FileInputStream(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a property list stream and put key/value pairs into the Map
|
||||
*
|
||||
* @param input
|
||||
* @throws IOException
|
||||
*/
|
||||
public void load(InputStream input) throws IOException {
|
||||
String[] lines = PApplet.loadStrings(input);
|
||||
for (String line : lines) {
|
||||
if (line.length() == 0 || line.charAt(0) == '#')
|
||||
continue;
|
||||
|
||||
int equals = line.indexOf('=');
|
||||
if (equals != -1) {
|
||||
String key = line.substring(0, equals);
|
||||
String value = line.substring(equals + 1);
|
||||
put(key.trim(), value.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> createFirstLevelMap() {
|
||||
Map<String, PreferencesMap> res = new HashMap<String, PreferencesMap>();
|
||||
for (String key : keySet()) {
|
||||
int dot = key.indexOf('.');
|
||||
if (dot == -1)
|
||||
continue;
|
||||
|
||||
String parent = key.substring(0, dot);
|
||||
String child = key.substring(dot + 1);
|
||||
|
||||
if (!res.containsKey(parent))
|
||||
res.put(parent, new PreferencesMap());
|
||||
res.get(parent).put(child, get(key));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 2330591567444282843L;
|
||||
}
|
@ -23,18 +23,25 @@
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
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.core.*;
|
||||
import processing.app.I18n;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import processing.core.PApplet;
|
||||
|
||||
public class Compiler implements MessageConsumer {
|
||||
static final String BUGS_URL =
|
||||
@ -45,60 +52,54 @@ public class Compiler implements MessageConsumer {
|
||||
Sketch sketch;
|
||||
String buildPath;
|
||||
String primaryClassName;
|
||||
String platform;
|
||||
String board;
|
||||
|
||||
boolean verbose;
|
||||
|
||||
RunnerException exception;
|
||||
|
||||
HashMap<String, String> configPreferences;
|
||||
HashMap<String, String> platformPreferences;
|
||||
|
||||
String avrBasePath;
|
||||
String corePath;
|
||||
|
||||
List<File> objectFiles;
|
||||
ArrayList<String> includePaths;
|
||||
|
||||
public Compiler() { }
|
||||
|
||||
/**
|
||||
* Compile with avr-gcc.
|
||||
*
|
||||
* @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 _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
|
||||
* @return true if successful.
|
||||
* @throws RunnerException Only if there's a problem. Only then.
|
||||
*/
|
||||
public boolean compile(Sketch sketch,
|
||||
String buildPath,
|
||||
String primaryClassName,
|
||||
boolean verbose) throws RunnerException {
|
||||
this.sketch = sketch;
|
||||
this.buildPath = buildPath;
|
||||
this.primaryClassName = primaryClassName;
|
||||
this.verbose = verbose;
|
||||
public boolean compile(Sketch _sketch,
|
||||
String _buildPath,
|
||||
String _primaryClassName,
|
||||
boolean _verbose) throws RunnerException {
|
||||
sketch = _sketch;
|
||||
buildPath = _buildPath;
|
||||
primaryClassName = _primaryClassName;
|
||||
verbose = _verbose;
|
||||
objectFiles = new ArrayList<File>();
|
||||
|
||||
Map<String, String> boardPreferences = Base.getBoardPreferences();
|
||||
PreferencesMap boardPreferences = Base.getBoardPreferences();
|
||||
|
||||
//Check for null platform, and use system default if not found
|
||||
platform = boardPreferences.get("platform");
|
||||
// Check for null platform, and use system default if not found
|
||||
PreferencesMap platformPreferences;
|
||||
String platform = boardPreferences.get("platform");
|
||||
if (platform == null)
|
||||
{
|
||||
platformPreferences = new HashMap(Base.getPlatformPreferences());
|
||||
}
|
||||
platformPreferences = Base.getPlatformPreferences();
|
||||
else
|
||||
{
|
||||
platformPreferences = new HashMap(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, "");
|
||||
}
|
||||
|
||||
System.out.println("////////////////////////////compiler.java is doing stuff/////////////////");
|
||||
//Put all the global preference configuration into one Master configpreferences
|
||||
configPreferences = mergePreferences( Preferences.getMap(), platformPreferences, boardPreferences);
|
||||
avrBasePath = configPreferences.get("compiler.path");
|
||||
String avrBasePath = configPreferences.get("compiler.path");
|
||||
if (avrBasePath == null)
|
||||
{
|
||||
avrBasePath = Base.getAvrBasePath();
|
||||
@ -118,23 +119,19 @@ public class Compiler implements MessageConsumer {
|
||||
Object[] Args = {basePath};
|
||||
avrBasePath = compileFormat.format( Args );
|
||||
System.out.println("avrBasePath:new: " + avrBasePath);
|
||||
|
||||
|
||||
}
|
||||
this.board = configPreferences.get("board");
|
||||
if (this.board == "")
|
||||
{
|
||||
this.board = "_UNKNOWN";
|
||||
}
|
||||
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."));
|
||||
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);
|
||||
@ -148,7 +145,6 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
String variant = boardPreferences.get("build.variant");
|
||||
String variantPath = null;
|
||||
|
||||
if (variant != null) {
|
||||
if (variant.indexOf(':') == -1) {
|
||||
Target t = Base.getTarget();
|
||||
@ -164,25 +160,25 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
// 0. include paths for core + all libraries
|
||||
sketch.setCompilingProgress(20);
|
||||
ArrayList<String> includePaths = new ArrayList<String>();
|
||||
List<String> includePaths = new ArrayList<String>();
|
||||
includePaths.add(corePath);
|
||||
if (variantPath != null) includePaths.add(variantPath);
|
||||
for (File file : sketch.getImportedLibraries()) {
|
||||
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);
|
||||
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);
|
||||
System.out.println("2. compileLibraries");
|
||||
sketch.setCompilingProgress(40);
|
||||
compileLibraries(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
/*
|
||||
|
||||
for (File libraryFolder : sketch.getImportedLibraries()) {
|
||||
@ -215,7 +211,7 @@ public class Compiler implements MessageConsumer {
|
||||
System.out.println("3. compileCore");
|
||||
System.out.println("corePath: " + corePath);
|
||||
sketch.setCompilingProgress(50);
|
||||
compileCore(avrBasePath, buildPath, corePath, variant, variantPath, configPreferences);
|
||||
compileCore(avrBasePath, _buildPath, corePath, variant, variantPath, configPreferences);
|
||||
|
||||
|
||||
/*
|
||||
@ -244,7 +240,7 @@ public class Compiler implements MessageConsumer {
|
||||
// 4. link it all together into the .elf file
|
||||
sketch.setCompilingProgress(60);
|
||||
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[] {
|
||||
@ -291,7 +287,7 @@ public class Compiler implements MessageConsumer {
|
||||
execAsynchronously(commandObjcopy);
|
||||
*/
|
||||
System.out.println("5. compileEep");
|
||||
compileEep(avrBasePath, buildPath, includePaths, configPreferences);
|
||||
compileEep(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
// 6. build the .hex file
|
||||
sketch.setCompilingProgress(80);
|
||||
@ -304,7 +300,7 @@ public class Compiler implements MessageConsumer {
|
||||
execAsynchronously(commandObjcopy);
|
||||
*/
|
||||
System.out.println("6. compileHex");
|
||||
compileHex(avrBasePath, buildPath, includePaths, configPreferences);
|
||||
compileHex(avrBasePath, _buildPath, includePaths, configPreferences);
|
||||
|
||||
sketch.setCompilingProgress(90);
|
||||
return true;
|
||||
@ -312,10 +308,10 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
|
||||
private List<File> compileFiles(String avrBasePath,
|
||||
String buildPath, ArrayList<String> includePaths,
|
||||
ArrayList<File> sSources,
|
||||
ArrayList<File> cSources, ArrayList<File> cppSources,
|
||||
Map<String, String> boardPreferences)
|
||||
String buildPath, List<String> includePaths,
|
||||
List<File> sSources,
|
||||
List<File> cSources, List<File> cppSources,
|
||||
PreferencesMap prefs)
|
||||
throws RunnerException {
|
||||
|
||||
List<File> objectPaths = new ArrayList<File>();
|
||||
@ -326,7 +322,7 @@ public class Compiler implements MessageConsumer {
|
||||
execAsynchronously(getCommandCompilerS(avrBasePath, includePaths,
|
||||
file.getAbsolutePath(),
|
||||
objectPath,
|
||||
configPreferences));
|
||||
prefs));
|
||||
}
|
||||
|
||||
for (File file : cSources) {
|
||||
@ -335,11 +331,11 @@ public class Compiler implements MessageConsumer {
|
||||
File objectFile = new File(objectPath);
|
||||
File dependFile = new File(dependPath);
|
||||
objectPaths.add(objectFile);
|
||||
if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue;
|
||||
if (is_already_compiled(file, objectFile, dependFile, prefs)) continue;
|
||||
execAsynchronously(getCommandCompilerC(avrBasePath, includePaths,
|
||||
file.getAbsolutePath(),
|
||||
objectPath,
|
||||
configPreferences));
|
||||
prefs));
|
||||
}
|
||||
|
||||
for (File file : cppSources) {
|
||||
@ -348,11 +344,11 @@ public class Compiler implements MessageConsumer {
|
||||
File objectFile = new File(objectPath);
|
||||
File dependFile = new File(dependPath);
|
||||
objectPaths.add(objectFile);
|
||||
if (is_already_compiled(file, objectFile, dependFile, boardPreferences)) continue;
|
||||
if (is_already_compiled(file, objectFile, dependFile, prefs)) continue;
|
||||
execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths,
|
||||
file.getAbsolutePath(),
|
||||
objectPath,
|
||||
configPreferences));
|
||||
prefs));
|
||||
}
|
||||
|
||||
return objectPaths;
|
||||
@ -621,9 +617,9 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////
|
||||
static private String[] getCommandCompilerS(String avrBasePath,
|
||||
ArrayList<String> includePaths, String sourceName, String objectName,
|
||||
HashMap<String, String> configPreferences)
|
||||
{
|
||||
List<String> includePaths, String sourceName, String objectName,
|
||||
PreferencesMap configPreferences)
|
||||
{
|
||||
System.out.println("getCommandCompilerS: start");
|
||||
String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
|
||||
MessageFormat compileFormat = new MessageFormat(baseCommandString);
|
||||
@ -682,8 +678,8 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
//removed static
|
||||
private String[] getCommandCompilerC(String avrBasePath,
|
||||
ArrayList<String> includePaths, String sourceName, String objectName,
|
||||
HashMap<String, String> configPreferences)
|
||||
List<String> includePaths, String sourceName, String objectName,
|
||||
PreferencesMap configPreferences)
|
||||
{
|
||||
System.out.println("getCommandCompilerC: start");
|
||||
String baseCommandString = configPreferences.get("recipe.c.o.pattern");
|
||||
@ -691,7 +687,7 @@ public class Compiler implements MessageConsumer {
|
||||
//getIncludes to String
|
||||
String includes = preparePaths(includePaths);
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.c.cmd"),
|
||||
configPreferences.get("compiler.c.flags"),
|
||||
@ -699,13 +695,13 @@ public class Compiler implements MessageConsumer {
|
||||
configPreferences.get("build.mcu"),
|
||||
configPreferences.get("build.f_cpu"),
|
||||
configPreferences.get("software"),
|
||||
Base.REVISION,
|
||||
"" + Base.REVISION,
|
||||
includes,
|
||||
sourceName,
|
||||
objectName
|
||||
};
|
||||
|
||||
String command = compileFormat.format( Args );
|
||||
String command = compileFormat.format(args);
|
||||
String[] commandArray = command.split("\\|");
|
||||
return commandArray;
|
||||
}
|
||||
@ -743,8 +739,8 @@ public class Compiler implements MessageConsumer {
|
||||
*/
|
||||
|
||||
static private String[] getCommandCompilerCPP(String avrBasePath,
|
||||
ArrayList<String> includePaths, String sourceName, String objectName,
|
||||
HashMap<String, String> configPreferences)
|
||||
List<String> includePaths, String sourceName, String objectName,
|
||||
PreferencesMap configPreferences)
|
||||
{
|
||||
System.out.println("getCommandCompilerCPP: start");
|
||||
String baseCommandString = configPreferences.get("recipe.cpp.o.pattern");
|
||||
@ -752,7 +748,7 @@ public class Compiler implements MessageConsumer {
|
||||
//getIncludes to String
|
||||
String includes = preparePaths(includePaths);
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.cpp.cmd"),
|
||||
configPreferences.get("compiler.cpp.flags"),
|
||||
@ -760,13 +756,13 @@ public class Compiler implements MessageConsumer {
|
||||
configPreferences.get("build.mcu"),
|
||||
configPreferences.get("build.f_cpu"),
|
||||
configPreferences.get("software"),
|
||||
Base.REVISION,
|
||||
"" + Base.REVISION,
|
||||
includes,
|
||||
sourceName,
|
||||
objectName
|
||||
};
|
||||
|
||||
String command = compileFormat.format( Args );
|
||||
String command = compileFormat.format(args);
|
||||
String[] commandArray = command.split("\\|");
|
||||
|
||||
/*
|
||||
@ -803,15 +799,15 @@ public class Compiler implements MessageConsumer {
|
||||
return (new File(path)).list(onlyHFiles);
|
||||
}
|
||||
|
||||
static public ArrayList<File> findFilesInPath(String path, String extension,
|
||||
boolean recurse) {
|
||||
System.out.println("findFilesInPath: " + path);
|
||||
static public List<File> findFilesInPath(String path, String extension,
|
||||
boolean recurse) {
|
||||
System.out.println("findFilesInPath: " + path);
|
||||
return findFilesInFolder(new File(path), extension, recurse);
|
||||
}
|
||||
|
||||
static public ArrayList<File> findFilesInFolder(File folder, String extension,
|
||||
boolean recurse) {
|
||||
ArrayList<File> files = new ArrayList<File>();
|
||||
static public List<File> findFilesInFolder(File folder, String extension,
|
||||
boolean recurse) {
|
||||
List<File> files = new ArrayList<File>();
|
||||
|
||||
if (folder.listFiles() == null) return files;
|
||||
|
||||
@ -831,17 +827,18 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
void compileSketch(String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences)
|
||||
void compileSketch(String avrBasePath, String buildPath,
|
||||
List<String> includePaths, PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
System.out.println("compileSketch: start");
|
||||
System.out.println("includePaths: ");
|
||||
for (int i = 0; i < includePaths.size(); i++) {
|
||||
System.out.println("-I" + (String) includePaths.get(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < includePaths.size(); i++) {
|
||||
System.out.println("-I" + (String) includePaths.get(i));
|
||||
}
|
||||
|
||||
//logger.debug("compileSketch: start");
|
||||
this.objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths,
|
||||
objectFiles.addAll(compileFiles(avrBasePath, buildPath, includePaths,
|
||||
findFilesInPath(buildPath, "S", false),
|
||||
findFilesInPath(buildPath, "c", false),
|
||||
findFilesInPath(buildPath, "cpp", false),
|
||||
@ -851,11 +848,11 @@ public class Compiler implements MessageConsumer {
|
||||
// 2. compile the libraries, outputting .o files to:
|
||||
// <buildPath>/<library>/
|
||||
void compileLibraries (String avrBasePath, String buildPath,
|
||||
ArrayList<String> includePaths,
|
||||
HashMap<String, String> configPreferences)
|
||||
List<String> includePaths,
|
||||
PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
System.out.println("compileLibraries: start");
|
||||
System.out.println("compileLibraries: start");
|
||||
|
||||
for (File libraryFolder : sketch.getImportedLibraries()) {
|
||||
System.out.println("libraryFolder: " + libraryFolder);
|
||||
@ -894,20 +891,19 @@ public class Compiler implements MessageConsumer {
|
||||
// collecting them into the core.a library file.
|
||||
void compileCore (String avrBasePath, String buildPath,
|
||||
String corePath, String variant, String variantPath,
|
||||
HashMap<String, String> configPreferences)
|
||||
PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
System.out.println("compileCore(...) start");
|
||||
|
||||
ArrayList<String> includePaths = new ArrayList();
|
||||
List<String> includePaths = new ArrayList<String>();
|
||||
includePaths.add(corePath); //include core path only
|
||||
if (variantPath != null) includePaths.add(variantPath);
|
||||
|
||||
//debug includePaths
|
||||
System.out.println("includePaths: ");
|
||||
for (int i = 0; i < includePaths.size(); i++) {
|
||||
for (int i = 0; i < includePaths.size(); i++)
|
||||
System.out.println("-I" + (String) includePaths.get(i));
|
||||
}
|
||||
|
||||
String baseCommandString = configPreferences.get("recipe.ar.pattern");
|
||||
String commandString = "";
|
||||
@ -926,7 +922,7 @@ public class Compiler implements MessageConsumer {
|
||||
//List commandAR = new ArrayList(baseCommandAR);
|
||||
//commandAR = commandAR + file.getAbsolutePath();
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.ar.cmd"),
|
||||
configPreferences.get("compiler.ar.flags"),
|
||||
@ -936,20 +932,18 @@ public class Compiler implements MessageConsumer {
|
||||
//objectName
|
||||
file.getAbsolutePath()
|
||||
};
|
||||
System.out.println("compileCore(...) substitute");
|
||||
|
||||
commandString = compileFormat.format( Args );
|
||||
System.out.println("compileCore(...) substitute");
|
||||
|
||||
commandString = compileFormat.format(args);
|
||||
String[] commandArray = commandString.split("\\|");
|
||||
execAsynchronously(commandArray);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 4. link it all together into the .elf file
|
||||
void compileLink(String avrBasePath, String buildPath,
|
||||
String corePath, ArrayList<String> includePaths,
|
||||
HashMap<String, String> configPreferences)
|
||||
String corePath, List<String> includePaths,
|
||||
PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
// For atmega2560, need --relax linker option to link larger
|
||||
@ -969,7 +963,7 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
System.out.println("objectFileList: " + objectFileList);
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.c.elf.cmd"),
|
||||
configPreferences.get("compiler.c.elf.flags")+optRelax,
|
||||
@ -983,128 +977,59 @@ public class Compiler implements MessageConsumer {
|
||||
corePath,
|
||||
configPreferences.get("ldscript"),
|
||||
};
|
||||
commandString = compileFormat.format( Args );
|
||||
commandString = compileFormat.format(args);
|
||||
String[] commandArray = commandString.split("\\|");
|
||||
execAsynchronously(commandArray);
|
||||
}
|
||||
|
||||
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
|
||||
void compileEep (String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences)
|
||||
void compileEep (String avrBasePath, String buildPath,
|
||||
List<String> includePaths, PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
//logger.debug("compileEep: start");
|
||||
String baseCommandString = configPreferences.get("recipe.objcopy.eep.pattern");
|
||||
String commandString = "";
|
||||
MessageFormat compileFormat = new MessageFormat(baseCommandString);
|
||||
String objectFileList = "";
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.objcopy.cmd"),
|
||||
configPreferences.get("compiler.objcopy.eep.flags"),
|
||||
buildPath + File.separator + primaryClassName,
|
||||
buildPath + File.separator + primaryClassName
|
||||
};
|
||||
commandString = compileFormat.format( Args );
|
||||
commandString = compileFormat.format(args);
|
||||
String[] commandArray = commandString.split("\\|");
|
||||
execAsynchronously(commandArray);
|
||||
}
|
||||
|
||||
// 6. build the .hex file
|
||||
void compileHex (String avrBasePath, String buildPath, ArrayList<String> includePaths, HashMap<String, String> configPreferences)
|
||||
void compileHex (String avrBasePath, String buildPath,
|
||||
List<String> includePaths, PreferencesMap configPreferences)
|
||||
throws RunnerException
|
||||
{
|
||||
//logger.debug("compileHex: start");
|
||||
String baseCommandString = configPreferences.get("recipe.objcopy.hex.pattern");
|
||||
String commandString = "";
|
||||
MessageFormat compileFormat = new MessageFormat(baseCommandString);
|
||||
String objectFileList = "";
|
||||
|
||||
Object[] Args = {
|
||||
String[] args = {
|
||||
avrBasePath,
|
||||
configPreferences.get("compiler.elf2hex.cmd"),
|
||||
configPreferences.get("compiler.elf2hex.flags"),
|
||||
buildPath + File.separator + primaryClassName,
|
||||
buildPath + File.separator + primaryClassName
|
||||
};
|
||||
commandString = compileFormat.format( Args );
|
||||
commandString = compileFormat.format(args);
|
||||
String[] commandArray = commandString.split("\\|");
|
||||
execAsynchronously(commandArray);
|
||||
}
|
||||
|
||||
//merge all the preferences file in the correct order of precedence
|
||||
HashMap mergePreferences(Map Preferences, Map platformPreferences, Map boardPreferences)
|
||||
{
|
||||
HashMap _map = new HashMap();
|
||||
|
||||
Iterator iterator = Preferences.entrySet().iterator();
|
||||
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Map.Entry pair = (Map.Entry)iterator.next();
|
||||
if (pair.getValue() == null)
|
||||
{
|
||||
_map.put(pair.getKey(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
_map.put(pair.getKey(), pair.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//logger.debug("Done: Preferences");
|
||||
|
||||
iterator = platformPreferences.entrySet().iterator();
|
||||
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Map.Entry pair = (Map.Entry)iterator.next();
|
||||
|
||||
if (pair.getValue() == null)
|
||||
{
|
||||
_map.put(pair.getKey(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
_map.put(pair.getKey(), pair.getValue());
|
||||
}
|
||||
//System.out.println(pair.getKey() + " = " + pair.getValue());
|
||||
}
|
||||
|
||||
//System.out.println("Done: platformPreferences");
|
||||
iterator = boardPreferences.entrySet().iterator();
|
||||
|
||||
while(iterator.hasNext())
|
||||
{
|
||||
Map.Entry pair = (Map.Entry)iterator.next();
|
||||
|
||||
if (pair.getValue() == null)
|
||||
{
|
||||
_map.put(pair.getKey(), "");
|
||||
}
|
||||
else
|
||||
{
|
||||
_map.put(pair.getKey(), pair.getValue());
|
||||
}
|
||||
//System.out.println(pair.getKey() + " = " + pair.getValue());
|
||||
}
|
||||
//System.out.println("Done: boardPreferences");
|
||||
|
||||
|
||||
return _map;
|
||||
}
|
||||
|
||||
private static String preparePaths(ArrayList<String> includePaths) {
|
||||
//getIncludes to String
|
||||
//logger.debug("Start: Prepare paths");
|
||||
private static String preparePaths(List<String> includePaths) {
|
||||
String includes = "";
|
||||
for (int i = 0; i < includePaths.size(); i++)
|
||||
{
|
||||
includes = includes + (" -I" + (String) includePaths.get(i)) + "|";
|
||||
}
|
||||
//logger.debug("Paths prepared: " + includes);
|
||||
for (String p : includePaths)
|
||||
includes += " -I" + p + "|";
|
||||
return includes;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,122 +1,105 @@
|
||||
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Target - represents a hardware platform
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
Target - represents a hardware platform
|
||||
Part of the Arduino project - http://www.arduino.cc/
|
||||
|
||||
Copyright (c) 2009 David A. Mellis
|
||||
Copyright (c) 2009 David A. Mellis
|
||||
|
||||
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 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.
|
||||
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
|
||||
|
||||
$Id$
|
||||
*/
|
||||
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
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
package processing.app.debug;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.Preferences;
|
||||
//import processing.app.Base;
|
||||
import processing.app.PreferencesMap;
|
||||
|
||||
public class Target {
|
||||
private String name;
|
||||
private File folder;
|
||||
private Map boards;
|
||||
private Map programmers;
|
||||
private Map platforms;
|
||||
private String name;
|
||||
private File folder;
|
||||
private Map<String, PreferencesMap> boards;
|
||||
private Map<String, PreferencesMap> programmers;
|
||||
private Map<String, PreferencesMap> platforms;
|
||||
|
||||
public Target(String name, File folder) {
|
||||
System.out.println("Target: constructor start, name: " + name);
|
||||
this.name = name;
|
||||
this.folder = folder;
|
||||
this.boards = new LinkedHashMap();
|
||||
this.programmers = new LinkedHashMap();
|
||||
this.platforms = new LinkedHashMap();
|
||||
|
||||
File boardsFile = new File(folder, "boards.txt");
|
||||
try {
|
||||
if (boardsFile.exists()) {
|
||||
Map boardPreferences = new LinkedHashMap();
|
||||
Preferences.load(new FileInputStream(boardsFile), boardPreferences);
|
||||
for (Object k : boardPreferences.keySet()) {
|
||||
String key = (String) k;
|
||||
String board = key.substring(0, key.indexOf('.'));
|
||||
if (!boards.containsKey(board)) boards.put(board, new HashMap());
|
||||
((Map) boards.get(board)).put(
|
||||
key.substring(key.indexOf('.') + 1),
|
||||
boardPreferences.get(key));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading boards from " + boardsFile + ": " + e);
|
||||
public Target(String _name, File _folder) {
|
||||
System.out.println("Target: constructor start, name: " + _name);
|
||||
name = _name;
|
||||
folder = _folder;
|
||||
boards = new HashMap<String, PreferencesMap>();
|
||||
programmers = new HashMap<String, PreferencesMap>();
|
||||
platforms = new HashMap<String, PreferencesMap>();
|
||||
|
||||
}
|
||||
try {
|
||||
File boardsFile = new File(_folder, "boards.txt");
|
||||
if (boardsFile.exists()) {
|
||||
PreferencesMap boardPreferences = new PreferencesMap();
|
||||
boardPreferences.load(boardsFile);
|
||||
boards = boardPreferences.createFirstLevelMap();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading boards from boards.txt: " + e);
|
||||
}
|
||||
|
||||
File platformsFile = new File(folder,"platforms.txt");
|
||||
try
|
||||
{
|
||||
if(platformsFile.exists()){
|
||||
Map platformPreferences = new LinkedHashMap();
|
||||
Preferences.load(new FileInputStream(platformsFile), platformPreferences);
|
||||
for(Object k : platformPreferences.keySet())
|
||||
{
|
||||
String key=(String) k;
|
||||
String platform=key.substring(0,key.indexOf('.'));
|
||||
if (!platforms.containsKey(platform)) platforms.put(platform, new HashMap());
|
||||
((Map) platforms.get(platform)).put(key.substring(key.indexOf('.') + 1),platformPreferences.get(key));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading platforms from " +
|
||||
platformsFile + ": " + e);
|
||||
//System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
File platformsFile = new File(_folder, "platforms.txt");
|
||||
if (platformsFile.exists()) {
|
||||
PreferencesMap platformPreferences = new PreferencesMap();
|
||||
platformPreferences.load(platformsFile);
|
||||
platforms = platformPreferences.createFirstLevelMap();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading platforms from platform.txt: "
|
||||
+ e);
|
||||
}
|
||||
|
||||
File programmersFile = new File(folder, "programmers.txt");
|
||||
try {
|
||||
if (programmersFile.exists()) {
|
||||
Map programmerPreferences = new LinkedHashMap();
|
||||
Preferences.load(new FileInputStream(programmersFile), programmerPreferences);
|
||||
for (Object k : programmerPreferences.keySet()) {
|
||||
String key = (String) k;
|
||||
String programmer = key.substring(0, key.indexOf('.'));
|
||||
if (!programmers.containsKey(programmer)) programmers.put(programmer, new HashMap());
|
||||
((Map) programmers.get(programmer)).put(
|
||||
key.substring(key.indexOf('.') + 1),
|
||||
programmerPreferences.get(key));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error loading programmers from " +
|
||||
programmersFile + ": " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public File getFolder() { return folder; }
|
||||
public Map<String, Map<String, String>> getBoards() {
|
||||
return boards;
|
||||
}
|
||||
public Map<String, Map<String, String>> getProgrammers() {
|
||||
return programmers;
|
||||
}
|
||||
public Map<String, Map<String, String>> getPlatforms() {
|
||||
return platforms;
|
||||
}
|
||||
try {
|
||||
File programmersFile = new File(_folder, "programmers.txt");
|
||||
if (programmersFile.exists()) {
|
||||
PreferencesMap prefs = new PreferencesMap();
|
||||
prefs.load(programmersFile);
|
||||
programmers = prefs.createFirstLevelMap();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err
|
||||
.println("Error loading programmers from programmers.txt: "
|
||||
+ e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public File getFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> getBoards() {
|
||||
return boards;
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> getProgrammers() {
|
||||
return programmers;
|
||||
}
|
||||
|
||||
public Map<String, PreferencesMap> getPlatforms() {
|
||||
return platforms;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user