Allow custom build and resource files to be excluded from builds

This commit is contained in:
Jason Perkins 2014-02-11 18:04:07 -05:00
parent d52a835bdd
commit 407861bc80
3 changed files with 185 additions and 1 deletions

View File

@ -496,7 +496,29 @@
if #files > 0 then
_p(1,'<ItemGroup>')
for _, file in ipairs(files) do
_x(2,'<%s Include=\"%s\" />', group, path.translate(file.relpath))
-- Capture the contents of the <ClCompile> element, if any, so
-- I know which form to use.
local contents = p.capture(function ()
if group == "ResourceCompile" then
for cfg in project.eachconfig(prj) do
local condition = vc2010.condition(cfg)
local filecfg = fileconfig.getconfig(file, cfg)
if cfg.system == premake.WINDOWS then
vc2010.excludedFromBuild(cfg, filecfg)
end
end
end
end)
if #contents > 0 then
_x(2,'<%s Include=\"%s\">', group, path.translate(file.relpath))
_p("%s", contents)
_p(2,'</%s>', group)
else
_x(2,'<%s Include=\"%s\" />', group, path.translate(file.relpath))
end
end
_p(1,'</ItemGroup>')
end
@ -555,6 +577,8 @@
local condition = vc2010.condition(cfg)
local filecfg = fileconfig.getconfig(file, cfg)
if fileconfig.hasCustomBuildRule(filecfg) then
vc2010.excludedFromBuild(cfg, filecfg)
local commands = table.concat(filecfg.buildcommands,'\r\n')
_p(3,'<Command %s>%s</Command>', condition, premake.esc(commands))

View File

@ -259,6 +259,62 @@
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludedFile()
files { "hello.cg" }
configuration "**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
configuration "Debug"
removefiles { "hello.cg" }
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.cg"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludeFlag()
files { "hello.cg" }
configuration "**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<Files>
<File
RelativePath="hello.cg"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCustomBuildTool"
CommandLine="cgc $(InputFile)"
Outputs="$(InputName).obj"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
]]
end
--
-- If a custom build rule is supplied, the custom build tool settings should be used.

View File

@ -15,6 +15,7 @@
local sln, prj
function suite.setup()
_ACTION = "vs2010"
sln = test.createsolution()
end
@ -164,6 +165,109 @@
]]
end
function suite.excludedFromBuild_onResourceFile_excludedFile()
files { "hello.rc" }
configuration "Debug"
removefiles { "hello.rc" }
prepare()
test.capture [[
<ItemGroup>
<ResourceCompile Include="hello.rc">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
</ResourceCompile>
</ItemGroup>
]]
end
function suite.excludedFromBuild_onResourceFile_excludeFlag()
files { "hello.rc" }
configuration "hello.rc"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<ItemGroup>
<ResourceCompile Include="hello.rc">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ResourceCompile>
</ItemGroup>
]]
end
function suite.excludedFromBuild_onResourceFile_excludeFlag_nonWindows()
files { "hello.rc" }
system "PS3"
configuration "hello.rc"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<ItemGroup>
<ResourceCompile Include="hello.rc" />
</ItemGroup>
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludedFile()
files { "hello.cg" }
configuration "**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
configuration "Debug"
removefiles { "hello.cg" }
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.cg">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">cgc $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(InputName).obj</Outputs>
</CustomBuild>
</ItemGroup>
]]
end
function suite.excludedFromBuild_onCustomBuildRule_excludeFlag()
files { "hello.cg" }
configuration "**.cg"
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.cg">
<FileType>Document</FileType>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">cgc $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(InputName).obj</Outputs>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">cgc $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(InputName).obj</Outputs>
</CustomBuild>
</ItemGroup>
]]
end
function suite.excludedFromBuild_onCustomBuildRule_withNoCommands()
files { "hello.cg" }
configuration { "**.cg", "Debug" }
buildcommands { "cgc $(InputFile)" }
buildoutputs { "$(InputName).obj" }
configuration { "**.cg" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<ItemGroup>
<CustomBuild Include="hello.cg">
<FileType>Document</FileType>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">cgc $(InputFile)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(InputName).obj</Outputs>
</CustomBuild>
</ItemGroup>
]]
end
--
-- If two files at different folder levels have the same name, a different