Skip to content

Commit 61592d7

Browse files
author
Federico Fissore
committed
New preference: enable all compiler warnings, off by default. Fixes #1728 and #2415. Also affects #2634 and #2207
1 parent 37e2a19 commit 61592d7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Diff for: app/src/processing/app/Preferences.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ public String toString() {
203203
JCheckBox verboseCompilationBox;
204204
JCheckBox verboseUploadBox;
205205
JCheckBox displayLineNumbersBox;
206+
JCheckBox enableCompilerWarningsBox;
206207
JCheckBox verifyUploadBox;
207208
JCheckBox externalEditorBox;
208-
JCheckBox memoryOverrideBox;
209-
JTextField memoryField;
210209
JCheckBox checkUpdatesBox;
211210
JTextField fontSizeField;
212211
JCheckBox updateExtensionBox;
@@ -352,6 +351,15 @@ public void actionPerformed(ActionEvent e) {
352351
pane.add(box);
353352
d = box.getPreferredSize();
354353
box.setBounds(left, top, d.width, d.height);
354+
top += d.height + GUI_BETWEEN;
355+
356+
// [ ] Enable all compiler warnings
357+
358+
enableCompilerWarningsBox = new JCheckBox(_("Enable all compiler warnings"));
359+
pane.add(enableCompilerWarningsBox);
360+
d = enableCompilerWarningsBox.getPreferredSize();
361+
enableCompilerWarningsBox.setBounds(left, top, d.width + 10, d.height);
362+
right = Math.max(right, left + d.width);
355363
top += d.height + GUI_BETWEEN;
356364

357365
// [ ] Display line numbers
@@ -674,6 +682,7 @@ protected void applyFrame() {
674682
PreferencesData.setBoolean("editor.linenumbers", displayLineNumbersBox.isSelected());
675683
PreferencesData.setBoolean("upload.verify", verifyUploadBox.isSelected());
676684
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
685+
PreferencesData.setBoolean("build.allwarnings", enableCompilerWarningsBox.isSelected());
677686

678687
// setBoolean("sketchbook.closing_last_window_quits",
679688
// closingLastQuitsBox.isSelected());
@@ -758,6 +767,7 @@ protected void showFrame(Editor editor) {
758767
verboseUploadBox.setSelected(PreferencesData.getBoolean("upload.verbose"));
759768
displayLineNumbersBox.setSelected(PreferencesData.getBoolean("editor.linenumbers"));
760769
verifyUploadBox.setSelected(PreferencesData.getBoolean("upload.verify"));
770+
enableCompilerWarningsBox.setSelected(PreferencesData.getBoolean("build.allwarnings"));
761771

762772
//closingLastQuitsBox.
763773
// setSelected(getBoolean("sketchbook.closing_last_window_quits"));

Diff for: arduino-core/src/processing/app/debug/Compiler.java

+14
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
559559
File objectFile = new File(outputPath, file.getName() + ".o");
560560
objectPaths.add(objectFile);
561561
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.S.o.pattern");
562+
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
562563
execAsynchronously(cmd);
563564
}
564565

@@ -569,6 +570,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
569570
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
570571
continue;
571572
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.c.o.pattern");
573+
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
572574
execAsynchronously(cmd);
573575
}
574576

@@ -579,12 +581,24 @@ private List<File> compileFiles(File outputPath, File sourcePath,
579581
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
580582
continue;
581583
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.cpp.o.pattern");
584+
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
582585
execAsynchronously(cmd);
583586
}
584587

585588
return objectPaths;
586589
}
587590

591+
private String[] enableWarnings(String[] cmd, boolean enable) {
592+
if (!enable) {
593+
return cmd;
594+
}
595+
596+
List<String> cmdList = new ArrayList<String>(Arrays.asList(cmd));
597+
cmdList.remove("-w");
598+
599+
return cmdList.toArray(new String[cmdList.size()]);
600+
}
601+
588602
/**
589603
* Strip escape sequences used in makefile dependency files (.d)
590604
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845

Diff for: arduino-core/src/processing/app/helpers/PreferencesMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public File getFile(String key, String subFolder) {
311311
* insensitive compared), <b>false</b> in any other case
312312
*/
313313
public boolean getBoolean(String key) {
314-
return new Boolean(get(key));
314+
return Boolean.valueOf(get(key));
315315
}
316316

317317
/**

0 commit comments

Comments
 (0)