summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-29 00:39:19 +0800
committerruki <[email protected]>2025-04-08 15:31:56 +0800
commitfec05b2bbe38fcaa6b6eb1546fad2f4ab80300b1 (patch)
tree3454669dd3b5ae5035f1a5ec36b26f9cf8b06b48
parent6be0431dd8d7462d53fc4cce2609adfacc57089a (diff)
match sourcebatches
-rw-r--r--xmake/actions/build/target_utils.lua60
1 files changed, 60 insertions, 0 deletions
diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua
index 7708bba88..3563bdc2c 100644
--- a/xmake/actions/build/target_utils.lua
+++ b/xmake/actions/build/target_utils.lua
@@ -225,12 +225,72 @@ function _get_targetjobs(targets_root, opt)
return jobgraph
end
+-- match source files
+function _match_sourcefiles(sourcefile, filepatterns)
+ for _, filepattern in ipairs(filepatterns) do
+ if sourcefile:match(filepattern.pattern) == sourcefile then
+ if filepattern.excludes then
+ if filepattern.rootdir and sourcefile:startswith(filepattern.rootdir) then
+ sourcefile = sourcefile:sub(#filepattern.rootdir + 2)
+ end
+ for _, exclude in ipairs(filepattern.excludes) do
+ if sourcefile:match(exclude) == sourcefile then
+ return false
+ end
+ end
+ end
+ return true
+ end
+ end
+end
+
+-- match sourcebatches
+function _match_sourcebatches(target, filepatterns)
+ local newbatches = {}
+ local sourcecount = 0
+ for rulename, sourcebatch in pairs(target:sourcebatches()) do
+ local objectfiles = sourcebatch.objectfiles
+ local dependfiles = sourcebatch.dependfiles
+ local sourcekind = sourcebatch.sourcekind
+ for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ if _match_sourcefiles(sourcefile, filepatterns) then
+ local newbatch = newbatches[rulename]
+ if not newbatch then
+ newbatch = {}
+ newbatch.sourcekind = sourcekind
+ newbatch.rulename = rulename
+ newbatch.sourcefiles = {}
+ end
+ table.insert(newbatch.sourcefiles, sourcefile)
+ if objectfiles then
+ newbatch.objectfiles = newbatch.objectfiles or {}
+ table.insert(newbatch.objectfiles, objectfiles[idx])
+ end
+ if dependfiles then
+ newbatch.dependfiles = newbatch.dependfiles or {}
+ table.insert(newbatch.dependfiles, dependfiles[idx])
+ end
+ newbatches[rulename] = newbatch
+ sourcecount = sourcecount + 1
+ end
+ end
+ end
+ if sourcecount > 0 then
+ return newbatches
+ end
+end
+
-- add file jobs for the given target
function _add_filejobs(jobgraph, target, opt)
opt = opt or {}
if not target:is_enabled() then
return
end
+
+ -- get sourcebatches
+ local filepatterns = opt.filepatterns
+ local sourcebatches = filepatterns and _match_sourcebatches(target, filepatterns) or target:sourcebatches()
+
end
-- add file jobs for the given target and deps