Skip to content

Commit b42c666

Browse files
author
Federico Fissore
committed
Better preference for setting warnings level. See arduino@61592d7#commitcomment-10668365
1 parent c740f25 commit b42c666

File tree

4 files changed

+73
-27
lines changed

4 files changed

+73
-27
lines changed

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

+39-7
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,25 @@ public String toString() {
165165
new Language(_("Western Frisian"), "Western Frisian", "fy"),
166166
};
167167

168+
private static class WarningItem {
169+
private final String value;
170+
private final String translation;
171+
172+
public WarningItem(String value, String translation) {
173+
this.value = value;
174+
this.translation = translation;
175+
}
176+
177+
public String getValue() {
178+
return value;
179+
}
180+
181+
@Override
182+
public String toString() {
183+
return translation;
184+
}
185+
}
186+
168187
/**
169188
* Standardized width for buttons. Mac OS X 10.3 wants 70 as its default,
170189
* Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper.
@@ -203,14 +222,14 @@ public String toString() {
203222
JCheckBox verboseCompilationBox;
204223
JCheckBox verboseUploadBox;
205224
JCheckBox displayLineNumbersBox;
206-
JCheckBox enableCompilerWarningsBox;
207225
JCheckBox verifyUploadBox;
208226
JCheckBox externalEditorBox;
209227
JCheckBox checkUpdatesBox;
210228
JTextField fontSizeField;
211229
JCheckBox updateExtensionBox;
212230
JCheckBox autoAssociateBox;
213231
JComboBox comboLanguage;
232+
JComboBox comboWarnings;
214233
JCheckBox saveVerifyUploadBox;
215234
JTextField proxyHTTPServer;
216235
JTextField proxyHTTPPort;
@@ -355,10 +374,22 @@ public void actionPerformed(ActionEvent e) {
355374

356375
// [ ] Enable all compiler warnings
357376

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);
377+
box = Box.createHorizontalBox();
378+
label = new JLabel(_("Compiler warnings: "));
379+
box.add(label);
380+
WarningItem[] warningItems = new WarningItem[]{new WarningItem("none", _("none")), new WarningItem("normal", _("normal")), new WarningItem("all", _("all")), new WarningItem("extra", _("extra")), };
381+
comboWarnings = new JComboBox(warningItems);
382+
String currentWarningLevel = PreferencesData.get("compiler.warning_flags", "none");
383+
for (WarningItem item : warningItems) {
384+
if (currentWarningLevel.equals(item.getValue())) {
385+
comboWarnings.setSelectedItem(item);
386+
}
387+
}
388+
box.add(comboWarnings);
389+
pane.add(box);
390+
d = box.getPreferredSize();
391+
box.setForeground(Color.gray);
392+
box.setBounds(left, top, d.width, d.height);
362393
right = Math.max(right, left + d.width);
363394
top += d.height + GUI_BETWEEN;
364395

@@ -682,7 +713,6 @@ protected void applyFrame() {
682713
PreferencesData.setBoolean("editor.linenumbers", displayLineNumbersBox.isSelected());
683714
PreferencesData.setBoolean("upload.verify", verifyUploadBox.isSelected());
684715
PreferencesData.setBoolean("editor.save_on_verify", saveVerifyUploadBox.isSelected());
685-
PreferencesData.setBoolean("build.allwarnings", enableCompilerWarningsBox.isSelected());
686716

687717
// setBoolean("sketchbook.closing_last_window_quits",
688718
// closingLastQuitsBox.isSelected());
@@ -740,6 +770,9 @@ protected void applyFrame() {
740770
Language newLanguage = (Language) comboLanguage.getSelectedItem();
741771
PreferencesData.set("editor.languages.current", newLanguage.isoCode);
742772

773+
WarningItem warningItem = (WarningItem) comboWarnings.getSelectedItem();
774+
PreferencesData.set("compiler.warning_flags", warningItem.getValue());
775+
743776
Preferences.set("proxy.http.server", proxyHTTPServer.getText());
744777
try {
745778
Preferences.set("proxy.http.port", Integer.valueOf(proxyHTTPPort.getText()).toString());
@@ -767,7 +800,6 @@ protected void showFrame(Editor editor) {
767800
verboseUploadBox.setSelected(PreferencesData.getBoolean("upload.verbose"));
768801
displayLineNumbersBox.setSelected(PreferencesData.getBoolean("editor.linenumbers"));
769802
verifyUploadBox.setSelected(PreferencesData.getBoolean("upload.verify"));
770-
enableCompilerWarningsBox.setSelected(PreferencesData.getBoolean("build.allwarnings"));
771803

772804
//closingLastQuitsBox.
773805
// setSelected(getBoolean("sketchbook.closing_last_window_quits"));

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

+17-14
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ private List<File> compileFiles(File outputPath, File sourcePath,
557557
File objectFile = new File(outputPath, file.getName() + ".o");
558558
objectPaths.add(objectFile);
559559
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.S.o.pattern");
560-
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
561560
execAsynchronously(cmd);
562561
}
563562

@@ -568,7 +567,6 @@ private List<File> compileFiles(File outputPath, File sourcePath,
568567
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
569568
continue;
570569
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.c.o.pattern");
571-
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
572570
execAsynchronously(cmd);
573571
}
574572

@@ -579,24 +577,12 @@ private List<File> compileFiles(File outputPath, File sourcePath,
579577
if (isAlreadyCompiled(file, objectFile, dependFile, prefs))
580578
continue;
581579
String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.cpp.o.pattern");
582-
cmd = enableWarnings(cmd, prefs.getBoolean("build.allwarnings"));
583580
execAsynchronously(cmd);
584581
}
585582

586583
return objectPaths;
587584
}
588585

589-
private String[] enableWarnings(String[] cmd, boolean enable) {
590-
if (!enable) {
591-
return cmd;
592-
}
593-
594-
List<String> cmdList = new ArrayList<String>(Arrays.asList(cmd));
595-
cmdList.remove("-w");
596-
597-
return cmdList.toArray(new String[cmdList.size()]);
598-
}
599-
600586
/**
601587
* Strip escape sequences used in makefile dependency files (.d)
602588
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
@@ -906,6 +892,8 @@ private String[] getCommandCompilerByRecipe(List<File> includeFolders, File sour
906892
dict.put("source_file", sourceFile.getAbsolutePath());
907893
dict.put("object_file", objectFile.getAbsolutePath());
908894

895+
setupWarningFlags(dict);
896+
909897
String cmd = prefs.getOrExcept(recipe);
910898
try {
911899
return StringReplacer.formatAndSplit(cmd, dict, true);
@@ -914,6 +902,19 @@ private String[] getCommandCompilerByRecipe(List<File> includeFolders, File sour
914902
}
915903
}
916904

905+
private void setupWarningFlags(PreferencesMap dict) {
906+
if (dict.containsKey("compiler.warning_flags")) {
907+
String key = "compiler.warning_flags." + dict.get("compiler.warning_flags");
908+
dict.put("compiler.warning_flags", dict.get(key));
909+
} else {
910+
dict.put("compiler.warning_flags", dict.get("compiler.warning_flags.none"));
911+
}
912+
913+
if (dict.get("compiler.warning_flags") == null) {
914+
dict.remove("compiler.warning_flags");
915+
}
916+
}
917+
917918
/////////////////////////////////////////////////////////////////////////////
918919

919920
private void createFolder(File folder) throws RunnerException {
@@ -1106,6 +1107,8 @@ void compileLink()
11061107
dict.put("object_files", objectFileList);
11071108
dict.put("ide_version", "" + BaseNoGui.REVISION);
11081109

1110+
setupWarningFlags(dict);
1111+
11091112
String[] cmdArray;
11101113
String cmd = prefs.getOrExcept("recipe.c.combine.pattern");
11111114
try {

Diff for: hardware/arduino/avr/platform.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Arduino AVR Core and platform.
33
# ------------------------------
4-
4+
#
55
# For more info:
66
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
77

@@ -11,17 +11,22 @@ version=1.6.3
1111
# AVR compile variables
1212
# ---------------------
1313

14+
compiler.warning_flags.none=-w
15+
compiler.warning_flags.normal=
16+
compiler.warning_flags.all=-Wall
17+
compiler.warning_flags.extra=-Wall -Wextra
18+
1419
# Default "compiler.path" is correct, change only if you want to overidde the initial value
1520
compiler.path={runtime.tools.avr-gcc.path}/bin/
1621
compiler.c.cmd=avr-gcc
17-
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD
22+
compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -MMD
1823
# -w flag added to avoid printing a wrong warning http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59396
1924
# This is fixed in gcc 4.8.3 and will be removed as soon as we update the toolchain
20-
compiler.c.elf.flags=-w -Os -Wl,--gc-sections
25+
compiler.c.elf.flags={compiler.warning_flags} -Os -Wl,--gc-sections
2126
compiler.c.elf.cmd=avr-gcc
2227
compiler.S.flags=-c -g -x assembler-with-cpp
2328
compiler.cpp.cmd=avr-g++
24-
compiler.cpp.flags=-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
29+
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD
2530
compiler.ar.cmd=avr-ar
2631
compiler.ar.flags=rcs
2732
compiler.objcopy.cmd=avr-objcopy

Diff for: hardware/arduino/sam/platform.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
# Arduino SAM Core and platform.
3+
# ------------------------------
34
#
45
# For more info:
56
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
@@ -10,14 +11,19 @@ version=1.6.3
1011
# SAM3 compile variables
1112
# ----------------------
1213

14+
compiler.warning_flags.none=-w
15+
compiler.warning_flags.normal=
16+
compiler.warning_flags.all=-Wall
17+
compiler.warning_flags.extra=-Wall -Wextra
18+
1319
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
1420
compiler.c.cmd=arm-none-eabi-gcc
15-
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD
21+
compiler.c.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -Dprintf=iprintf -MMD
1622
compiler.c.elf.cmd=arm-none-eabi-gcc
1723
compiler.c.elf.flags=-Os -Wl,--gc-sections
1824
compiler.S.flags=-c -g -x assembler-with-cpp
1925
compiler.cpp.cmd=arm-none-eabi-g++
20-
compiler.cpp.flags=-c -g -Os -w -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD
26+
compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -ffunction-sections -fdata-sections -nostdlib -fno-threadsafe-statics --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -MMD
2127
compiler.ar.cmd=arm-none-eabi-ar
2228
compiler.ar.flags=rcs
2329
compiler.objcopy.cmd=arm-none-eabi-objcopy

0 commit comments

Comments
 (0)