forked from microsoft/AppCenter-SDK-Unity-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
143 lines (124 loc) · 4.59 KB
/
build.cake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#addin "Cake.AzureStorage"
#addin nuget:?package=Cake.FileHelpers
#addin nuget:?package=NuGet.Core
#load "utility.cake"
using System;
using System.Linq;
using System.Net;
using System.Collections.Generic;
using System.Runtime.Versioning;
using NuGet;
// Task TARGET for build
var Target = Argument("target", Argument("t", "Default"));
// Spec files can have up to one dependency.
class UnityPackage
{
private string _packageName;
private string _packageVersion;
private List<string> _includePaths = new List<string>();
public UnityPackage(string specFilePath)
{
AddFilesFromSpec(specFilePath);
}
private void AddFilesFromSpec(string specFilePath)
{
_packageName = Statics.Context.XmlPeek(specFilePath, "package/@name");
_packageVersion = Statics.Context.XmlPeek(specFilePath, "package/@version");
if (_packageName == null || _packageVersion == null)
{
Statics.Context.Error("Invalid format for UnityPackageSpec file '" + specFilePath + "': missing package name or version");
return;
}
var xpathPrefix = "/package/include/file[";
var xpathSuffix= "]/@path";
string lastPath = Statics.Context.XmlPeek(specFilePath, xpathPrefix + "last()" + xpathSuffix);
var currentIdx = 1;
var currentPath = Statics.Context.XmlPeek(specFilePath, xpathPrefix + currentIdx++ + xpathSuffix);
if (currentPath != null)
{
_includePaths.Add(currentPath);
}
while (currentPath != lastPath)
{
currentPath = Statics.Context.XmlPeek(specFilePath, xpathPrefix + currentIdx++ + xpathSuffix);
_includePaths.Add(currentPath);
}
}
public void CreatePackage(string targetDirectory)
{
var args = "-exportPackage ";
foreach (var path in _includePaths)
{
args += " " + path;
}
var fullPackageName = _packageName + "-v" + _packageVersion + ".unitypackage";
args += " " + targetDirectory + "/" + fullPackageName;
var result = ExecuteUnityCommand(args, "Source");
if (result != 0)
{
Statics.Context.Error("Something went wrong while creating Unity package '" + fullPackageName + "'");
}
}
public void CopyFiles(DirectoryPath targetDirectory)
{
foreach (var path in _includePaths)
{
if (Statics.Context.DirectoryExists(path))
{
Statics.Context.CopyDirectory(path, targetDirectory.Combine(path));
}
else
{
Statics.Context.CopyFile(path, targetDirectory.CombineWithFilePath(path));
}
}
}
}
// Install Unity Editor for Windows
Task("Install-Unity-Windows").Does(() => {
const string unityDownloadUrl = @"https://netstorage.unity3d.com/unity/2207421190e9/Windows64EditorInstaller/UnitySetup64-2018.2.9f1.exe";
Information("Downloading Unity Editor...");
DownloadFile(unityDownloadUrl, "./UnitySetup64.exe");
Information("Installing Unity Editor...");
var result = StartProcess("./UnitySetup64.exe", " /S");
if (result != 0)
{
throw new Exception("Failed to install Unity Editor");
}
}).OnError(HandleError);
// Creates Unity packages corresponding to all ".unitypackagespec" files in "UnityPackageSpecs" folder
Task("CreatePackages").Does(()=>
{
// Store packages in a clean folder.
const string outputDirectory = "output";
CleanDirectory(outputDirectory);
var specFiles = GetFiles("UnityPackageSpecs/*.unitypackagespec");
foreach (var spec in specFiles)
{
var package = new UnityPackage(spec.FullPath);
package.CreatePackage(MakeAbsolute(Directory(outputDirectory)).FullPath);
}
});
Task("RegisterUnity").Does(()=>
{
var serialNumber = Argument<string>("UnitySerialNumber");
var username = Argument<string>("UnityUsername");
var password = Argument<string>("UnityPassword");
// This will produce an error, but that's okay because the project "noproject" is used so that the
// root isn't opened by unity, which could potentially remove important .meta files.
ExecuteUnityCommand($"-serial {serialNumber} -username {username} -password {password}", "noproject");
}).OnError(HandleError);
Task("UnregisterUnity").Does(()=>
{
ExecuteUnityCommand("-returnLicense", null);
}).OnError(HandleError);
// Default Task.
Task("Default").IsDependentOn("CreatePackages");
// Clean up files/directories.
Task("clean")
.IsDependentOn("RemoveTemporaries")
.Does(() =>
{
DeleteDirectoryIfExists("output");
});
RunTarget(Target);