Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Srdja Stetic-Kozic committed Nov 4, 2015
0 parents commit 52442fc
Show file tree
Hide file tree
Showing 8 changed files with 394 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.unsuccessfulbuild
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

#NuGet
packages/

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unity Proxy

Unity proxy is used to start Unity, redirect the log file to standard output and detect the magic string in the output that indicates if the build was successful or not. It also reports all progress bars as build progress to TeamCity. It can also copy the whole editor log after the build to the specified folder (artifactsPath). Command line arguments are as follows:
```sh
pathToUnityExecutable [-artifactsPath pathForBuildArtifacts]
```
20 changes: 20 additions & 0 deletions UnityProxy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityProxy", "UnityProxy\UnityProxy.csproj", "{828E2244-D220-4CC9-85E0-7FDDB617A346}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{828E2244-D220-4CC9-85E0-7FDDB617A346}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{828E2244-D220-4CC9-85E0-7FDDB617A346}.Debug|Any CPU.Build.0 = Debug|Any CPU
{828E2244-D220-4CC9-85E0-7FDDB617A346}.Release|Any CPU.ActiveCfg = Release|Any CPU
{828E2244-D220-4CC9-85E0-7FDDB617A346}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions UnityProxy/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
95 changes: 95 additions & 0 deletions UnityProxy/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace UnityProxy
{
class Program
{
/// <summary>
/// Magic string our build pipeline writes to the log after a successful build.
/// </summary>
private const string SuccessMagicString = "Successful build ~0xDEADBEEF";

static void Main(string[] args)
{
string unityPath, artifactsPath;
int startingArgumentIndex = ParseArguments(args, out unityPath, out artifactsPath);
string logPath = Path.GetTempFileName();

Watcher watcher = new Watcher(logPath);
Thread watcherThread = new Thread(watcher.Run);
watcherThread.Start();

Process unity = new Process();
unity.StartInfo = new ProcessStartInfo(unityPath);

unity.StartInfo.Arguments = "-logFile \"" + logPath + "\"";

for (int i = startingArgumentIndex; i < args.Length; i++)
{
unity.StartInfo.Arguments += " \"" + args[i] + "\"";
}

Console.WriteLine("Starting Unity with arguments: " + unity.StartInfo.Arguments);

unity.Start();

Console.WriteLine("##teamcity[setParameter name='{0}' value='{1}']", "unityPID", unity.Id);

unity.WaitForExit();
watcher.Stop();
watcherThread.Join();

if (artifactsPath != null)
{
SaveArtifacts(artifactsPath, watcher.FullLog);
}

if (watcher.FullLog.Contains(SuccessMagicString))
{
Console.WriteLine("Success.");
Environment.Exit(0);
}
else
{
Console.WriteLine("Failure.");
Environment.Exit(1);
}
}

/// <summary>
/// Saves build artifacts (log file) to the specified path.
/// </summary>
private static void SaveArtifacts(string artifactsPath, string logText)
{
Directory.CreateDirectory(artifactsPath);

File.WriteAllText(artifactsPath + "/editor.log", logText);
}

/// <summary>
/// Parses command line arguments.
/// </summary>
/// <param name="args">Arguments</param>
/// <param name="unityPath">Path to the unity executable.</param>
/// <param name="artifactsPath">PAth where the artifacts should be saved.</param>
/// <returns>The number of arguments parsed.</returns>
private static int ParseArguments(string[] args, out string unityPath, out string artifactsPath)
{
unityPath = args[0];
artifactsPath = null;

if (args.Length > 1)
{
if (args[1] == "-artifactsPath")
{
artifactsPath = args[2];
return 3;
}
}
return 1;
}
}
}
36 changes: 36 additions & 0 deletions UnityProxy/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UnityLogRedirector")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UnityLogRedirector")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("249cad89-dede-4755-9cb4-758b6adf4ed2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
59 changes: 59 additions & 0 deletions UnityProxy/UnityProxy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{828E2244-D220-4CC9-85E0-7FDDB617A346}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UnityProxy</RootNamespace>
<AssemblyName>UnityProxy</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Watcher.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 52442fc

Please sign in to comment.