Commits

Jason Perkins committed bfe3325

Add ExcludeFromBuild flag to mark source files as non-buildable

Comments (0)

Files changed (8)

src/actions/make/make_cpp.lua

 				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

src/actions/vstudio/vs200x_vcproj.lua

 --
 -- 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 = {}
 		_p(1,'</References>')
 
 		_p(1,'<Files>')
-		vc200x.files_ng(prj)
+		vc200x.files(prj)
 		_p(1,'</Files>')
 
 		_p(1,'<Globals>')
 -- Write out the source file tree.
 --
 
-	function vc200x.files_ng(prj)
+	function vc200x.files(prj)
 		local tr = project.getsourcetree(prj)
 
 		tree.traverse(tr, {
 				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
 

src/actions/vstudio/vs2010_vcxproj.lua

 					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
 
 			"DebugEnvsInherit",
 			"EnableSSE",
 			"EnableSSE2",
+			"ExcludeFromBuild",
 			"ExtraWarnings",
 			"FatalWarnings",
 			"FloatFast",

src/base/premake.lua

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

tests/actions/make/cpp/test_objects.lua

 --
 -- 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)
 	end
 
 
-
-
 --
 -- If a custom rule builds to an object file, include it in the
 -- link automatically to match the behavior of Visual Studio
 		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" }
 
 		]]
 	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

tests/actions/vstudio/vc200x/test_files.lua

 --
 -- 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
 
 
 		]]
 	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.
 		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" }
 					Outputs="$(IntDir)/$(InputName).obj"
 				/>
 			</FileConfiguration>
-		]]		
+		]]
 	end
 
 

tests/actions/vstudio/vc2010/test_files.lua

 --
 -- 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)
 	</ItemGroup>
 		]]
 	end
-		
+
 	function suite.clCompile_onCFile()
 		files { "hello.c" }
 		prepare()
 	</ItemGroup>
 		]]
 	end
-	
+
 	function suite.resourceCompile_onRCFile()
 		files { "resources/hello.rc" }
 		prepare()
 		]]
 	end
 
-	
+
 --
 -- If a PCH source is specified, ensure it is included in the file configuration.
 --
 		]]
 	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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.