Merge pull request #60 from starkos/fix-rule-var-paths

Fix rule var paths
This commit is contained in:
Manu Evans 2015-05-09 10:54:53 +10:00
commit c2b982885a
9 changed files with 108 additions and 79 deletions

View File

@ -383,6 +383,24 @@
end
---
-- Prepare a path value for output in a Visual Studio project or solution.
-- Converts path separators to backslashes, and makes relative to the project.
--
-- @param cfg
-- The project or configuration which contains the path.
-- @param value
-- The path to be prepared.
-- @return
-- The prepared path.
---
function vstudio.path(cfg, value)
cfg = cfg.project or cfg
return path.translate(project.getrelative(cfg, value))
end
--
-- Returns the Visual Studio project configuration identifier corresponding
-- to the given Premake configuration.

View File

@ -266,12 +266,12 @@
--
function cs2005.outputProps(cfg)
local outdir = project.getrelative(cfg.project, cfg.buildtarget.directory)
_x(2,'<OutputPath>%s\\</OutputPath>', path.translate(outdir))
local outdir = vstudio.path(cfg, cfg.buildtarget.directory)
_x(2,'<OutputPath>%s\\</OutputPath>', outdir)
-- Want to set BaseIntermediateOutputPath because otherwise VS will create obj/
-- anyway. But VS2008 throws up ominous warning if present.
local objdir = path.translate(project.getrelative(cfg.project, cfg.objdir))
local objdir = vstudio.path(cfg, cfg.objdir)
if _ACTION > "vs2008" then
_x(2,'<BaseIntermediateOutputPath>%s\\</BaseIntermediateOutputPath>', objdir)
_p(2,'<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>')
@ -325,8 +325,8 @@
local deps = project.getdependencies(prj, true)
if #deps > 0 then
for _, dep in ipairs(deps) do
local relpath = project.getrelative(prj, vstudio.projectfile(dep))
_x(2,'<ProjectReference Include="%s">', path.translate(relpath))
local relpath = vstudio.path(prj, vstudio.projectfile(dep))
_x(2,'<ProjectReference Include="%s">', relpath)
_p(3,'<Project>{%s}</Project>', dep.uuid)
_x(3,'<Name>%s</Name>', dep.name)
@ -376,7 +376,7 @@
function cs2005.applicationIcon(prj)
if prj.icon then
local icon = path.translate(project.getrelative(prj, prj.icon))
local icon = vstudio.path(prj, prj.icon)
_p(1,'<PropertyGroup>')
_x(2,'<ApplicationIcon>%s</ApplicationIcon>', icon)
_p(1,'</PropertyGroup>')

View File

@ -75,7 +75,7 @@
-- Per-configuration reference paths aren't supported (are they?) so just
-- use the first configuration in the project
local cfg = p.project.getfirstconfig(prj)
local paths = path.translate(p.project.getrelative(prj, cfg.libdirs))
local paths = p.vstudio.path(prj, cfg.libdirs)
if #paths > 0 then
p.w('<ReferencePath>%s</ReferencePath>', table.concat(paths, ";"))
end

View File

@ -102,7 +102,7 @@
-- Build a relative path from the solution file to the project file
local prjpath = vstudio.projectfile(prj)
prjpath = path.translate(path.getrelative(prj.solution.location, prjpath))
prjpath = vstudio.path(prj.solution, prjpath)
-- Unlike projects, solutions must use old-school %...% DOS style
-- for environment variables.

View File

@ -841,16 +841,16 @@
function m.additionalIncludeDirectories(cfg)
if #cfg.includedirs > 0 then
local dirs = project.getrelative(cfg.project, cfg.includedirs)
p.x('AdditionalIncludeDirectories="%s"', path.translate(table.concat(dirs, ";")))
local dirs = vstudio.path(cfg, cfg.includedirs)
p.x('AdditionalIncludeDirectories="%s"', table.concat(dirs, ";"))
end
end
function m.additionalLibraryDirectories(cfg)
if #cfg.libdirs > 0 then
local dirs = table.concat(project.getrelative(cfg.project, cfg.libdirs), ";")
p.x('AdditionalLibraryDirectories="%s"', path.translate(dirs))
local dirs = vstudio.path(cfg, cfg.libdirs)
p.x('AdditionalLibraryDirectories="%s"', table.concat(dirs, ";"))
end
end
@ -887,8 +887,8 @@
function m.additionalResourceIncludeDirectories(cfg)
local dirs = table.join(cfg.includedirs, cfg.resincludedirs)
if #dirs > 0 then
dirs = project.getrelative(cfg.project, dirs)
p.x('AdditionalIncludeDirectories="%s"', path.translate(table.concat(dirs, ";")))
dirs = vstudio.path(cfg, dirs)
p.x('AdditionalIncludeDirectories="%s"', table.concat(dirs, ";"))
end
end
@ -1151,11 +1151,11 @@
function m.forcedIncludeFiles(cfg)
if #cfg.forceincludes > 0 then
local includes = path.translate(project.getrelative(cfg.project, cfg.forceincludes))
local includes = vstudio.path(cfg, cfg.forceincludes)
p.w('ForcedIncludeFiles="%s"', table.concat(includes, ';'))
end
if #cfg.forceusings > 0 then
local usings = path.translate(project.getrelative(cfg.project, cfg.forceusings))
local usings = vstudio.path(cfg, cfg.forceusings)
p.w('ForcedUsingFiles="%s"', table.concat(usings, ';'))
end
end
@ -1229,8 +1229,8 @@
implibdir = path.join(cfg.objdir, path.getname(implibdir))
end
implibdir = project.getrelative(cfg.project, implibdir)
p.x('ImportLibrary="%s"', path.translate(implibdir))
implibdir = vstudio.path(cfg, implibdir)
p.x('ImportLibrary="%s"', implibdir)
end
end
@ -1245,11 +1245,11 @@
function m.intermediateDirectory(cfg)
local objdir
if not cfg.fake then
objdir = project.getrelative(cfg.project, cfg.objdir)
objdir = vstudio.path(cfg, cfg.objdir)
else
objdir = "$(PlatformName)/$(ConfigurationName)"
objdir = "$(PlatformName)\\$(ConfigurationName)"
end
p.x('IntermediateDirectory="%s"', path.translate(objdir))
p.x('IntermediateDirectory="%s"', objdir)
end
@ -1448,17 +1448,16 @@
-- in more than one solution. But that's how they do it.
for i, dep in ipairs(deps) do
local relpath = path.getrelative(prj.solution.location, vstudio.projectfile(dep))
local relpath = vstudio.path(prj.solution, vstudio.projectfile(dep))
-- Visual Studio wants the path to start with ./ or ../
if not relpath:startswith(".") then
relpath = "./" .. relpath
relpath = ".\\" .. relpath
end
p.push('<ProjectReference')
p.w('ReferencedProjectIdentifier="{%s}"', dep.uuid)
p.w('RelativePathToProject="%s"', path.translate(relpath))
p.w('RelativePathToProject="%s"', relpath)
p.pop('/>')
end
end

View File

@ -109,16 +109,14 @@
function m.debugCommand(cfg)
if cfg.debugcommand then
local command = p.project.getrelative(cfg.project, cfg.debugcommand)
p.x('Command="%s"', path.translate(command))
p.x('Command="%s"', p.vstudio.path(cfg, cfg.debugcommand))
end
end
function m.debugDir(cfg)
if cfg.debugdir then
local debugdir = p.project.getrelative(cfg.project, cfg.debugdir)
p.x('WorkingDirectory="%s"', path.translate(debugdir))
p.x('WorkingDirectory="%s"', p.vstudio.path(cfg, cfg.debugdir))
end
end

View File

@ -516,7 +516,11 @@
local fld = p.rule.getPropertyField(rule, prop)
local value = cfg[fld.name]
if value ~= nil then
value = p.rule.getPropertyString(rule, prop, value)
if fld.kind == "path" then
value = vstudio.path(cfg, value)
else
value = p.rule.getPropertyString(rule, prop, value)
end
if value ~= nil and #value > 0 then
m.element(prop.name, nil, '%s', value)
end
@ -857,8 +861,8 @@
if #refs > 0 then
p.push('<ItemGroup>')
for _, ref in ipairs(refs) do
local relpath = project.getrelative(prj, vstudio.projectfile(ref))
p.push('<ProjectReference Include=\"%s\">', path.translate(relpath))
local relpath = vstudio.path(prj, vstudio.projectfile(ref))
p.push('<ProjectReference Include=\"%s\">', relpath)
p.callArray(m.elements.projectReferences, prj, ref)
p.pop('</ProjectReference>')
end
@ -895,8 +899,7 @@
function m.additionalIncludeDirectories(cfg, includedirs)
if #includedirs > 0 then
local dirs = project.getrelative(cfg.project, includedirs)
dirs = path.translate(table.concat(dirs, ";"))
local dirs = table.concat(vstudio.path(cfg, includedirs), ";")
p.x('<AdditionalIncludeDirectories>%s;%%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>', dirs)
end
end
@ -904,16 +907,14 @@
function m.additionalLibraryDirectories(cfg)
if #cfg.libdirs > 0 then
local dirs = project.getrelative(cfg.project, cfg.libdirs)
dirs = path.translate(table.concat(dirs, ";"))
local dirs = table.concat(vstudio.path(cfg, cfg.libdirs), ";")
_x(3,'<AdditionalLibraryDirectories>%s;%%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>', dirs)
end
end
function m.additionalUsingDirectories(cfg)
if #cfg.usingdirs > 0 then
local dirs = project.getrelative(cfg.project, cfg.usingdirs)
dirs = path.translate(table.concat(dirs, ";"))
local dirs = table.concat(vstudio.path(cfg, cfg.usingdirs), ";")
p.x('<AdditionalUsingDirectories>%s;%%(AdditionalUsingDirectories)</AdditionalUsingDirectories>', dirs)
end
end
@ -944,9 +945,8 @@
function m.buildLog(cfg)
if cfg.buildlog and #cfg.buildlog > 0 then
local relpath = project.getrelative(cfg.project, cfg.buildlog)
p.push('<BuildLog>')
p.x('<Path>%s</Path>', path.translate(relpath))
p.x('<Path>%s</Path>', vstudio.path(cfg, cfg.buildlog))
p.pop('</BuildLog>')
end
end
@ -1119,11 +1119,11 @@
function m.forceIncludes(cfg, condition)
if #cfg.forceincludes > 0 then
local includes = path.translate(project.getrelative(cfg.project, cfg.forceincludes))
local includes = vstudio.path(cfg, cfg.forceincludes)
m.element("ForcedIncludeFiles", condition, table.concat(includes, ';'))
end
if #cfg.forceusings > 0 then
local usings = path.translate(project.getrelative(cfg.project, cfg.forceusings))
local usings = vstudio.path(cfg, cfg.forceusings)
m.element("ForcedUsingFiles", condition, table.concat(usings, ';'))
end
end
@ -1203,8 +1203,8 @@
for i = 1, #prj.rules do
local rule = p.global.getRule(prj.rules[i])
local loc = project.getrelative(prj, premake.filename(rule, ".targets"))
p.x('<Import Project="%s" />', path.translate(loc))
local loc = vstudio.path(prj, p.filename(rule, ".targets"))
p.x('<Import Project="%s" />', loc)
end
p.pop('</ImportGroup>')
@ -1224,8 +1224,8 @@
for i = 1, #prj.rules do
local rule = p.global.getRule(prj.rules[i])
local loc = project.getrelative(prj, premake.filename(rule, ".props"))
p.x('<Import Project="%s" />', path.translate(loc))
local loc = vstudio.path(prj, p.filename(rule, ".props"))
p.x('<Import Project="%s" />', loc)
end
p.pop('</ImportGroup>')
@ -1241,8 +1241,8 @@
function m.intDir(cfg)
local objdir = project.getrelative(cfg.project, cfg.objdir)
_x(2,'<IntDir>%s\\</IntDir>', path.translate(objdir))
local objdir = vstudio.path(cfg, cfg.objdir)
_x(2,'<IntDir>%s\\</IntDir>', objdir)
end
@ -1394,8 +1394,8 @@
function m.outDir(cfg)
local outdir = project.getrelative(cfg.project, cfg.buildtarget.directory)
_x(2,'<OutDir>%s\\</OutDir>', path.translate(outdir))
local outdir = vstudio.path(cfg, cfg.buildtarget.directory)
_x(2,'<OutDir>%s\\</OutDir>', outdir)
end

View File

@ -87,8 +87,8 @@
function m.localDebuggerCommand(cfg)
if cfg.debugcommand then
local dir = p.project.getrelative(cfg.project, cfg.debugcommand)
p.w('<LocalDebuggerCommand>%s</LocalDebuggerCommand>', path.translate(dir))
local dir = p.vstudio.path(cfg, cfg.debugcommand)
p.w('<LocalDebuggerCommand>%s</LocalDebuggerCommand>', dir)
end
end
@ -104,8 +104,8 @@
function m.localDebuggerWorkingDirectory(cfg)
if cfg.debugdir then
local dir = p.project.getrelative(cfg.project, cfg.debugdir)
p.x('<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', path.translate(dir))
local dir = p.vstudio.path(cfg, cfg.debugdir)
p.x('<LocalDebuggerWorkingDirectory>%s</LocalDebuggerWorkingDirectory>', dir)
end
end

View File

@ -1,7 +1,8 @@
--
-- tests/actions/vstudio/vc2010/test_rule_vars.lua
-- Validate generation of custom rule variables at the project level.
-- Copyright (c) 2014 Jason Perkins and the Premake project
-- Author Jason Perkins
-- Copyright (c) 2014-2015 Jason Perkins and the Premake project
--
local suite = test.declare("vstudio_vs2010_rule_vars")
@ -49,18 +50,6 @@
-- Test setting the various property kinds.
--
function suite.onStringVar()
createVar { name="MyVar", kind="string" }
myRuleVars { MyVar = "hello" }
prepare()
test.capture [[
<MyRule>
<MyVar>hello</MyVar>
</MyRule>
]]
end
function suite.onBooleanVar()
createVar { name="MyVar", kind="boolean" }
myRuleVars { MyVar = false }
@ -73,18 +62,6 @@
end
function suite.onListVar()
createVar { name="MyVar", kind="list" }
myRuleVars { MyVar = { "a", "b", "c" } }
prepare()
test.capture [[
<MyRule>
<MyVar>a b c</MyVar>
</MyRule>
]]
end
function suite.onEnumVar()
createVar {
name = "MyVar",
@ -106,3 +83,40 @@
</MyRule>
]]
end
function suite.onListVar()
createVar { name="MyVar", kind="list" }
myRuleVars { MyVar = { "a", "b", "c" } }
prepare()
test.capture [[
<MyRule>
<MyVar>a b c</MyVar>
</MyRule>
]]
end
function suite.onPathVar()
createVar { name="MyVar", kind="path" }
myRuleVars { MyVar = "../../path/to/file" }
prepare()
test.capture [[
<MyRule>
<MyVar>..\..\path\to\file</MyVar>
</MyRule>
]]
end
function suite.onStringVar()
createVar { name="MyVar", kind="string" }
myRuleVars { MyVar = "hello" }
prepare()
test.capture [[
<MyRule>
<MyVar>hello</MyVar>
</MyRule>
]]
end