Skip to content

Commit 81808d5

Browse files
committed
Merge branch 'ide-1.5.x-fail-when-no-platform-txt' of https://github.com/ffissore/Arduino into ide-1.5.x
2 parents 60309fe + b16ee6c commit 81808d5

File tree

3 files changed

+46
-109
lines changed

3 files changed

+46
-109
lines changed

app/src/processing/app/Editor.java

+19-24
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,8 @@ public void setHandlers(Runnable runHandler, Runnable presentHandler,
14261426

14271427

14281428
public void resetHandlers() {
1429-
runHandler = new DefaultRunHandler();
1430-
presentHandler = new DefaultPresentHandler();
1429+
runHandler = new BuildHandler();
1430+
presentHandler = new BuildHandler(true);
14311431
stopHandler = new DefaultStopHandler();
14321432
exportHandler = new DefaultExportHandler();
14331433
exportAppHandler = new DefaultExportAppHandler();
@@ -1917,30 +1917,28 @@ public void handleRun(final boolean verbose) {
19171917
new Thread(verbose ? presentHandler : runHandler).start();
19181918
}
19191919

1920-
// DAM: in Arduino, this is compile
1921-
class DefaultRunHandler implements Runnable {
1922-
public void run() {
1923-
try {
1924-
sketch.prepare();
1925-
sketch.build(false);
1926-
statusNotice(_("Done compiling."));
1927-
} catch (Exception e) {
1928-
status.unprogress();
1929-
statusError(e);
1930-
}
1920+
class BuildHandler implements Runnable {
19311921

1932-
status.unprogress();
1933-
toolbar.deactivate(EditorToolbar.RUN);
1922+
private final boolean verbose;
1923+
1924+
public BuildHandler() {
1925+
this(false);
19341926
}
1935-
}
19361927

1937-
// DAM: in Arduino, this is compile (with verbose output)
1938-
class DefaultPresentHandler implements Runnable {
1928+
public BuildHandler(boolean verbose) {
1929+
this.verbose = verbose;
1930+
}
1931+
1932+
@Override
19391933
public void run() {
19401934
try {
19411935
sketch.prepare();
1942-
sketch.build(true);
1936+
sketch.build(verbose);
19431937
statusNotice(_("Done compiling."));
1938+
} catch (PreferencesMapException e) {
1939+
statusError(I18n.format(
1940+
_("Error while compiling: missing '{0}' configuration parameter"),
1941+
e.getMessage()));
19441942
} catch (Exception e) {
19451943
status.unprogress();
19461944
statusError(e);
@@ -1953,11 +1951,8 @@ public void run() {
19531951

19541952
class DefaultStopHandler implements Runnable {
19551953
public void run() {
1956-
try {
1957-
// DAM: we should try to kill the compilation or upload process here.
1958-
} catch (Exception e) {
1959-
statusError(e);
1960-
}
1954+
// TODO
1955+
// DAM: we should try to kill the compilation or upload process here.
19611956
}
19621957
}
19631958

app/src/processing/app/Sketch.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import processing.app.debug.RunnerException;
3030
import processing.app.forms.PasswordAuthorizationDialog;
3131
import processing.app.helpers.OSUtils;
32+
import processing.app.helpers.PreferencesMapException;
3233
import processing.app.packages.Library;
3334
import static processing.app.I18n._;
3435

@@ -1129,7 +1130,7 @@ public void prepare() throws IOException {
11291130
* @return null if compilation failed, main class name if not
11301131
* @throws RunnerException
11311132
*/
1132-
public String build(boolean verbose) throws RunnerException {
1133+
public String build(boolean verbose) throws RunnerException, PreferencesMapException {
11331134
return build(tempBuildFolder.getAbsolutePath(), verbose);
11341135
}
11351136

@@ -1142,7 +1143,7 @@ public String build(boolean verbose) throws RunnerException {
11421143
*
11431144
* @return null if compilation failed, main class name if not
11441145
*/
1145-
public String build(String buildPath, boolean verbose) throws RunnerException {
1146+
public String build(String buildPath, boolean verbose) throws RunnerException, PreferencesMapException {
11461147
// run the preprocessor
11471148
editor.status.progressUpdate(20);
11481149

arduino-core/src/processing/app/debug/Compiler.java

+24-83
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@
4949
import processing.app.PreferencesData;
5050
import processing.app.SketchCode;
5151
import processing.app.SketchData;
52-
import processing.app.helpers.FileUtils;
53-
import processing.app.helpers.PreferencesMap;
54-
import processing.app.helpers.ProcessUtils;
55-
import processing.app.helpers.StringReplacer;
52+
import processing.app.helpers.*;
5653
import processing.app.helpers.filefilters.OnlyDirs;
5754
import processing.app.packages.Library;
5855
import processing.app.packages.LibraryList;
@@ -86,7 +83,7 @@ public interface ProgressListener {
8683

8784
private ProgressListener progressListener;
8885

89-
static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException {
86+
static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException, PreferencesMapException {
9087
if (SketchData.checkSketchFile(data.getPrimaryFile()) == null)
9188
BaseNoGui.showError(_("Bad file selected"),
9289
_("Bad sketch primary file or bad sketck directory structure"), null);
@@ -338,12 +335,12 @@ protected void size(PreferencesMap prefs) throws RunnerException {
338335

339336
/**
340337
* Compile sketch.
341-
* @param buildPath
338+
* @param _verbose
342339
*
343340
* @return true if successful.
344341
* @throws RunnerException Only if there's a problem. Only then.
345342
*/
346-
public boolean compile(boolean _verbose) throws RunnerException {
343+
public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapException {
347344
preprocess(prefs.get("build.path"));
348345

349346
verbose = _verbose || PreferencesData.getBoolean("build.verbose");
@@ -404,11 +401,11 @@ public boolean compile(boolean _verbose) throws RunnerException {
404401

405402
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
406403
progressListener.progress(70);
407-
compileEep();
404+
runRecipe("recipe.objcopy.eep.pattern");
408405

409406
// 6. build the .hex file
410407
progressListener.progress(80);
411-
compileHex();
408+
runRecipe("recipe.objcopy.hex.pattern");
412409

413410
progressListener.progress(90);
414411
return true;
@@ -505,7 +502,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
505502

506503
private List<File> compileFiles(File outputPath, File sourcePath,
507504
boolean recurse, List<File> includeFolders)
508-
throws RunnerException {
505+
throws RunnerException, PreferencesMapException {
509506
List<File> sSources = findFilesInFolder(sourcePath, "S", recurse);
510507
List<File> cSources = findFilesInFolder(sourcePath, "c", recurse);
511508
List<File> cppSources = findFilesInFolder(sourcePath, "cpp", recurse);
@@ -514,7 +511,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
514511
for (File file : sSources) {
515512
File objectFile = new File(outputPath, file.getName() + ".o");
516513
objectPaths.add(objectFile);
517-
String[] cmd = getCommandCompilerS(includeFolders, file, objectFile);
514+
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.S.o.pattern");
518515
execAsynchronously(cmd);
519516
}
520517

@@ -524,7 +521,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
524521
objectPaths.add(objectFile);
525522
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
526523
continue;
527-
String[] cmd = getCommandCompilerC(includeFolders, file, objectFile);
524+
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.c.o.pattern");
528525
execAsynchronously(cmd);
529526
}
530527

@@ -534,7 +531,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
534531
objectPaths.add(objectFile);
535532
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
536533
continue;
537-
String[] cmd = getCommandCompilerCPP(includeFolders, file, objectFile);
534+
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.cpp.o.pattern");
538535
execAsynchronously(cmd);
539536
}
540537

@@ -545,7 +542,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
545542
* Strip escape sequences used in makefile dependency files (.d)
546543
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
547544
*
548-
* @param dep
545+
* @param line
549546
* @return
550547
*/
551548
protected static String unescapeDepFile(String line) {
@@ -814,55 +811,15 @@ public void message(String s) {
814811
System.err.print(s);
815812
}
816813

817-
private String[] getCommandCompilerS(List<File> includeFolders,
818-
File sourceFile, File objectFile)
819-
throws RunnerException {
820-
String includes = prepareIncludes(includeFolders);
821-
PreferencesMap dict = new PreferencesMap(prefs);
822-
dict.put("ide_version", "" + BaseNoGui.REVISION);
823-
dict.put("includes", includes);
824-
dict.put("source_file", sourceFile.getAbsolutePath());
825-
dict.put("object_file", objectFile.getAbsolutePath());
826-
827-
try {
828-
String cmd = prefs.get("recipe.S.o.pattern");
829-
return StringReplacer.formatAndSplit(cmd, dict, true);
830-
} catch (Exception e) {
831-
throw new RunnerException(e);
832-
}
833-
}
834-
835-
private String[] getCommandCompilerC(List<File> includeFolders,
836-
File sourceFile, File objectFile)
837-
throws RunnerException {
838-
String includes = prepareIncludes(includeFolders);
839-
840-
PreferencesMap dict = new PreferencesMap(prefs);
841-
dict.put("ide_version", "" + BaseNoGui.REVISION);
842-
dict.put("includes", includes);
843-
dict.put("source_file", sourceFile.getAbsolutePath());
844-
dict.put("object_file", objectFile.getAbsolutePath());
845-
846-
String cmd = prefs.get("recipe.c.o.pattern");
847-
try {
848-
return StringReplacer.formatAndSplit(cmd, dict, true);
849-
} catch (Exception e) {
850-
throw new RunnerException(e);
851-
}
852-
}
853-
854-
private String[] getCommandCompilerCPP(List<File> includeFolders,
855-
File sourceFile, File objectFile)
856-
throws RunnerException {
814+
private String[] getCommandCompilerByRecipe(List<File> includeFolders, File sourceFile, File objectFile, String recipe) throws PreferencesMapException, RunnerException {
857815
String includes = prepareIncludes(includeFolders);
858-
859816
PreferencesMap dict = new PreferencesMap(prefs);
860817
dict.put("ide_version", "" + BaseNoGui.REVISION);
861818
dict.put("includes", includes);
862819
dict.put("source_file", sourceFile.getAbsolutePath());
863820
dict.put("object_file", objectFile.getAbsolutePath());
864821

865-
String cmd = prefs.get("recipe.cpp.o.pattern");
822+
String cmd = prefs.getOrExcept(recipe);
866823
try {
867824
return StringReplacer.formatAndSplit(cmd, dict, true);
868825
} catch (Exception e) {
@@ -909,21 +866,21 @@ static public List<File> findFilesInFolder(File folder, String extension,
909866
}
910867

911868
// 1. compile the sketch (already in the buildPath)
912-
void compileSketch(List<File> includeFolders) throws RunnerException {
869+
void compileSketch(List<File> includeFolders) throws RunnerException, PreferencesMapException {
913870
File buildPath = prefs.getFile("build.path");
914871
objectFiles.addAll(compileFiles(buildPath, buildPath, false, includeFolders));
915872
}
916873

917874
// 2. compile the libraries, outputting .o files to:
918875
// <buildPath>/<library>/
919-
void compileLibraries(List<File> includeFolders) throws RunnerException {
876+
void compileLibraries(List<File> includeFolders) throws RunnerException, PreferencesMapException {
920877
for (Library lib : importedLibraries) {
921878
compileLibrary(lib, includeFolders);
922879
}
923880
}
924881

925882
private void compileLibrary(Library lib, List<File> includeFolders)
926-
throws RunnerException {
883+
throws RunnerException, PreferencesMapException {
927884
File libFolder = lib.getSrcFolder();
928885
File libBuildFolder = prefs.getFile(("build.path"), lib.getName());
929886

@@ -949,15 +906,15 @@ private void compileLibrary(Library lib, List<File> includeFolders)
949906
}
950907
}
951908

952-
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<File> includeFolders) throws RunnerException {
909+
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<File> includeFolders) throws RunnerException, PreferencesMapException {
953910
compileFilesInFolder(srcBuildFolder, srcFolder, includeFolders);
954911
for (File subFolder : srcFolder.listFiles(new OnlyDirs())) {
955912
File subBuildFolder = new File(srcBuildFolder, subFolder.getName());
956913
recursiveCompileFilesInFolder(subBuildFolder, subFolder, includeFolders);
957914
}
958915
}
959916

960-
private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> includeFolders) throws RunnerException {
917+
private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> includeFolders) throws RunnerException, PreferencesMapException {
961918
createFolder(buildFolder);
962919
List<File> objects = compileFiles(buildFolder, srcFolder, false, includeFolders);
963920
objectFiles.addAll(objects);
@@ -968,7 +925,7 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> i
968925
// Also compiles the variant (if it supplies actual source files),
969926
// which are included in the link directly (not through core.a)
970927
void compileCore()
971-
throws RunnerException {
928+
throws RunnerException, PreferencesMapException {
972929

973930
File coreFolder = prefs.getFile("build.core.path");
974931
File variantFolder = prefs.getFile("build.variant.path");
@@ -1024,8 +981,8 @@ void compileCore()
1024981
dict.put("object_file", file.getAbsolutePath());
1025982

1026983
String[] cmdArray;
984+
String cmd = prefs.getOrExcept("recipe.ar.pattern");
1027985
try {
1028-
String cmd = prefs.get("recipe.ar.pattern");
1029986
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
1030987
} catch (Exception e) {
1031988
throw new RunnerException(e);
@@ -1040,7 +997,7 @@ void compileCore()
1040997

1041998
// 4. link it all together into the .elf file
1042999
void compileLink()
1043-
throws RunnerException {
1000+
throws RunnerException, PreferencesMapException {
10441001

10451002
// TODO: Make the --relax thing in configuration files.
10461003

@@ -1063,38 +1020,22 @@ void compileLink()
10631020
dict.put("ide_version", "" + BaseNoGui.REVISION);
10641021

10651022
String[] cmdArray;
1023+
String cmd = prefs.getOrExcept("recipe.c.combine.pattern");
10661024
try {
1067-
String cmd = prefs.get("recipe.c.combine.pattern");
10681025
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
10691026
} catch (Exception e) {
10701027
throw new RunnerException(e);
10711028
}
10721029
execAsynchronously(cmdArray);
10731030
}
10741031

1075-
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
1076-
void compileEep() throws RunnerException {
1077-
PreferencesMap dict = new PreferencesMap(prefs);
1078-
dict.put("ide_version", "" + BaseNoGui.REVISION);
1079-
1080-
String[] cmdArray;
1081-
try {
1082-
String cmd = prefs.get("recipe.objcopy.eep.pattern");
1083-
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
1084-
} catch (Exception e) {
1085-
throw new RunnerException(e);
1086-
}
1087-
execAsynchronously(cmdArray);
1088-
}
1089-
1090-
// 6. build the .hex file
1091-
void compileHex() throws RunnerException {
1032+
void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
10921033
PreferencesMap dict = new PreferencesMap(prefs);
10931034
dict.put("ide_version", "" + BaseNoGui.REVISION);
10941035

10951036
String[] cmdArray;
1037+
String cmd = prefs.getOrExcept(recipe);
10961038
try {
1097-
String cmd = prefs.get("recipe.objcopy.hex.pattern");
10981039
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
10991040
} catch (Exception e) {
11001041
throw new RunnerException(e);

0 commit comments

Comments
 (0)