Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle buildaction "Copy" for gmake2. #2188

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions modules/codelite/codelite_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -405,31 +405,31 @@
local dependencies = {}
local makefilerules = {}
local function addrule(dependencies, makefilerules, config, filename)
if config.buildaction == "Copy" and filename ~= "" then
if #config.buildcommands > 0 and #config.buildoutputs > 0 then
local inputs = table.implode(project.getrelative(cfg.project, config.buildinputs), "", "", " ")
if filename ~= "" and inputs ~= "" then
filename = filename .. " "
end
local outputs = project.getrelative(cfg.project, config.buildoutputs[1])
local buildmessage = ""
if config.buildmessage then
buildmessage = "\t@{ECHO} " .. p.quote(config.buildmessage) .. "\n"
end
local commands = table.implode(config.buildcommands,"\t","\n","")
table.insert(makefilerules, os.translateCommandsAndPaths(outputs .. ": " .. filename .. inputs .. "\n" .. buildmessage .. "\t@$(MakeDirCommand) $(@D)\n" .. commands, cfg.project.basedir, cfg.project.location))
table.insertflat(dependencies, outputs)
return true
elseif config.buildaction == "Copy" and filename ~= "" then
local output = project.getrelative(cfg.workspace, path.join(cfg.targetdir, config.name))
local create_directory_command = '\t@$(MakeDirCommand) $(@D)\n'
local command = '\t' .. os.translateCommands('{COPYFILE} "' .. filename .. '" "' .. output ..'"') .. '\n'

table.insert(makefilerules, output .. ": " .. filename .. '\n' .. create_directory_command .. command)
table.insert(dependencies, output)
return true
end
if #config.buildcommands == 0 or #config.buildoutputs == 0 then
else
return false
end
local inputs = table.implode(project.getrelative(cfg.project, config.buildinputs), "", "", " ")
if filename ~= "" and inputs ~= "" then
filename = filename .. " "
end
local outputs = project.getrelative(cfg.project, config.buildoutputs[1])
local buildmessage = ""
if config.buildmessage then
buildmessage = "\t@{ECHO} " .. p.quote(config.buildmessage) .. "\n"
end
local commands = table.implode(config.buildcommands,"\t","\n","")
table.insert(makefilerules, os.translateCommandsAndPaths(outputs .. ": " .. filename .. inputs .. "\n" .. buildmessage .. "\t@$(MakeDirCommand) $(@D)\n" .. commands, cfg.project.basedir, cfg.project.location))
table.insertflat(dependencies, outputs)
return true
end
local tr = project.getsourcetree(cfg.project)
p.tree.traverse(tr, {
Expand Down
9 changes: 9 additions & 0 deletions modules/gmake2/gmake2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@
_p('endif')
end

function gmake2.copyfile_cmds(source, dest)
local cmd = '$(SILENT) {COPYFILE} ' .. source .. ' ' .. dest
return { 'ifeq (posix,$(SHELLTYPE))',
'\t' .. os.translateCommands(cmd, 'posix'),
'else',
'\t' .. os.translateCommands(cmd, 'windows'),
'endif' }
end

function gmake2.mkdirRules(dirname)
_p('%s:', dirname)
_p('\t@echo Creating %s', dirname)
Expand Down
17 changes: 16 additions & 1 deletion modules/gmake2/gmake2_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@
cpp.addGeneratedFile(cfg, node, output)
end
end
elseif filecfg.buildaction == "Copy" then
local output = '$(TARGETDIR)/' .. node.name
local file = {
buildoutputs = { output },
source = node.relpath,
buildmessage = '$(notdir $<)',
verbatimbuildcommands = gmake2.copyfile_cmds('"$<"', '"$@"'),
buildinputs = {'$(TARGETDIR)'}
}
table.insert(cfg._gmake.fileRules, file)
cpp.addGeneratedFile(cfg, node, output)
else
cpp.addRuleFile(cfg, node)
end
Expand Down Expand Up @@ -761,7 +772,11 @@
end
end
end

if file.verbatimbuildcommands then
for _, cmd in ipairs(file.verbatimbuildcommands) do
_p('%s', cmd);
end
end
-- TODO: this is a hack with some imperfect side-effects.
-- better solution would be to emit a dummy file for the rule, and then outputs depend on it (must clean up dummy in 'clean')
-- better yet, is to use pattern rules, but we need to detect that all outputs have the same stem
Expand Down
24 changes: 24 additions & 0 deletions modules/gmake2/tests/test_gmake2_file_rules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,27 @@ test2.obj: test2.rule
$(SILENT) dorule S1 "test2.rule"
]]
end

function suite.fileRulesOnBuildactionCopy()
files { "hello.dll" }
filter { "Debug", "files:hello.dll" }
buildaction "Copy"
filter {}
prepare()
test.capture [[
# File Rules
# #############################################

ifeq ($(config),debug)
$(TARGETDIR)/hello.dll: hello.dll $(TARGETDIR)
@echo "$(notdir $<)"
ifeq (posix,$(SHELLTYPE))
$(SILENT) cp -f "$<" "$@"
else
$(SILENT) copy /B /Y "$<" "$@"
endif

endif
]]
end

23 changes: 23 additions & 0 deletions modules/gmake2/tests/test_gmake2_objects.lua
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,26 @@ endif

]]
end

function suite.objectsOnBuildactionCopy()
files { "hello.dll" }
filter { "Debug", "files:hello.dll" }
buildaction "Copy"
filter {}
prepare()
test.capture [[
# File sets
# #############################################

CUSTOM :=
GENERATED :=

ifeq ($(config),debug)
CUSTOM += $(TARGETDIR)/hello.dll
GENERATED += $(TARGETDIR)/hello.dll

endif

]]
end

Loading