Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Add "Exclude" attribute support to Compile tag (Protobuild#258)
Browse files Browse the repository at this point in the history
* Add "Exclude" attribute support to Compile tag

According to the following documents:
https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-exclude-files-from-the-build
https://docs.microsoft.com/en-us/dotnet/core/tools/csproj

The Compile & Content tags did support glob patterns, and "exclude" is an essential complement to "include".
This is very useful for porting existing Unity modules / plugins to Protobuild (for example exclude those files inside the Editor folder while using globs).

* Build Protobuild and add tests
  • Loading branch information
ming4883 authored and hach-que committed Oct 12, 2017
1 parent 9d1b0ed commit 8c12ead
Show file tree
Hide file tree
Showing 24 changed files with 299 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Build/Projects/Protobuild.FunctionalTests.definition
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<Compile Include="ExampleCocos2DXNATest.cs" />
<Compile Include="ExampleCSToolsTest.cs" />
<Compile Include="ExampleMonoGameTest.cs" />
<Compile Include="ExcludeAttributeMissingOnItemsThatDontUseItTest.cs" />
<Compile Include="ExcludeAttributeOnItemsGeneratedCorrectlyTest.cs" />
<Compile Include="ExcludeAttributeOnItemsSynchronisedCorrectlyTest.cs" />
<Compile Include="ExternalCPlusPlusProjectReferencesAreCorrectInSolutionTest.cs" />
<Compile Include="ExternalProjectReferencesAreFlattenedTest.cs" />
<Compile Include="ExtractXSLTWorksTest.cs" />
Expand Down Expand Up @@ -258,6 +261,16 @@
<None Include="TestData\ExampleMonoGame\MonoGame\Build\Projects\MonoGame.Framework.definition" />
<None Include="TestData\ExampleMonoGame\MonoGame\MonoGame.Framework\MyClass.DirectX.cs" />
<None Include="TestData\ExampleMonoGame\MonoGame\MonoGame.Framework\MyClass.OpenGL.cs" />
<None Include="TestData\ExcludeAttributeMissingOnItemsThatDontUseIt\Build\Module.xml" />
<None Include="TestData\ExcludeAttributeMissingOnItemsThatDontUseIt\Build\Projects\Console.definition" />
<None Include="TestData\ExcludeAttributeMissingOnItemsThatDontUseIt\Console\Program.cs" />
<None Include="TestData\ExcludeAttributeOnItemsGeneratedCorrectly\Build\Module.xml" />
<None Include="TestData\ExcludeAttributeOnItemsGeneratedCorrectly\Build\Projects\Console.definition" />
<None Include="TestData\ExcludeAttributeOnItemsGeneratedCorrectly\Console\Program.cs" />
<None Include="TestData\ExcludeAttributeOnItemsSynchronisedCorrectly\Build\Module.xml" />
<None Include="TestData\ExcludeAttributeOnItemsSynchronisedCorrectly\Build\OriginalProjects\Console.definition" />
<None Include="TestData\ExcludeAttributeOnItemsSynchronisedCorrectly\Build\Projects\Console.definition" />
<None Include="TestData\ExcludeAttributeOnItemsSynchronisedCorrectly\Console\Program.cs" />
<None Include="TestData\ExternalCPlusPlusProjectReferencesAreCorrectInSolution\Build\Module.xml" />
<None Include="TestData\ExternalCPlusPlusProjectReferencesAreCorrectInSolution\Build\Projects\Console.definition" />
<None Include="TestData\ExternalCPlusPlusProjectReferencesAreCorrectInSolution\Build\Projects\ExternalCPlusPlus.definition" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Protobuild.Tests
{
using System.IO;
using Prototest.Library.Version1;

public class ExcludeAttributeMissingOnItemsThatDontUseItTest : ProtobuildTest
{
private readonly IAssert _assert;

public ExcludeAttributeMissingOnItemsThatDontUseItTest(IAssert assert) : base(assert)
{
_assert = assert;
}

public void GenerationIsCorrect()
{
this.SetupTest("ExcludeAttributeMissingOnItemsThatDontUseIt");

this.Generate("Windows");

_assert.True(File.Exists(this.GetPath(@"Module.Windows.sln")));
_assert.True(File.Exists(this.GetPath(@"Console\Console.Windows.csproj")));

var projectContents = this.ReadFile(@"Console\Console.Windows.csproj");

_assert.DoesNotContain("Exclude=", projectContents);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Protobuild.Tests
{
using System.IO;
using Prototest.Library.Version1;

public class ExcludeAttributeOnItemsGeneratedCorrectlyTest : ProtobuildTest
{
private readonly IAssert _assert;

public ExcludeAttributeOnItemsGeneratedCorrectlyTest(IAssert assert) : base(assert)
{
_assert = assert;
}

public void GenerationIsCorrect()
{
this.SetupTest("ExcludeAttributeOnItemsGeneratedCorrectly");

this.Generate("Windows");

_assert.True(File.Exists(this.GetPath(@"Module.Windows.sln")));
_assert.True(File.Exists(this.GetPath(@"Console\Console.Windows.csproj")));

var projectContents = this.ReadFile(@"Console\Console.Windows.csproj");

_assert.Contains("<Compile Include=\"*\" Exclude=\"Program.cs\" />", projectContents);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace Protobuild.Tests
{
using System.IO;
using Prototest.Library.Version1;

public class ExcludeAttributeOnItemsSynchronisedCorrectlyTest : ProtobuildTest
{
private readonly IAssert _assert;

public ExcludeAttributeOnItemsSynchronisedCorrectlyTest(IAssert assert) : base(assert)
{
_assert = assert;
}

public void GenerationIsCorrect()
{
this.SetupTest("ExcludeAttributeOnItemsSynchronisedCorrectly");

// Reset the definition back to it's original version for the test.
var original = this.GetPath(@"Build\OriginalProjects\Console.definition");
var target = this.GetPath(@"Build\Projects\Console.definition");
File.Copy(original, target, true);

this.OtherMode("sync", "Windows", purge: false);

var targetContents = this.ReadFile(@"Build\Projects\Console.definition");

try
{
_assert.Contains("Exclude=\"Program.cs\"", targetContents);
}
finally
{
// Reset the file back after the test passes so that Git doesn't
// report this file as changed.
File.Copy(original, target, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Module>
<Name>Module</Name>
<DefaultAction>resync</DefaultAction>
<GenerateNuGetRepositories>true</GenerateNuGetRepositories>
</Module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Name="Console" Path="Console" Type="Console">
<References>
<Reference Include="System" />
</References>
<Files>
<Compile Include="Test.cs" />
</Files>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Console
{
public static class Program
{
public static void Main(string[] args)
{
// TODO: Implement console app.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Module>
<Name>Module</Name>
<DefaultAction>resync</DefaultAction>
<GenerateNuGetRepositories>true</GenerateNuGetRepositories>
</Module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Name="Console" Path="Console" Type="Console">
<References>
<Reference Include="System" />
</References>
<Files>
<Compile Include="*" Exclude="Program.cs" />
</Files>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Console
{
public static class Program
{
public static void Main(string[] args)
{
// TODO: Implement console app.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Module>
<Name>Module</Name>
<DefaultAction>resync</DefaultAction>
<GenerateNuGetRepositories>true</GenerateNuGetRepositories>
</Module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Name="Console" Path="Console" Type="Console">
<References>
<Reference Include="System" />
</References>
<Files />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Name="Console" Path="Console" Type="Console">
<References>
<Reference Include="System" />
</References>
<Files />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{736E6F43-6C6F-2E65-5769-6E646F777343}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Console</RootNamespace>
<AssemblyName>Console</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn></NoWarn>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
<LangVersion>6</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
<OutputPath>bin\Windows\AnyCPU\Debug</OutputPath>
<IntermediateOutputPath>obj\Windows\AnyCPU\Debug</IntermediateOutputPath>
<DocumentationFile>bin\Windows\AnyCPU\Debug\Console.xml</DocumentationFile>
<DefineConstants>DEBUG;PLATFORM_WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<OutputPath>bin\Windows\AnyCPU\Release</OutputPath>
<IntermediateOutputPath>obj\Windows\AnyCPU\Release</IntermediateOutputPath>
<DocumentationFile>bin\Windows\AnyCPU\Release\Console.xml</DocumentationFile>
<DefineConstants>PLATFORM_WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="*" Exclude="Program.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<_PostBuildHookTimestamp>@(IntermediateAssembly-&gt;'%(FullPath).timestamp')</_PostBuildHookTimestamp>
<_PostBuildHookHostPlatform>$(Platform)</_PostBuildHookHostPlatform>
</PropertyGroup>
<Target Name="PostBuildHooks" Inputs="@(IntermediateAssembly);@(ReferencePath)" Outputs="@(IntermediateAssembly);$(_PostBuildHookTimestamp)" AfterTargets="CoreCompile" BeforeTargets="AfterCompile">
<Touch Files="$(_PostBuildHookTimestamp)" AlwaysCreate="True" />
</Target>
<ItemGroup />
<ItemGroup />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Console
{
public static class Program
{
public static void Main(string[] args)
{
// TODO: Implement console app.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console.Windows", "Console\Console.Windows.csproj", "{736E6F43-6C6F-2E65-5769-6E646F777343}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{736E6F43-6C6F-2E65-5769-6E646F777343}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{736E6F43-6C6F-2E65-5769-6E646F777343}.Debug|Any CPU.Build.0 = Debug|Any CPU
{736E6F43-6C6F-2E65-5769-6E646F777343}.Release|Any CPU.ActiveCfg = Release|Any CPU
{736E6F43-6C6F-2E65-5769-6E646F777343}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@
<xsl:attribute name="Include">
<xsl:value-of select="@Include" />
</xsl:attribute>
<xsl:if test="@Exclude">
<xsl:attribute name="Exclude">
<xsl:value-of select="@Exclude" />
</xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</xsl:element>
</xsl:if>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified Protobuild.exe
Binary file not shown.
Binary file modified Protobuild/Protobuild.Internal.dll.lzma
Binary file not shown.

0 comments on commit 8c12ead

Please sign in to comment.