Merge pull request #769 from Blizzard/cmdpath-token
[core] new cmd path decorations with %[] syntax
This commit is contained in:
commit
863b89625f
@ -256,7 +256,7 @@
|
|||||||
local steps = cfg[event .. "commands"]
|
local steps = cfg[event .. "commands"]
|
||||||
local msg = cfg[event .. "message"]
|
local msg = cfg[event .. "message"]
|
||||||
if #steps > 0 then
|
if #steps > 0 then
|
||||||
steps = os.translateCommands(steps)
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
||||||
msg = msg or string.format("Running %s commands", event)
|
msg = msg or string.format("Running %s commands", event)
|
||||||
_p('\t@echo %s', msg)
|
_p('\t@echo %s', msg)
|
||||||
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
||||||
|
@ -178,7 +178,7 @@
|
|||||||
_p('%s: %s', output, dependencies)
|
_p('%s: %s', output, dependencies)
|
||||||
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
|
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
|
||||||
|
|
||||||
local cmds = os.translateCommands(filecfg.buildcommands)
|
local cmds = os.translateCommandsAndPaths(filecfg.buildcommands, cfg.project.basedir, cfg.project.location)
|
||||||
for _, cmd in ipairs(cmds) do
|
for _, cmd in ipairs(cmds) do
|
||||||
if cfg.bindirs and #cfg.bindirs > 0 then
|
if cfg.bindirs and #cfg.bindirs > 0 then
|
||||||
_p('\t$(SILENT) $(EXE_PATHS) %s', cmd)
|
_p('\t$(SILENT) $(EXE_PATHS) %s', cmd)
|
||||||
|
@ -72,7 +72,7 @@
|
|||||||
_p(' define BUILDCMDS')
|
_p(' define BUILDCMDS')
|
||||||
local steps = cfg.buildcommands
|
local steps = cfg.buildcommands
|
||||||
if #steps > 0 then
|
if #steps > 0 then
|
||||||
steps = os.translateCommands(steps)
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
||||||
_p('\t@echo Running build commands')
|
_p('\t@echo Running build commands')
|
||||||
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
||||||
end
|
end
|
||||||
@ -84,7 +84,7 @@
|
|||||||
_p(' define CLEANCMDS')
|
_p(' define CLEANCMDS')
|
||||||
local steps = cfg.cleancommands
|
local steps = cfg.cleancommands
|
||||||
if #steps > 0 then
|
if #steps > 0 then
|
||||||
steps = os.translateCommands(steps)
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
||||||
_p('\t@echo Running clean commands')
|
_p('\t@echo Running clean commands')
|
||||||
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
_p('\t%s', table.implode(steps, "", "", "\n\t"))
|
||||||
end
|
end
|
||||||
|
@ -226,7 +226,7 @@
|
|||||||
function cs2005.buildEvents(prj)
|
function cs2005.buildEvents(prj)
|
||||||
local function output(name, steps)
|
local function output(name, steps)
|
||||||
if #steps > 0 then
|
if #steps > 0 then
|
||||||
steps = os.translateCommands(steps, p.WINDOWS)
|
steps = os.translateCommandsAndPaths(steps, prj.basedir, prj.location)
|
||||||
steps = table.implode(steps, "", "", "\r\n")
|
steps = table.implode(steps, "", "", "\r\n")
|
||||||
_x(2,'<%sBuildEvent>%s</%sBuildEvent>', name, steps, name)
|
_x(2,'<%sBuildEvent>%s</%sBuildEvent>', name, steps, name)
|
||||||
end
|
end
|
||||||
|
@ -945,7 +945,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function m.buildCommandLine(cfg)
|
function m.buildCommandLine(cfg)
|
||||||
local cmds = os.translateCommands(cfg.buildcommands, p.WINDOWS)
|
local cmds = os.translateCommandsAndPaths(cfg.buildcommands, cfg.project.basedir, cfg.project.location)
|
||||||
p.x('BuildCommandLine="%s"', table.concat(cmds, "\r\n"))
|
p.x('BuildCommandLine="%s"', table.concat(cmds, "\r\n"))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -960,7 +960,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function m.cleanCommandLine(cfg)
|
function m.cleanCommandLine(cfg)
|
||||||
local cmds = os.translateCommands(cfg.cleancommands, p.WINDOWS)
|
local cmds = os.translateCommandsAndPaths(cfg.cleancommands, cfg.project.basedir, cfg.project.location)
|
||||||
cmds = table.concat(cmds, "\r\n")
|
cmds = table.concat(cmds, "\r\n")
|
||||||
p.x('CleanCommandLine="%s"', cmds)
|
p.x('CleanCommandLine="%s"', cmds)
|
||||||
end
|
end
|
||||||
@ -975,7 +975,7 @@
|
|||||||
if msg then
|
if msg then
|
||||||
p.x('Description="%s"', msg)
|
p.x('Description="%s"', msg)
|
||||||
end
|
end
|
||||||
steps = os.translateCommands(steps, p.WINDOWS)
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
||||||
p.x('CommandLine="%s"', table.implode(steps, "", "", "\r\n"))
|
p.x('CommandLine="%s"', table.implode(steps, "", "", "\r\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1045,7 +1045,7 @@
|
|||||||
function m.customBuildTool(cfg)
|
function m.customBuildTool(cfg)
|
||||||
local cfg, filecfg = config.normalize(cfg)
|
local cfg, filecfg = config.normalize(cfg)
|
||||||
if filecfg and fileconfig.hasCustomBuildRule(filecfg) then
|
if filecfg and fileconfig.hasCustomBuildRule(filecfg) then
|
||||||
local cmds = os.translateCommands(filecfg.buildcommands, p.WINDOWS)
|
local cmds = os.translateCommandsAndPaths(filecfg.buildcommands, filecfg.project.basedir, filecfg.project.location)
|
||||||
p.x('CommandLine="%s"', table.concat(cmds,'\r\n'))
|
p.x('CommandLine="%s"', table.concat(cmds,'\r\n'))
|
||||||
|
|
||||||
local outputs = project.getrelative(filecfg.project, filecfg.buildoutputs)
|
local outputs = project.getrelative(filecfg.project, filecfg.buildoutputs)
|
||||||
|
@ -511,7 +511,7 @@
|
|||||||
local msg = cfg[field .. "message"]
|
local msg = cfg[field .. "message"]
|
||||||
|
|
||||||
if #steps > 0 then
|
if #steps > 0 then
|
||||||
steps = os.translateCommands(steps, p.WINDOWS)
|
steps = os.translateCommandsAndPaths(steps, cfg.project.basedir, cfg.project.location)
|
||||||
p.push('<%s>', name)
|
p.push('<%s>', name)
|
||||||
p.x('<Command>%s</Command>', table.implode(steps, "", "", "\r\n"))
|
p.x('<Command>%s</Command>', table.implode(steps, "", "", "\r\n"))
|
||||||
if msg then
|
if msg then
|
||||||
@ -1131,7 +1131,7 @@
|
|||||||
|
|
||||||
|
|
||||||
function m.buildCommands(fcfg, condition)
|
function m.buildCommands(fcfg, condition)
|
||||||
local commands = os.translateCommands(fcfg.buildcommands, p.WINDOWS)
|
local commands = os.translateCommandsAndPaths(fcfg.buildcommands, fcfg.project.basedir, fcfg.project.location)
|
||||||
commands = table.concat(commands,'\r\n')
|
commands = table.concat(commands,'\r\n')
|
||||||
m.element("Command", condition, '%s', commands)
|
m.element("Command", condition, '%s', commands)
|
||||||
end
|
end
|
||||||
@ -1768,7 +1768,7 @@
|
|||||||
|
|
||||||
function m.nmakeCommandLine(cfg, commands, phase)
|
function m.nmakeCommandLine(cfg, commands, phase)
|
||||||
if #commands > 0 then
|
if #commands > 0 then
|
||||||
commands = os.translateCommands(commands, p.WINDOWS)
|
commands = os.translateCommandsAndPaths(commands, cfg.project.basedir, cfg.project.location)
|
||||||
commands = table.concat(p.esc(commands), p.eol())
|
commands = table.concat(p.esc(commands), p.eol())
|
||||||
p.w('<NMake%sCommandLine>%s</NMake%sCommandLine>', phase, commands, phase)
|
p.w('<NMake%sCommandLine>%s</NMake%sCommandLine>', phase, commands, phase)
|
||||||
end
|
end
|
||||||
|
@ -610,6 +610,47 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Translate decorated command paths into their OS equivalents.
|
||||||
|
---
|
||||||
|
|
||||||
|
function os.translateCommandsAndPaths(cmds, basedir, location, map)
|
||||||
|
local translatedBaseDir = path.getrelative(location, basedir)
|
||||||
|
|
||||||
|
map = map or os.target()
|
||||||
|
|
||||||
|
local translateFunction = function(value)
|
||||||
|
local result = path.join(translatedBaseDir, value)
|
||||||
|
if value:endswith('/') or value:endswith('\\') or
|
||||||
|
value:endswith('/"') or value:endswith('\\"') then
|
||||||
|
result = result .. '/'
|
||||||
|
end
|
||||||
|
if map == 'windows' then
|
||||||
|
result = path.translate(result)
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local processOne = function(cmd)
|
||||||
|
local replaceFunction = function(value)
|
||||||
|
value = value:sub(3, #value - 1)
|
||||||
|
return '"' .. translateFunction(value) .. '"'
|
||||||
|
end
|
||||||
|
return string.gsub(cmd, "%%%[[^%]\r\n]*%]", replaceFunction)
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(cmds) == "table" then
|
||||||
|
local result = {}
|
||||||
|
for i = 1, #cmds do
|
||||||
|
result[i] = processOne(cmds[i])
|
||||||
|
end
|
||||||
|
return os.translateCommands(result, map)
|
||||||
|
else
|
||||||
|
return os.translateCommands(processOne(cmds), map)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Generate a UUID.
|
-- Generate a UUID.
|
||||||
--
|
--
|
||||||
|
@ -281,3 +281,22 @@
|
|||||||
local version = os.getversion();
|
local version = os.getversion();
|
||||||
test.istrue(version ~= nil)
|
test.istrue(version ~= nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- os.translateCommandsAndPaths.
|
||||||
|
--
|
||||||
|
|
||||||
|
function suite.translateCommandsAndPaths()
|
||||||
|
test.isequal('cmdtool "../foo/path1"', os.translateCommandsAndPaths("cmdtool %[path1]", '../foo', '.', 'osx'))
|
||||||
|
end
|
||||||
|
|
||||||
|
function suite.translateCommandsAndPaths_PreserveSlash()
|
||||||
|
test.isequal('cmdtool "../foo/path1/"', os.translateCommandsAndPaths("cmdtool %[path1/]", '../foo', '.', 'osx'))
|
||||||
|
end
|
||||||
|
|
||||||
|
function suite.translateCommandsAndPaths_MultipleTokens()
|
||||||
|
test.isequal('cmdtool "../foo/path1" "../foo/path2/"', os.translateCommandsAndPaths("cmdtool %[path1] %[path2/]", '../foo', '.', 'osx'))
|
||||||
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user