mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
Rider-project for Builder folder
This commit is contained in:
parent
5d0c1ba5c1
commit
abf39fb044
56
Builder/.gitignore
vendored
Normal file
56
Builder/.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
#
|
||||
# Note: Non default ignore file, as this only tests Builder script.
|
||||
#
|
||||
|
||||
[Ll]ibrary/
|
||||
[Tt]emp/
|
||||
[Oo]bj/
|
||||
[Bb]uild/
|
||||
[Bb]uilds/
|
||||
[Ll]ogs/
|
||||
|
||||
# Additional ignores
|
||||
[Bb]in/
|
||||
|
||||
# Uncomment this line if you wish to ignore the asset store tools plugin
|
||||
# [Aa]ssets/AssetStoreTools*
|
||||
|
||||
# IDEs
|
||||
.vs/
|
||||
.idea/
|
||||
|
||||
# Gradle cache directory
|
||||
.gradle/
|
||||
|
||||
# Autogenerated VS/MD/Consulo solution and project files
|
||||
ExportedObj/
|
||||
.consulo/
|
||||
#*.csproj
|
||||
*.unityproj
|
||||
*.sln
|
||||
*.suo
|
||||
*.tmp
|
||||
*.user
|
||||
*.userprefs
|
||||
*.pidb
|
||||
*.booproj
|
||||
*.svd
|
||||
*.pdb
|
||||
*.mdb
|
||||
*.opendb
|
||||
*.VC.db
|
||||
|
||||
# Unity3D generated meta files
|
||||
*.pidb.meta
|
||||
*.pdb.meta
|
||||
*.mdb.meta
|
||||
|
||||
# Unity3D generated file on crash reports
|
||||
sysinfo.txt
|
||||
|
||||
# Builds
|
||||
*.apk
|
||||
*.unitypackage
|
||||
|
||||
# Crashlytics generated file
|
||||
crashlytics-build.properties
|
@ -6,139 +6,142 @@ using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
static class Builder
|
||||
namespace UnityBuilderAction
|
||||
{
|
||||
private static string EOL = Environment.NewLine;
|
||||
|
||||
private static void ParseCommandLineArguments(out Dictionary<string, string> providedArguments)
|
||||
static class Builder
|
||||
{
|
||||
providedArguments = new Dictionary<string, string>();
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
private static string EOL = Environment.NewLine;
|
||||
|
||||
Console.WriteLine(
|
||||
$"{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"# Parsing settings #{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"{EOL}"
|
||||
);
|
||||
private static void ParseCommandLineArguments(out Dictionary<string, string> providedArguments)
|
||||
{
|
||||
providedArguments = new Dictionary<string, string>();
|
||||
string[] args = Environment.GetCommandLineArgs();
|
||||
|
||||
// Extract flags with optional values
|
||||
for (int current = 0, next = 1; current < args.Length; current++, next++) {
|
||||
// Parse flag
|
||||
bool isFlag = args[current].StartsWith("-");
|
||||
if (!isFlag) continue;
|
||||
string flag = args[current].TrimStart('-');
|
||||
Console.WriteLine(
|
||||
$"{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"# Parsing settings #{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"{EOL}"
|
||||
);
|
||||
|
||||
// Parse optional value
|
||||
bool flagHasValue = next < args.Length && !args[next].StartsWith("-");
|
||||
string value = flagHasValue ? args[next].TrimStart('-') : "";
|
||||
// Extract flags with optional values
|
||||
for (int current = 0, next = 1; current < args.Length; current++, next++) {
|
||||
// Parse flag
|
||||
bool isFlag = args[current].StartsWith("-");
|
||||
if (!isFlag) continue;
|
||||
string flag = args[current].TrimStart('-');
|
||||
|
||||
// Assign
|
||||
Console.WriteLine($"Found flag \"{flag}\" with value \"{value}\".");
|
||||
providedArguments.Add(flag, value);
|
||||
}
|
||||
}
|
||||
// Parse optional value
|
||||
bool flagHasValue = next < args.Length && !args[next].StartsWith("-");
|
||||
string value = flagHasValue ? args[next].TrimStart('-') : "";
|
||||
|
||||
private static Dictionary<string, string> GetValidatedOptions()
|
||||
{
|
||||
ParseCommandLineArguments(out var validatedOptions);
|
||||
|
||||
if (!validatedOptions.TryGetValue("projectPath", out var projectPath)) {
|
||||
Console.WriteLine("Missing argument -projectPath");
|
||||
EditorApplication.Exit(110);
|
||||
// Assign
|
||||
Console.WriteLine($"Found flag \"{flag}\" with value \"{value}\".");
|
||||
providedArguments.Add(flag, value);
|
||||
}
|
||||
}
|
||||
|
||||
if (!validatedOptions.TryGetValue("buildTarget", out var buildTarget)) {
|
||||
Console.WriteLine("Missing argument -buildTarget");
|
||||
EditorApplication.Exit(120);
|
||||
private static Dictionary<string, string> GetValidatedOptions()
|
||||
{
|
||||
ParseCommandLineArguments(out var validatedOptions);
|
||||
|
||||
if (!validatedOptions.TryGetValue("projectPath", out var projectPath)) {
|
||||
Console.WriteLine("Missing argument -projectPath");
|
||||
EditorApplication.Exit(110);
|
||||
}
|
||||
|
||||
if (!validatedOptions.TryGetValue("buildTarget", out var buildTarget)) {
|
||||
Console.WriteLine("Missing argument -buildTarget");
|
||||
EditorApplication.Exit(120);
|
||||
}
|
||||
|
||||
if (!Enum.IsDefined(typeof(BuildTarget), buildTarget)) {
|
||||
EditorApplication.Exit(121);
|
||||
}
|
||||
|
||||
if (!validatedOptions.TryGetValue("customBuildPath", out var customBuildPath)) {
|
||||
Console.WriteLine("Missing argument -customBuildPath");
|
||||
EditorApplication.Exit(130);
|
||||
}
|
||||
|
||||
string defaultCustomBuildName = "TestBuild";
|
||||
if (!validatedOptions.TryGetValue("customBuildName", out var customBuildName)) {
|
||||
Console.WriteLine($"Missing argument -customBuildName, defaulting to {defaultCustomBuildName}.");
|
||||
validatedOptions.Add("customBuildName", defaultCustomBuildName);
|
||||
}
|
||||
else if (customBuildName == "") {
|
||||
Console.WriteLine($"Invalid argument -customBuildName, defaulting to {defaultCustomBuildName}.");
|
||||
validatedOptions.Add("customBuildName", defaultCustomBuildName);
|
||||
}
|
||||
|
||||
return validatedOptions;
|
||||
}
|
||||
|
||||
if (!Enum.IsDefined(typeof(BuildTarget), buildTarget)) {
|
||||
EditorApplication.Exit(121);
|
||||
public static void BuildProject()
|
||||
{
|
||||
// Gather values from args
|
||||
var options = GetValidatedOptions();
|
||||
|
||||
// Gather values from project
|
||||
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
||||
|
||||
// Define BuildPlayer Options
|
||||
var buildOptions = new BuildPlayerOptions {
|
||||
scenes = scenes,
|
||||
locationPathName = options["customBuildPath"],
|
||||
target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
|
||||
};
|
||||
|
||||
// Perform build
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildOptions);
|
||||
|
||||
// Summary
|
||||
BuildSummary summary = buildReport.summary;
|
||||
ReportSummary(summary);
|
||||
|
||||
// Result
|
||||
BuildResult result = summary.result;
|
||||
ExitWithResult(result);
|
||||
}
|
||||
|
||||
if (!validatedOptions.TryGetValue("customBuildPath", out var customBuildPath)) {
|
||||
Console.WriteLine("Missing argument -customBuildPath");
|
||||
EditorApplication.Exit(130);
|
||||
private static void ReportSummary(BuildSummary summary)
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"# Build results #{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"{EOL}" +
|
||||
$"Duration: {summary.totalTime.ToString()}{EOL}" +
|
||||
$"Warnings: {summary.totalWarnings.ToString()}{EOL}" +
|
||||
$"Errors: {summary.totalErrors.ToString()}{EOL}" +
|
||||
$"Size: {summary.totalSize.ToString()} bytes{EOL}" +
|
||||
$"{EOL}"
|
||||
);
|
||||
}
|
||||
|
||||
string defaultCustomBuildName = "TestBuild";
|
||||
if (!validatedOptions.TryGetValue("customBuildName", out var customBuildName)) {
|
||||
Console.WriteLine($"Missing argument -customBuildName, defaulting to {defaultCustomBuildName}.");
|
||||
validatedOptions.Add("customBuildName", defaultCustomBuildName);
|
||||
}
|
||||
else if (customBuildName == "") {
|
||||
Console.WriteLine($"Invalid argument -customBuildName, defaulting to {defaultCustomBuildName}.");
|
||||
validatedOptions.Add("customBuildName", defaultCustomBuildName);
|
||||
}
|
||||
private static void ExitWithResult(BuildResult result)
|
||||
{
|
||||
if (result == BuildResult.Succeeded) {
|
||||
Console.WriteLine("Build succeeded!");
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
|
||||
return validatedOptions;
|
||||
}
|
||||
if (result == BuildResult.Failed) {
|
||||
Console.WriteLine("Build failed!");
|
||||
EditorApplication.Exit(101);
|
||||
}
|
||||
|
||||
public static void BuildProject()
|
||||
{
|
||||
// Gather values from args
|
||||
var options = GetValidatedOptions();
|
||||
if (result == BuildResult.Cancelled) {
|
||||
Console.WriteLine("Build cancelled!");
|
||||
EditorApplication.Exit(102);
|
||||
}
|
||||
|
||||
// Gather values from project
|
||||
var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray();
|
||||
|
||||
// Define BuildPlayer Options
|
||||
var buildOptions = new BuildPlayerOptions {
|
||||
scenes = scenes,
|
||||
locationPathName = options["customBuildPath"],
|
||||
target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]),
|
||||
};
|
||||
|
||||
// Perform build
|
||||
BuildReport buildReport = BuildPipeline.BuildPlayer(buildOptions);
|
||||
|
||||
// Summary
|
||||
BuildSummary summary = buildReport.summary;
|
||||
ReportSummary(summary);
|
||||
|
||||
// Result
|
||||
BuildResult result = summary.result;
|
||||
ExitWithResult(result);
|
||||
}
|
||||
|
||||
private static void ReportSummary(BuildSummary summary)
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"# Build results #{EOL}" +
|
||||
$"###########################{EOL}" +
|
||||
$"{EOL}" +
|
||||
$"Duration: {summary.totalTime.ToString()}{EOL}" +
|
||||
$"Warnings: {summary.totalWarnings.ToString()}{EOL}" +
|
||||
$"Errors: {summary.totalErrors.ToString()}{EOL}" +
|
||||
$"Size: {summary.totalSize.ToString()} bytes{EOL}" +
|
||||
$"{EOL}"
|
||||
);
|
||||
}
|
||||
|
||||
private static void ExitWithResult(BuildResult result)
|
||||
{
|
||||
if (result == BuildResult.Succeeded) {
|
||||
Console.WriteLine("Build succeeded!");
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
|
||||
if (result == BuildResult.Failed) {
|
||||
Console.WriteLine("Build failed!");
|
||||
EditorApplication.Exit(101);
|
||||
}
|
||||
|
||||
if (result == BuildResult.Cancelled) {
|
||||
Console.WriteLine("Build cancelled!");
|
||||
EditorApplication.Exit(102);
|
||||
}
|
||||
|
||||
if (result == BuildResult.Unknown) {
|
||||
Console.WriteLine("Build result is unknown!");
|
||||
EditorApplication.Exit(103);
|
||||
if (result == BuildResult.Unknown) {
|
||||
Console.WriteLine("Build result is unknown!");
|
||||
EditorApplication.Exit(103);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc057061ce9f406aa6b57a62d67fe9c0
|
||||
timeCreated: 1575145310
|
35
Builder/Properties/AssemblyInfo.cs
Normal file
35
Builder/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
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("UnityBuilderAction")]
|
||||
[assembly: AssemblyDescription("Builder script for Unity Builder action")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("UnityBuilderAction")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019-present")]
|
||||
[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("031F5EE1-35CE-4F77-975A-7E326F898185")]
|
||||
|
||||
// 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")]
|
57
Builder/UnityBuilderAction.csproj
Normal file
57
Builder/UnityBuilderAction.csproj
Normal file
@ -0,0 +1,57 @@
|
||||
<?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>{031F5EE1-35CE-4F77-975A-7E326F898185}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>UnityBuilderAction</RootNamespace>
|
||||
<AssemblyName>UnityBuilderAction</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</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" />
|
||||
<Reference Include="UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
|
||||
<HintPath>..\..\..\Program Files\Unity\2019.2.11f1\Editor\Data\Managed\UnityEditor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>C:\Program Files\Unity\2019.2.11f1\Editor\Data\Managed\UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Builder.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</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…
Reference in New Issue
Block a user