Add virtual paths and improve external file links for C# projects (James Whitworth)
This commit is contained in:
parent
1e1b9d50f3
commit
09b0dd1182
@ -7,7 +7,7 @@
|
||||
* Enabled per-configuration file lists
|
||||
* Enabled per-configuration toolset selection
|
||||
* Added custom build rules
|
||||
* Added support for Visual Studio 2012 (mopey)
|
||||
* Added support for Visual Studio 2012 (James Whitworth)
|
||||
* Added token expansion
|
||||
* Added external() to reference non-Premake generated projects
|
||||
* Added remove...() API to remove values from list fields
|
||||
@ -36,6 +36,7 @@
|
||||
* Fixed assembly references for Visual Studio Managed C++ projects
|
||||
* Improved Xbox 360 support
|
||||
* Added support for Clang C/C++ compiler
|
||||
* Added external files and virtual paths for C# projects (James Whitworth)
|
||||
|
||||
|
||||
-------
|
||||
|
@ -132,22 +132,37 @@
|
||||
local tr = project.getsourcetree(prj)
|
||||
premake.tree.traverse(tr, {
|
||||
onleaf = function(node, depth)
|
||||
|
||||
-- Some settings applied at project level; can't be changed in cfg
|
||||
local cfg = project.getfirstconfig(prj)
|
||||
local filecfg = config.getfileconfig(cfg, node.abspath)
|
||||
|
||||
local action = dotnet.getbuildaction(filecfg)
|
||||
local fname = path.translate(node.relpath)
|
||||
local external = node.relpath:startswith("../")
|
||||
local elements, dependency = cs2005.getrelated(prj, filecfg, action)
|
||||
|
||||
-- Files that live outside of the project tree need to be "linked"
|
||||
-- and provided with a project relative pseudo-path. Check for any
|
||||
-- leading "../" sequences and, if found, remove them and mark this
|
||||
-- path as external.
|
||||
|
||||
local link, count = node.relpath:gsub("%.%.%/", "")
|
||||
local external = (count > 0)
|
||||
|
||||
-- Try to provide a little bit of flexibility by allowing virtual
|
||||
-- paths for external files. Would be great to support them for all
|
||||
-- files but Visual Studio chokes if file is already in project area.
|
||||
|
||||
if external and node.vpath ~= node.relpath then
|
||||
link = node.vpath
|
||||
end
|
||||
|
||||
if elements == "None" and not external then
|
||||
_p(2,'<%s Include="%s" />', action, fname)
|
||||
else
|
||||
_p(2,'<%s Include="%s">', action, fname)
|
||||
|
||||
if external then
|
||||
_p(3,'<Link>%s</Link>', path.getname(fname))
|
||||
_p(3,'<Link>%s</Link>', path.translate(link))
|
||||
end
|
||||
|
||||
if elements == "AutoGen" then
|
||||
@ -161,10 +176,12 @@
|
||||
elseif elements ~= "None" then
|
||||
_p(3,'<SubType>%s</SubType>', elements)
|
||||
end
|
||||
|
||||
if dependency then
|
||||
dependency = project.getrelative(prj, dependency)
|
||||
_x(3,'<DependentUpon>%s</DependentUpon>', path.translate(dependency))
|
||||
end
|
||||
|
||||
_p(2,'</%s>', action)
|
||||
end
|
||||
|
||||
|
@ -89,25 +89,73 @@
|
||||
-- links, with a relative path. Weird but true.
|
||||
--
|
||||
|
||||
function suite.usesLinks_onExternalSourceFile()
|
||||
files { "../Src/Hello.cs" }
|
||||
function suite.usesLink_onExternalSourceCode()
|
||||
files { "../Hello.cs" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Compile Include="..\Src\Hello.cs">
|
||||
<Compile Include="..\Hello.cs">
|
||||
<Link>Hello.cs</Link>
|
||||
</Compile>
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.copyAction_onExternalResource()
|
||||
function suite.usesLinkInFolder_onExternalSourceCode()
|
||||
files { "../Src/Hello.cs" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Compile Include="..\Src\Hello.cs">
|
||||
<Link>Src\Hello.cs</Link>
|
||||
</Compile>
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.usesLinkInFolder_onExternalContent()
|
||||
files { "../Resources/Hello.txt" }
|
||||
configuration "**.txt"
|
||||
buildaction "Copy"
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Content Include="..\Resources\Hello.txt">
|
||||
<Link>Hello.txt</Link>
|
||||
<Link>Resources\Hello.txt</Link>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.usesLinkInFolder_onExternalReference()
|
||||
files { "../Resources/Hello.txt" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<None Include="..\Resources\Hello.txt">
|
||||
<Link>Resources\Hello.txt</Link>
|
||||
</None>
|
||||
]]
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Files that exist outside the project's folder are allowed to be
|
||||
-- placed into a folder using a virtual path, which is better than
|
||||
-- dropping them at the root. Files within the project folder cannot
|
||||
-- use virtual paths, because Visual Studio won't allow it.
|
||||
--
|
||||
|
||||
function suite.usesLinks_onVpath_onLocalSourceFile()
|
||||
files { "Hello.cs" }
|
||||
vpaths { ["Sources"] = "**.cs" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Compile Include="Hello.cs" />
|
||||
]]
|
||||
end
|
||||
|
||||
function suite.usesLinks_onVpath_onExternalSourceFile()
|
||||
files { "../Src/Hello.cs" }
|
||||
vpaths { ["Sources"] = "../**.cs" }
|
||||
prepare()
|
||||
test.capture [[
|
||||
<Compile Include="..\Src\Hello.cs">
|
||||
<Link>Sources\Hello.cs</Link>
|
||||
</Compile>
|
||||
]]
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user