summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-04-09 23:48:29 +0800
committerruki <[email protected]>2025-04-09 23:48:29 +0800
commit699e40f3e45469b3597f5fa24ad6bb2c922b8a4b (patch)
tree79de788dd4459a6cf1e26fb195f1561d98061e29
parent260f07164381c235422ec7150e26396604fabdb5 (diff)
move rule_group to deprecated
-rw-r--r--xmake/actions/build/deprecated/kinds/object.lua2
-rw-r--r--xmake/actions/build/deprecated/kinds/rule_groups.lua (renamed from xmake/modules/private/utils/rule_groups.lua)0
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua14
-rw-r--r--xmake/plugins/project/utils/target_cmds.lua90
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua17
5 files changed, 8 insertions, 115 deletions
diff --git a/xmake/actions/build/deprecated/kinds/object.lua b/xmake/actions/build/deprecated/kinds/object.lua
index b5359f79e..c4ed8721a 100644
--- a/xmake/actions/build/deprecated/kinds/object.lua
+++ b/xmake/actions/build/deprecated/kinds/object.lua
@@ -25,7 +25,7 @@ import("core.project.config")
import("core.project.project")
import("async.runjobs")
import("private.utils.batchcmds")
-import("private.utils.rule_groups")
+import("rule_groups")
-- has scripts for the custom rule
function _has_scripts_for_rule(ruleinst, suffix)
diff --git a/xmake/modules/private/utils/rule_groups.lua b/xmake/actions/build/deprecated/kinds/rule_groups.lua
index d64a75d62..d64a75d62 100644
--- a/xmake/modules/private/utils/rule_groups.lua
+++ b/xmake/actions/build/deprecated/kinds/rule_groups.lua
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index c36cb8ade..4cf6eb1ab 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -27,7 +27,6 @@ import("core.project.project")
import("core.language.language")
import("private.utils.batchcmds")
import("private.utils.executable_path")
-import("private.utils.rule_groups")
import("plugins.project.utils.target_cmds", {rootdir = os.programdir()})
import("actions.test.main", {rootdir = os.programdir(), alias = "test_action"})
@@ -242,25 +241,16 @@ end
-- add target commands
function _add_target_commands(jsonfile, target)
- -- build sourcebatch groups first
- local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches())
-
-- add before commands
-- we use irpairs(groups), because the last group that should be given the highest priority.
- local cmds_before = {}
- target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before"})
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before"})
- -- rule.on_buildcmd_files should also be executed before building the target, as cmake PRE_BUILD does not work.
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups)
+ local cmds_before = target_cmds.get_target_buildcmds(target, {stages = {"before", "on"}})
_add_target_custom_commands(jsonfile, target, "before", cmds_before)
-- add target source commands
_add_target_source_commands(jsonfile, target)
-- add after commands
- local cmds_after = {}
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"})
- target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"})
+ local cmds_after = target_cmds.get_target_buildcmds(target, {stages = {"after"}})
_add_target_custom_commands(jsonfile, target, "after", cmds_after)
end
diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua
index 835117d50..b18acb943 100644
--- a/xmake/plugins/project/utils/target_cmds.lua
+++ b/xmake/plugins/project/utils/target_cmds.lua
@@ -24,98 +24,8 @@ import("core.project.config")
import("core.base.hashset")
import("core.project.rule")
import("private.utils.batchcmds")
-import("private.utils.rule_groups")
import("private.action.build.target", {alias = "target_buildutils"})
--- this sourcebatch is built?
-function _sourcebatch_is_built(sourcebatch)
- -- we can only use rulename to filter them because sourcekind may be bound to multiple rules
- local rulename = sourcebatch.rulename
- if rulename == "c.build" or rulename == "c++.build"
- or rulename == "asm.build" or rulename == "cuda.build"
- or rulename == "objc.build" or rulename == "objc++.build"
- or rulename == "win.sdk.resource" then
- return true
- end
-end
-
--- get target buildcmd commands
-function get_target_buildcmd(target, cmds, opt)
- opt = opt or {}
- local suffix = opt.suffix
- local ignored_rules = hashset.from(opt.ignored_rules or {})
- for _, ruleinst in ipairs(target:orderules()) do
- if not ignored_rules:has(ruleinst:name()) then
- local scriptname = "buildcmd" .. (suffix and ("_" .. suffix) or "")
- local script = ruleinst:script(scriptname)
- if script then
- local batchcmds_ = batchcmds.new({target = target})
- script(target, batchcmds_, {})
- if not batchcmds_:empty() then
- table.join2(cmds, batchcmds_:cmds())
- end
- end
- end
- end
-end
-
--- get target buildcmd_files commands
-function get_target_buildcmd_files(target, cmds, sourcebatch, opt)
- opt = opt or {}
-
- -- get rule
- local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!")
- local ruleinst = assert(target:rule(rulename) or project.rule(rulename, {namespace = target:namespace()}) or
- rule.rule(rulename), "unknown rule: %s", rulename)
- local ignored_rules = hashset.from(opt.ignored_rules or {})
- if ignored_rules:has(ruleinst:name()) then
- return
- end
-
- -- generate commands for xx_buildcmd_files
- local suffix = opt.suffix
- local scriptname = "buildcmd_files" .. (suffix and ("_" .. suffix) or "")
- local script = ruleinst:script(scriptname)
- if script then
- local batchcmds_ = batchcmds.new({target = target})
- script(target, batchcmds_, sourcebatch, {})
- if not batchcmds_:empty() then
- table.join2(cmds, batchcmds_:cmds())
- end
- end
-
- -- generate commands for xx_buildcmd_file
- if not script then
- scriptname = "buildcmd_file" .. (suffix and ("_" .. suffix) or "")
- script = ruleinst:script(scriptname)
- if script then
- local sourcekind = sourcebatch.sourcekind
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local batchcmds_ = batchcmds.new({target = target})
- script(target, batchcmds_, sourcefile, {})
- if not batchcmds_:empty() then
- table.join2(cmds, batchcmds_:cmds())
- end
- end
- end
- end
-end
-
--- get target buildcmd commands of source group
-function get_target_buildcmd_sourcegroups(target, cmds, sourcegroups, opt)
- for idx, group in irpairs(sourcegroups) do
- for _, item in pairs(group) do
- -- buildcmd scripts are always in rule, so we need to ignore target item (item.target).
- local sourcebatch = item.sourcebatch
- if item.rule then
- if not _sourcebatch_is_built(sourcebatch) then
- get_target_buildcmd_files(target, cmds, sourcebatch, opt)
- end
- end
- end
- end
-end
-
-- prepare targets
function prepare_targets()
local targets_root = target_buildutils.get_root_targets()
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 0a23a1847..e3b9ddc95 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -39,7 +39,6 @@ import("private.action.require.install", {alias = "install_requires"})
import("private.action.run.runenvs")
import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()})
import("private.utils.batchcmds")
-import("private.utils.rule_groups")
import("plugins.project.utils.target_cmds", {rootdir = os.programdir()})
function _translate_path(dir, vcxprojdir)
@@ -132,24 +131,18 @@ function _make_custom_commands(target, vcxprojdir)
return _translate_path(p, vcxprojdir)
end)
- -- build sourcebatch groups first
- local sourcegroups = rule_groups.build_sourcebatch_groups(target, target:sourcebatches())
-
-- ignore c++ modules rules
local ignored_rules = _get_cxxmodules_rules()
-- add before commands
-- we use irpairs(groups), because the last group that should be given the highest priority.
- local cmds_before = {}
- target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before", ignored_rules = ignored_rules})
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before", ignored_rules = ignored_rules})
- -- rule.on_buildcmd_files should also be executed before building the target, as cmake PRE_BUILD does not work.
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {ignored_rules = ignored_rules})
+ -- rule.on_buildcmd_files should also be executed before building the target
+ local cmds_before = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"before", "on"}})
+ _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "before", cmds_before)
-- add after commands
- local cmds_after = {}
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after", ignored_rules = ignored_rules})
- target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after", ignored_rules = ignored_rules})
+ local cmds_after = target_cmds.get_target_buildcmds(target, {ignored_rules = ignored_rules, stages = {"after"}})
+ _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "after", cmds_after)
local commands = {}
for _, cmd in ipairs(cmds_before) do