Commits

Jason Perkins committed 9cf448b

Allow custom build and resource files to be excluded from builds

  • Participants
  • Parent commits 01e8486

Comments (0)

Files changed (3)

src/actions/vstudio/vs2010_vcxproj.lua

 		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
 					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))
 

tests/actions/vstudio/vc200x/test_files.lua

 		]]
 	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.

tests/actions/vstudio/vc2010/test_files.lua

 	local sln, prj
 
 	function suite.setup()
+		_ACTION = "vs2010"
 		sln = test.createsolution()
 	end
 
 		]]
 	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