summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-29 00:37:12 +0800
committerruki <[email protected]>2025-04-08 15:31:56 +0800
commit6be0431dd8d7462d53fc4cce2609adfacc57089a (patch)
treea68adef89ef4976c2565c49535dc11572520a4e2
parentb8949110acd9d2b76ff5c214d95fdc4dda076b5a (diff)
add filejobs stub
-rw-r--r--xmake/actions/build/build.lua3
-rw-r--r--xmake/actions/build/build_files.lua60
-rw-r--r--xmake/actions/build/deprecated/build.lua1
-rw-r--r--xmake/actions/build/target_utils.lua50
4 files changed, 113 insertions, 1 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index 6a4c14ed5..22097669a 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -23,14 +23,17 @@ import("core.base.option")
import("core.project.config")
import("core.project.project")
import("target_utils")
+import("private.service.distcc_build.client", {alias = "distcc_build_client"})
import("deprecated.build", {alias = "deprecated_build"})
+-- run prepare jobs
function _prepare(targets_root, opt)
opt = opt or {}
opt.job_kind = "prepare"
target_utils.run_targetjobs(targets_root, opt)
end
+-- run build jobs
function _build(targets_root, opt)
opt = opt or {}
opt.job_kind = "build"
diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua
index 718390e0b..e26c11aae 100644
--- a/xmake/actions/build/build_files.lua
+++ b/xmake/actions/build/build_files.lua
@@ -24,12 +24,72 @@ import("core.base.hashset")
import("core.project.config")
import("core.project.project")
import("target_utils")
+import("private.service.distcc_build.client", {alias = "distcc_build_client"})
import("deprecated.build_files", {alias = "deprecated_build_files"})
+-- convert all sourcefiles to lua pattern
+function _get_file_patterns(sourcefiles)
+ local patterns = {}
+ for _, sourcefile in ipairs(path.splitenv(sourcefiles)) do
+
+ -- get the excludes
+ local pattern = sourcefile:trim()
+ local excludes = pattern:match("|.*$")
+ if excludes then excludes = excludes:split("|", {plain = true}) end
+
+ -- translate excludes
+ if excludes then
+ local _excludes = {}
+ for _, exclude in ipairs(excludes) do
+ exclude = path.translate(exclude)
+ exclude = path.pattern(exclude)
+ table.insert(_excludes, exclude)
+ end
+ excludes = _excludes
+ end
+
+ -- translate path and remove some repeat separators
+ pattern = path.translate(pattern:gsub("|.*$", ""))
+
+ -- remove "./" or '.\\' prefix
+ if pattern:sub(1, 2):find('%.[/\\]') then
+ pattern = pattern:sub(3)
+ end
+
+ -- get the root directory
+ local rootdir = pattern
+ local startpos = pattern:find("*", 1, true)
+ if startpos then
+ rootdir = rootdir:sub(1, startpos - 1)
+ end
+ rootdir = path.directory(rootdir)
+
+ -- convert to lua path pattern
+ pattern = path.pattern(pattern)
+ table.insert(patterns, {pattern = pattern, excludes = excludes, rootdir = rootdir})
+ end
+ return patterns
+end
+
+-- run prepare files jobs
function _prepare_files(targets_root, opt)
+ opt = opt or {}
+ opt.job_kind = "prepare"
+ opt.filepatterns = _get_file_patterns(opt.sourcefiles)
+ target_utils.run_filejobs(targets_root, opt)
end
+-- run build files jobs
function _build_files(targets_root, opt)
+ opt = opt or {}
+ opt.job_kind = "build"
+ opt.filepatterns = _get_file_patterns(opt.sourcefiles)
+ if distcc_build_client.is_connected() then
+ opt.distcc = distcc_build_client.singleton()
+ end
+ if not target_utils.run_filejobs(targets_root, opt) then
+ wprint("%s not found!", opt.sourcefiles)
+ end
end
function main(targetnames, opt)
diff --git a/xmake/actions/build/deprecated/build.lua b/xmake/actions/build/deprecated/build.lua
index 1c8d47a18..377ab5e18 100644
--- a/xmake/actions/build/deprecated/build.lua
+++ b/xmake/actions/build/deprecated/build.lua
@@ -26,7 +26,6 @@ import("private.async.jobpool")
import("async.runjobs")
import("private.utils.batchcmds")
import("core.base.hashset")
-import("private.service.remote_cache.client", {alias = "remote_cache_client"})
import("private.service.distcc_build.client", {alias = "distcc_build_client"})
-- clean target for rebuilding
diff --git a/xmake/actions/build/target_utils.lua b/xmake/actions/build/target_utils.lua
index 613063ef2..7708bba88 100644
--- a/xmake/actions/build/target_utils.lua
+++ b/xmake/actions/build/target_utils.lua
@@ -225,6 +225,37 @@ function _get_targetjobs(targets_root, opt)
return jobgraph
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
+end
+
+-- add file jobs for the given target and deps
+function _add_filejobs_and_deps(jobgraph, target, targetrefs, opt)
+ local targetname = target:fullname()
+ if not targetrefs[targetname] then
+ targetrefs[targetname] = target
+ _add_filejobs(jobgraph, target, opt)
+ for _, depname in ipairs(target:get("deps")) do
+ local dep = project.target(depname, {namespace = target:namespace()})
+ _add_filejobs_and_deps(jobgraph, dep, targetrefs, opt)
+ end
+ end
+end
+
+-- get files jobs
+function _get_filejobs(targets_root, opt)
+ local jobgraph = async_jobgraph.new()
+ local targetrefs = {}
+ for _, target in ipairs(targets_root) do
+ _add_filejobs_and_deps(jobgraph, target, targetrefs, opt)
+ end
+ return jobgraph
+end
+
-- get all root targets
function get_root_targets(targetnames, opt)
opt = opt or {}
@@ -287,5 +318,24 @@ function run_targetjobs(targets_root, opt)
end
end, comax = option.get("jobs") or 1, curdir = curdir, distcc = opt.distcc})
os.cd(curdir)
+ return true
+ end
+end
+
+-- run files-level jobs, e.g. on_prepare_files, on_build_files, ...
+function run_filejobs(targets_root, opt)
+ opt = opt or {}
+ local job_kind = opt.job_kind
+ local jobgraph = _get_filejobs(targets_root, opt)
+ if jobgraph and not jobgraph:empty() then
+ local curdir = os.curdir()
+ async_runjobs(job_kind, jobgraph, {on_exit = function (errors)
+ import("utils.progress")
+ if errors and progress.showing_without_scroll() then
+ print("")
+ end
+ end, comax = option.get("jobs") or 1, curdir = curdir, distcc = opt.distcc})
+ os.cd(curdir)
+ return true
end
end