Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(unity): add auto discoverability, testing, and publishing for unity3d projects #236

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AM.Condo/Targets/Prepare.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(CondoTargetsPath)Prepare$(slash)Unity.targets" />
<Import Project="$(CondoTargetsPath)Prepare$(slash)Node.targets" />
<Import Project="$(CondoTargetsPath)Prepare$(slash)Bower.targets" />
<Import Project="$(CondoTargetsPath)Prepare$(slash)Polymer.targets" />
Expand Down
67 changes: 67 additions & 0 deletions src/AM.Condo/Targets/Prepare/Unity.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- unity projects must have a unity.condo file in the root of the repository -->
<Target Name="GetUnityInfo" Returns="@(UnityProjectPath)">
<ItemGroup>
<UnityProjectPath Include="$(RepositoryRoot)" Condition=" Exists('$(RepositoryRoot)unity.condo') " />
</ItemGroup>

<PropertyGroup>
<UnityEnabled Condition=" '$(SKIP_UNITY)' != '' ">false</UnityEnabled>
<UnityEnabled Condition=" '$(UnityEnabled)' != '' AND '$(UnityEnabled.ToLower())' != 'true' ">false</UnityEnabled>
<UnityEnabled Condition=" '$(UnityEnabled)' == '' ">true</UnityEnabled>

<UnityRequired>false</UnityRequired>
<UnityRequired Condition=" @(UnityProjectPath->Count()) > 0 ">$(UnityEnabled)</UnityRequired>
</PropertyGroup>
</Target>

<Target Name="PrintUnityProjects" Condition=" $(UnityRequired) ">
<Message Importance="High" Text="Project: @(UnityProjectPath)" />
</Target>

<Target Name="ConfigureUnity">
<!-- UNITY_PATH env var must be set to find unity. unity must be run from reletive path -->
<PropertyGroup>
<UnityPath Condition=" '$(UNITY_PATH)' != '' ">$(UNITY_PATH)</UnityPath>
<HasUnity>false</HasUnity>
<HasUnity Condition=" '$(UNITY_PATH)' != ''">true</HasUnity>
<UnityEnabled Condition=" $(UnityEnabled) ">$(HasUnity)</UnityEnabled>
</PropertyGroup>

<Warning Condition=" !$(HasUnity) AND $(UnityRequired) "
Text="A unity.condo file was located at: @(UnityProjectPath), but the unity command or executable could not be found.
Please set UNITY_PATH env variable." />

<PropertyGroup>
<UnityRequired Condition=" $(UnityRequired) ">$(HasUnity)</UnityRequired>

<UnityPublish Condition=" '$(SKIP_UNITY_PUBLISH)' != '' ">false</UnityPublish>
<UnityPublish Condition=" '$(UnityPublish)' != '' AND '$(UnityPublish.ToLower())' != 'true' ">false</UnityPublish>
<UnityPublish Condition=" '$(UnityPublish)' == '' ">$(HasUnity)</UnityPublish>

<UnityTest Condition=" '$(SKIP_UNITY_TEST)' != '' ">false</UnityTest>
<UnityTest Condition=" '$(UnityTest)' != '' AND '$(UnityTest.ToLower())' != 'true' ">false</UnityTest>
<UnityTest Condition=" '$(UnityTest)' == '' ">$(HasUnity)</UnityTest>

<!-- Unity creates its own dotnet projects, skip dotnet -->
<SKIP_DOTNET Condition=" $(UnityRequired) ">true</SKIP_DOTNET>
<!-- Unity creates a package.json, skip npm -->
<SKIP_NPM Condition=" $(UnityRequired) ">true</SKIP_NPM>
<!-- Default build target to WebGL -->
<UnityTargets Condition=" '$(UNITY_TARGETS)' == '' ">WebGL</UnityTargets>
<UnityTargets Condition=" '$(UNITY_TARGETS)' != '' ">$(UNITY_TARGETS)</UnityTargets>
</PropertyGroup>
</Target>

<PropertyGroup>

<BeforePrepare>
$(BeforePrepare);
GetUnityInfo;
ConfigureUnity;
PrintUnityProjects;
</BeforePrepare>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions src/AM.Condo/Targets/Publish.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(CondoTargetsPath)Publish$(slash)Unity.targets" />
<Import Project="$(CondoTargetsPath)Publish$(slash)Dotnet.targets" />
<Import Project="$(CondoTargetsPath)Publish$(slash)Docker.targets" />
<Import Project="$(CondoTargetsPath)Publish$(slash)Go.targets" />
Expand Down
20 changes: 20 additions & 0 deletions src/AM.Condo/Targets/Publish/Unity.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<UnityPublishOptions Condition=" $(UNITY_PUBLISH_OPTIONS) != '' ">$(UNITY_PUBLISH_OPTIONS)</UnityPublishOptions>
</PropertyGroup>

<Target Name="UnityPublish" Condition=" $(UnityPublish) ">
<Exec Command="xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' &quot;$(UnityPath)&quot; -projectPath &quot;@(UnityProjectPath)&quot; -quit -batchmode -buildTarget %(UnityTargets) -customBuildTarget %(UnityTargets) -customBuildPath &quot;$(PublishArtifactsRoot)%(UnityTargets.ToLower())&quot; -customBuildOptions AcceptExternalModificationsToPlayer -executeMethod Build.PerformBuild -logFile $(UnityPublishOptions)"
WorkingDirectory="@(UnityProjectPath)"
IgnoreExitCode="true" />
</Target>

<PropertyGroup>
<PublishDependsOn>
$(PublishDependsOn);
UnityPublish;
</PublishDependsOn>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/AM.Condo/Targets/Test.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(CondoTargetsPath)Test$(slash)Unity.targets" />
<Import Project="$(CondoTargetsPath)Test$(slash)Node.targets" />
<Import Project="$(CondoTargetsPath)Test$(slash)Polymer.targets" />
<Import Project="$(CondoTargetsPath)Test$(slash)Dotnet.targets" />
Expand Down
20 changes: 20 additions & 0 deletions src/AM.Condo/Targets/Test/Unity.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<UnityTestOptions Condition=" $(UNITY_TEST_OPTIONS) != '' ">$(UNITY_TEST_OPTIONS)</UnityTestOptions>
</PropertyGroup>

<Target Name="UnityTest" Condition=" $(UnityTest) ">
<Exec Command="xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' &quot;$(UnityPath)&quot; -projectPath &quot;@(UnityProjectPath)&quot; -batchmode -testPlatform @(UnityTargets) -runTests -testResults &quot;$(TestArtifactsRoot)@(UnityTargets)$(slash)results.xml&quot; -logFile $(UnityTestOptions)"
WorkingDirectory="@(UnityProjectPath)"
IgnoreExitCode="true" />
</Target>

<PropertyGroup>
<TestDependsOn>
$(TestDependsOn);
UnityTest;
</TestDependsOn>
</PropertyGroup>
</Project>