summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-06-19 21:38:58 +0800
committerruki <[email protected]>2022-06-19 21:38:58 +0800
commitd43525ea44aeebe87068817549b2b9dbdb43c47b (patch)
treee74d4a8645ce147b09a97f0e1bc8ef5c9b0a7c43
parente3b3ffbc6230e9dee45a38356095705f9705966f (diff)
add build.warning policy
-rw-r--r--xmake/core/project/policy.lua2
-rw-r--r--xmake/modules/core/tools/cl.lua18
-rw-r--r--xmake/modules/core/tools/gcc.lua18
3 files changed, 36 insertions, 2 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index c169b921e..e6a20aef9 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -47,6 +47,8 @@ function policy.policies()
["build.merge_archive"] = {description = "Enable merge archive intead of linking for all dependent targets.", default = false, type = "boolean"},
-- C/C++ build cache
["build.ccache"] = {description = "Enable C/C++ build cache.", type = "boolean"},
+ -- Enable build warning output, it's disabled by default and we need `xmake -w/-vD` to look at it.
+ ["build.warning"] = {description = "Enable build warning output.", type = "boolean"},
-- preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess
["preprocessor.linemarkers"] = {description = "Enable linemarkers for preprocessor.", default = true, type = "boolean"},
-- preprocessor configuration for ccache/distcc, we can disable it to avoid cache object file with __DATE__, __TIME__
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua
index d736c0ad2..703250c8b 100644
--- a/xmake/modules/core/tools/cl.lua
+++ b/xmake/modules/core/tools/cl.lua
@@ -366,6 +366,22 @@ function _compargv_pch(self, pcheaderfile, pcoutputfile, flags)
return self:program(), table.join("-c", "-Yc", pchflags, "-Fp" .. pcoutputfile, "-Fo" .. pcoutputfile .. ".obj", pcheaderfile)
end
+-- has warnings output?
+function _has_warnings()
+ local warnings = _g.warnings
+ if warnings == nil then
+ warnings = option.get("diagnosis") or option.get("warning")
+ if warnings == nil and os.isfile(os.projectfile()) and project.policy("build.warning") ~= nil then
+ warnings = project.policy("build.warning")
+ end
+ if warnings == nil then
+ warnings = global.get("build_warning")
+ end
+ _g.warnings = warnings or false
+ end
+ return warnings
+end
+
-- has /sourceDependencies xxx.json @see https://github.com/xmake-io/xmake/issues/868?
function _has_source_dependencies(self)
local has_source_dependencies = _g._HAS_SOURCE_DEPENDENCIES
@@ -616,7 +632,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
function (ok, outdata, errdata)
-- show warnings?
- if ok and (option.get("diagnosis") or option.get("warning") or global.get("build_warning")) then
+ if ok and _has_warnings() then
local output = outdata or ""
if #output:trim() == 0 then
output = errdata or ""
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index cf8fad4db..93674a702 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -368,6 +368,22 @@ function link(self, objectfiles, targetkind, targetfile, flags)
os.runv(program, argv, {envs = self:runenvs()})
end
+-- has warnings output?
+function _has_warnings()
+ local warnings = _g.warnings
+ if warnings == nil then
+ warnings = option.get("diagnosis") or option.get("warning")
+ if warnings == nil and os.isfile(os.projectfile()) and project.policy("build.warning") ~= nil then
+ warnings = project.policy("build.warning")
+ end
+ if warnings == nil then
+ warnings = global.get("build_warning")
+ end
+ _g.warnings = warnings or false
+ end
+ return warnings
+end
+
-- has color diagnostics?
function _has_color_diagnostics(self)
local colors_diagnostics = _g._HAS_COLOR_DIAGNOSTICS
@@ -657,7 +673,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags)
{
function (ok, outdata, errdata)
-- show warnings?
- if ok and errdata and #errdata > 0 and (option.get("diagnosis") or option.get("warning") or global.get("build_warning")) then
+ if ok and errdata and #errdata > 0 and _has_warnings() then
local lines = errdata:split('\n', {plain = true})
if #lines > 0 then
if not option.get("diagnosis") then