summaryrefslogtreecommitdiff
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
parent058005193f33d0461bbe2ee11428ce41d4cd3083 (diff)
add remove_files
-rw-r--r--xmake/core/base/interpreter.lua42
-rw-r--r--xmake/core/base/scopeinfo.lua60
-rw-r--r--xmake/core/project/option.lua6
-rw-r--r--xmake/core/project/target.lua47
4 files changed, 124 insertions, 31 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.
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 8f5502390..0364b3b47 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -420,6 +420,12 @@ function _instance:del(name, ...)
self:_invalidate()
end
+-- remove the value to the option info (deprecated)
+function _instance:remove(name, ...)
+ self._INFO:apival_remove(name, ...)
+ self:_invalidate()
+end
+
-- get the extra configuration
function _instance:extraconf(name, item, key)
return self._INFO:extraconf(name, item, key)
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index 1a489b1ce..68073187b 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -387,12 +387,18 @@ function _instance:add(name, ...)
self:_invalidate(name)
end
--- remove the value to the target info
+-- remove the value to the target info (deprecated)
function _instance:del(name, ...)
self._INFO:apival_del(name, ...)
self:_invalidate(name)
end
+-- remove the value to the target info
+function _instance:remove(name, ...)
+ self._INFO:apival_remove(name, ...)
+ self:_invalidate(name)
+end
+
-- get the extra configuration
function _instance:extraconf(name, item, key)
return self._INFO:extraconf(name, item, key)
@@ -1267,24 +1273,25 @@ function _instance:sourcefiles()
local i = 1
local count = 0
local sourcefiles = {}
- local sourcefiles_deleted = {}
+ local sourcefiles_removed = {}
local sourcefiles_inserted = {}
- local deleted_count = 0
+ local removed_count = 0
local targetcache = memcache.cache("core.project.target")
for _, file in ipairs(table.wrap(files)) do
- -- mark as deleted files?
- local deleted = false
- if file:startswith("__del_") then
- file = file:sub(7)
- deleted = true
+ -- mark as removed files?
+ local removed = false
+ local prefix = "__remove_"
+ if file:startswith(prefix) then
+ file = file:sub(#prefix + 1)
+ removed = true
end
-- find source files and try to cache the matching results of os.match across targets
-- @see https://github.com/xmake-io/xmake/issues/1353
local results = targetcache:get2("sourcefiles", file)
if not results then
- if deleted then
+ if removed then
results = {file}
else
results = os.files(file)
@@ -1311,7 +1318,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(), (deleted and "del" or "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(), (removed and "remove" or "add"), file, sourceinfo.file or "", sourceinfo.line or -1)
end
-- process source files
@@ -1322,10 +1329,10 @@ function _instance:sourcefiles()
sourcefile = path.relative(sourcefile, os.projectdir())
end
- -- add or delete it
- if deleted then
- deleted_count = deleted_count + 1
- table.insert(sourcefiles_deleted, sourcefile)
+ -- add or remove it
+ if removed then
+ removed_count = removed_count + 1
+ table.insert(sourcefiles_removed, sourcefile)
elseif not sourcefiles_inserted[sourcefile] then
table.insert(sourcefiles, sourcefile)
sourcefiles_inserted[sourcefile] = true
@@ -1333,12 +1340,12 @@ function _instance:sourcefiles()
end
end
- -- remove all deleted source files
- if deleted_count > 0 then
+ -- remove all source files which need be removed
+ if removed_count > 0 then
for i = #sourcefiles, 1, -1 do
local sourcefile = sourcefiles[i]
- for _, deletefile in ipairs(sourcefiles_deleted) do
- local pattern = path.translate(deletefile:gsub("|.*$", ""))
+ for _, removed_file in ipairs(sourcefiles_removed) do
+ local pattern = path.translate(removed_file:gsub("|.*$", ""))
if pattern:sub(1, 2):find('%.[/\\]') then
pattern = pattern:sub(3)
end
@@ -2034,8 +2041,10 @@ function target.apis()
, "target.add_cleanfiles"
, "target.add_configfiles"
, "target.add_installfiles"
- -- target.del_xxx
+ -- target.del_xxx (deprecated)
, "target.del_files"
+ -- target.remove_xxx
+ , "target.remove_files"
}
, dictionary =
{