summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-03-24 22:50:28 +0800
committerruki <[email protected]>2025-04-08 15:31:55 +0800
commit0a01105ef8e83039523a4aa97cb3ca0c8726df04 (patch)
tree4d45d54eff7e451b409945573775974c0c8bf10b
parent502f7b6ddf39b8053c523d7a58532e0a5998c414 (diff)
pass target roots as args
-rw-r--r--xmake/actions/build/build.lua14
-rw-r--r--xmake/actions/build/build_files.lua12
-rw-r--r--xmake/actions/build/prepare.lua47
-rw-r--r--xmake/actions/build/prepare_files.lua2
-rw-r--r--xmake/modules/private/diagnosis/dump_buildjobs.lua30
-rw-r--r--xmake/modules/private/diagnosis/dump_targets.lua74
6 files changed, 17 insertions, 162 deletions
diff --git a/xmake/actions/build/build.lua b/xmake/actions/build/build.lua
index e890faa0a..05284490d 100644
--- a/xmake/actions/build/build.lua
+++ b/xmake/actions/build/build.lua
@@ -231,11 +231,8 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, target, jobrefs,
end
end
--- get batch jobs, @note we need to export it for private.diagnosis.dump_buildjobs
-function get_batchjobs(targetnames, opt)
-
- -- get root targets
- local targets_root = target_utils.get_root_targets(targetnames, opt)
+-- get batch jobs
+function _get_batchjobs(targets_root, opt)
-- generate batch jobs for default or all targets
local jobrefs = {}
@@ -265,8 +262,11 @@ end
function main(targetnames, opt)
+ -- get root targets
+ local targets_root = target_utils.get_root_targets(targetnames, opt)
+
-- prepare to build
- prepare_build(targetnames, opt)
+ prepare_build(targets_root, opt)
-- enable distcc?
local distcc
@@ -275,7 +275,7 @@ function main(targetnames, opt)
end
-- build all jobs
- local batchjobs = get_batchjobs(targetnames, opt)
+ local batchjobs = _get_batchjobs(targets_root, opt)
if batchjobs and batchjobs:size() > 0 then
local curdir = os.curdir()
runjobs("build", batchjobs, {on_exit = function (errors)
diff --git a/xmake/actions/build/build_files.lua b/xmake/actions/build/build_files.lua
index ae09fc838..8d1383cbb 100644
--- a/xmake/actions/build/build_files.lua
+++ b/xmake/actions/build/build_files.lua
@@ -116,14 +116,11 @@ function _add_batchjobs_for_target_and_deps(batchjobs, rootjob, jobrefs, target,
end
-- get batch jobs
-function _get_batchjobs(targetnames, opt)
+function _get_batchjobs(targets_root, opt)
-- convert all sourcefiles to lua pattern
local filepatterns = _get_file_patterns(opt.sourcefiles)
- -- get root targets
- local targets_root = target_utils.get_root_targets(targetnames, opt)
-
-- generate batch jobs for default or all targets
local jobrefs = {}
local batchjobs = jobpool.new()
@@ -180,11 +177,14 @@ end
-- the main entry
function main(targetnames, opt)
+ -- get root targets
+ local targets_root = target_utils.get_root_targets(targetnames, opt)
+
-- prepare to build files
- prepare_build_files(targetnames, opt)
+ prepare_build_files(targets_root, opt)
-- build all jobs
- local batchjobs = _get_batchjobs(targetnames, opt)
+ local batchjobs = _get_batchjobs(targets_root, opt)
if batchjobs and batchjobs:size() > 0 then
local curdir = os.curdir()
runjobs("build_files", batchjobs, {comax = option.get("jobs") or 1, curdir = curdir})
diff --git a/xmake/actions/build/prepare.lua b/xmake/actions/build/prepare.lua
index 45f0d75b9..aea951168 100644
--- a/xmake/actions/build/prepare.lua
+++ b/xmake/actions/build/prepare.lua
@@ -25,52 +25,11 @@ import("async.runjobs")
import("async.jobgraph", {alias = "async_jobgraph"})
-- get prepare jobs
-function _get_prepare_jobs(targetnames, opt)
+function _get_prepare_jobs(targets_root, opt)
local jobgraph = async_jobgraph.new()
return jobgraph
- -- get root targets
--[[
- local targets_root = {}
- if targetnames then
- for _, targetname in ipairs(table.wrap(targetnames)) do
- local target = project.target(targetname)
- if target then
- table.insert(targets_root, target)
- if option.get("rebuild") then
- target:data_set("rebuilt", true)
- if not option.get("shallow") then
- for _, dep in ipairs(target:orderdeps()) do
- dep:data_set("rebuilt", true)
- end
- end
- end
- end
- end
- else
- local group_pattern = opt.group_pattern
- local depset = hashset.new()
- local targets = {}
- for _, target in ipairs(project.ordertargets()) do
- if target:is_enabled() then
- local group = target:get("group")
- if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then
- for _, depname in ipairs(target:get("deps")) do
- depset:insert(depname)
- end
- table.insert(targets, target)
- end
- end
- end
- for _, target in ipairs(targets) do
- if not depset:has(target:name()) then
- table.insert(targets_root, target)
- end
- if option.get("rebuild") then
- target:data_set("rebuilt", true)
- end
- end
- end
-- generate batch jobs for default or all targets
local jobrefs = {}
@@ -98,8 +57,8 @@ function _get_prepare_jobs(targetnames, opt)
return jobgraph]]
end
-function main(targetnames, opt)
- local jobgraph = _get_prepare_jobs(targetnames, opt)
+function main(targets_root, opt)
+ local jobgraph = _get_prepare_jobs(targets_root, opt)
if jobgraph and not jobgraph:empty() then
local curdir = os.curdir()
runjobs("prepare", jobgraph, {on_exit = function (errors)
diff --git a/xmake/actions/build/prepare_files.lua b/xmake/actions/build/prepare_files.lua
index acdc41b0e..3abb3ef31 100644
--- a/xmake/actions/build/prepare_files.lua
+++ b/xmake/actions/build/prepare_files.lua
@@ -22,5 +22,5 @@
import("core.base.option")
import("core.project.config")
-function main(targetnames, opt)
+function main(targets_root, opt)
end
diff --git a/xmake/modules/private/diagnosis/dump_buildjobs.lua b/xmake/modules/private/diagnosis/dump_buildjobs.lua
deleted file mode 100644
index 16083a40b..000000000
--- a/xmake/modules/private/diagnosis/dump_buildjobs.lua
+++ /dev/null
@@ -1,30 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file dump_buildjobs.lua
---
-
--- imports
-import("core.project.config")
-import("actions.build.build", {rootdir = os.programdir()})
-
--- dump the build jobs, e.g. xmake l private.diagnosis.dump_buildjobs [targetname]
-function main(targetname)
- config.load()
- print(build.get_batchjobs(targetname))
-end
-
diff --git a/xmake/modules/private/diagnosis/dump_targets.lua b/xmake/modules/private/diagnosis/dump_targets.lua
deleted file mode 100644
index c992a28f0..000000000
--- a/xmake/modules/private/diagnosis/dump_targets.lua
+++ /dev/null
@@ -1,74 +0,0 @@
---!A cross-platform build utility based on Lua
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
---
--- http://www.apache.org/licenses/LICENSE-2.0
---
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
---
--- Copyright (C) 2015-present, TBOOX Open Source Group.
---
--- @author ruki
--- @file dump_targets.lua
---
-
--- imports
-import("core.base.hashset")
-import("core.project.config")
-import("core.project.project")
-
--- get targets
-function _get_targets(targetname)
-
- -- get targets
- local targets = {}
- if targetname then
- table.insert(targets, project.target(targetname))
- else
- for _, target in pairs(project.targets()) do
- table.insert(targets, target)
- end
- end
- return targets
-end
-
--- dump the build jobs, e.g. xmake l private.diagnosis.dump_buildjobs [targetname]
-function main(targetname)
- config.load()
- for _, target in ipairs(_get_targets(targetname)) do
- cprint("${bright}target(%s):${clear} %s", target:name(), target:kind())
- local deps = target:get("deps")
- if deps then
- cprint(" ${color.dump.string}deps:")
- cprint(" ${yellow}->${clear} %s", table.concat(table.wrap(deps), ", "))
- end
- local options = {}
- for _, optname in ipairs(target:get("options")) do
- if not optname:startswith("__") then
- table.insert(options, optname)
- end
- end
- if #options > 0 then
- cprint(" ${color.dump.string}options:")
- cprint(" ${yellow}->${clear} %s", table.concat(table.wrap(options), ", "))
- end
- local packages = target:get("packages")
- if packages then
- cprint(" ${color.dump.string}packages:")
- cprint(" ${yellow}->${clear} %s", table.concat(table.wrap(packages), ", "))
- end
- local rules = target:get("rules")
- if rules then
- cprint(" ${color.dump.string}rules:")
- cprint(" ${yellow}->${clear} %s", table.concat(table.wrap(rules), ", "))
- end
- print("")
- end
-end
-