Skip to content

Commit

Permalink
Builder improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa committed Mar 27, 2018
1 parent 49c1221 commit e10351d
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 220 deletions.
49 changes: 25 additions & 24 deletions source/Cosmos.Build.Builder/CosmosTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Cosmos.Build.Builder {
/// Cosmos task.
/// </summary>
/// <seealso cref="Cosmos.Build.Installer.Task" />
public class CosmosTask : Task {
internal class CosmosTask : Tasks.Task {
private string mCosmosPath; // Root Cosmos dir
private string mVsipPath; // Build/VSIP
private string mAppDataPath; // User Kit in AppData
Expand All @@ -27,7 +27,8 @@ public class CosmosTask : Task {
private int mReleaseNo;
private List<string> mExceptionList = new List<string>();

public CosmosTask(string aCosmosDir, int aReleaseNo) {
public CosmosTask(ILogger logger, string aCosmosDir, int aReleaseNo)
: base(logger) {
mCosmosPath = aCosmosDir;
mVsipPath = Path.Combine(mCosmosPath, @"Build\VSIP");
mSourcePath = Path.Combine(mCosmosPath, "source");
Expand Down Expand Up @@ -56,11 +57,11 @@ public static string GetSetupName(int releaseNumber) {

private void CleanDirectory(string aName, string aPath) {
if (Directory.Exists(aPath)) {
Log.WriteLine("Cleaning up existing " + aName + " directory.");
Logger.LogMessage("Cleaning up existing " + aName + " directory.");
Directory.Delete(aPath, true);
}

Log.WriteLine("Creating " + aName + " as " + aPath);
Logger.LogMessage("Creating " + aName + " as " + aPath);
Directory.CreateDirectory(aPath);
}

Expand Down Expand Up @@ -111,15 +112,15 @@ protected int NumProcessesContainingName(string name) {

protected void CheckIfBuilderRunning() {
//Check for builder process
Log.WriteLine("Check if Builder is running.");
Logger.LogMessage("Check if Builder is running.");
// Check > 1 so we exclude ourself.
if (NumProcessesContainingName("Cosmos.Build.Builder") > 1) {
throw new Exception("Another instance of builder is running.");
}
}

protected void CheckIfUserKitRunning() {
Log.WriteLine("Check if User Kit Installer is already running.");
Logger.LogMessage("Check if User Kit Installer is already running.");
if (NumProcessesContainingName("CosmosUserKit") > 0) {
throw new Exception("Another instance of the user kit installer is running.");
}
Expand All @@ -129,34 +130,34 @@ protected void CheckIfVSandCoRunning() {
bool xRunningFound = false;
if (IsRunning("devenv")) {
xRunningFound = true;
Log.WriteLine("--Visual Studio is running.");
Logger.LogMessage("--Visual Studio is running.");
}
if (IsRunning("VSIXInstaller")) {
xRunningFound = true;
Log.WriteLine("--VSIXInstaller is running.");
Logger.LogMessage("--VSIXInstaller is running.");
}
if (IsRunning("ServiceHub.IdentityHost")) {
xRunningFound = true;
Log.WriteLine("--ServiceHub.IdentityHost is running.");
Logger.LogMessage("--ServiceHub.IdentityHost is running.");
}
if (IsRunning("ServiceHub.VSDetouredHost")) {
xRunningFound = true;
Log.WriteLine("--ServiceHub.VSDetouredHost is running.");
Logger.LogMessage("--ServiceHub.VSDetouredHost is running.");
}
if (IsRunning("ServiceHub.Host.Node.x86")) {
xRunningFound = true;
Log.WriteLine("--ServiceHub.Host.Node.x86 is running.");
Logger.LogMessage("--ServiceHub.Host.Node.x86 is running.");
}
if (IsRunning("ServiceHub.SettingsHost")) {
xRunningFound = true;
Log.WriteLine("--ServiceHub.SettingsHost is running.");
Logger.LogMessage("--ServiceHub.SettingsHost is running.");
}
if (IsRunning("ServiceHub.Host.CLR.x86")) {
xRunningFound = true;
Log.WriteLine("--ServiceHub.Host.CLR.x86 is running.");
Logger.LogMessage("--ServiceHub.Host.CLR.x86 is running.");
}
if (xRunningFound) {
Log.WriteLine("--Running blockers found. Setup will warning you and wait for it.");
Logger.LogMessage("--Running blockers found. Setup will warning you and wait for it.");
}
}

Expand All @@ -182,7 +183,7 @@ protected bool PrereqsOK() {

private void CheckForRepos()
{
Log.WriteLine("Checking for existing IL2CPU and XSharp repositories...");
Logger.LogMessage("Checking for existing IL2CPU and XSharp repositories...");
if (!Directory.Exists(mIL2CPUPath))
{
if (!File.Exists(Path.Combine(mIL2CPUPath, @"IL2CPU.sln")))
Expand All @@ -204,7 +205,7 @@ private void CheckForRepos()
}

private void CheckForInno() {
Log.WriteLine("Check for Inno Setup");
Logger.LogMessage("Check for Inno Setup");
using (var xLocalMachineKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) {
using (var xKey = xLocalMachineKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 5_is1", false)) {
if (xKey == null) {
Expand All @@ -221,7 +222,7 @@ private void CheckForInno() {
}
}

Log.WriteLine("Check for Inno Preprocessor");
Logger.LogMessage("Check for Inno Preprocessor");
if (!File.Exists(Path.Combine(mInnoPath, "ISPP.dll"))) {
mExceptionList.Add("Inno Preprocessor not detected.");
mBuildState = BuildState.PrerequisiteMissing;
Expand All @@ -230,7 +231,7 @@ private void CheckForInno() {
}

private void CheckForNetCore() {
Log.WriteLine("Check for .NET Core");
Logger.LogMessage("Check for .NET Core");

if (!Paths.VSInstancePackages.Contains("Microsoft.VisualStudio.Workload.NetCoreTools")) {
mExceptionList.Add(".NET Core not detected.");
Expand All @@ -239,7 +240,7 @@ private void CheckForNetCore() {
}

private void CheckForVisualStudioExtensionTools() {
Log.WriteLine("Check for Visual Studio Extension Tools");
Logger.LogMessage("Check for Visual Studio Extension Tools");

if (!Paths.VSInstancePackages.Contains("Microsoft.VisualStudio.Workload.VisualStudioExtension")) {
mExceptionList.Add("Visual Studio Extension tools not detected.");
Expand Down Expand Up @@ -269,7 +270,7 @@ private void Clean(string project)

var xStart = new ProcessStartInfo();
xStart.FileName = xNuget;
xStart.WorkingDirectory = CurrPath;
xStart.WorkingDirectory = Directory.GetCurrentDirectory();
xStart.Arguments = xListParams;
xStart.UseShellExecute = false;
xStart.CreateNoWindow = true;
Expand Down Expand Up @@ -391,7 +392,7 @@ private void CompileCosmos() {
private void CopyTemplates() {
Section("Copy Templates");

using (var x = new FileMgr(Path.Combine(mSourcePath, @"Cosmos.VS.Package\obj\Debug"), mVsipPath)) {
using (var x = new FileMgr(Logger, Path.Combine(mSourcePath, @"Cosmos.VS.Package\obj\Debug"), mVsipPath)) {
x.Copy("CosmosProject (C#).zip");
x.Copy("CosmosKernel (C#).zip");
x.Copy("CosmosProject (F#).zip");
Expand All @@ -418,7 +419,7 @@ private void CreateSetup() {
if (App.BuilderConfiguration.VsExpHive) {
vsVersionConfiguration += "Exp";
}
Log.WriteLine($" {xISCC} /Q {Quoted(mInnoFile)} /dBuildConfiguration={xCfg} /dVSVersion={vsVersionConfiguration} /dChangeSetVersion={Quoted(mReleaseNo.ToString())}");
Logger.LogMessage($" {xISCC} /Q {Quoted(mInnoFile)} /dBuildConfiguration={xCfg} /dVSVersion={vsVersionConfiguration} /dChangeSetVersion={Quoted(mReleaseNo.ToString())}");
StartConsole(xISCC, $"/Q {Quoted(mInnoFile)} /dBuildConfiguration={xCfg} /dVSVersion={vsVersionConfiguration} /dChangeSetVersion={Quoted(mReleaseNo.ToString())}");
}

Expand All @@ -432,11 +433,11 @@ private void LaunchVS() {
}

if (App.BuilderConfiguration.ResetHive) {
Log.WriteLine("Resetting hive");
Logger.LogMessage("Resetting hive");
Start(xVisualStudio, @"/setup /rootsuffix Exp /ranu");
}

Log.WriteLine("Launching Visual Studio");
Logger.LogMessage("Launching Visual Studio");
Start(xVisualStudio, Quoted(mCosmosPath + @"Kernel.sln"), false, true);
}

Expand Down
107 changes: 57 additions & 50 deletions source/Cosmos.Build.Builder/FileMgr.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,65 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cosmos.Build.Installer;

namespace Cosmos.Build.Builder {
public class FileMgr : IDisposable {
public string SrcPath;
public string DestPath;

public FileMgr(string aSrcPath, string aDestPath) {
SrcPath = aSrcPath;
DestPath = aDestPath;
}

public void ResetReadOnly(string aPathname) {
var xAttrib = File.GetAttributes(aPathname);
if ((xAttrib & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) {
File.SetAttributes(aPathname, xAttrib & ~FileAttributes.ReadOnly);
}
}
namespace Cosmos.Build.Builder
{
internal class FileMgr : IDisposable
{
private string _srcPath;
private string _destPath;
private ILogger _logger;

public void Copy(string aSrcPathname, bool aClearReadonly = true) {
Copy(aSrcPathname, Path.GetFileName(aSrcPathname), aClearReadonly);
}
public void Copy(string aSrcPathname, string aDestPathname, bool aClearReadonly = true) {
Log.WriteLine("Copy");

string xSrc = Path.Combine(SrcPath, aSrcPathname);
Log.WriteLine(" From: " + xSrc);

string xDest = Path.Combine(DestPath, aDestPathname);
Log.WriteLine(" To: " + xDest);

// Copying files that are in TFS often they will be read only, so need to kill this file before copy
// We don't use TFS any more.. but left the code.
if (aClearReadonly && File.Exists(xDest)) {
ResetReadOnly(xDest);
}
File.Copy(xSrc, xDest, true);
ResetReadOnly(xDest);
}
public FileMgr(ILogger logger, string srcPath, string destPath)
{
_srcPath = srcPath;
_destPath = destPath;
_logger = logger;
}

// Dummy pattern to allow scoping via using.
// Hacky, but for what we are doing its fine and the GC
// effects are negligible in our usage.
protected virtual void Dispose(bool aDisposing) {
}
public void ResetReadOnly(string aPathname)
{
var xAttrib = File.GetAttributes(aPathname);
if ((xAttrib & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
File.SetAttributes(aPathname, xAttrib & ~FileAttributes.ReadOnly);
}
}

public void Dispose() {
Dispose(true);
}
public void Copy(string aSrcPathname, bool aClearReadonly = true)
{
Copy(aSrcPathname, Path.GetFileName(aSrcPathname), aClearReadonly);
}
public void Copy(string aSrcPathname, string aDestPathname, bool aClearReadonly = true)
{
_logger.LogMessage("Copy");

}
string xSrc = Path.Combine(_srcPath, aSrcPathname);
_logger.LogMessage(" From: " + xSrc);

string xDest = Path.Combine(_destPath, aDestPathname);
_logger.LogMessage(" To: " + xDest);

// Copying files that are in TFS often they will be read only, so need to kill this file before copy
// We don't use TFS any more.. but left the code.
if (aClearReadonly && File.Exists(xDest))
{
ResetReadOnly(xDest);
}
File.Copy(xSrc, xDest, true);
ResetReadOnly(xDest);
}

// Dummy pattern to allow scoping via using.
// Hacky, but for what we are doing its fine and the GC
// effects are negligible in our usage.
protected virtual void Dispose(bool aDisposing)
{
}

public void Dispose()
{
Dispose(true);
}

}
}
9 changes: 9 additions & 0 deletions source/Cosmos.Build.Builder/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Cosmos.Build.Builder
{
internal interface ILogger
{
void NewSection(string name);
void LogMessage(string text);
void SetError();
}
}
24 changes: 0 additions & 24 deletions source/Cosmos.Build.Builder/Log.cs

This file was deleted.

Loading

0 comments on commit e10351d

Please sign in to comment.