Skip to content

Commit e82febe

Browse files
committed
Move FatalWarnings flags to existing fatalwarnings API
1 parent 5c440ef commit e82febe

File tree

19 files changed

+278
-34
lines changed

19 files changed

+278
-34
lines changed

modules/vstudio/tests/cs2005/test_compiler_props.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,15 @@
8181
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
8282
]]
8383
end
84+
85+
86+
function suite.treatWarningsAsErrors_onFatalWarningsAPI()
87+
fatalwarnings { "Compile" }
88+
prepare()
89+
test.capture [[
90+
<DefineConstants></DefineConstants>
91+
<ErrorReport>prompt</ErrorReport>
92+
<WarningLevel>4</WarningLevel>
93+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
94+
]]
95+
end

modules/vstudio/tests/vc200x/test_compiler_block.lua

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@
354354
-- Verify the correct warnings settings are used when FatalWarnings are enabled.
355355
--
356356

357-
function suite.runtimeLibraryIsDebug_onFatalWarnings()
357+
function suite.runtimeLibraryIsDebug_onFatalWarningsViaFlag()
358358
flags { "FatalWarnings" }
359359
prepare()
360360
test.capture [[
@@ -373,11 +373,30 @@
373373
end
374374

375375

376+
function suite.runtimeLibraryIsDebug_onFatalWarningsViaAPI()
377+
fatalwarnings { "Compile" }
378+
prepare()
379+
test.capture [[
380+
<Tool
381+
Name="VCCLCompilerTool"
382+
Optimization="0"
383+
BasicRuntimeChecks="3"
384+
RuntimeLibrary="2"
385+
EnableFunctionLevelLinking="true"
386+
UsePrecompiledHeader="0"
387+
WarningLevel="3"
388+
WarnAsError="true"
389+
DebugInformationFormat="0"
390+
/>
391+
]]
392+
end
393+
394+
376395
--
377396
-- Verify the correct warnings settings are used when no warnings are enabled.
378397
--
379398

380-
function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlags()
399+
function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlagsViaFlag()
381400
flags { "FatalWarnings" }
382401
warnings "Off"
383402
prepare()
@@ -396,6 +415,25 @@
396415
end
397416

398417

418+
function suite.runtimeLibraryIsDebug_onNoWarnings_whichDisablesAllOtherWarningsFlagsViaAPI()
419+
fatalwarnings { "Compile" }
420+
warnings "Off"
421+
prepare()
422+
test.capture [[
423+
<Tool
424+
Name="VCCLCompilerTool"
425+
Optimization="0"
426+
BasicRuntimeChecks="3"
427+
RuntimeLibrary="2"
428+
EnableFunctionLevelLinking="true"
429+
UsePrecompiledHeader="0"
430+
WarningLevel="0"
431+
DebugInformationFormat="0"
432+
/>
433+
]]
434+
end
435+
436+
399437
--
400438
-- Verify the correct Detect64BitPortabilityProblems settings are used when _ACTION < "VS2008".
401439
--

modules/vstudio/tests/vc2010/test_compile_settings.lua

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@
158158
<ClCompile>
159159
<PrecompiledHeader>NotUsing</PrecompiledHeader>
160160
<WarningLevel>TurnOffAllWarnings</WarningLevel>
161+
<Optimization>Disabled</Optimization>
162+
]]
163+
end
164+
165+
166+
function suite.warningLevel_onNoWarningsOverOtherWarningsAPI()
167+
fatalwarnings { "Compile" }
168+
warnings "Off"
169+
prepare()
170+
test.capture [[
171+
<ClCompile>
172+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
173+
<WarningLevel>TurnOffAllWarnings</WarningLevel>
174+
<Optimization>Disabled</Optimization>
161175
]]
162176
end
163177

@@ -544,7 +558,7 @@
544558
-- Add <TreatWarningAsError> if FatalWarnings flag is set.
545559
--
546560

547-
function suite.treatWarningsAsError_onFatalWarnings()
561+
function suite.treatWarningsAsError_onFatalWarningsViaFlag()
548562
flags { "FatalCompileWarnings" }
549563
prepare()
550564
test.capture [[
@@ -556,6 +570,18 @@
556570
end
557571

558572

573+
function suite.treatWarningsAsError_onFatalWarningsViaAPI()
574+
fatalwarnings { "Compile" }
575+
prepare()
576+
test.capture [[
577+
<ClCompile>
578+
<PrecompiledHeader>NotUsing</PrecompiledHeader>
579+
<WarningLevel>Level3</WarningLevel>
580+
<TreatWarningAsError>true</TreatWarningAsError>
581+
]]
582+
end
583+
584+
559585
--
560586
-- Check the handling of the Symbols flag.
561587
--

modules/vstudio/vs2005_dotnetbase.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@
286286
dotnetbase.allowUnsafeBlocks(cfg)
287287
end
288288

289-
if cfg.flags.FatalCompileWarnings then
289+
if p.hasFatalCompileWarnings(cfg.fatalwarnings) then
290290
_p(2,'<TreatWarningsAsErrors>true</TreatWarningsAsErrors>')
291291
end
292292

modules/vstudio/vs200x_vcproj.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@
15851585

15861586

15871587
function m.warnAsError(cfg)
1588-
if cfg.flags.FatalCompileWarnings and cfg.warnings ~= p.OFF then
1588+
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and cfg.warnings ~= p.OFF then
15891589
p.w('WarnAsError="true"')
15901590
end
15911591
end

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,7 +3179,7 @@
31793179

31803180

31813181
function m.treatLinkerWarningAsErrors(cfg)
3182-
if cfg.flags.FatalLinkWarnings then
3182+
if p.hasFatalLinkWarnings(cfg.fatalwarnings) then
31833183
local el = iif(cfg.kind == p.STATICLIB, "Lib", "Linker")
31843184
m.element("Treat" .. el .. "WarningAsErrors", nil, "true")
31853185
end
@@ -3196,7 +3196,7 @@
31963196

31973197

31983198
function m.treatWarningAsError(cfg)
3199-
if cfg.flags.FatalCompileWarnings and cfg.warnings ~= p.OFF then
3199+
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and cfg.warnings ~= p.OFF then
32003200
m.element("TreatWarningAsError", nil, "true")
32013201
end
32023202
end
@@ -3212,8 +3212,10 @@
32123212

32133213

32143214
function m.treatSpecificWarningsAsErrors(cfg, condition)
3215-
if #cfg.fatalwarnings > 0 then
3216-
local fatal = table.concat(cfg.fatalwarnings, ";")
3215+
local filteredWarnings = p.filterFatalWarnings(cfg.fatalwarnings)
3216+
3217+
if #filteredWarnings > 0 then
3218+
local fatal = table.concat(filteredWarnings, ";")
32173219
fatal = fatal .. ";%%(TreatSpecificWarningsAsErrors)"
32183220
m.element('TreatSpecificWarningsAsErrors', condition, fatal)
32193221
end

modules/xcode/tests/test_xcode_project.lua

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@
26982698
end
26992699

27002700

2701-
function suite.XCBuildConfigurationProject_OnFatalWarnings()
2701+
function suite.XCBuildConfigurationProject_OnFatalWarningsViaFlag()
27022702
flags { "FatalWarnings" }
27032703
prepare()
27042704
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
@@ -2724,6 +2724,32 @@
27242724
end
27252725

27262726

2727+
function suite.XCBuildConfigurationProject_OnFatalWarningsViaAPI()
2728+
fatalwarnings { "Compile", "Link" }
2729+
prepare()
2730+
xcode.XCBuildConfiguration_Project(tr, tr.configs[1])
2731+
test.capture [[
2732+
A14350AC4595EE5E57CE36EC /* Debug */ = {
2733+
isa = XCBuildConfiguration;
2734+
buildSettings = {
2735+
ARCHS = "$(NATIVE_ARCH_ACTUAL)";
2736+
CONFIGURATION_BUILD_DIR = "$(SYMROOT)";
2737+
CONFIGURATION_TEMP_DIR = "$(OBJROOT)";
2738+
GCC_OPTIMIZATION_LEVEL = 0;
2739+
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
2740+
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
2741+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
2742+
GCC_WARN_UNUSED_VARIABLE = YES;
2743+
OBJROOT = obj/Debug;
2744+
ONLY_ACTIVE_ARCH = NO;
2745+
SYMROOT = bin/Debug;
2746+
};
2747+
name = Debug;
2748+
};
2749+
]]
2750+
end
2751+
2752+
27272753
function suite.XCBuildConfigurationProject_OnFloatFast()
27282754
floatingpoint "Fast"
27292755
prepare()

modules/xcode/xcode_common.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@
15061506
settings['GCC_CHAR_IS_UNSIGNED_CHAR'] = iif(cfg.unsignedchar, "YES", "NO")
15071507
end
15081508

1509-
if cfg.flags.FatalWarnings then
1509+
if p.hasFatalCompileWarnings(cfg.fatalwarnings) and p.hasFatalLinkWarnings(cfg.fatalwarnings) then
15101510
settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
15111511
end
15121512

src/_premake_init.lua

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,9 @@
335335
"DebugEnvsDontMerge",
336336
"DebugEnvsInherit",
337337
"ExcludeFromBuild",
338-
"FatalCompileWarnings",
339-
"FatalLinkWarnings",
338+
"FatalCompileWarnings", -- DEPRECATED
339+
"FatalLinkWarnings", -- DEPRECATED
340+
"FatalWarnings", -- DEPRECATED
340341
"LinkTimeOptimization", -- DEPRECATED
341342
"Maps",
342343
"MFC",
@@ -357,9 +358,6 @@
357358
"UndefinedIdentifiers",
358359
"WPF",
359360
},
360-
aliases = {
361-
FatalWarnings = { "FatalWarnings", "FatalCompileWarnings", "FatalLinkWarnings" },
362-
},
363361
}
364362

365363
api.register {
@@ -1113,6 +1111,56 @@
11131111
linktimeoptimization("Default")
11141112
end)
11151113

1114+
api.deprecateValue("flags", "FatalWarnings", "Use `fatalwarnings { \"Compile\", \"Link\" }` instead.",
1115+
function(value)
1116+
fatalwarnings({ "Compile", "Link" })
1117+
end,
1118+
function(value)
1119+
removefatalwarnings({ "Compile", "Link" })
1120+
end)
1121+
1122+
api.deprecateValue("flags", "FatalCompileWarnings", "Use `fatalwarnings { \"Compile\" }` instead.",
1123+
function(value)
1124+
fatalwarnings({ "Compile" })
1125+
end,
1126+
function(value)
1127+
removefatalwarnings({ "Compile" })
1128+
end)
1129+
1130+
api.deprecateValue("flags", "FatalLinkWarnings", "Use `fatalwarnings { \"Link\" }` instead.",
1131+
function(value)
1132+
fatalwarnings({ "Link" })
1133+
end,
1134+
function(value)
1135+
removefatalwarnings({ "Link" })
1136+
end)
1137+
1138+
premake.filterFatalWarnings = function(tbl)
1139+
if type(tbl) == "table" then
1140+
return table.filter(tbl, function(warning)
1141+
return not (warning == "Compile" or warning == "Link")
1142+
end)
1143+
else
1144+
return tbl
1145+
end
1146+
end
1147+
1148+
premake.hasFatalCompileWarnings = function(tbl)
1149+
if (type(tbl) == "table") then
1150+
return table.contains(tbl, "Compile")
1151+
else
1152+
return false
1153+
end
1154+
end
1155+
1156+
premake.hasFatalLinkWarnings = function(tbl)
1157+
if (type(tbl) == "table") then
1158+
return table.contains(tbl, "Link")
1159+
else
1160+
return false
1161+
end
1162+
end
1163+
11161164

11171165
-----------------------------------------------------------------------------
11181166
--

src/tools/clang.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444

4545
clang.shared = {
4646
architecture = gcc.shared.architecture,
47+
fatalwarnings = {
48+
Compile = "-Werror"
49+
},
4750
flags = gcc.shared.flags,
4851
floatingpoint = {
4952
Fast = "-ffast-math",
@@ -227,6 +230,9 @@
227230
x86 = "-m32",
228231
x86_64 = "-m64",
229232
},
233+
fatalwarnings = {
234+
Link = "-Wl,--fatal-warnings",
235+
},
230236
linktimeoptimization = clang.shared.linktimeoptimization,
231237
kind = {
232238
SharedLib = function(cfg)

0 commit comments

Comments
 (0)