diff options
| author | ruki <[email protected]> | 2021-12-24 22:49:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-24 22:49:53 +0800 |
| commit | 86d94894f74e054bd170c7074b96f748ab81ed0e (patch) | |
| tree | ed6fd8ae052a128a2fe103c799d17d8c42399c40 | |
| parent | 48a2d0c64c39466190af8900e259f4ceb53a895f (diff) | |
add remove_headerfies
| -rw-r--r-- | xmake/core/project/target.lua | 86 |
1 files changed, 52 insertions, 34 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 68073187b..3541aa626 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1342,8 +1342,7 @@ function _instance:sourcefiles() -- remove all source files which need be removed if removed_count > 0 then - for i = #sourcefiles, 1, -1 do - local sourcefile = sourcefiles[i] + 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 @@ -1351,10 +1350,10 @@ function _instance:sourcefiles() end pattern = path.pattern(pattern) if sourcefile:match(pattern) then - table.remove(sourcefiles, i) + return true end end - end + end) end self._SOURCEFILES = sourcefiles @@ -1449,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 @@ -2045,6 +2062,7 @@ function target.apis() , "target.del_files" -- target.remove_xxx , "target.remove_files" + , "target.remove_headerfiles" } , dictionary = { |
