Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] get file/line information on deprecated API's. #764

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,19 @@
print(string.format(msg, ...))
end
end


--
-- make a string from debug.getinfo information.
--
function filelineinfo(level)
local info = debug.getinfo(level+1, "Sl")
if info == nil then
return nil
end
if info.what == "C" then
return "C function"
else
return string.format("%s(%d)", info.short_src, info.currentline)
end
end
20 changes: 13 additions & 7 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,12 @@
if field.deprecated and type(field.deprecated.handler) == "function" then
field.deprecated.handler(value)
if field.deprecated.message and api._deprecations ~= "off" then
p.warnOnce(field.name, "the field %s has been deprecated and will be removed.\n %s", field.name, field.deprecated.message)
if api._deprecations == "error" then error("deprecation errors enabled", 3) end
local caller = filelineinfo(2)
local key = field.name .. "_" .. caller
p.warnOnce(key, "the field %s has been deprecated and will be removed.\n %s\n @%s\n", field.name, field.deprecated.message, caller)
if api._deprecations == "error" then
error("deprecation errors enabled", 3)
end
end
end

Expand Down Expand Up @@ -536,13 +540,14 @@

local removes = {}

function check(value)
local function check(value)
if field.deprecated[value] then
local handler = field.deprecated[value]
if handler.remove then handler.remove(value) end
if handler.message and api._deprecations ~= "off" then
local key = field.name .. "_" .. value
p.warnOnce(key, "the %s value %s has been deprecated and will be removed.\n %s", field.name, value, handler.message)
local caller = filelineinfo(8)
local key = field.name .. "_" .. value .. "_" .. caller
p.warnOnce(key, "the %s value %s has been deprecated and will be removed.\n %s\n @%s\n", field.name, value, handler.message, caller)
if api._deprecations == "error" then
error { msg="deprecation errors enabled" }
end
Expand Down Expand Up @@ -647,8 +652,9 @@
local handler = field.deprecated[canonical]
handler.add(canonical)
if handler.message and api._deprecations ~= "off" then
local key = field.name .. "_" .. value
p.warnOnce(key, "the %s value %s has been deprecated and will be removed.\n %s", field.name, canonical, handler.message)
local caller = filelineinfo(9)
local key = field.name .. "_" .. value .. "_" .. caller
p.warnOnce(key, "the %s value %s has been deprecated and will be removed.\n %s\n @%s\n", field.name, canonical, handler.message, caller)
if api._deprecations == "error" then
return nil, "deprecation errors enabled"
end
Expand Down
6 changes: 4 additions & 2 deletions src/base/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@
end

function os.get()
premake.warnOnce("os.get", "os.get() is deprecated, use 'os.target()' or 'os.host()'.")
local caller = filelineinfo(2)
premake.warnOnce(caller, "os.get() is deprecated, use 'os.target()' or 'os.host()'.\n @%s\n", caller)
return os.target()
end

Expand Down Expand Up @@ -180,7 +181,8 @@
end

function os.is(id)
premake.warnOnce("os.is", "os.is() is deprecated, use 'os.istarget()' or 'os.ishost()'.")
local caller = filelineinfo(2)
premake.warnOnce(caller, "os.is() is deprecated, use 'os.istarget()' or 'os.ishost()'.\n @%s\n", caller)
return os.istarget(id)
end

Expand Down