summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-02-19 22:55:45 +0800
committerruki <[email protected]>2024-02-19 22:55:45 +0800
commitf4a9a9e3fa36f3f0cf1e655c58bf3fa4d546348b (patch)
tree0b42eb09db96cdc6cea528fafecc4e1b274d6d0e
parent7e126bdbcc883f59c43ccc94eb80f2607d612ef0 (diff)
improve target_buildcmd
-rw-r--r--xmake/plugins/project/clang/compile_commands.lua8
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua8
-rw-r--r--xmake/plugins/project/make/makefile.lua8
-rw-r--r--xmake/plugins/project/utils/target_cmds.lua12
4 files changed, 20 insertions, 16 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua
index e3dbe9520..059173c45 100644
--- a/xmake/plugins/project/clang/compile_commands.lua
+++ b/xmake/plugins/project/clang/compile_commands.lua
@@ -245,8 +245,8 @@ function _add_target_commands(jsonfile, target)
-- 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, "before")
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, "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)
_add_target_custom_commands(jsonfile, target, "before", cmds_before)
@@ -256,8 +256,8 @@ function _add_target_commands(jsonfile, target)
-- add after commands
local cmds_after = {}
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, "after")
- target_cmds.get_target_buildcmd(target, cmds_after, "after")
+ target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"})
+ target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"})
_add_target_custom_commands(jsonfile, target, "after", cmds_after)
end
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index 98a94338d..a6316adf2 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -976,16 +976,16 @@ function _add_target_custom_commands(cmakelists, target, outputdir)
-- 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, "before")
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, "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)
_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, "after")
- target_cmds.get_target_buildcmd(target, cmds_after, "after")
+ target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"})
+ target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"})
_add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, "after", cmds_after)
end
diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua
index 7d462b138..12b1b77e0 100644
--- a/xmake/plugins/project/make/makefile.lua
+++ b/xmake/plugins/project/make/makefile.lua
@@ -474,8 +474,8 @@ function _add_build_custom_commands_before(makefile, target, sourcegroups, outpu
-- 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, "before")
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, "before")
+ target_cmds.get_target_buildcmd(target, cmds_before, {suffix = "before"})
+ target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups, {suffix = "before"})
target_cmds.get_target_buildcmd_sourcegroups(target, cmds_before, sourcegroups)
local targetname = target:name()
@@ -496,8 +496,8 @@ end
-- add custom commands after building target
function _add_build_custom_commands_after(makefile, target, sourcegroups, outputdir)
local cmds_after = {}
- target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, "after")
- target_cmds.get_target_buildcmd(target, cmds_after, "after")
+ target_cmds.get_target_buildcmd_sourcegroups(target, cmds_after, sourcegroups, {suffix = "after"})
+ target_cmds.get_target_buildcmd(target, cmds_after, {suffix = "after"})
if #cmds_after > 0 then
for _, cmd in ipairs(cmds_after) do
local command = _get_command_string(cmd, outputdir)
diff --git a/xmake/plugins/project/utils/target_cmds.lua b/xmake/plugins/project/utils/target_cmds.lua
index 4c7f4f008..92d1bee47 100644
--- a/xmake/plugins/project/utils/target_cmds.lua
+++ b/xmake/plugins/project/utils/target_cmds.lua
@@ -39,7 +39,9 @@ function _sourcebatch_is_built(sourcebatch)
end
-- get target buildcmd commands
-function get_target_buildcmd(target, cmds, suffix)
+function get_target_buildcmd(target, cmds, opt)
+ opt = opt or {}
+ local suffix = opt.suffix
for _, ruleinst in ipairs(target:orderules()) do
local scriptname = "buildcmd" .. (suffix and ("_" .. suffix) or "")
local script = ruleinst:script(scriptname)
@@ -54,13 +56,15 @@ function get_target_buildcmd(target, cmds, suffix)
end
-- get target buildcmd_files commands
-function get_target_buildcmd_files(target, cmds, sourcebatch, suffix)
+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) or rule.rule(rulename), "unknown rule: %s", rulename)
-- 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
@@ -89,14 +93,14 @@ function get_target_buildcmd_files(target, cmds, sourcebatch, suffix)
end
-- get target buildcmd commands of source group
-function get_target_buildcmd_sourcegroups(target, cmds, sourcegroups, suffix)
+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, suffix)
+ get_target_buildcmd_files(target, cmds, sourcebatch, opt)
end
end
end