summaryrefslogtreecommitdiff
path: root/xmake/core/base
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
parent058005193f33d0461bbe2ee11428ce41d4cd3083 (diff)
add remove_files
Diffstat (limited to 'xmake/core/base')
-rw-r--r--xmake/core/base/interpreter.lua42
-rw-r--r--xmake/core/base/scopeinfo.lua60
2 files changed, 90 insertions, 12 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
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 6b7e566b5..7141482bc 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -62,12 +62,12 @@ function _instance:_api_handle(name, values)
local interp = self:interpreter()
if interp then
- -- remove repeat first for each slice with deleted item (__del_xxx)
+ -- remove repeat first for each slice with deleted item (__remove_xxx)
if self._DEDUPLICATE and not table.is_dictionary(values) then
local policy = interp: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
@@ -376,7 +376,7 @@ function _instance:_api_add_paths(name, ...)
self:_api_save_sourceinfo_to_scope(scope, name, paths)
end
--- remove the api paths to the scope info
+-- remove the api paths to the scope info (deprecated)
function _instance:_api_del_paths(name, ...)
-- get the scope info
@@ -394,7 +394,7 @@ function _instance:_api_del_paths(name, ...)
-- 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
@@ -404,6 +404,34 @@ function _instance:_api_del_paths(name, ...)
self:_api_save_sourceinfo_to_scope(scope, name, paths)
end
+-- remove the api paths to the scope info
+function _instance:_api_remove_paths(name, ...)
+
+ -- get the scope info
+ local scope = self._INFO
+
+ -- get interpreter
+ local interp = self:interpreter()
+
+ -- expand values
+ values = table.join(...)
+
+ -- translate paths
+ local paths = interp:_api_translate_paths(values, "remove_" .. name, 5)
+
+ -- 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] = self:_api_handle(name, table.join2(table.wrap(scope[name]), paths_removed))
+
+ -- save api source info, e.g. call api() in sourcefile:linenumber
+ self:_api_save_sourceinfo_to_scope(scope, name, paths)
+end
+
-- get the scope kind
function _instance:kind()
return self._KIND
@@ -506,12 +534,12 @@ function _instance:apival_add(name, ...)
end
end
--- remove the api values to the scope info
+-- remove the api values to the scope info (deprecated)
function _instance:apival_del(name, ...)
if type(name) == "string" then
local api_type = self:_api_type("del_" .. name)
if api_type then
- local del_xxx = self["_api_del_" .. api_type]
+ local del_xxx = self["_api_remove_" .. api_type]
if del_xxx then
del_xxx(self, name, ...)
else
@@ -526,6 +554,26 @@ function _instance:apival_del(name, ...)
end
end
+-- remove the api values to the scope info
+function _instance:apival_remove(name, ...)
+ if type(name) == "string" then
+ local api_type = self:_api_type("remove_" .. name)
+ if api_type then
+ local remove_xxx = self["_api_remove_" .. api_type]
+ if remove_xxx then
+ remove_xxx(self, name, ...)
+ else
+ os.raise("unknown apitype(%s) for %s:remove(%s, ...)", api_type, self:kind(), name)
+ end
+ else
+ os.raise("unknown api(%s) for %s:remove(%s, ...)", name, self:kind(), name)
+ end
+ elseif name ~= nil then
+ -- TODO
+ os.raise("cannot support to remove a dictionary!")
+ end
+end
+
-- get the extra configuration
--
-- e.g.