Move command token expansion into actions, to allow more control at point of export

This commit is contained in:
Jason Perkins 2014-11-29 14:51:49 -05:00
parent 56b8b65334
commit 6e12c6485f
11 changed files with 52 additions and 50 deletions

View File

@ -1 +1 @@
61225861a7aa58fcee0cab894206fde9a6be7736 modules/xcode
3935627f6ef6f848afd1ac3b22cc1eaa7b34a582 modules/xcode

View File

@ -68,7 +68,6 @@
scope = { "config", "rule" },
kind = "list:string",
tokens = true,
commands = true,
}
api.alias("buildcommands", "buildCommands")
@ -129,7 +128,6 @@
scope = "config",
kind = "list:string",
tokens = true,
commands = true,
}
@ -574,7 +572,6 @@
scope = "config",
kind = "list:string",
tokens = true,
commands = true,
}
api.register {
@ -589,7 +586,6 @@
scope = "config",
kind = "list:string",
tokens = true,
commands = true,
}
api.register {
@ -604,7 +600,6 @@
scope = "config",
kind = "list:string",
tokens = true,
commands = true,
}
api.register {
@ -625,7 +620,6 @@
scope = "config",
kind = "list:string",
tokens = true,
commands = true,
}
api.register {

View File

@ -218,6 +218,7 @@
local steps = cfg[event .. "commands"]
local msg = cfg[event .. "message"]
if #steps > 0 then
steps = os.translateCommands(steps)
msg = msg or string.format("Running %s commands", event)
_p('\t@echo %s', msg)
_p('\t%s', table.implode(steps, "", "", "\n\t"))

View File

@ -161,7 +161,9 @@
end
_x('%s: %s', output, dependencies)
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
for _, cmd in ipairs(filecfg.buildcommands) do
local cmds = os.translateCommands(filecfg.buildcommands)
for _, cmd in ipairs(cmds) do
_p('\t$(SILENT) %s', cmd)
end
_p('endif')

View File

@ -198,6 +198,7 @@
function cs2005.buildEvents(prj)
local function output(name, steps)
if #steps > 0 then
steps = os.translateCommands(steps, p.WINDOWS)
steps = table.implode(steps, "", "", "\r\n")
_x(2,'<%sBuildEvent>%s</%sBuildEvent>', name, steps, name)
end

View File

@ -940,8 +940,8 @@
function m.buildCommandLine(cfg)
commands = table.concat(cfg.buildcommands, "\r\n")
p.x('BuildCommandLine="%s"', commands)
local cmds = os.translateCommands(cfg.buildcommands, p.WINDOWS)
p.x('BuildCommandLine="%s"', table.concat(cmds, "\r\n"))
end
@ -955,8 +955,9 @@
function m.cleanCommandLine(cfg)
commands = table.concat(cfg.cleancommands, "\r\n")
p.x('CleanCommandLine="%s"', commands)
local cmds = os.translateCommands(cfg.cleancommands, p.WINDOWS)
cmds = table.concat(cmds, "\r\n")
p.x('CleanCommandLine="%s"', cmds)
end
@ -969,6 +970,7 @@
if msg then
p.x('Description="%s"', msg)
end
steps = os.translateCommands(steps, p.WINDOWS)
p.x('CommandLine="%s"', table.implode(steps, "", "", "\r\n"))
end
end
@ -1030,7 +1032,8 @@
function m.customBuildTool(cfg)
local cfg, filecfg = config.normalize(cfg)
if filecfg and fileconfig.hasCustomBuildRule(filecfg) then
p.x('CommandLine="%s"', table.concat(filecfg.buildcommands,'\r\n'))
local cmds = os.translateCommands(filecfg.buildcommands, p.WINDOWS)
p.x('CommandLine="%s"', table.concat(cmds,'\r\n'))
local outputs = project.getrelative(filecfg.project, filecfg.buildoutputs)
p.x('Outputs="%s"', table.concat(outputs, ' '))

View File

@ -145,7 +145,8 @@
function m.commandLineTemplates(r)
if #r.buildcommands then
local cmds = table.concat(r.buildcommands, p.eol())
local cmds = os.translateCommands(r.buildcommands, p.WINDOWS)
cmds = table.concat(cmds, p.eol())
p.x('<CommandLineTemplate>%s</CommandLineTemplate>', cmds)
end
end

View File

@ -471,6 +471,7 @@
local msg = cfg[field .. "message"]
if #steps > 0 then
steps = os.translateCommands(steps, p.WINDOWS)
_p(2,'<%s>', name)
_x(3,'<Command>%s</Command>', table.implode(steps, "", "", "\r\n"))
if msg then
@ -644,7 +645,8 @@
if fileconfig.hasCustomBuildRule(filecfg) then
m.excludedFromBuild(cfg, filecfg)
local commands = table.concat(filecfg.buildcommands,'\r\n')
local commands = os.translateCommands(filecfg.buildcommands, p.WINDOWS)
commands = table.concat(commands,'\r\n')
m.element("Command", condition, '%s', commands)
local outputs = project.getrelative(prj, filecfg.buildoutputs)
@ -1288,6 +1290,7 @@
function m.nmakeCommandLine(cfg, commands, phase)
if #commands > 0 then
commands = os.translateCommands(commands, p.WINDOWS)
commands = table.concat(premake.esc(commands), p.eol())
_p(2, '<NMake%sCommandLine>%s</NMake%sCommandLine>', phase, commands, phase)
end

View File

@ -442,38 +442,42 @@
---
os.commandTokens = {
copy = {
_ = function(v)
return "cp -r " .. v
end,
windows = function(v)
return "xcopy /Q /E /Y " .. path.translate(v)
end,
_ = {
copy = function(v) return "cp -r " .. v end,
},
windows = {
copy = function(v) return "xcopy /Q /E /Y " .. path.translate(v) end,
}
}
function os.translateCommand(cmd)
function os.translateCommands(cmd, map)
map = map or os.get()
if type(map) == "string" then
map = os.commandTokens[map] or os.commandTokens["_"]
end
local processOne = function(cmd)
local token = cmd:match("^{.+}")
if token then
token = token:sub(2, #token - 1):lower()
local args = cmd:sub(#token + 4)
local func = map[token] or os.commandTokens["_"][token]
if func then
cmd = func(args)
end
end
return cmd
end
if type(cmd) == "table" then
local result = {}
for i = 1, #cmd do
result[i] = os.translateCommand(cmd[i])
result[i] = processOne(cmd[i])
end
return result
else
return processOne(cmd)
end
local token = cmd:match("^{.+}")
if token then
local value = cmd:sub(#token + 2)
token = token:sub(2, #token - 1):lower()
local processors = os.commandTokens[token]
local processor = processors[_ACTION] or processors[os.get()] or processors["_"]
if processor then
return processor(value)
end
end
return cmd
end

View File

@ -489,13 +489,6 @@
ctx.location = ctx.location or prj.location
context.basedir(ctx, ctx.location)
-- Translate any tokens in command line fields
for f in p.field.each() do
if f.commands then
ctx[f.name] = os.translateCommand(ctx[f.name])
end
end
-- Fill in a few calculated for the configuration, including the long
-- and short names and the build and link target.

View File

@ -137,12 +137,12 @@
--
function suite.translateCommand_onNoToken()
test.isequal("cp a b", os.translateCommand("cp a b"))
test.isequal("cp a b", os.translateCommands("cp a b"))
end
function suite.translateCommand_callsProcessor()
os.commandTokens.copy.test = function(value)
return "test " .. value
end
test.isequal("test a b", os.translateCommand("{COPY} a b"))
os.commandTokens.test = {
copy = function(value) return "test " .. value end
}
test.isequal("test a b", os.translateCommands("{COPY} a b", "test"))
end