Skip to content

Commit

Permalink
Merge pull request CosmosOS#185 from sgetaz/master
Browse files Browse the repository at this point in the history
List all requirements 1-by-1
  • Loading branch information
mterwoord committed Sep 2, 2015
2 parents 59c2bba + f6b9f45 commit a2412e8
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 42 deletions.
95 changes: 62 additions & 33 deletions source/Cosmos.Build.Builder/CosmosTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@
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");
Expand Down Expand Up @@ -71,26 +80,31 @@ void CleanupAlreadyInstalled() {
}
}

protected override void DoRun() {
protected override List<string> DoRun() {
mOutputDir = Path.Combine(mCosmosDir, @"Build\VSIP");

if (!App.TestMode) {
CheckPrereqs(); //Working
CleanupVSIPFolder();

CompileCosmos(); //Working
CopyTemplates();

CreateScriptToUseChangesetWhichTaskIsUse();

CreateSetup(); //Working
if (!App.IsUserKit) {
CleanupAlreadyInstalled(); //Working
RunSetup(); //Working - forgot to run as user kit first
WriteDevKit(); //Working
if (!App.DoNotLaunchVS) { LaunchVS(); } //Working
// 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();

CreateScriptToUseChangesetWhichTaskIsUse();

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...");
Expand All @@ -114,6 +128,7 @@ protected override void DoRun() {

//Done();
}
return mExceptionList;
}

protected void MsBuild(string aSlnFile, string aBuildCfg) {
Expand Down Expand Up @@ -147,15 +162,16 @@ protected bool CheckForProduct(string aCheck, bool aCanThrow, string aKey, strin
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() {
Expand Down Expand Up @@ -191,7 +207,7 @@ protected void CheckOS() {
// 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");
}
}

Expand All @@ -207,7 +223,7 @@ protected void CheckIfBuilderRunning() {
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.");
}
}

Expand Down Expand Up @@ -239,7 +255,8 @@ private bool AreWeNowDebugTheBuilder() {
}

protected void NotFound(string aName) {
throw new Exception("Prerequisite '" + aName + "' not found.");
mExceptionList.Add("Prerequisite '" + aName + "' not found.");
mBuildState = BuildState.PrerequisiteMissing;
}

protected void CheckPrereqs() {
Expand All @@ -248,7 +265,8 @@ protected void CheckPrereqs() {

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...
Expand Down Expand Up @@ -280,8 +298,9 @@ protected void CheckPrereqs() {
}
}
}
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);
Expand Down Expand Up @@ -325,17 +344,23 @@ void CheckForInno() {
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;
}
}

Expand All @@ -347,7 +372,8 @@ void CheckVs2015() {
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;
}
}
}
Expand Down Expand Up @@ -434,7 +460,8 @@ void CreateSetup() {

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";
Expand All @@ -459,7 +486,8 @@ void LaunchVS() {

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) {
Expand Down Expand Up @@ -489,7 +517,8 @@ void RunSetup() {
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"));

Expand Down
22 changes: 13 additions & 9 deletions source/Cosmos.Build.Installer/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
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) {
Log.NewSection("Error");
Log.WriteLine(ex.Message);
Log.SetError();
}
var exceptions = DoRun();
if (exceptions.Count > 0) {
Log.NewSection("Error");
//Collect all the exceptions from the build stage, and list them
foreach(var msg in exceptions) {
Log.WriteLine(msg);
}
Log.SetError();
}

}

public bool AmRunning32Bit() {
Expand Down Expand Up @@ -165,4 +169,4 @@ public void Echo(string aText) {
mLog.WriteLine(aText);
}
}
}
}

0 comments on commit a2412e8

Please sign in to comment.