Fix: if link contains a token that expands to an absolute path, HintPath of C# projects will end up with absolute path

This commit is contained in:
Jason Perkins 2013-01-10 11:09:34 -05:00
parent 974d1a7d04
commit 8275e190a1
3 changed files with 42 additions and 16 deletions

View File

@ -372,6 +372,20 @@
end
--
-- Set a new value into a mixed value field, which contain both
-- simple strings and paths.
--
function api.setmixed(target, name, field, value)
-- if the value contains a '/' treat it as a path
if type(value) == "string" and value:find('/', nil, true) then
value = path.getabsolute(value)
end
return api.setstring(target, name, field, value)
end
--
-- Set a new object value on an API field.
--
@ -712,14 +726,7 @@
api.register {
name = "links",
scope = "config",
kind = "string-list",
allowed = function(value)
-- if library name contains a '/' then treat it as a path to a local file
if value:find('/', nil, true) then
value = path.getabsolute(value)
end
return value
end,
kind = "mixed-list",
tokens = true,
}

View File

@ -39,11 +39,11 @@
ctx.environ = environ or {}
ctx._filename = { filename } or {}
ctx.terms = {}
-- when a missing field is requested, fetch it from my config
-- set, and then cache the value for future lookups
setmetatable(ctx, context.__mt)
return ctx
end
@ -96,7 +96,7 @@
--
-- Check to see if a context's underlying configuration set is empty; that
-- Check to see if a context's underlying configuration set is empty; that
-- is, it does not contain any configuration blocks.
--
-- @param ctx
@ -129,17 +129,18 @@
-- do I need to expand tokens?
local field = premake.fields[key]
if field and field.tokens then
local ispath = field.kind:startswith("path")
local kind = field.kind
local ispath = kind:startswith("path") or kind:startswith("mixed")
value = premake.detoken.expand(value, ctx.environ, ispath)
end
-- store the result for later lookups
ctx[key] = value
end
return value
end
context.__mt = {
__index = context.fetchvalue
}

View File

@ -14,7 +14,7 @@
--
local sln, prj
function suite.setup()
_ACTION = "vs2008"
sln = test.createsolution()
@ -69,4 +69,22 @@
</Reference>
</ItemGroup>
]]
end
end
--
-- Assemblies referenced via a token that expands to an absolute
-- path should still end up with a relative hint path.
--
function suite.assemblyRef_onAbsoluteToken()
links { "%{path.getdirectory(os.getcwd())}/Libraries/nunit.framework" }
prepare()
test.capture [[
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\Libraries\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
]]
end