Improved use of premake.warnOnce()

This commit is contained in:
Jason Perkins 2013-08-29 12:20:53 -04:00
parent 1bebe7a52b
commit 191e81df8e
5 changed files with 39 additions and 36 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -272,6 +272,7 @@
premake.solution.list = { }
premake.api.reset()
premake.clearWarnings()
io.indent = nil
io.eol = "\n"