diff options
| author | ruki <[email protected]> | 2021-11-15 22:01:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-11-15 22:01:20 +0800 |
| commit | 0f6b878602f3d8e003b51ff34f9d12e6653129a9 (patch) | |
| tree | 335df560dbfe113171630a1a9be373e1ac1f5612 | |
| parent | f31338f204618c41ebadede7f99b15a0d2bb61a5 (diff) | |
improve custom commands for vs
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 1a55eb551..b7bc9c728 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -386,8 +386,9 @@ function _get_command_string(cmd) end end --- add custom command -function _make_custom_command(vcxprojfile, target, command, suffix) +-- make custom commands item +function _make_custom_commands_item(vcxprojfile, commands, suffix) + vcxprojfile:print("<ItemDefinitionGroup>") if suffix == "after" then vcxprojfile:print("<PostBuildEvent>") elseif suffix == "before" then @@ -395,7 +396,9 @@ function _make_custom_command(vcxprojfile, target, command, suffix) end vcxprojfile:print("<Message></Message>") vcxprojfile:print("<Command>setlocal") - vcxprojfile:print("%s", command) + for _, command in ipairs(commands) do + vcxprojfile:print("%s", command) + end vcxprojfile:write([[if %errorlevel% neq 0 goto :xmEnd :xmEnd endlocal & call :xmErrorLevel %errorlevel% & goto :xmDone @@ -409,10 +412,11 @@ if %errorlevel% neq 0 goto :VCEnd</Command> elseif suffix == "before" then vcxprojfile:print("</PreBuildEvent>") end + vcxprojfile:print("</ItemDefinitionGroup>") end -- add target custom commands for target -function _make_custom_commands_for_target(vcxprojfile, target, suffix) +function _make_custom_commands_for_target(commands, target, suffix) for _, ruleinst in ipairs(target:orderules()) do local scriptname = "buildcmd" .. (suffix and ("_" .. suffix) or "") local script = ruleinst:script(scriptname) @@ -423,7 +427,8 @@ function _make_custom_commands_for_target(vcxprojfile, target, suffix) for _, cmd in ipairs(batchcmds_:cmds()) do local command = _get_command_string(cmd) if command then - _make_custom_command(vcxprojfile, target, command, suffix) + commands[suffix] = commands[suffix] or {} + table.insert(commands[suffix], command) end end end @@ -432,7 +437,7 @@ function _make_custom_commands_for_target(vcxprojfile, target, suffix) end -- add target custom commands for object rules -function _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch, suffix) +function _make_custom_commands_for_objectrules(commands, target, sourcebatch, suffix) -- get rule local rulename = assert(sourcebatch.rulename, "unknown rule for sourcebatch!") @@ -448,7 +453,8 @@ function _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch, for _, cmd in ipairs(batchcmds_:cmds()) do local command = _get_command_string(cmd) if command then - _make_custom_command(vcxprojfile, target, command, suffix) + commands[suffix] = commands[suffix] or {} + table.insert(commands[suffix], command) end end end @@ -467,7 +473,8 @@ function _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch, for _, cmd in ipairs(batchcmds_:cmds()) do local command = _get_command_string(cmd) if command then - _make_custom_command(vcxprojfile, target, command, suffix) + commands[suffix] = commands[suffix] or {} + table.insert(commands[suffix], command) end end end @@ -478,16 +485,20 @@ end -- make custom commands function _make_custom_commands(vcxprojfile, target) - _make_custom_commands_for_target(vcxprojfile, target, "before") + local commands = {} + _make_custom_commands_for_target(commands, target, "before") for _, sourcebatch in pairs(target:sourcebatches()) do local sourcekind = sourcebatch.sourcekind if sourcekind ~= "cc" and sourcekind ~= "cxx" and sourcekind ~= "as" then - _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch, "before") - _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch) - _make_custom_commands_for_objectrules(vcxprojfile, target, sourcebatch, "after") + _make_custom_commands_for_objectrules(commands, target, sourcebatch, "before") + _make_custom_commands_for_objectrules(commands, target, sourcebatch) + _make_custom_commands_for_objectrules(commands, target, sourcebatch, "after") end end - _make_custom_commands_for_target(vcxprojfile, target, "after") + _make_custom_commands_for_target(commands, target, "after") + for suffix, cmds in pairs(commands) do + _make_custom_commands_item(vcxprojfile, cmds, suffix) + end end -- make common item @@ -577,9 +588,6 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo, vcxprojdir) vcxprojfile:leave("</ClCompile>") - -- make custom commands - _make_custom_commands(vcxprojfile, target.targetinst) - -- leave ItemDefinitionGroup vcxprojfile:leave("</ItemDefinitionGroup>") end @@ -913,6 +921,9 @@ function make(vsinfo, target) -- make common items _make_common_items(vcxprojfile, vsinfo, target, vcxprojdir) + -- make custom commands + _make_custom_commands(vcxprojfile, target.targetinst) + -- make source files _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir) |
