Skip to content

Commit a2412e8

Browse files
committed
Merge pull request #185 from sgetaz/master
List all requirements 1-by-1
2 parents 59c2bba + f6b9f45 commit a2412e8

File tree

2 files changed

+75
-42
lines changed

2 files changed

+75
-42
lines changed

source/Cosmos.Build.Builder/CosmosTask.cs

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88
using Microsoft.Win32;
99
using System.Windows;
1010

11+
public enum BuildState
12+
{
13+
CleanupError,
14+
CompilationError,
15+
PrerequisiteMissing,
16+
Running
17+
}
1118
namespace Cosmos.Build.Builder {
1219
public class CosmosTask : Task {
1320
protected string mCosmosDir;
1421
protected string mOutputDir;
22+
protected BuildState mBuildState;
1523
protected string mAppDataDir;
1624
protected int mReleaseNo;
1725
protected string mInnoFile;
1826
protected string mInnoPath;
27+
// Instead of throwing every exception, we collect them in a list
28+
protected List<string> mExceptionList = new List<string>();
1929
public string InnoScriptTargetFile = "Current.iss";
20-
2130
public CosmosTask(string aCosmosDir, int aReleaseNo) {
2231
mCosmosDir = aCosmosDir;
2332
mAppDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Cosmos User Kit");
@@ -71,26 +80,31 @@ void CleanupAlreadyInstalled() {
7180
}
7281
}
7382

74-
protected override void DoRun() {
83+
protected override List<string> DoRun() {
7584
mOutputDir = Path.Combine(mCosmosDir, @"Build\VSIP");
76-
7785
if (!App.TestMode) {
7886
CheckPrereqs(); //Working
79-
CleanupVSIPFolder();
80-
81-
CompileCosmos(); //Working
82-
CopyTemplates();
83-
84-
CreateScriptToUseChangesetWhichTaskIsUse();
85-
86-
CreateSetup(); //Working
87-
if (!App.IsUserKit) {
88-
CleanupAlreadyInstalled(); //Working
89-
RunSetup(); //Working - forgot to run as user kit first
90-
WriteDevKit(); //Working
91-
if (!App.DoNotLaunchVS) { LaunchVS(); } //Working
87+
// No point in continuing if Prerequisites are missing
88+
// Could potentially add more State checks in the future, but for now
89+
// only the prerequisites are handled...
90+
if (mBuildState != BuildState.PrerequisiteMissing)
91+
{
92+
CleanupVSIPFolder();
93+
94+
CompileCosmos(); //Working
95+
CopyTemplates();
96+
97+
CreateScriptToUseChangesetWhichTaskIsUse();
98+
99+
CreateSetup(); //Working
100+
if (!App.IsUserKit)
101+
{
102+
CleanupAlreadyInstalled(); //Working
103+
RunSetup(); //Working - forgot to run as user kit first
104+
WriteDevKit(); //Working
105+
if (!App.DoNotLaunchVS) { LaunchVS(); } //Working
106+
}
92107
}
93-
94108
Done();
95109
} else {
96110
Section("Testing...");
@@ -114,6 +128,7 @@ protected override void DoRun() {
114128

115129
//Done();
116130
}
131+
return mExceptionList;
117132
}
118133

119134
protected void MsBuild(string aSlnFile, string aBuildCfg) {
@@ -147,15 +162,16 @@ protected bool CheckForProduct(string aCheck, bool aCanThrow, string aKey, strin
147162
using (var xKey = Registry.LocalMachine.OpenSubKey(aKey + xSubKey)) {
148163
string xValue = (string)xKey.GetValue(aValueName);
149164
if (xValue != null && xValue.ToUpper().Contains(xCheck)) {
150-
return true;
165+
mBuildState = BuildState.Running;
166+
return true;
151167
}
152168
}
153169
}
154170

155171
if (aCanThrow) {
156-
NotFound(aCheck);
172+
NotFound(aCheck);
157173
}
158-
return false;
174+
return false;
159175
}
160176

161177
protected void CheckNet35Sp1() {
@@ -191,7 +207,7 @@ protected void CheckOS() {
191207
// 6.3 Windows 8
192208
// 6.4 Windows 10
193209
if (xVer < 6.0m) {
194-
NotFound("Minimum Supported OS is Vista/2008");
210+
NotFound("Minimum Supported OS is Vista/2008");
195211
}
196212
}
197213

@@ -207,7 +223,7 @@ protected void CheckIfBuilderRunning() {
207223
protected void CheckIfUserKitRunning() {
208224
Echo("Check if User Kit Installer is already running.");
209225
if (NumProcessesContainingName("CosmosUserKit") > 1) {
210-
throw new Exception("Another instance of the user kit installer is running.");
226+
throw new Exception("Another instance of the user kit installer is running.");
211227
}
212228
}
213229

@@ -239,7 +255,8 @@ private bool AreWeNowDebugTheBuilder() {
239255
}
240256

241257
protected void NotFound(string aName) {
242-
throw new Exception("Prerequisite '" + aName + "' not found.");
258+
mExceptionList.Add("Prerequisite '" + aName + "' not found.");
259+
mBuildState = BuildState.PrerequisiteMissing;
243260
}
244261

245262
protected void CheckPrereqs() {
@@ -248,7 +265,8 @@ protected void CheckPrereqs() {
248265

249266
Echo("Checking for x86 run.");
250267
if (!AmRunning32Bit()) {
251-
throw new Exception("Builder must run as x86");
268+
mExceptionList.Add("Builder must run as x86");
269+
mBuildState = BuildState.PrerequisiteMissing;
252270
}
253271

254272
// We assume they have normal .NET stuff if user was able to build the builder...
@@ -280,8 +298,9 @@ protected void CheckPrereqs() {
280298
}
281299
}
282300
}
283-
if (!vmWareInstalled && !bochsInstalled) { NotFound("VMWare or Bochs"); }
284-
301+
if (!vmWareInstalled && !bochsInstalled) {
302+
NotFound("VMWare or Bochs");
303+
}
285304
// VIX is installed with newer VMware Workstations (8+ for sure). VMware player does not install it?
286305
// We need to just watch this and adjust as needed.
287306
//CheckForInstall("VMWare VIX", true);
@@ -325,17 +344,23 @@ void CheckForInno() {
325344
Echo("Checking for Inno Setup");
326345
using (var xKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1", false)) {
327346
if (xKey == null) {
328-
throw new Exception("Cannot find Inno Setup.");
347+
mExceptionList.Add("Cannot find Inno Setup.");
348+
mBuildState = BuildState.PrerequisiteMissing;
349+
return;
329350
}
330351
mInnoPath = (string)xKey.GetValue("InstallLocation");
331352
if (string.IsNullOrWhiteSpace(mInnoPath)) {
332-
throw new Exception("Cannot find Inno Setup.");
353+
mExceptionList.Add("Cannot find Inno Setup.");
354+
mBuildState = BuildState.PrerequisiteMissing;
355+
return;
333356
}
334357
}
335358

336359
Echo("Checking for Inno Preprocessor");
337360
if (!File.Exists(Path.Combine(mInnoPath, "ISPP.dll"))) {
338-
throw new Exception("Inno Preprocessor not detected.");
361+
mExceptionList.Add("Inno Preprocessor not detected.");
362+
mBuildState = BuildState.PrerequisiteMissing;
363+
return;
339364
}
340365
}
341366

@@ -347,7 +372,8 @@ void CheckVs2015() {
347372
using (var xKey = Registry.LocalMachine.OpenSubKey(key)) {
348373
string xDir = (string)xKey.GetValue("InstallDir");
349374
if (String.IsNullOrWhiteSpace(xDir)) {
350-
throw new Exception("Visual Studio 2015 RC not detected!");
375+
mExceptionList.Add("Visual Studio 2015 RC not detected!");
376+
mBuildState = BuildState.PrerequisiteMissing;
351377
}
352378
}
353379
}
@@ -434,7 +460,8 @@ void CreateSetup() {
434460

435461
string xISCC = Path.Combine(mInnoPath, "ISCC.exe");
436462
if (!File.Exists(xISCC)) {
437-
throw new Exception("Cannot find Inno setup.");
463+
mExceptionList.Add("Cannot find Inno setup.");
464+
return;
438465
}
439466
string xCfg = App.IsUserKit ? "UserKit" : "DevKit";
440467
string vsVersionConfiguration = "vs2015";
@@ -459,7 +486,8 @@ void LaunchVS() {
459486

460487
string xVisualStudio = Paths.VSInstall + @"\devenv.exe";
461488
if (!File.Exists(xVisualStudio)) {
462-
throw new Exception("Cannot find Visual Studio.");
489+
mExceptionList.Add("Cannot find Visual Studio.");
490+
return;
463491
}
464492

465493
if (App.ResetHive) {
@@ -489,7 +517,8 @@ void RunSetup() {
489517
var xTimed = DateTime.Now;
490518
Echo("Waiting " + xSeconds + " seconds for Setup to start.");
491519
if (WaitForStart(setupName, xSeconds * 1000)) {
492-
throw new Exception("Setup did not start.");
520+
mExceptionList.Add("Setup did not start.");
521+
return;
493522
}
494523
Echo("Setup is running. " + DateTime.Now.Subtract(xTimed).ToString(@"ss\.fff"));
495524

source/Cosmos.Build.Installer/Task.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
using System.IO;
33
using System.Diagnostics;
44
using System.Threading;
5+
using System.Collections.Generic;
56

67
namespace Cosmos.Build.Installer {
78
public abstract class Task {
8-
protected abstract void DoRun();
9+
protected abstract List<string> DoRun();
910

1011
public void Run() {
11-
try {
12-
DoRun();
13-
} catch (Exception ex) {
14-
Log.NewSection("Error");
15-
Log.WriteLine(ex.Message);
16-
Log.SetError();
17-
}
12+
var exceptions = DoRun();
13+
if (exceptions.Count > 0) {
14+
Log.NewSection("Error");
15+
//Collect all the exceptions from the build stage, and list them
16+
foreach(var msg in exceptions) {
17+
Log.WriteLine(msg);
18+
}
19+
Log.SetError();
20+
}
21+
1822
}
1923

2024
public bool AmRunning32Bit() {
@@ -165,4 +169,4 @@ public void Echo(string aText) {
165169
mLog.WriteLine(aText);
166170
}
167171
}
168-
}
172+
}

0 commit comments

Comments
 (0)