Merge remote-tracking branch 'Jarod42/HandleBuildCommandForCodelite'

This commit is contained in:
starkos 2021-07-08 06:40:55 -04:00
commit e12e5afca0
2 changed files with 80 additions and 1 deletions

View File

@ -377,7 +377,41 @@
_p(3, '<AdditionalRules>')
_p(4, '<CustomPostBuild/>')
_p(4, '<CustomPreBuild/>')
local dependencies = {}
local rules = {}
local function addrule(dependencies, rules, config, filename)
if #config.buildcommands == 0 or #config.buildOutputs == 0 then
return
end
local inputs = table.implode(config.buildInputs,"",""," ")
if filename ~= "" and inputs ~= "" then
filename = filename .. " "
end
local outputs = config.buildOutputs[1]
local buildmessage = ""
if config.buildmessage then
buildmessage = "\t@{ECHO} " .. config.buildmessage .. "\n"
end
local commands = table.implode(config.buildCommands,"\t","\n","")
table.insert(rules, os.translateCommandsAndPaths(outputs .. ": " .. filename .. inputs .. "\n" .. buildmessage .. commands, cfg.project.basedir, cfg.project.location))
table.insertflat(dependencies, config.buildOutputs[1])
end
local tr = project.getsourcetree(cfg.project)
p.tree.traverse(tr, {
onleaf = function(node, depth)
local filecfg = p.fileconfig.getconfig(node, cfg)
addrule(dependencies, rules, filecfg, node.relpath)
end
})
addrule(dependencies, rules, cfg, "")
if #rules == 0 and #dependencies == 0 then
_p(4, '<CustomPreBuild/>')
else
_p(4, '<CustomPreBuild>' .. table.implode(dependencies,"",""," "))
_p(0, table.implode(rules,"","","\n") .. '</CustomPreBuild>')
end
_p(3, '</AdditionalRules>')
end

View File

@ -203,6 +203,51 @@
]]
end
function suite.OnProjectCfg_BuildCommand()
files {"/c/foo.txt", "/c/bar.txt"}
buildinputs { "/c/toto.txt", "/c/extra_dependency" }
buildoutputs { "/c/toto.c" }
buildcommands { "test", "test /c/toto.c" }
buildmessage "Some message"
prepare()
codelite.project.additionalRules(cfg)
test.capture [[
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild>/c/toto.c
/c/toto.c: /c/toto.txt /c/extra_dependency
@echo Some message
test
test /c/toto.c
</CustomPreBuild>
</AdditionalRules>]]
end
function suite.OnProjectCfg_BuildCommandPerFile()
files {"/c/foo.txt", "/c/bar.txt"}
filter "files:**.txt"
buildinputs { "/c/%{file.basename}.h", "/c/extra_dependency" }
buildoutputs { "/c/%{file.basename}.c" }
buildcommands { "test", "test /c/%{file.basename}" }
buildmessage "Some message"
prepare()
codelite.project.additionalRules(cfg)
test.capture [[
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild>/c/bar.c /c/foo.c
/c/bar.c: /c/bar.txt /c/bar.h /c/extra_dependency
@echo Some message
test
test /c/bar
/c/foo.c: /c/foo.txt /c/foo.h /c/extra_dependency
@echo Some message
test
test /c/foo
</CustomPreBuild>
</AdditionalRules>]]
end
function suite.OnProjectCfg_General()
system "Windows"