From 191e81df8e0876ee8f0e2d3c94f8dbf5311c963c Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Thu, 29 Aug 2013 12:20:53 -0400 Subject: [PATCH] Improved use of premake.warnOnce() --- src/_premake_main.lua | 6 +++--- src/base/api.lua | 30 +++++++++--------------------- src/base/os.lua | 2 +- src/base/premake.lua | 36 +++++++++++++++++++++++++----------- tests/testfx.lua | 1 + 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index bc355c9f..8562d513 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -39,9 +39,9 @@ -- name so the extension directory name _must_ be the same as the -- extension Lua file. eg. .../d/d.lua, .../codelite/codelite.lua etc local home = os.getenv("HOME") or os.getenv("USERPROFILE") - local extdirs = { + local extdirs = { home .. "/.premake/?/?.lua", - path.getdirectory( _PREMAKE_COMMAND ) .. "/ext/?/?.lua", + path.getdirectory( _PREMAKE_COMMAND ) .. "/ext/?/?.lua", "./premake/?/?.lua", "/usr/share/premake/?/?.lua" } for _,v in ipairs(extdirs) do @@ -51,7 +51,7 @@ -- The "next-gen" actions have now replaced their deprecated counterparts. -- Provide a warning for a little while before I remove them entirely. if _ACTION and _ACTION:endswith("ng") then - io.stderr:write(string.format("** Warning: '%s' has been deprecated; use '%s' instead\n", _ACTION, _ACTION:sub(1, -3))) + premake.warnOnce(_ACTION, "'%s' has been deprecated; use '%s' instead", _ACTION, _ACTION:sub(1, -3)) end -- Set up the environment for the chosen action early, so side-effects diff --git a/src/base/api.lua b/src/base/api.lua index 46e158fa..843878c8 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -19,13 +19,6 @@ api.scope = {} --- --- A place to remember warning messages, so each will only be shown once. --- - - api.warnings = {} - - -- -- Create a "root" configuration set, to hold the global configuration. Values -- that are added to this set become available for all add-ons, solution, projects, @@ -141,21 +134,16 @@ -- function api.deprecated(field, value) - local key = value or field - if not api.warnings[key] then - api.warnings[key] = true - - local msg - if value then - msg = "the %s value %s" - else - msg = "the field %s" - end - msg = string.format(msg, field.name, value) - - msg = string.format("** Warning: %s has been deprecated.\n See %s for more information.\n", msg, _PREMAKE_URL) - io.stderr:write(msg) + local msg + if value then + msg = "the %s value %s" + else + msg = "the field %s" end + msg = string.format(msg, field.name, value) + + local key = value or field + premake.warnOnce(key, "%s has been deprecated.\n See %s for more information.", msg, _PREMAKE_URL) end diff --git a/src/base/os.lua b/src/base/os.lua index a6121530..4a68a6d4 100644 --- a/src/base/os.lua +++ b/src/base/os.lua @@ -300,7 +300,7 @@ local id = builtin_uuid(name) if name then if os._uuids[id] and os._uuids[id] ~= name then - io.stderr:write(string.format("** Warning: UUID clash between %s and %s\n", os._uuids[id], name)) + premake.warnOnce(id, "UUID clash between %s and %s", os._uuids[id], name) end os._uuids[id] = name end diff --git a/src/base/premake.lua b/src/base/premake.lua index cc8c3673..5df60c2e 100644 --- a/src/base/premake.lua +++ b/src/base/premake.lua @@ -16,6 +16,13 @@ premake.extensions = {} +-- +-- List of warning messages that have been fired so far. +-- + + local warnings = {} + + -- -- Define some commonly used symbols, for future-proofing. -- @@ -75,6 +82,16 @@ end +-- +-- Clears the list of already fired warning messages, allowing them +-- to be fired again. +-- + + function premake.clearWarnings() + warnings = {} + end + + -- -- Raises an error, with a formatted message built from the provided -- arguments. @@ -182,7 +199,6 @@ function premake.validate() local ctx = {} - ctx.warnings = {} for sln in solution.each() do premake.validateSolution(sln, ctx) @@ -294,11 +310,6 @@ okay = true end - -- already warned about this field? - if ctx.warnings[field.name] then - okay = true - end - -- this one needs to checked if not okay then okay = premake.api.comparevalues(field, cfg[field.scope][name], cfg[name]) @@ -306,8 +317,8 @@ -- found a problem? if not okay then - ctx.warnings[field.name] = true - premake.warn("'%s' on %s '%s' differs from %s '%s'; may be set out of scope", name, expected, cfg.name, field.scope, cfg[field.scope].name) + local key = "validate." .. field.name + premake.warnOnce(key, "'%s' on %s '%s' differs from %s '%s'; may be set out of scope", name, expected, cfg.name, field.scope, cfg[field.scope].name) end end @@ -332,15 +343,18 @@ -- -- Displays a warning just once per run. -- +-- @param key +-- A unique key to identify this warning. Subsequent warnings messages +-- using the same key will not be shown. -- @param message -- The warning message, which may contain string formatting tokens. -- @param ... -- Values to fill in the string formatting tokens. -- - function premake.warnOnce(ctx, message, ...) - if not ctx.warnings[message] then - ctx.warnings[message] = true + function premake.warnOnce(key, message, ...) + if not warnings[key] then + warnings[key] = true premake.warn(message, ...) end end diff --git a/tests/testfx.lua b/tests/testfx.lua index a84e6633..ef699702 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -272,6 +272,7 @@ premake.solution.list = { } premake.api.reset() + premake.clearWarnings() io.indent = nil io.eol = "\n"