summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-12-24 15:42:47 +0800
committerGitHub <[email protected]>2021-12-24 15:42:47 +0800
commite695208e9d42d5bd59af0afa34151c6f6a2c7aef (patch)
treedc8cccf292985bf6cf7d71b92bdd6d5de22631aa
parent058005193f33d0461bbe2ee11428ce41d4cd3083 (diff)
parent35699384e0ef579b3b5e048bce311b139d3d1660 (diff)
Merge pull request #1941 from xmake-io/remove
Add `remove_files` and `remove_headerfiles`
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/core/base/deprecated/interpreter.lua140
-rw-r--r--xmake/core/base/interpreter.lua112
-rw-r--r--xmake/core/base/scopeinfo.lua74
-rw-r--r--xmake/core/project/deprecated/project.lua1
-rw-r--r--xmake/core/project/option.lua6
-rw-r--r--xmake/core/project/target.lua133
7 files changed, 195 insertions, 273 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 61bba3c68..8f907817e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
* [#1298](https://github.com/xmake-io/xmake/issues/1928): Support vcpkg manifest mode and select version for package/install
* [#1896](https://github.com/xmake-io/xmake/issues/1896): Add `python.library` rule to build pybind modules
+* [#1939](https://github.com/xmake-io/xmake/issues/1939): Add `remove_files`, `remove_headerfiles` and mark `del_files` as deprecated
### Changes
@@ -1179,6 +1180,7 @@
* [#1298](https://github.com/xmake-io/xmake/issues/1928): 支持 vcpkg 清单模式安装包,实现安装包的版本选择
* [#1896](https://github.com/xmake-io/xmake/issues/1896): 添加 `python.library` 规则去构建 pybind 模块,并且支持 soabi
+* [#1939](https://github.com/xmake-io/xmake/issues/1939): 添加 `remove_files`, `remove_headerfiles` 并且标记 `del_files` 作为废弃接口
### 改进
diff --git a/xmake/core/base/deprecated/interpreter.lua b/xmake/core/base/deprecated/interpreter.lua
deleted file mode 100644
index 4213de8a0..000000000
--- a/xmake/core/base/deprecated/interpreter.lua
+++ /dev/null
@@ -1,140 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file deprecated_interpreter.lua
---
-
--- define module: deprecated_interpreter
-local deprecated_interpreter = deprecated_interpreter or {}
-
--- load modules
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local string = require("base/string")
-local deprecated = require("base/deprecated")
-local sandbox = require("sandbox/sandbox")
-
--- register api for set_scope()
-function deprecated_interpreter:api_register_set_scope(...)
-
- -- check
- assert(self)
-
- -- define implementation
- local implementation = function (self, scopes, scope_kind, scope_name)
-
- -- init scope for kind
- local scope_for_kind = scopes[scope_kind] or {}
- scopes[scope_kind] = scope_for_kind
-
- -- deprecated
- if not scope_name:startswith("__") then
- deprecated.add("%s(\"%s\")", "set_%s(\"%s\")", scope_kind, scope_name)
- end
-
- -- check
- if not scope_for_kind[scope_name] then
- utils.error("set_%s(\"%s\") failed, %s not found!", scope_kind, scope_name, scope_name)
- os.raise("please uses add_%s(\"%s\") first!", scope_kind, scope_name)
- end
-
- -- init scope for name
- scope_for_kind[scope_name] = scope_for_kind[scope_name] or {}
-
- -- save the current scope
- scopes._CURRENT = scope_for_kind[scope_name]
-
- -- update the current scope kind
- scopes._CURRENT_KIND = scope_kind
-
- end
-
- -- register implementation
- self:_api_register_scope_api(nil, "set", implementation, ...)
-end
-
--- register api for add_scope()
-function deprecated_interpreter:api_register_add_scope(...)
-
- -- check
- assert(self)
-
- -- define implementation
- local implementation = function (self, scopes, scope_kind, scope_name)
-
- -- init scope for kind
- local scope_for_kind = scopes[scope_kind] or {}
- scopes[scope_kind] = scope_for_kind
-
- -- deprecated
- if not scope_name:startswith("__") then
- deprecated.add("%s(\"%s\")", "add_%s(\"%s\")", scope_kind, scope_name)
- end
-
- -- check
- if scope_for_kind[scope_name] then
- utils.error("add_%s(\"%s\") failed, %s have been defined!", scope_kind, scope_name, scope_name)
- os.raise("please uses set_%s(\"%s\")!", scope_kind, scope_name)
- end
-
- -- init scope for name
- scope_for_kind[scope_name] = scope_for_kind[scope_name] or {}
-
- -- save the current scope
- scopes._CURRENT = scope_for_kind[scope_name]
-
- -- update the current scope kind
- scopes._CURRENT_KIND = scope_kind
-
- end
-
- -- register implementation
- self:_api_register_scope_api(nil, "add", implementation, ...)
-end
-
--- register api for set_script
-function deprecated_interpreter:api_register_set_script(scope_kind, ...)
-
- -- check
- assert(self)
-
- -- define implementation
- local implementation = function (self, scope, name, script)
-
- -- deprecated
- deprecated.add("on_%s()", "set_%s()", name)
-
- -- make sandbox instance with the given script
- local instance, errors = sandbox.new(script, self:filter(), self:rootdir())
- if not instance then
- os.raise("set_%s(): %s", name, errors)
- end
-
- -- update script?
- scope[name] = {}
- table.insert(scope[name], instance:script())
-
- end
-
- -- register implementation
- self:_api_register_xxx_values(scope_kind, "set", implementation, ...)
-end
-
--- return module: deprecated_interpreter
-return deprecated_interpreter
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua
index 01de8047d..e8e379e08 100644
--- a/xmake/core/base/interpreter.lua
+++ b/xmake/core/base/interpreter.lua
@@ -22,13 +22,14 @@
local interpreter = interpreter or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
-local string = require("base/string")
-local scopeinfo = require("base/scopeinfo")
-local sandbox = require("sandbox/sandbox")
+local os = require("base/os")
+local path = require("base/path")
+local table = require("base/table")
+local utils = require("base/utils")
+local string = require("base/string")
+local scopeinfo = require("base/scopeinfo")
+local deprecated = require("base/deprecated")
+local sandbox = require("sandbox/sandbox")
-- traceback
function interpreter._traceback(errors)
@@ -160,8 +161,6 @@ end
-- register scope end: scopename_end()
function interpreter:_api_register_scope_end(...)
-
- -- check
assert(self and self._PUBLIC and self._PRIVATE)
-- done
@@ -191,8 +190,6 @@ end
-- register scope api: xxx_apiname()
function interpreter:_api_register_scope_api(scope_kind, action, apifunc, ...)
-
- -- check
assert(self and self._PUBLIC and self._PRIVATE)
assert(apifunc)
@@ -226,8 +223,6 @@ end
-- register api: xxx_values()
function interpreter:_api_register_xxx_values(scope_kind, action, apifunc, ...)
-
- -- check
assert(self and self._PUBLIC and self._PRIVATE)
assert(action and apifunc)
@@ -257,7 +252,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
@@ -372,8 +367,6 @@ end
-- get api function within scope
function interpreter:_api_within_scope(scope_kind, apiname)
-
- -- the private
local priv = self._PRIVATE
assert(priv)
@@ -394,8 +387,6 @@ end
-- set api function within scope
function interpreter:_api_within_scope_set(scope_kind, apiname, apifunc)
-
- -- the private
local priv = self._PRIVATE
assert(priv)
@@ -416,8 +407,6 @@ end
-- clear results
function interpreter:_clear()
-
- -- check
assert(self and self._PRIVATE)
-- clear it
@@ -427,8 +416,6 @@ end
-- filter values
function interpreter:_filter(values, level)
-
- -- check
assert(self and values ~= nil)
-- return values directly if no filter
@@ -482,8 +469,6 @@ end
-- handle scope data
function interpreter:_handle(scope, deduplicate, enable_filter)
-
- -- check
assert(scope)
-- remove repeat values and unwrap it
@@ -498,12 +483,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
@@ -518,8 +503,6 @@ end
-- make results
function interpreter:_make(scope_kind, deduplicate, enable_filter)
-
- -- check
assert(self and self._PRIVATE)
-- the scopes
@@ -719,8 +702,6 @@ end
-- @param opt {on_load_data = function (data) return data end}
--
function interpreter:load(file, opt)
-
- -- check
assert(self and self._PUBLIC and self._PRIVATE and file)
-- load the script
@@ -847,8 +828,6 @@ end
-- get apis
function interpreter:apis(scope_kind)
-
- -- check
assert(self and self._PRIVATE)
-- get apis from the given scope kind
@@ -889,8 +868,6 @@ end
-- }
--
function interpreter:api_register(scope_kind, name, func)
-
- -- check
assert(self and self._PUBLIC and self._PRIVATE)
assert(name and func)
@@ -924,11 +901,7 @@ end
-- register api for builtin
function interpreter:api_register_builtin(name, func)
-
- -- check
assert(self and self._PUBLIC and func)
-
- -- register it
self._PUBLIC[name] = func
end
@@ -974,9 +947,6 @@ end
--
function interpreter:api_register_scope(...)
- -- check
- assert(self)
-
-- define implementation
local implementation = function (self, scopes, scope_kind, scope_name, scope_info)
@@ -1259,9 +1229,6 @@ end
-- register api for set_dictionary
function interpreter:api_register_set_dictionary(scope_kind, ...)
- -- check
- assert(self)
-
-- define implementation
local implementation = function (self, scope, name, dict_or_key, value, extra_config)
@@ -1289,9 +1256,6 @@ end
-- register api for add_dictionary
function interpreter:api_register_add_dictionary(scope_kind, ...)
- -- check
- assert(self)
-
-- define implementation
local implementation = function (self, scope, name, dict_or_key, value, extra_config)
@@ -1321,9 +1285,6 @@ end
-- register api for set_paths
function interpreter:api_register_set_paths(scope_kind, ...)
- -- check
- assert(self)
-
-- define implementation
local implementation = function (self, scope, name, ...)
@@ -1360,12 +1321,9 @@ 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
- assert(self)
-
-- define implementation
local implementation = function (self, scope, name, ...)
@@ -1373,10 +1331,13 @@ function interpreter:api_register_del_paths(scope_kind, ...)
local values = table.join(...)
local paths = self:_api_translate_paths(values, "del_" .. name)
+ -- it has been marked as deprecated
+ deprecated.add("remove_" .. name .. "(%s)", "del_" .. name .. "(%s)", table.concat(values, ", "), table.concat(values, ", "))
+
-- 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,12 +1351,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, ...)
+
+ -- 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, ...)
- -- check
- assert(self)
-
-- define implementation
local implementation = function (self, scope, name, ...)
@@ -1509,7 +1494,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
@@ -1734,27 +1719,18 @@ end
-- get api function
function interpreter:api_func(apiname)
-
- -- check
assert(self and self._PUBLIC and apiname)
-
- -- get api function
return self._PUBLIC[apiname]
end
-- call api
function interpreter:api_call(apiname, ...)
-
- -- check
assert(self and apiname)
- -- get api function
local apifunc = self:api_func(apiname)
if not apifunc then
os.raise("call %s() failed, this api not found!", apiname)
end
-
- -- call api function
return apifunc(...)
end
diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua
index 6b7e566b5..26be325eb 100644
--- a/xmake/core/base/scopeinfo.lua
+++ b/xmake/core/base/scopeinfo.lua
@@ -23,11 +23,12 @@ local scopeinfo = scopeinfo or {}
local _instance = _instance or {}
-- load modules
-local io = require("base/io")
-local os = require("base/os")
-local path = require("base/path")
-local table = require("base/table")
-local utils = require("base/utils")
+local io = require("base/io")
+local os = require("base/os")
+local path = require("base/path")
+local table = require("base/table")
+local utils = require("base/utils")
+local deprecated = require("base/deprecated")
-- new an instance
function _instance.new(kind, info, opt)
@@ -62,12 +63,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 +377,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
@@ -388,13 +389,16 @@ function _instance:_api_del_paths(name, ...)
-- expand values
values = table.join(...)
+ -- it has been marked as deprecated
+ deprecated.add("remove_" .. name .. "(%s)", "del_" .. name .. "(%s)", table.concat(values, ", "), table.concat(values, ", "))
+
-- translate paths
local paths = interp:_api_translate_paths(values, "del_" .. name, 5)
-- 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 +408,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 +538,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 +558,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/deprecated/project.lua b/xmake/core/project/deprecated/project.lua
index dceeac9ba..46e06b7be 100644
--- a/xmake/core/project/deprecated/project.lua
+++ b/xmake/core/project/deprecated/project.lua
@@ -31,7 +31,6 @@ local rule = require("project/rule")
local config = require("project/config")
local platform = require("platform/platform")
local deprecated = require("base/deprecated")
-local deprecated_interpreter = require("base/deprecated/interpreter")
-- add_headers for target
function deprecated_project._api_target_add_headers(interp)
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..3541aa626 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,21 +1340,20 @@ function _instance:sourcefiles()
end
end
- -- remove all deleted source files
- if deleted_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("|.*$", ""))
+ -- remove all source files which need be removed
+ if removed_count > 0 then
+ table.remove_if(sourcefiles, function (i, sourcefile)
+ 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
pattern = path.pattern(pattern)
if sourcefile:match(pattern) then
- table.remove(sourcefiles, i)
+ return true
end
end
- end
+ end)
end
self._SOURCEFILES = sourcefiles
@@ -1442,58 +1448,76 @@ function _instance:headerfiles(outputdir, only_deprecated)
-- get the source paths and destinate paths
local srcheaders = {}
local dstheaders = {}
+ local srcheaders_removed = {}
+ local removed_count = 0
for _, header in ipairs(table.wrap(headers)) do
+ -- mark as removed files?
+ local removed = false
+ local prefix = "__remove_"
+ if header:startswith(prefix) then
+ header = header:sub(#prefix + 1)
+ removed = true
+ end
+
-- get the root directory
local rootdir, count = header:gsub("|.*$", ""):gsub("%(.*%)$", "")
if count == 0 then
rootdir = nil
end
- -- remove '(' and ')'
+ -- remove '(' and ')' first
local srcpaths = header:gsub("[%(%)]", "")
if srcpaths then
-- get the source paths
srcpaths = os.match(srcpaths)
if srcpaths then
+ if removed then
+ removed_count = removed_count + #srcpaths
+ table.join2(srcheaders_removed, srcpaths)
+ else
+ -- add the source headers
+ table.join2(srcheaders, srcpaths)
- -- add the source headers
- table.join2(srcheaders, srcpaths)
-
- -- get the destinate directories if the install directory exists
- if headerdir then
-
- -- get the prefix directory
- local prefixdir = (extrainfo[header] or {}).prefixdir
-
- -- add the destinate headers
- for _, srcpath in ipairs(srcpaths) do
-
- -- get the destinate directory
- local dstdir = headerdir
- if prefixdir then
- dstdir = path.join(dstdir, prefixdir)
- end
-
- -- the destinate header
- local dstheader = nil
- if rootdir then
- dstheader = path.absolute(path.relative(srcpath, rootdir), dstdir)
- else
- dstheader = path.join(dstdir, path.filename(srcpath))
+ -- get the destinate directories if the install directory exists
+ if headerdir then
+ local prefixdir = (extrainfo[header] or {}).prefixdir
+ for _, srcpath in ipairs(srcpaths) do
+ local dstdir = headerdir
+ if prefixdir then
+ dstdir = path.join(dstdir, prefixdir)
+ end
+ local dstheader = nil
+ if rootdir then
+ dstheader = path.absolute(path.relative(srcpath, rootdir), dstdir)
+ else
+ dstheader = path.join(dstdir, path.filename(srcpath))
+ end
+ table.insert(dstheaders, dstheader)
end
- assert(dstheader)
-
- -- add it
- table.insert(dstheaders, dstheader)
end
end
end
end
end
- -- ok?
+ -- remove all header files which need be removed
+ if removed_count > 0 then
+ table.remove_if(srcheaders, function (i, srcheader)
+ for _, removed_file in ipairs(srcheaders_removed) do
+ local pattern = path.translate(removed_file:gsub("|.*$", ""))
+ if pattern:sub(1, 2):find('%.[/\\]') then
+ pattern = pattern:sub(3)
+ end
+ pattern = path.pattern(pattern)
+ if srcheader:match(pattern) then
+ table.remove(dstheaders, i)
+ return true
+ end
+ end
+ end)
+ end
return srcheaders, dstheaders
end
@@ -2034,8 +2058,11 @@ 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"
+ , "target.remove_headerfiles"
}
, dictionary =
{