Merge pull request #1 from sgetaz/Requirements-list

List requirements 1-by-1
This commit is contained in:
sgetaz 2015-08-09 17:32:19 +02:00
commit 1c710704fb
2 changed files with 68 additions and 37 deletions

View file

@ -8,16 +8,25 @@ using System.IO;
using Microsoft.Win32;
using System.Windows;
public enum BuildState
{
CleanupError,
CompilationError,
PrerequisiteMissing,
Running
}
namespace Cosmos.Build.Builder {
public class CosmosTask : Task {
protected string mCosmosDir;
protected string mOutputDir;
protected BuildState mBuildState;
protected string mAppDataDir;
protected int mReleaseNo;
protected string mInnoFile;
protected string mInnoPath;
// Instead of throwing every exception, we collect them in a list
protected List<string> mExceptionList = new List<string>();
public string InnoScriptTargetFile = "Current.iss";
public CosmosTask(string aCosmosDir, int aReleaseNo) {
mCosmosDir = aCosmosDir;
mAppDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Cosmos User Kit");
@ -71,26 +80,31 @@ namespace Cosmos.Build.Builder {
}
}
protected override void DoRun() {
protected override List<string> DoRun() {
mOutputDir = Path.Combine(mCosmosDir, @"Build\VSIP");
if (!App.TestMode) {
CheckPrereqs(); //Working
CleanupVSIPFolder();
// No point in continuing if Prerequisites are missing
// Could potentially add more State checks in the future, but for now
// only the prerequisites are handled...
if (mBuildState != BuildState.PrerequisiteMissing)
{
CleanupVSIPFolder();
CompileCosmos(); //Working
CopyTemplates();
CompileCosmos(); //Working
CopyTemplates();
CreateScriptToUseChangesetWhichTaskIsUse();
CreateScriptToUseChangesetWhichTaskIsUse();
CreateSetup(); //Working
if (!App.IsUserKit) {
CleanupAlreadyInstalled(); //Working
RunSetup(); //Working - forgot to run as user kit first
WriteDevKit(); //Working
if (!App.DoNotLaunchVS) { LaunchVS(); } //Working
CreateSetup(); //Working
if (!App.IsUserKit)
{
CleanupAlreadyInstalled(); //Working
RunSetup(); //Working - forgot to run as user kit first
WriteDevKit(); //Working
if (!App.DoNotLaunchVS) { LaunchVS(); } //Working
}
}
Done();
} else {
Section("Testing...");
@ -114,6 +128,7 @@ namespace Cosmos.Build.Builder {
//Done();
}
return mExceptionList;
}
protected void MsBuild(string aSlnFile, string aBuildCfg) {
@ -147,15 +162,16 @@ namespace Cosmos.Build.Builder {
using (var xKey = Registry.LocalMachine.OpenSubKey(aKey + xSubKey)) {
string xValue = (string)xKey.GetValue(aValueName);
if (xValue != null && xValue.ToUpper().Contains(xCheck)) {
return true;
mBuildState = BuildState.Running;
return true;
}
}
}
if (aCanThrow) {
NotFound(aCheck);
NotFound(aCheck);
}
return false;
return false;
}
protected void CheckNet35Sp1() {
@ -191,7 +207,7 @@ namespace Cosmos.Build.Builder {
// 6.3 Windows 8
// 6.4 Windows 10
if (xVer < 6.0m) {
NotFound("Minimum Supported OS is Vista/2008");
NotFound("Minimum Supported OS is Vista/2008");
}
}
@ -207,7 +223,7 @@ namespace Cosmos.Build.Builder {
protected void CheckIfUserKitRunning() {
Echo("Check if User Kit Installer is already running.");
if (NumProcessesContainingName("CosmosUserKit") > 1) {
throw new Exception("Another instance of the user kit installer is running.");
throw new Exception("Another instance of the user kit installer is running.");
}
}
@ -239,7 +255,8 @@ namespace Cosmos.Build.Builder {
}
protected void NotFound(string aName) {
throw new Exception("Prerequisite '" + aName + "' not found.");
mExceptionList.Add("Prerequisite '" + aName + "' not found.");
mBuildState = BuildState.PrerequisiteMissing;
}
protected void CheckPrereqs() {
@ -248,7 +265,8 @@ namespace Cosmos.Build.Builder {
Echo("Checking for x86 run.");
if (!AmRunning32Bit()) {
throw new Exception("Builder must run as x86");
mExceptionList.Add("Builder must run as x86");
mBuildState = BuildState.PrerequisiteMissing;
}
// We assume they have normal .NET stuff if user was able to build the builder...
@ -280,8 +298,9 @@ namespace Cosmos.Build.Builder {
}
}
}
if (!vmWareInstalled && !bochsInstalled) { NotFound("VMWare or Bochs"); }
if (!vmWareInstalled && !bochsInstalled) {
NotFound("VMWare or Bochs");
}
// VIX is installed with newer VMware Workstations (8+ for sure). VMware player does not install it?
// We need to just watch this and adjust as needed.
//CheckForInstall("VMWare VIX", true);
@ -325,17 +344,23 @@ namespace Cosmos.Build.Builder {
Echo("Checking for Inno Setup");
using (var xKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1", false)) {
if (xKey == null) {
throw new Exception("Cannot find Inno Setup.");
mExceptionList.Add("Cannot find Inno Setup.");
mBuildState = BuildState.PrerequisiteMissing;
return;
}
mInnoPath = (string)xKey.GetValue("InstallLocation");
if (string.IsNullOrWhiteSpace(mInnoPath)) {
throw new Exception("Cannot find Inno Setup.");
mExceptionList.Add("Cannot find Inno Setup.");
mBuildState = BuildState.PrerequisiteMissing;
return;
}
}
Echo("Checking for Inno Preprocessor");
if (!File.Exists(Path.Combine(mInnoPath, "ISPP.dll"))) {
throw new Exception("Inno Preprocessor not detected.");
mExceptionList.Add("Inno Preprocessor not detected.");
mBuildState = BuildState.PrerequisiteMissing;
return;
}
}
@ -347,7 +372,8 @@ namespace Cosmos.Build.Builder {
using (var xKey = Registry.LocalMachine.OpenSubKey(key)) {
string xDir = (string)xKey.GetValue("InstallDir");
if (String.IsNullOrWhiteSpace(xDir)) {
throw new Exception("Visual Studio 2015 RC not detected!");
mExceptionList.Add("Visual Studio 2015 RC not detected!");
mBuildState = BuildState.PrerequisiteMissing;
}
}
}
@ -434,7 +460,8 @@ namespace Cosmos.Build.Builder {
string xISCC = Path.Combine(mInnoPath, "ISCC.exe");
if (!File.Exists(xISCC)) {
throw new Exception("Cannot find Inno setup.");
mExceptionList.Add("Cannot find Inno setup.");
return;
}
string xCfg = App.IsUserKit ? "UserKit" : "DevKit";
string vsVersionConfiguration = "vs2015";
@ -459,7 +486,8 @@ namespace Cosmos.Build.Builder {
string xVisualStudio = Paths.VSInstall + @"\devenv.exe";
if (!File.Exists(xVisualStudio)) {
throw new Exception("Cannot find Visual Studio.");
mExceptionList.Add("Cannot find Visual Studio.");
return;
}
if (App.ResetHive) {
@ -489,7 +517,8 @@ namespace Cosmos.Build.Builder {
var xTimed = DateTime.Now;
Echo("Waiting " + xSeconds + " seconds for Setup to start.");
if (WaitForStart(setupName, xSeconds * 1000)) {
throw new Exception("Setup did not start.");
mExceptionList.Add("Setup did not start.");
return;
}
Echo("Setup is running. " + DateTime.Now.Subtract(xTimed).ToString(@"ss\.fff"));

View file

@ -2,19 +2,21 @@
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Collections.Generic;
namespace Cosmos.Build.Installer {
public abstract class Task {
protected abstract void DoRun();
protected abstract List<string> DoRun();
public void Run() {
try {
DoRun();
} catch (Exception ex) {
var exceptions = DoRun();
Log.NewSection("Error");
Log.WriteLine(ex.Message);
//Collect all the exceptions from the build stage, and list them
foreach(var msg in exceptions)
{
Log.WriteLine(msg);
}
Log.SetError();
}
}
public bool AmRunning32Bit() {