-
-
Notifications
You must be signed in to change notification settings - Fork 7k
update Sketch menu, add Save hex option #2567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
|
@@ -67,6 +68,7 @@ public class Compiler implements MessageConsumer { | |
private SketchData sketch; | ||
private PreferencesMap prefs; | ||
private boolean verbose; | ||
private boolean saveHex; | ||
|
||
private List<File> objectFiles; | ||
|
||
|
@@ -83,7 +85,7 @@ public interface ProgressListener { | |
|
||
private ProgressListener progressListener; | ||
|
||
static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException, PreferencesMapException { | ||
static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose, boolean save) throws RunnerException, PreferencesMapException { | ||
if (SketchData.checkSketchFile(data.getPrimaryFile()) == null) | ||
BaseNoGui.showError(_("Bad file selected"), | ||
_("Bad sketch primary file or bad sketch directory structure"), null); | ||
|
@@ -112,7 +114,7 @@ static public String build(SketchData data, String buildPath, File tempBuildFold | |
|
||
// compile the program. errors will happen as a RunnerException | ||
// that will bubble up to whomever called build(). | ||
if (compiler.compile(verbose)) { | ||
if (compiler.compile(verbose, save)) { | ||
compiler.size(compiler.getBuildPreferences()); | ||
return primaryClassName; | ||
} | ||
|
@@ -340,10 +342,11 @@ protected void size(PreferencesMap prefs) throws RunnerException { | |
* @return true if successful. | ||
* @throws RunnerException Only if there's a problem. Only then. | ||
*/ | ||
public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapException { | ||
public boolean compile(boolean _verbose, boolean _save) throws RunnerException, PreferencesMapException { | ||
preprocess(prefs.get("build.path")); | ||
|
||
verbose = _verbose || PreferencesData.getBoolean("build.verbose"); | ||
saveHex = _save; | ||
sketchIsCompiled = false; | ||
objectFiles = new ArrayList<File>(); | ||
|
||
|
@@ -381,31 +384,37 @@ public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapE | |
} | ||
|
||
// 1. compile the sketch (already in the buildPath) | ||
progressListener.progress(30); | ||
progressListener.progress(20); | ||
compileSketch(includeFolders); | ||
sketchIsCompiled = true; | ||
|
||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/ | ||
// Doesn't really use configPreferences | ||
progressListener.progress(40); | ||
progressListener.progress(30); | ||
compileLibraries(includeFolders); | ||
|
||
// 3. compile the core, outputting .o files to <buildPath> and then | ||
// collecting them into the core.a library file. | ||
progressListener.progress(50); | ||
progressListener.progress(40); | ||
compileCore(); | ||
|
||
// 4. link it all together into the .elf file | ||
progressListener.progress(60); | ||
progressListener.progress(50); | ||
compileLink(); | ||
|
||
// 5. extract EEPROM data (from EEMEM directive) to .eep file. | ||
progressListener.progress(70); | ||
progressListener.progress(60); | ||
runRecipe("recipe.objcopy.eep.pattern"); | ||
|
||
// 6. build the .hex file | ||
progressListener.progress(80); | ||
progressListener.progress(70); | ||
runRecipe("recipe.objcopy.hex.pattern"); | ||
|
||
// 7. save the hex file | ||
if (saveHex) { | ||
progressListener.progress(80); | ||
saveHex(); | ||
} | ||
|
||
progressListener.progress(90); | ||
return true; | ||
|
@@ -1042,6 +1051,37 @@ void runRecipe(String recipe) throws RunnerException, PreferencesMapException { | |
} | ||
execAsynchronously(cmdArray); | ||
} | ||
|
||
//7. Save the .hex file | ||
void saveHex() throws RunnerException { | ||
PreferencesMap dict = new PreferencesMap(prefs); | ||
dict.put("ide_version", "" + BaseNoGui.REVISION); | ||
|
||
String[] cmdArray; | ||
try { | ||
String tmp_file = prefs.getOrExcept("recipe.output.tmp_file"); | ||
tmp_file = StringReplacer.replaceFromMapping(tmp_file, dict); | ||
String save_file = prefs.getOrExcept("recipe.output.save_file"); | ||
save_file = StringReplacer.replaceFromMapping(save_file, dict); | ||
|
||
File hexFile = new File(prefs.get("build.path") + "/" + tmp_file); | ||
File saveFile = new File(sketch.getFolder().getAbsolutePath() + "/" + save_file); | ||
|
||
FileReader in = new FileReader(hexFile); | ||
FileWriter out = new FileWriter(saveFile); | ||
|
||
int c; | ||
while ((c = in.read()) != -1) | ||
out.write(c); | ||
|
||
in.close(); | ||
out.close(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May you add a message for verbose compile? Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also for AVR we would like to save the .eep ?? Arnav Gupta (championswimmer) On 18 February 2015 at 16:08, Cristian Maglie notifications@github.com
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, maybe we would like to list the files as a comma separated list? |
||
} catch (Exception e) { | ||
throw new RunnerException(e); | ||
} | ||
} | ||
|
||
|
||
private static String prepareIncludes(List<File> includeFolders) { | ||
String res = ""; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileUtils.copyFile may be used here.