forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCosmosBuildDefinition.cs
207 lines (156 loc) · 7.31 KB
/
CosmosBuildDefinition.cs
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.Setup.Configuration;
using Cosmos.Build.Builder.BuildTasks;
using Cosmos.Build.Builder.Dependencies;
using Cosmos.Build.Builder.Services;
namespace Cosmos.Build.Builder
{
internal class CosmosBuildDefinition : IBuildDefinition
{
private readonly IInnoSetupService _innoSetupService;
private readonly IMSBuildService _msBuildService;
private readonly ISetupInstance2 _visualStudioInstance;
private readonly string _cosmosDir;
public CosmosBuildDefinition(
IInnoSetupService innoSetupService,
IMSBuildService msBuildService,
ISetupInstance2 visualStudioInstance)
{
_innoSetupService = innoSetupService;
_msBuildService = msBuildService;
_visualStudioInstance = visualStudioInstance;
_cosmosDir = Path.GetFullPath(Directory.GetCurrentDirectory());
if (!Directory.Exists(Path.Combine(_cosmosDir, "source", "Cosmos.Build.Builder")))
{
_cosmosDir = Path.GetFullPath(Path.Combine(_cosmosDir, "..", "..", "..", "..", ".."));
}
}
public IEnumerable<IDependency> GetDependencies()
{
yield return new ReposDependency(_cosmosDir);
yield return new ProperRepoNameDependency(_cosmosDir);
yield return new VisualStudioDependency(_visualStudioInstance);
yield return new VisualStudioWorkloadsDependency(_visualStudioInstance);
yield return new InnoSetupDependency(_innoSetupService);
}
public IEnumerable<IBuildTask> GetBuildTasks()
{
// remove Cosmos packages from the cache
var xGlobalFolder = NuGet.Configuration.SettingsUtility.GetGlobalPackagesFolder(
NuGet.Configuration.Settings.LoadDefaultSettings(Environment.SystemDirectory));
void CleanPackage(string aPackage)
{
var xPath = Path.Combine(xGlobalFolder, aPackage);
if (Directory.Exists(xPath))
{
Directory.Delete(xPath, true);
}
}
// Later we should specify the packages, currently we're moving to gen3 so package names are a bit unstable
foreach (var xFolder in Directory.EnumerateDirectories(xGlobalFolder))
{
if (new DirectoryInfo(xFolder).Name.StartsWith("Cosmos", StringComparison.InvariantCultureIgnoreCase))
{
CleanPackage(xFolder);
}
}
var il2cpuDir = Path.GetFullPath(Path.Combine(_cosmosDir, "..", "IL2CPU"));
var xSharpDir = Path.GetFullPath(Path.Combine(_cosmosDir, "..", "XSharp"));
var cosmosSourceDir = Path.Combine(_cosmosDir, "source");
var il2cpuSourceDir = Path.Combine(il2cpuDir, "source");
var xSharpSourceDir = Path.Combine(xSharpDir, "source");
var buildSlnPath = Path.Combine(_cosmosDir, "Build.sln");
var vsipDir = Path.Combine(_cosmosDir, "Build", "VSIP") + '\\';
if (Directory.Exists(vsipDir))
{
Directory.Delete(vsipDir, true);
}
// Restore Build.sln
yield return new RestoreTask(_msBuildService, buildSlnPath);
// Build Build.sln
yield return new BuildTask(_msBuildService, buildSlnPath, vsipDir, vsipDir);
// Publish IL2CPU
var il2cpuProjectPath = Path.Combine(il2cpuSourceDir, "IL2CPU", "IL2CPU.csproj");
var il2cpuPublishPath = Path.Combine(vsipDir, "IL2CPU");
yield return new RestoreTask(_msBuildService, il2cpuProjectPath);
yield return new PublishTask(_msBuildService, il2cpuProjectPath, il2cpuPublishPath);
// Pack build system and kernel assemblies
var cosmosPackageProjects = new List<string>()
{
"Cosmos.Build.Tasks",
};
foreach (var task in PackProject(cosmosPackageProjects, new List<string>(), new List<string>()))
{
yield return task;
}
cosmosPackageProjects = new List<string>()
{
"Cosmos.Core_Plugs", // we ned to restore il2cpu.debug.
"Cosmos.Common",
"Cosmos.Core",
"Cosmos.Core_Asm",
"Cosmos.HAL2",
"Cosmos.System2",
"Cosmos.System2_Plugs",
"Cosmos.Debug.Kernel",
"Cosmos.Debug.Kernel.Plugs.Asm",
"Cosmos.Plugs"
};
var il2cpuPackageProjects = new List<string>()
{
"IL2CPU.API"
};
var xSharpProjects = new List<string>()
{
"Spruce",
"XSharp/XSharp"
};
foreach (var task in PackProject(cosmosPackageProjects, il2cpuPackageProjects, xSharpProjects))
{
yield return task;
}
var cosmosSetupDir = Path.Combine(_cosmosDir, "setup");
// Create Setup
var innoSetupScriptPath = Path.Combine(cosmosSetupDir, "Cosmos.iss");
var cosmosSetupVersion = App.BuilderConfiguration.UserKit ? DateTime.Now.ToString("yyyyMMdd") : "106027";
yield return new CreateSetupTask(
_innoSetupService,
innoSetupScriptPath,
App.BuilderConfiguration.UserKit ? "UserKit" : "DevKit",
cosmosSetupVersion,
App.BuilderConfiguration.BuildExtensions);
if (!App.BuilderConfiguration.UserKit)
{
var cosmosSetupPath = Path.Combine(cosmosSetupDir, "Output", $"CosmosUserKit-{cosmosSetupVersion}-vs2022.exe");
// Run Setup
yield return new StartProcessTask(cosmosSetupPath, "/SILENT", "Cosmos Setup", true);
// Write Dev Kit path
using (var xKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\Cosmos"))
{
xKey.SetValue("DevKit", _cosmosDir);
}
}
IEnumerable<IBuildTask> PackProject(List<string> cosmosProjects, List<string> il2cpuProjects, List<string> xSharpProjects)
{
var packageProjectPaths = cosmosProjects.Select(p => Path.Combine(cosmosSourceDir, p))
.Concat(il2cpuProjects.Select(p => Path.Combine(il2cpuSourceDir, p)))
.Concat(xSharpProjects.Select(p => Path.Combine(xSharpSourceDir, p)));
var packagesDir = Path.Combine(vsipDir, "packages");
var packageVersionLocalBuildSuffix = DateTime.Now.ToString("yyyyMMddhhmmss");
var restore = true;
foreach (var projectPath in packageProjectPaths)
{
if (restore)
{
yield return new RestoreTask(_msBuildService, projectPath);
restore = false;
}
yield return new PackTask(_msBuildService, projectPath, packagesDir, packageVersionLocalBuildSuffix);
}
}
}
}
}