diff options
| author | ruki <[email protected]> | 2024-03-14 23:40:53 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-03-14 23:40:53 +0800 |
| commit | fb0a5cb9f8beea482f7240c537ceb2a3e6d63edd (patch) | |
| tree | 72226e382e1ca871b799674ef43d484822b39c1f /xmake/core/base/private | |
| parent | e971dacae2e572575b5ef11d37cbfde2785b4daf (diff) | |
improve headerfiles
Diffstat (limited to 'xmake/core/base/private')
| -rw-r--r-- | xmake/core/base/private/match_copyfiles.lua | 119 |
1 files changed, 78 insertions, 41 deletions
diff --git a/xmake/core/base/private/match_copyfiles.lua b/xmake/core/base/private/match_copyfiles.lua index 06a773fd2..4dc751b00 100644 --- a/xmake/core/base/private/match_copyfiles.lua +++ b/xmake/core/base/private/match_copyfiles.lua @@ -31,11 +31,14 @@ local os = require("base/os") -- add_configfiles -- add_installfiles -- add_extrafiles -function match_copyfiles(instance, filetype, outputdir, pathfilter) +function match_copyfiles(instance, filetype, outputdir, opt) + opt = opt or {} - -- no copied files? - local copyfiles = instance:get(filetype) - if not copyfiles then return end + -- get copyfiles? + local copyfiles = opt.copyfiles or instance:get(filetype) + if not copyfiles then + return + end -- get the extra information local extrainfo = table.wrap(instance:extraconf(filetype)) @@ -44,8 +47,18 @@ function match_copyfiles(instance, filetype, outputdir, pathfilter) local srcfiles = {} local dstfiles = {} local fileinfos = {} + local srcfiles_removed = {} + local removed_count = 0 for _, copyfile in ipairs(table.wrap(copyfiles)) do + -- mark as removed files? + local removed = false + local prefix = "__remove_" + if copyfile:startswith(prefix) then + copyfile = copyfile:sub(#prefix + 1) + removed = true + end + -- get the root directory local rootdir, count = copyfile:gsub("|.*$", ""):gsub("%(.*%)$", "") if count == 0 then @@ -62,58 +75,82 @@ function match_copyfiles(instance, filetype, outputdir, pathfilter) -- get the source paths srcpaths = os.match(srcpaths) if srcpaths and #srcpaths > 0 then + if removed then + removed_count = removed_count + #srcpaths + table.join2(srcfiles_removed, srcpaths) + else - -- add the source copied files - table.join2(srcfiles, srcpaths) + -- add the source copied files + table.join2(srcfiles, srcpaths) - -- the copied directory exists? - if outputdir then + -- the copied directory exists? + if outputdir then - -- get the file info - local fileinfo = extrainfo[copyfile] or {} + -- get the file info + local fileinfo = extrainfo[copyfile] or {} - -- get the prefix directory - local prefixdir = fileinfo.prefixdir - if fileinfo.rootdir then - rootdir = fileinfo.rootdir - end + -- get the prefix directory + local prefixdir = fileinfo.prefixdir + if fileinfo.rootdir then + rootdir = fileinfo.rootdir + end - -- add the destinate copied files - for _, srcpath in ipairs(srcpaths) do + -- add the destinate copied files + for _, srcpath in ipairs(srcpaths) do - -- get the destinate directory - local dstdir = outputdir - if prefixdir then - dstdir = path.join(dstdir, prefixdir) - end + -- get the destinate directory + local dstdir = outputdir + if prefixdir then + dstdir = path.join(dstdir, prefixdir) + end - -- the destinate file - local dstfile = nil - if rootdir then - dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir) - else - dstfile = path.join(dstdir, path.filename(srcpath)) - end - assert(dstfile) + -- the destinate file + local dstfile = nil + if rootdir then + dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir) + else + dstfile = path.join(dstdir, path.filename(srcpath)) + end + assert(dstfile) - -- modify filename - if fileinfo.filename then - dstfile = path.join(path.directory(dstfile), fileinfo.filename) - end + -- modify filename + if fileinfo.filename then + dstfile = path.join(path.directory(dstfile), fileinfo.filename) + end - -- filter the destinate file path - if pathfilter then - dstfile = pathfilter(dstfile, fileinfo) - end + -- filter the destinate file path + if opt.pathfilter then + dstfile = opt.pathfilter(dstfile, fileinfo) + end - -- add it - table.insert(dstfiles, dstfile) - table.insert(fileinfos, fileinfo) + -- add it + table.insert(dstfiles, dstfile) + table.insert(fileinfos, fileinfo) + end end end end end end + + -- remove all srcfiles which need be removed + if removed_count > 0 then + table.remove_if(srcfiles, function (i, srcfile) + for _, removed_file in ipairs(srcfiles_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 srcfile:match(pattern) then + if i <= #dstfiles then + table.remove(dstfiles, i) + end + return true + end + end + end) + end return srcfiles, dstfiles, fileinfos end |
