Move command token expansion into actions, to allow more control at point of export
This commit is contained in:
parent
56b8b65334
commit
6e12c6485f
@ -1 +1 @@
|
|||||||
61225861a7aa58fcee0cab894206fde9a6be7736 modules/xcode
|
3935627f6ef6f848afd1ac3b22cc1eaa7b34a582 modules/xcode
|
||||||
|
@ -68,7 +68,6 @@
|
|||||||
scope = { "config", "rule" },
|
scope = { "config", "rule" },
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.alias("buildcommands", "buildCommands")
|
api.alias("buildcommands", "buildCommands")
|
||||||
@ -129,7 +128,6 @@
|
|||||||
scope = "config",
|
scope = "config",
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -574,7 +572,6 @@
|
|||||||
scope = "config",
|
scope = "config",
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.register {
|
api.register {
|
||||||
@ -589,7 +586,6 @@
|
|||||||
scope = "config",
|
scope = "config",
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.register {
|
api.register {
|
||||||
@ -604,7 +600,6 @@
|
|||||||
scope = "config",
|
scope = "config",
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.register {
|
api.register {
|
||||||
@ -625,7 +620,6 @@
|
|||||||
scope = "config",
|
scope = "config",
|
||||||
kind = "list:string",
|
kind = "list:string",
|
||||||
tokens = true,
|
tokens = true,
|
||||||
commands = true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
api.register {
|
api.register {
|
||||||
|
@ -218,6 +218,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)
|
||||||
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"))
|
||||||
|
@ -161,7 +161,9 @@
|
|||||||
end
|
end
|
||||||
_x('%s: %s', output, dependencies)
|
_x('%s: %s', output, dependencies)
|
||||||
_p('\t@echo "%s"', filecfg.buildmessage or ("Building " .. filecfg.relpath))
|
_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)
|
_p('\t$(SILENT) %s', cmd)
|
||||||
end
|
end
|
||||||
_p('endif')
|
_p('endif')
|
||||||
|
@ -198,6 +198,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 = 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
|
||||||
|
@ -940,8 +940,8 @@
|
|||||||
|
|
||||||
|
|
||||||
function m.buildCommandLine(cfg)
|
function m.buildCommandLine(cfg)
|
||||||
commands = table.concat(cfg.buildcommands, "\r\n")
|
local cmds = os.translateCommands(cfg.buildcommands, p.WINDOWS)
|
||||||
p.x('BuildCommandLine="%s"', commands)
|
p.x('BuildCommandLine="%s"', table.concat(cmds, "\r\n"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -955,8 +955,9 @@
|
|||||||
|
|
||||||
|
|
||||||
function m.cleanCommandLine(cfg)
|
function m.cleanCommandLine(cfg)
|
||||||
commands = table.concat(cfg.cleancommands, "\r\n")
|
local cmds = os.translateCommands(cfg.cleancommands, p.WINDOWS)
|
||||||
p.x('CleanCommandLine="%s"', commands)
|
cmds = table.concat(cmds, "\r\n")
|
||||||
|
p.x('CleanCommandLine="%s"', cmds)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -969,6 +970,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)
|
||||||
p.x('CommandLine="%s"', table.implode(steps, "", "", "\r\n"))
|
p.x('CommandLine="%s"', table.implode(steps, "", "", "\r\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1030,7 +1032,8 @@
|
|||||||
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
|
||||||
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)
|
local outputs = project.getrelative(filecfg.project, filecfg.buildoutputs)
|
||||||
p.x('Outputs="%s"', table.concat(outputs, ' '))
|
p.x('Outputs="%s"', table.concat(outputs, ' '))
|
||||||
|
@ -145,7 +145,8 @@
|
|||||||
|
|
||||||
function m.commandLineTemplates(r)
|
function m.commandLineTemplates(r)
|
||||||
if #r.buildcommands then
|
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)
|
p.x('<CommandLineTemplate>%s</CommandLineTemplate>', cmds)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -471,6 +471,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)
|
||||||
_p(2,'<%s>', name)
|
_p(2,'<%s>', name)
|
||||||
_x(3,'<Command>%s</Command>', table.implode(steps, "", "", "\r\n"))
|
_x(3,'<Command>%s</Command>', table.implode(steps, "", "", "\r\n"))
|
||||||
if msg then
|
if msg then
|
||||||
@ -644,7 +645,8 @@
|
|||||||
if fileconfig.hasCustomBuildRule(filecfg) then
|
if fileconfig.hasCustomBuildRule(filecfg) then
|
||||||
m.excludedFromBuild(cfg, filecfg)
|
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)
|
m.element("Command", condition, '%s', commands)
|
||||||
|
|
||||||
local outputs = project.getrelative(prj, filecfg.buildoutputs)
|
local outputs = project.getrelative(prj, filecfg.buildoutputs)
|
||||||
@ -1288,6 +1290,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 = table.concat(premake.esc(commands), p.eol())
|
commands = table.concat(premake.esc(commands), p.eol())
|
||||||
_p(2, '<NMake%sCommandLine>%s</NMake%sCommandLine>', phase, commands, phase)
|
_p(2, '<NMake%sCommandLine>%s</NMake%sCommandLine>', phase, commands, phase)
|
||||||
end
|
end
|
||||||
|
@ -442,38 +442,42 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
os.commandTokens = {
|
os.commandTokens = {
|
||||||
copy = {
|
_ = {
|
||||||
_ = function(v)
|
copy = function(v) return "cp -r " .. v end,
|
||||||
return "cp -r " .. v
|
},
|
||||||
end,
|
windows = {
|
||||||
windows = function(v)
|
copy = function(v) return "xcopy /Q /E /Y " .. path.translate(v) end,
|
||||||
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
|
if type(cmd) == "table" then
|
||||||
local result = {}
|
local result = {}
|
||||||
for i = 1, #cmd do
|
for i = 1, #cmd do
|
||||||
result[i] = os.translateCommand(cmd[i])
|
result[i] = processOne(cmd[i])
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
|
else
|
||||||
|
return processOne(cmd)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -489,13 +489,6 @@
|
|||||||
ctx.location = ctx.location or prj.location
|
ctx.location = ctx.location or prj.location
|
||||||
context.basedir(ctx, ctx.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
|
-- Fill in a few calculated for the configuration, including the long
|
||||||
-- and short names and the build and link target.
|
-- and short names and the build and link target.
|
||||||
|
|
||||||
|
@ -137,12 +137,12 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function suite.translateCommand_onNoToken()
|
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
|
end
|
||||||
|
|
||||||
function suite.translateCommand_callsProcessor()
|
function suite.translateCommand_callsProcessor()
|
||||||
os.commandTokens.copy.test = function(value)
|
os.commandTokens.test = {
|
||||||
return "test " .. value
|
copy = function(value) return "test " .. value end
|
||||||
end
|
}
|
||||||
test.isequal("test a b", os.translateCommand("{COPY} a b"))
|
test.isequal("test a b", os.translateCommands("{COPY} a b", "test"))
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user