summaryrefslogtreecommitdiff
path: root/xmake/core/base/interpreter.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-24 22:44:42 +0800
committerruki <[email protected]>2021-12-24 22:44:42 +0800
commit96d63a27f174e4eba17903e5faec887de5c3d3e7 (patch)
tree85d1f05aa969154064a9c7cf64ac573adbeec302 /xmake/core/base/interpreter.lua
parent058005193f33d0461bbe2ee11428ce41d4cd3083 (diff)
add remove_files
Diffstat (limited to 'xmake/core/base/interpreter.lua')
-rw-r--r--xmake/core/base/interpreter.lua42
1 files changed, 36 insertions, 6 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 01de8047d..62325b2ad 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -257,7 +257,7 @@ function interpreter:_api_register_xxx_values(scope_kind, action, apifunc, ...)
assert(scope)
-- set values (set, on, before, after ...)? mark as "override"
- if apiname and (action ~= "add" and action ~= "del") then
+ if apiname and (action ~= "add" and action ~= "del" and action ~= "remove") then
scope["__override_" .. apiname] = true
end
@@ -498,12 +498,12 @@ function interpreter:_handle(scope, deduplicate, enable_filter)
values = self:_filter(values)
end
- -- remove repeat first for each slice with deleted item (__del_xxx)
+ -- remove repeat first for each slice with removed item (__remove_xxx)
if deduplicate and not table.is_dictionary(values) then
local policy = self:deduplication_policy(name)
if policy ~= false then
local unique_func = policy == "toleft" and table.reverse_unique or table.unique
- values = unique_func(values, function (v) return type(v) == "string" and v:startswith("__del_") end)
+ values = unique_func(values, function (v) return type(v) == "string" and v:startswith("__remove_") end)
end
end
@@ -1360,7 +1360,7 @@ function interpreter:api_register_set_paths(scope_kind, ...)
self:_api_register_xxx_values(scope_kind, "set", implementation, ...)
end
--- register api for del_paths
+-- register api for del_paths (deprecated)
function interpreter:api_register_del_paths(scope_kind, ...)
-- check
@@ -1376,7 +1376,7 @@ function interpreter:api_register_del_paths(scope_kind, ...)
-- mark these paths as deleted
local paths_deleted = {}
for _, pathname in ipairs(paths) do
- table.insert(paths_deleted, "__del_" .. pathname)
+ table.insert(paths_deleted, "__remove_" .. pathname)
end
-- save values
@@ -1390,6 +1390,36 @@ function interpreter:api_register_del_paths(scope_kind, ...)
self:_api_register_xxx_values(scope_kind, "del", implementation, ...)
end
+-- register api for remove_paths
+function interpreter:api_register_remove_paths(scope_kind, ...)
+
+ -- check
+ assert(self)
+
+ -- define implementation
+ local implementation = function (self, scope, name, ...)
+
+ -- translate paths
+ local values = table.join(...)
+ local paths = self:_api_translate_paths(values, "remove_" .. name)
+
+ -- mark these paths as removed
+ local paths_removed = {}
+ for _, pathname in ipairs(paths) do
+ table.insert(paths_removed, "__remove_" .. pathname)
+ end
+
+ -- save values
+ scope[name] = table.join2(scope[name] or {}, paths_removed)
+
+ -- save api source info, e.g. call api() in sourcefile:linenumber
+ self:_save_sourceinfo_to_scope(scope, name, paths)
+ end
+
+ -- register implementation
+ self:_api_register_xxx_values(scope_kind, "remove", implementation, ...)
+end
+
-- register api for add_paths
function interpreter:api_register_add_paths(scope_kind, ...)
@@ -1509,7 +1539,7 @@ function interpreter:api_define(apis)
-- get function prefix
local prefix = nil
- for _, name in ipairs({"set", "add", "del", "on", "before", "after"}) do
+ for _, name in ipairs({"set", "add", "del", "remove", "on", "before", "after"}) do
if funcname:startswith(name .. "_") then
prefix = name
break