Add ExcludeFromBuild flag to mark source files as non-buildable

This commit is contained in:
Jason Perkins 2013-02-07 10:58:31 -05:00
parent 41fcff188e
commit 9c752adf4a
8 changed files with 119 additions and 36 deletions

View File

@ -285,7 +285,7 @@
local custom = false
for cfg in project.eachconfig(prj) do
local filecfg = config.getfileconfig(cfg, node.abspath)
if filecfg then
if filecfg and not filecfg.flags.ExcludeFromBuild then
incfg[cfg] = filecfg
custom = (filecfg.buildrule ~= nil)
else

View File

@ -1,7 +1,7 @@
--
-- vs200x_vcproj.lua
-- Generate a Visual Studio 2002-2008 C/C++ project.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
premake.vstudio.vc200x = {}
@ -65,7 +65,7 @@
_p(1,'</References>')
_p(1,'<Files>')
vc200x.files_ng(prj)
vc200x.files(prj)
_p(1,'</Files>')
_p(1,'<Globals>')
@ -792,7 +792,7 @@
-- Write out the source file tree.
--
function vc200x.files_ng(prj)
function vc200x.files(prj)
local tr = project.getsourcetree(prj)
tree.traverse(tr, {
@ -867,7 +867,7 @@
depth = depth + 1
_p(depth, 'Name="%s"', vstudio.projectConfig(cfg))
if not filecfg then
if not filecfg or filecfg.flags.ExcludeFromBuild then
_p(depth, 'ExcludedFromBuild="true"')
end

View File

@ -447,7 +447,7 @@
local condition = vc2010.condition(cfg)
local filecfg = config.getfileconfig(cfg, file.abspath)
if not filecfg then
if not filecfg or filecfg.flags.ExcludeFromBuild then
_p(3,'<ExcludedFromBuild %s>true</ExcludedFromBuild>', condition)
end

View File

@ -624,6 +624,7 @@
"DebugEnvsInherit",
"EnableSSE",
"EnableSSE2",
"ExcludeFromBuild",
"ExtraWarnings",
"FatalWarnings",
"FloatFast",

View File

@ -244,7 +244,7 @@
--
function premake.warn(message, ...)
io.stderr:write(string.format("** Warning: " .. message .. "\n", ...), 0)
io.stderr:write(string.format("** Warning: " .. message .. "\n", ...))
end

View File

@ -1,25 +1,24 @@
--
-- tests/actions/make/cpp/test_objects.lua
-- Validate the list of objects for a makefile.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
T.make_cpp_objects = { }
local suite = T.make_cpp_objects
local suite = test.declare("make_cpp_objects")
local cpp = premake.make.cpp
local project = premake5.project
--
-- Setup
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
cpp.objects(prj)
@ -122,8 +121,6 @@ RESOURCES := \
end
--
-- If a custom rule builds to an object file, include it in the
-- link automatically to match the behavior of Visual Studio
@ -134,8 +131,8 @@ RESOURCES := \
configuration "**.x"
buildrule {
description = "Compiling %{file.name}",
commands = {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
commands = {
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
},
outputs = { "%{cfg.objdir}/%{file.basename}.obj" }
@ -154,3 +151,46 @@ endif
]]
end
--
-- If a file is excluded from a configuration, it should not be listed.
--
function suite.excludedFromBuild_onExcludedFile()
files { "hello.cpp" }
configuration "Debug"
removefiles { "hello.cpp" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
ifeq ($(config),release)
OBJECTS += \
$(OBJDIR)/hello.o \
endif
]]
end
function suite.excludedFromBuild_onExcludeFlag()
files { "hello.cpp" }
configuration { "Debug", "hello.cpp" }
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
OBJECTS := \
RESOURCES := \
ifeq ($(config),release)
OBJECTS += \
$(OBJDIR)/hello.o \
endif
]]
end

View File

@ -1,27 +1,26 @@
--
-- tests/actions/vstudio/vc200x/test_files.lua
-- Validate generation of <files/> block in Visual Studio 200x projects.
-- Copyright (c) 2009-2012 Jason Perkins and the Premake project
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
--
T.vstudio_vs200x_files = { }
local suite = T.vstudio_vs200x_files
local suite = test.declare("vstudio_vs200x_files")
local vc200x = premake.vstudio.vc200x
--
-- Setup
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
vc200x.files_ng(prj)
vc200x.files(prj)
end
@ -224,6 +223,35 @@
]]
end
function suite.excludedFromBuild_onExcludeFlag()
files { "hello.cpp" }
configuration "hello.cpp"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<File
RelativePath="hello.cpp"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
]]
end
--
-- If a custom build rule is supplied, the custom build tool settings should be used.
@ -234,8 +262,8 @@
configuration "**.x"
buildrule {
description = "Compiling $(InputFile)",
commands = {
'cxc -c "$(InputFile)" -o "$(IntDir)/$(InputName).xo"',
commands = {
'cxc -c "$(InputFile)" -o "$(IntDir)/$(InputName).xo"',
'c2o -c "$(IntDir)/$(InputName).xo" -o "$(IntDir)/$(InputName).obj"'
},
outputs = { "$(IntDir)/$(InputName).obj" }
@ -254,7 +282,7 @@
Outputs="$(IntDir)/$(InputName).obj"
/>
</FileConfiguration>
]]
]]
end

View File

@ -1,24 +1,23 @@
--
-- tests/actions/vstudio/vc2010/test_files.lua
-- Validate generation of files block in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011-2012 Jason Perkins and the Premake project
-- Copyright (c) 2011-2013 Jason Perkins and the Premake project
--
T.vstudio_vs2010_files = { }
local suite = T.vstudio_vs2010_files
local suite = test.declare("vstudio_vs2010_files")
local vc2010 = premake.vstudio.vc2010
--
-- Setup
-- Setup
--
local sln, prj
function suite.setup()
sln = test.createsolution()
end
local function prepare()
prj = premake.solution.getproject_ng(sln, 1)
vc2010.files_ng(prj)
@ -38,7 +37,7 @@
</ItemGroup>
]]
end
function suite.clCompile_onCFile()
files { "hello.c" }
prepare()
@ -49,7 +48,7 @@
</ItemGroup>
]]
end
function suite.resourceCompile_onRCFile()
files { "resources/hello.rc" }
prepare()
@ -91,7 +90,7 @@
]]
end
--
-- If a PCH source is specified, ensure it is included in the file configuration.
--
@ -130,6 +129,21 @@
]]
end
function suite.excludedFromBuild_onExcludeFlag()
files { "hello.cpp" }
configuration "hello.cpp"
flags { "ExcludeFromBuild" }
prepare()
test.capture [[
<ItemGroup>
<ClCompile Include="hello.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
]]
end
--
-- If two files at different folder levels have the same name, a different