/* Compiler - default compiler class that connects to the external compiler Part of the Arduino project - http://arduino.berlios.de Derived from the Processing project - http://processing.org Copyleft 2005 Massimo Banzi (arduino modifications) Copyright (c) 2004-05 Ben Fry and Casey Reas Copyright (c) 2001-04 Massachusetts Institute of Technology 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; import java.io.*; import java.util.*; import java.util.zip.*; import javax.swing.*; public class Compiler implements MessageConsumer { static final String BUGS_URL = "http://arduino.berlios.de"; static final String SUPER_BADNESS = "Compiler error, please submit this code to " + BUGS_URL; Sketch sketch; String buildPath; //String buildPath; //String className; //File includeFolder; RunnerException exception; //Editor editor; /* public Compiler(String buildPath, String className, File includeFolder, Editor editor) { this.buildPath = buildPath; this.includeFolder = includeFolder; this.className = className; this.editor = editor; } public boolean compile(PrintStream leechErr) { */ public Compiler() { } // null constructor public boolean compile(Sketch sketch, String buildPath) throws RunnerException { this.sketch = sketch; this.buildPath = buildPath; // the pms object isn't used for anything but storage MessageStream pms = new MessageStream(this); String userdir = System.getProperty("user.dir") + File.separator; System.out.println("Compiling Arduino program"); Process process; String commandLine = ""; //TODO test this in windows // FIXME: this is really nasty, it seems that MACOS is making the // compilation inside the lib folder, while windows is doing it // inside the work folder ... why why why --DojoDave if (Base.isWindows()) { commandLine = userdir + "tools\\gnumake.exe -C " + userdir + ". compile"; } else if (Base.isMacOS()) { commandLine = userdir + "tools/gnumake -C " + userdir + "lib compile"; } int result = 0; try { // System.out.println(commandLine); process = Runtime.getRuntime().exec(commandLine); new MessageSiphon(process.getInputStream(), this); new MessageSiphon(process.getErrorStream(), this); boolean compiling = true; while (compiling) { try { result = process.waitFor(); compiling = false; } catch (InterruptedException ignored) { } } } catch (Exception e) { e.printStackTrace(); System.out.println("Error: GNUMake probably couldn't be found"); result = 99; } if(0 == result){ System.out.println("Arduino Compilation Successful"); }else{ System.out.println("Arduino Compilation Unsuccessful (error: " + result + ")"); } return (result == 0); } boolean firstErrorFound; boolean secondErrorFound; /** * Part of the MessageConsumer interface, this is called * whenever a piece (usually a line) of error message is spewed * out from the compiler. The errors are parsed for their contents * and line number, which is then reported back to Editor. * In Arduino v1 this is very very crude */ public void message(String s) { // This receives messages as full lines, so a newline needs // to be added as they're printed to the console. //System.out.print(s); //if ((s.indexOf("warning:") != -1) && (s.indexOf("prog.c:") != -1) ) { // String[] result = s.split(":"); // for (int x=0; x