Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for recursive token expansion #927

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/gmake2/tests/_tests.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require ("gmake2")

return {
"test_gmake2_buildcmds.lua",
"test_gmake2_clang.lua",
"test_gmake2_file_rules.lua",
"test_gmake2_flags.lua",
Expand Down
57 changes: 57 additions & 0 deletions modules/gmake2/tests/test_gmake2_buildcmds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@



local suite = test.declare("gmake2_buildcommands")
local gmake2 = premake.modules.gmake2

premake.api.register {
name = 'test_libdir', -- this controls the targetdir for StaticLib projects.
scope = 'config',
kind = 'path',
tokens = true,
pathVars = true,
}

local wks, prj, cfg

function suite.setup()
wks = workspace("MyWorkspace")
test_libdir (path.join(_MAIN_SCRIPT_DIR, 'lib'))
configurations { "Debug", "Release" }
prj = test.createProject(wks)
end


local function prepare()
wks = test.getWorkspace(wks)
prj = test.getproject(wks, 1)
cfg = test.getconfig(prj, "Debug")

local toolset = gmake2.getToolSet(cfg)
gmake2.postBuildCmds(cfg, toolset)
end


function suite.postbuildcommands()
targetname "blink"
kind "StaticLib"
language "C++"

postbuildcommands
{
"mkdir %{cfg.test_libdir}/www",
"mkdir %{cfg.test_libdir}/www"
}

prepare()

test.capture [[
define POSTBUILDCMDS
@echo Running postbuild commands
mkdir lib/www
mkdir lib/www
endef
]]
end


58 changes: 30 additions & 28 deletions src/base/detoken.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@
--

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 {}
function expandtoken(token, e, f)
-- fetch the path variable from the action, if needed
local varMap = {}
if f.pathVars then
local action = p.action.current()
if action then
varMap = action.pathVars or {}
end
end
end
-- fetch the pathVars from the enviroment.
local envMap = e.pathVars or {}

-- fetch the pathVars from the enviroment.
local envMap = environ.pathVars or {}
-- enable access to the global environment
setmetatable(e, {__index = _G})

-- enable access to the global environment
setmetatable(environ, {__index = _G})

function expandtoken(token, e)
local isAbs = false
local err
local result
Expand Down Expand Up @@ -111,7 +108,7 @@
result = path.resolvedeferredjoin(result)
end
isAbs = path.isabsolute(result)
if isAbs and not field.paths and basedir and not dontMakeRelative then
if isAbs and not f.paths and basedir and not dontMakeRelative then
result = path.getrelative(basedir, result)
end
end
Expand All @@ -132,22 +129,21 @@
-- result, which should always be the last absolute path specified:
-- "/home/user/myprj/obj/Debug"

if result ~= nil and isAbs and field.paths then
if result ~= nil and isAbs and f.paths then
result = "\0" .. result
end

return result, err
end

function expandvalue(value, e)
function expandvalue(value, e, f)
if type(value) ~= "string" then
return value
end

local count
repeat
value, count = value:gsub("%%{(.-)}", function(token)
local result, err = expandtoken(token:gsub("\\", "\\\\"), e)
local result, err = expandtoken(token:gsub("\\", "\\\\"), e, f)
if err then
error(err .. " in token: " .. token, 0)
end
Expand All @@ -159,7 +155,7 @@
until count == 0

-- if a path, look for a split out embedded absolute paths
if field.paths then
if f.paths then
local i, j
repeat
i, j = value:find("\0")
Expand All @@ -168,29 +164,35 @@
end
until not i
end

return value
end

function recurse(value, e)
local expand_cache = {}

function recurse(value, e, f)
if type(value) == "table" then
local res_table = {}

for k, v in pairs(value) do
if tonumber(k) ~= nil then
res_table[k] = recurse(v, e)
res_table[k] = recurse(v, e, f)
else
local nk = recurse(k, e);
res_table[nk] = recurse(v, e)
local nk = recurse(k, e, f)
res_table[nk] = recurse(v, e, f)
end
end

return res_table
else
return expandvalue(value, e)
local res = expand_cache[value]
if res == nil then
res = expandvalue(value, e, f)
expand_cache[value] = res
end
return res
end
end

return recurse(value, environ)
return recurse(value, environ, field or {})
end