diff options
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 37 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 9 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 29 |
4 files changed, 63 insertions, 14 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 12f258812..24fa05185 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -242,8 +242,8 @@ function interpreter:_api_register_xxx_values(scope_kind, action, apifunc, ...) local scope = scopes._CURRENT or root assert(scope) - -- set values? mark as "override" - if apiname and action ~= "add" then + -- set values (set, on, before, after ...)? mark as "override" + if apiname and (action ~= "add" or action ~= "del") then scope["__override_" .. apiname] = true end @@ -446,9 +446,9 @@ function interpreter:_handle(scope, remove_repeat, enable_filter) local results = {} for name, values in pairs(scope) do - -- remove repeat first + -- remove repeat first for each slice with deleted item (__del_xxx) if remove_repeat and not table.is_dictionary(values) then - values = table.unique(values) + values = table.unique(values, function (v) return v:startswith("__del_") end) end -- filter values @@ -1206,6 +1206,33 @@ function interpreter:api_register_set_pathes(scope_kind, ...) self:_api_register_xxx_values(scope_kind, "set", implementation, ...) end +-- register api for del_pathes +function interpreter:api_register_del_pathes(scope_kind, ...) + + -- check + assert(self) + + -- define implementation + local implementation = function (self, scope, name, ...) + + -- translate pathes + local values = {...} + local pathes = self:_api_translate_pathes(values) + + -- mark these pathes as deleted + local pathes_deleted = {} + for _, pathname in ipairs(pathes) do + table.insert(pathes_deleted, "__del_" .. pathname) + end + + -- save values + scope[name] = table.join2(scope[name] or {}, pathes_deleted) + end + + -- register implementation + self:_api_register_xxx_values(scope_kind, "del", implementation, ...) +end + -- register api for add_pathes function interpreter:api_register_add_pathes(scope_kind, ...) @@ -1317,7 +1344,7 @@ function interpreter:api_define(apis) -- get function prefix local prefix = nil - for _, name in ipairs({"set", "add", "on", "before", "after"}) do + for _, name in ipairs({"set", "add", "del", "on", "before", "after"}) do if funcname:startswith(name .. "_") then prefix = name break diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 410b4a329..3b4013232 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -280,7 +280,7 @@ function table.wrap(object) end -- remove repeat from the given array -function table.unique(array) +function table.unique(array, barrier) -- remove repeat if type(array) == "table" then @@ -292,6 +292,13 @@ function table.unique(array) local exists = {} local unique = {} for _, v in ipairs(array) do + + -- exists barrier? clear the current existed items + if barrier and barrier(v) then + exists = {} + end + + -- add unique item if type(v) == "string" then if not exists[v] then exists[v] = true diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index dc628feb1..7c9ab62b8 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -248,6 +248,8 @@ function project.interpreter() , "target.set_objectdir" -- target.add_xxx , "target.add_files" + -- target.del_xxx + , "target.del_files" } , script = { diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index c2f9d852b..bfdc62b20 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -374,6 +374,13 @@ function target:sourcefiles() local sourcefiles = {} 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 + end + -- normalize *.[o|obj] and [lib]*.[a|lib] filename for _, pattern in ipairs(patterns) do file, count = file:gsub(pattern[1], target.filename(pattern[2], pattern[3])) @@ -386,7 +393,7 @@ function target:sourcefiles() -- match source files local results = os.match(file) if #results == 0 then - utils.warning("cannot match add_files(\"%s\")", file) + utils.warning("cannot match %s_files(\"%s\")", utils.ifelse(deleted, "del", "add"), file) end -- process source files @@ -397,22 +404,28 @@ function target:sourcefiles() sourcefile = path.relative(sourcefile, os.projectdir()) end - -- save it - sourcefiles[i] = sourcefile - i = i + 1 + -- add or delete it + if deleted then + sourcefiles[sourcefile] = nil + else + sourcefiles[sourcefile] = true + end end end - -- remove repeat files - sourcefiles = table.unique(sourcefiles) + -- make last source files + local sourcefiles_last = {} + for sourcefile, _ in pairs(sourcefiles) do + table.insert(sourcefiles_last, sourcefile) + end -- cache it if cache then - self._SOURCEFILES = sourcefiles + self._SOURCEFILES = sourcefiles_last end -- ok? modified? - return sourcefiles, not cache + return sourcefiles_last, not cache end -- get object file from source file |
