From d01e1179518962989f6f4d1f28e1cbd164239da8 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sat, 3 Jul 2021 13:29:43 +0200 Subject: [PATCH] Handle `buildcommand` for Codelite. --- modules/codelite/codelite_project.lua | 36 ++++++++++++++- .../codelite/tests/test_codelite_config.lua | 45 +++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/modules/codelite/codelite_project.lua b/modules/codelite/codelite_project.lua index af356897..4396f0c0 100755 --- a/modules/codelite/codelite_project.lua +++ b/modules/codelite/codelite_project.lua @@ -377,7 +377,41 @@ _p(3, '') _p(4, '') - _p(4, '') + + 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, '') + else + _p(4, '' .. table.implode(dependencies,"",""," ")) + _p(0, table.implode(rules,"","","\n") .. '') + end _p(3, '') end diff --git a/modules/codelite/tests/test_codelite_config.lua b/modules/codelite/tests/test_codelite_config.lua index 4a72da68..193e335e 100644 --- a/modules/codelite/tests/test_codelite_config.lua +++ b/modules/codelite/tests/test_codelite_config.lua @@ -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 [[ + + + /c/toto.c +/c/toto.c: /c/toto.txt /c/extra_dependency + @echo Some message + test + test /c/toto.c + + ]] + 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 [[ + + + /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 + + ]] + end function suite.OnProjectCfg_General() system "Windows"