Skip to content

Commit

Permalink
Handle buildaction "Copy" for gmake2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Feb 19, 2024
1 parent ca21153 commit 70b4a25
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
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
20 changes: 18 additions & 2 deletions modules/gmake2/gmake2_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,19 @@
end

-- process custom build commands.
if fileconfig.hasCustomBuildRule(filecfg) then
if 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)

elseif fileconfig.hasCustomBuildRule(filecfg) then
local env = table.shallowcopy(filecfg.environ)
env.PathVars = {
["file.basename"] = { absolute = false, token = node.basename },
Expand Down Expand Up @@ -761,7 +773,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

0 comments on commit 70b4a25

Please sign in to comment.