Add ability to map Premake tokens to toolset specific variables
This commit is contained in:
parent
da75753b0d
commit
3f718a470c
@ -68,6 +68,7 @@
|
||||
scope = { "config", "rule" },
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.alias("buildcommands", "buildCommands")
|
||||
@ -78,6 +79,7 @@
|
||||
scope = { "rule" },
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +87,8 @@
|
||||
name = "buildmessage",
|
||||
scope = { "config", "rule" },
|
||||
kind = "string",
|
||||
tokens = true
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.alias("buildmessage", "buildMessage")
|
||||
@ -96,6 +99,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
|
||||
@ -104,6 +108,7 @@
|
||||
scope = { "config", "rule" },
|
||||
kind = "list:path",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.alias("buildoutputs", "buildOutputs")
|
||||
@ -114,6 +119,7 @@
|
||||
scope = "config",
|
||||
kind = "list:path",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -128,6 +134,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
|
||||
@ -184,6 +191,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -191,6 +199,7 @@
|
||||
scope = "config",
|
||||
kind = "path",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -198,6 +207,7 @@
|
||||
scope = "config",
|
||||
kind = "path",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -205,6 +215,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -572,6 +583,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -579,6 +591,7 @@
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -586,6 +599,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -593,6 +607,7 @@
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -600,6 +615,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -607,6 +623,7 @@
|
||||
scope = "config",
|
||||
kind = "string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
@ -620,6 +637,7 @@
|
||||
scope = "config",
|
||||
kind = "list:string",
|
||||
tokens = true,
|
||||
pathVars = true,
|
||||
}
|
||||
|
||||
api.register {
|
||||
|
@ -1,7 +1,7 @@
|
||||
--
|
||||
-- actions/vstudio/vs2010.lua
|
||||
-- Add support for the Visual Studio 2010 project formats.
|
||||
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2009-2014 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
premake.vstudio.vs2010 = {}
|
||||
@ -13,6 +13,16 @@
|
||||
local tree = p.tree
|
||||
|
||||
|
||||
---
|
||||
-- Map Premake tokens to the corresponding Visual Studio variables.
|
||||
---
|
||||
|
||||
vstudio.pathVars = {
|
||||
["cfg.objdir"] = "$(IntDir)",
|
||||
}
|
||||
|
||||
|
||||
|
||||
---
|
||||
-- Identify the type of project being exported and hand it off
|
||||
-- the right generator.
|
||||
@ -102,6 +112,8 @@
|
||||
oncleanproject = vstudio.cleanProject,
|
||||
oncleantarget = vstudio.cleanTarget,
|
||||
|
||||
pathVars = vstudio.pathVars,
|
||||
|
||||
-- This stuff is specific to the Visual Studio exporters
|
||||
|
||||
vstudio = {
|
||||
|
@ -44,6 +44,8 @@
|
||||
oncleanproject = vstudio.cleanProject,
|
||||
oncleantarget = vstudio.cleanTarget,
|
||||
|
||||
pathVars = vstudio.pathVars,
|
||||
|
||||
-- This stuff is specific to the Visual Studio exporters
|
||||
|
||||
vstudio = {
|
||||
|
@ -46,6 +46,8 @@
|
||||
oncleanproject = vstudio.cleanProject,
|
||||
oncleantarget = vstudio.cleanTarget,
|
||||
|
||||
pathVars = vstudio.pathVars,
|
||||
|
||||
-- This stuff is specific to the Visual Studio exporters
|
||||
|
||||
vstudio = {
|
||||
|
@ -176,7 +176,7 @@
|
||||
if value then
|
||||
-- do I need to expand tokens?
|
||||
if field and field.tokens then
|
||||
value = p.detoken.expand(value, ctx.environ, field.paths, ctx._basedir)
|
||||
value = p.detoken.expand(value, ctx.environ, field, ctx._basedir)
|
||||
end
|
||||
|
||||
-- store the result for later lookups
|
||||
|
@ -3,11 +3,13 @@
|
||||
--
|
||||
-- Expands tokens.
|
||||
--
|
||||
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
premake.detoken = {}
|
||||
local detoken = premake.detoken
|
||||
|
||||
local p = premake
|
||||
local detoken = p.detoken
|
||||
|
||||
|
||||
--
|
||||
@ -16,24 +18,38 @@
|
||||
-- @param value
|
||||
-- The value containing the tokens to be expanded.
|
||||
-- @param environ
|
||||
-- An execution environment for any token expansion. This is a list of key-
|
||||
-- value pairs that will be inserted as global variables into the token
|
||||
-- expansion runtime environment.
|
||||
-- @param ispath
|
||||
-- If true, the value treated as a file system path, and checks will be made
|
||||
-- for nested absolute paths from expanded tokens.
|
||||
-- An execution environment for any token expansion. This is a list of
|
||||
-- key-value pairs that will be inserted as global variables into the
|
||||
-- token expansion runtime environment.
|
||||
-- @param field
|
||||
-- The definition of the field which stores the value.
|
||||
-- @param basedir
|
||||
-- If provided, path tokens encountered in non-path fields (where the ispath
|
||||
-- parameter is set to false) will be made relative to this location.
|
||||
-- If provided, path tokens encountered in non-path fields (where
|
||||
-- field.paths is set to false) will be made relative to this location.
|
||||
-- @return
|
||||
-- The value with any contained tokens expanded.
|
||||
--
|
||||
|
||||
function detoken.expand(value, environ, ispath, basedir)
|
||||
function detoken.expand(value, environ, field, basedir)
|
||||
field = field or {}
|
||||
|
||||
-- fetch the path variable from the action, if needed
|
||||
local varMap = {}
|
||||
if field.pathVars then
|
||||
local action = p.action.current()
|
||||
if action then
|
||||
varMap = action.pathVars or {}
|
||||
end
|
||||
end
|
||||
|
||||
-- enable access to the global environment
|
||||
setmetatable(environ, {__index = _G})
|
||||
|
||||
function expandtoken(token, environ)
|
||||
if varMap[token] then
|
||||
return varMap[token]
|
||||
end
|
||||
|
||||
-- convert the token into a function to execute
|
||||
local func, err = loadstring("return " .. token)
|
||||
if not func then
|
||||
@ -62,7 +78,7 @@
|
||||
-- "/home/user/myprj/obj/Debug"
|
||||
|
||||
local isAbs = path.isabsolute(result)
|
||||
if isAbs and ispath then
|
||||
if isAbs and field.paths then
|
||||
result = "\0" .. result
|
||||
end
|
||||
|
||||
@ -71,7 +87,7 @@
|
||||
-- will contain it. Otherwise I ended up with an absolute path in
|
||||
-- the generated project, and it can no longer be moved around.
|
||||
|
||||
if isAbs and not ispath and basedir then
|
||||
if isAbs and not field.paths and basedir then
|
||||
result = path.getrelative(basedir, result)
|
||||
end
|
||||
|
||||
@ -95,7 +111,7 @@
|
||||
until count == 0
|
||||
|
||||
-- if a path, look for a split out embedded absolute paths
|
||||
if ispath then
|
||||
if field.paths then
|
||||
local i, j
|
||||
repeat
|
||||
i, j = value:find("\0")
|
||||
|
@ -1,7 +1,7 @@
|
||||
--
|
||||
-- tests/base/test_detoken.lua
|
||||
-- Test suite for the token expansion API.
|
||||
-- Copyright (c) 2011-2012 Jason Perkins and the Premake project
|
||||
-- Copyright (c) 2011-2014 Jason Perkins and the Premake project
|
||||
--
|
||||
|
||||
local suite = test.declare("detoken")
|
||||
@ -13,9 +13,18 @@
|
||||
-- Setup
|
||||
--
|
||||
|
||||
local x
|
||||
local x, action
|
||||
local environ = {}
|
||||
|
||||
function suite.setup()
|
||||
action = premake.action.get("test")
|
||||
end
|
||||
|
||||
function suite.teardown()
|
||||
action.pathVars = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- The contents of the token should be executed and the results returned.
|
||||
@ -66,7 +75,7 @@
|
||||
|
||||
function suite.canExpandToAbsPath()
|
||||
environ.cfg = { basedir = os.getcwd() }
|
||||
x = detoken.expand("bin/debug/%{cfg.basedir}", environ, true)
|
||||
x = detoken.expand("bin/debug/%{cfg.basedir}", environ, {paths=true})
|
||||
test.isequal(os.getcwd(), x)
|
||||
end
|
||||
|
||||
@ -79,7 +88,7 @@
|
||||
function suite.canExpandToRelPath()
|
||||
local cwd = os.getcwd()
|
||||
environ.cfg = { basedir = path.getdirectory(cwd) }
|
||||
x = detoken.expand("cd %{cfg.basedir}", environ, false, cwd)
|
||||
x = detoken.expand("cd %{cfg.basedir}", environ, {}, cwd)
|
||||
test.isequal("cd ..", x)
|
||||
end
|
||||
|
||||
@ -93,3 +102,14 @@
|
||||
test.isequal({ "A1", "B2", "C3" }, x)
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- If the field being expanded supports path variable mapping, and the
|
||||
-- action provides a map, replace tokens with the mapped values.
|
||||
--
|
||||
|
||||
function suite.replacesToken_onSupportedAndMapped()
|
||||
action.pathVars = { ["cfg.objdir"] = "$(IntDir)" }
|
||||
x = detoken.expand("cmd %{cfg.objdir}/file", environ, {pathVars=true})
|
||||
test.isequal("cmd $(IntDir)/file", x)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user