summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-09 22:34:26 +0800
committerruki <[email protected]>2020-04-09 09:26:39 +0800
commit72be2469a576bcf8c1e0b4a737f581f1d9b3837b (patch)
tree29fbd7cd6c99c0ac19bde555c9a834d072f7c029
parentc044ba9a3ee4af1308632e08e9f78fb2974beda2 (diff)
check invalid pathes
-rw-r--r--xmake/core/base/interpreter.lua13
-rw-r--r--xmake/core/base/scopeinfo.lua8
-rw-r--r--xmake/core/project/target.lua2
3 files changed, 13 insertions, 10 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 9e9583d32..fe56aa44a 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -351,10 +351,13 @@ function interpreter:_api_register_xxx_script(scope_kind, action, ...)
end
-- translate api pathes
-function interpreter:_api_translate_pathes(values)
+function interpreter:_api_translate_pathes(values, apiname, infolevel)
local results = {}
for _, p in ipairs(values) do
- assert(type(p) == "string", "invalid path value: " .. tostring(p))
+ if type(p) ~= "string" or #p == 0 then
+ local sourceinfo = debug.getinfo(infolevel or 3, "Sl")
+ os.raise("%s(%s): invalid path value at %s:%d", apiname, tostring(p), sourceinfo.short_src or sourceinfo.source, sourceinfo.currentline)
+ end
if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then
table.insert(results, path.relative(path.absolute(p, self:scriptdir()), self:rootdir()))
else
@@ -1264,7 +1267,7 @@ function interpreter:api_register_set_pathes(scope_kind, ...)
end
-- translate pathes
- local pathes = self:_api_translate_pathes(values)
+ local pathes = self:_api_translate_pathes(values, "set_" .. name)
-- save values
scope[name] = pathes
@@ -1297,7 +1300,7 @@ function interpreter:api_register_del_pathes(scope_kind, ...)
-- translate pathes
local values = {...}
- local pathes = self:_api_translate_pathes(values)
+ local pathes = self:_api_translate_pathes(values, "del_" .. name)
-- mark these pathes as deleted
local pathes_deleted = {}
@@ -1335,7 +1338,7 @@ function interpreter:api_register_add_pathes(scope_kind, ...)
end
-- translate pathes
- local pathes = self:_api_translate_pathes(values)
+ local pathes = self:_api_translate_pathes(values, "add_" .. name)
-- save values
scope[name] = table.join2(scope[name] or {}, pathes)
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 25dd2a9bf..2480f64ee 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -299,7 +299,7 @@ function _instance:_api_set_pathes(name, ...)
values = table.join(unpack(values))
-- translate pathes
- local pathes = interp:_api_translate_pathes(values)
+ local pathes = interp:_api_translate_pathes(values, "set_" .. name, 5)
-- save values
scope[name] = self:_api_handle(pathes)
@@ -339,7 +339,7 @@ function _instance:_api_add_pathes(name, ...)
values = table.join(unpack(values))
-- translate pathes
- local pathes = interp:_api_translate_pathes(values)
+ local pathes = interp:_api_translate_pathes(values, "add_" .. name, 5)
-- save values
scope[name] = self:_api_handle(table.join2(table.wrap(scope[name]), pathes))
@@ -370,12 +370,12 @@ function _instance:_api_del_pathes(name, ...)
values = table.join(...)
-- translate pathes
- local pathes = interp:_api_translate_pathes(values)
+ local pathes = interp:_api_translate_pathes(values, "del_" .. name)
-- mark these pathes as deleted
local pathes_deleted = {}
for _, pathname in ipairs(pathes) do
- table.insert(pathes_deleted, "__del_" .. pathname)
+ table.insert(pathes_deleted, "__del_" .. pathname, 5)
end
-- save values
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index e91f09408..b61ec4f9b 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -989,7 +989,7 @@ function _instance:sourcefiles()
end
if #results == 0 then
local sourceinfo = (self:get("__sourceinfo_files") or {})[file] or {}
- utils.warning("cannot match %s(%s).%s_files(\"%s\") at %s:%d", self:type(), self:name(), utils.ifelse(deleted, "del", "add"), file, sourceinfo.file or "", sourceinfo.line or -1)
+ utils.warning("cannot match %s(%s).%s_files(\"%s\") at %s:%d", self:type(), self:name(), (deleted and "del" or "add"), file, sourceinfo.file or "", sourceinfo.line or -1)
end
-- process source files