diff --git a/CClash/CClashServer.cs b/CClash/CClashServer.cs index 037f4a6..0111fc4 100644 --- a/CClash/CClashServer.cs +++ b/CClash/CClashServer.cs @@ -29,6 +29,34 @@ public sealed class CClashServer : IDisposable public CClashServer() { Directory.SetCurrentDirectory(mydocs); + + } + + Mutex serverMutex; + + public bool Preflight(string cachedir) + { + Logging.Emit("cclash server preflight check"); + var mtx = new Mutex(false, "cclash_serv_" + cachedir.ToLower().GetHashCode()); + serverMutex = mtx; + try + { + if (!mtx.WaitOne(1000)) + { + quitnow = true; + Logging.Error("another server is already running"); + return false; // some other process is holding it! + } + else + { + Logging.Emit("cclash server preflight ok"); + } + } + catch (AbandonedMutexException) + { + Logging.Warning("previous instance did not exit cleanly!"); + } + return true; } int busyThreads = 0; @@ -158,21 +186,7 @@ void NewServerThread(string cachedir) public void Listen(string cachedir) { Environment.CurrentDirectory = mydocs; - var mtx = new Mutex(false, "cclash_serv_" + cachedir.ToLower().GetHashCode()); - try - { - - if (!mtx.WaitOne(1000)) - { - quitnow = true; - Logging.Error("another server is already running"); - return; // some other process is holding it! - } - } - catch (AbandonedMutexException) - { - Logging.Warning("previous instance did not exit cleanly!"); - } + Logging.Emit("creating direct cache server.."); cache = new DirectCompilerCacheServer(cachedir); Logging.Emit("starting server threads.."); @@ -204,8 +218,7 @@ public void Listen(string cachedir) cache.SetupStats(); Logging.Emit("server quitting"); - mtx.ReleaseMutex(); - + serverMutex.ReleaseMutex(); } public static string MakePipeName(string cachedir) diff --git a/CClash/CClashServerClient.cs b/CClash/CClashServerClient.cs index 4a41e27..e6663be 100644 --- a/CClash/CClashServerClient.cs +++ b/CClash/CClashServerClient.cs @@ -71,7 +71,7 @@ void Connect() System.Threading.Thread.Sleep(1000); ConnectClient(); } catch (Exception e) { - Logging.Emit("error starting cclash server process", e.Message); + Logging.Emit("error starting cclash server process {0}", e.ToString()); throw new CClashErrorException("could not start/connect to server"); } } diff --git a/CClash/CacheInformation.cs b/CClash/CacheInformation.cs index f6bcbf0..59feed8 100644 --- a/CClash/CacheInformation.cs +++ b/CClash/CacheInformation.cs @@ -103,7 +103,9 @@ public void Commit() public CacheInfo(FileCacheStore statCache) { cache = statCache; + Logging.Emit("creating cache info mutex"); statMtx = new Mutex(false, "cclash_stat_" + cache.FolderPath.ToLower().GetHashCode()); + Logging.Emit("created cache info mutex"); } diff --git a/CClash/Compiler.cs b/CClash/Compiler.cs index a237f3c..e0ce53e 100644 --- a/CClash/Compiler.cs +++ b/CClash/Compiler.cs @@ -150,8 +150,6 @@ public static string Find() public Compiler() { compilerExe = "cl"; - StdErrorText = new StringBuilder(1024); - StdOutputText = new StringBuilder(1024); Created = DateTime.Now; } @@ -249,9 +247,6 @@ public string[] SourceFiles public bool PdbExistsAlready { get; set; } public string ResponseFile { get; set; } - public StringBuilder StdErrorText { get; private set; } - public StringBuilder StdOutputText { get; private set; } - public Action StdErrorCallback { get; set; } public Action StdOutputCallback { get; set; } @@ -806,11 +801,10 @@ public int InvokeCompiler(IEnumerable args, Action onStdErr, Act } else { - if (onStdOut != null) onStdOut(a.Data); - lock (StdOutputText) - { - StdOutputText.AppendLine(a.Data); - } + if (StdOutputCallback != null) + StdOutputCallback(a.Data); + if (onStdOut != null) + onStdOut(a.Data); } } @@ -820,20 +814,14 @@ public int InvokeCompiler(IEnumerable args, Action onStdErr, Act { if (a.Data != null) { + if (StdErrorCallback != null) + StdErrorCallback(a.Data); if (onStdErr != null) - { - onStdErr(a.Data); - } - lock (StdErrorText) - { - StdErrorText.AppendLine(a.Data); - } } }; p.BeginErrorReadLine(); - p.BeginOutputReadLine(); p.WaitForExit(); @@ -861,11 +849,7 @@ public int InvokeCompiler(IEnumerable args, Action onStdErr, Act { string logmsg = string.Format("cl exited with zero but failed to create the object file! {0}", ObjectTarget); // let the retry system have a go with this - Logging.Warning("stderr was {0}", StdErrorText.ToString()); - if (onStdErr != null) - { - onStdErr(logmsg); - } + Logging.Warning("{0}, re-running!", logmsg); retry = true; } diff --git a/CClash/CompilerCacheBase.cs b/CClash/CompilerCacheBase.cs index fcfd814..0857ab3 100644 --- a/CClash/CompilerCacheBase.cs +++ b/CClash/CompilerCacheBase.cs @@ -51,12 +51,19 @@ public abstract class CompilerCacheBase : IDisposable ICacheInfo stats = null; - public CompilerCacheBase(string cacheFolder) + protected CompilerCacheBase() { + } + + public CompilerCacheBase(string cacheFolder) : this() + { + Logging.Emit("setting up file stores"); if (string.IsNullOrEmpty(cacheFolder)) throw new ArgumentNullException("cacheFolder"); outputCache = FileCacheStore.Load(Path.Combine(cacheFolder, "outputs")); includeCache = FileCacheStore.Load(Path.Combine(cacheFolder, "includes")); + Logging.Emit("setup cache info"); stats = new CacheInfo(outputCache); + Logging.Emit("setup hasher"); hasher = new HashUtil(includeCache); } diff --git a/CClash/DirectCompilerCache.cs b/CClash/DirectCompilerCache.cs index 336532e..07406b0 100644 --- a/CClash/DirectCompilerCache.cs +++ b/CClash/DirectCompilerCache.cs @@ -10,6 +10,7 @@ public class DirectCompilerCache : CompilerCacheBase, ICompilerCache public DirectCompilerCache(string cacheFolder) : base(cacheFolder) { + Logging.Emit("direct compiler cache"); } public FileCacheStore OutputCache diff --git a/CClash/DirectCompilerCacheServer.cs b/CClash/DirectCompilerCacheServer.cs index 478aa38..6ffc49b 100644 --- a/CClash/DirectCompilerCacheServer.cs +++ b/CClash/DirectCompilerCacheServer.cs @@ -19,6 +19,7 @@ public DirectCompilerCacheServer(string cachedir) { SetupStats(); base.includeCache.CacheEntryChecksInMemory = true; + Logging.Emit("server locking cache data"); base.Lock(CacheLockType.ReadWrite); // base is a multi-process lock, keep this forever } diff --git a/CClash/FileCacheStore.cs b/CClash/FileCacheStore.cs index bcb66bb..cbef3b0 100644 --- a/CClash/FileCacheStore.cs +++ b/CClash/FileCacheStore.cs @@ -36,7 +36,7 @@ public void ReleaseMutex() { FolderPath = Path.GetFullPath(folderPath); mtx = new Mutex(false, "cclash_mtx_" + FolderPath.ToLower().GetHashCode()); - + Logging.Emit("locking file store: {0}", FolderPath); WaitOne(); var tlist = new List(); @@ -57,12 +57,18 @@ public void ReleaseMutex() if (bad_cache_format) { + Logging.Emit("corrupt filestore, deleting: {0}", FolderPath); // cache is too old, wiping Directory.Delete(FolderPath, true); Directory.CreateDirectory(FolderPath); File.WriteAllText(Path.Combine(FolderPath, CacheInfo.F_CacheVersion), CacheInfo.CacheFormat); } } + Logging.Emit("filestore ready: {0}", FolderPath); + } + catch (IOException) + { + throw new CClashErrorException("could not clear cache!"); } catch (UnauthorizedAccessException uae) { diff --git a/CClash/ICompiler.cs b/CClash/ICompiler.cs index 4bce7e9..bd707fe 100644 --- a/CClash/ICompiler.cs +++ b/CClash/ICompiler.cs @@ -37,9 +37,6 @@ public interface ICompiler Action StdErrorCallback { get; set; } Action StdOutputCallback { get; set; } - StringBuilder StdErrorText { get; } - StringBuilder StdOutputText { get; } - } } diff --git a/CClash/NullCompilerCache.cs b/CClash/NullCompilerCache.cs index 316ab7a..95e2224 100644 --- a/CClash/NullCompilerCache.cs +++ b/CClash/NullCompilerCache.cs @@ -8,7 +8,7 @@ namespace CClash { public class NullCompilerCache : CompilerCacheBase , ICompilerCache { public NullCompilerCache(string cachedir) - : base(cachedir) { + : base() { } public override void Setup() { diff --git a/CClash/Program.cs b/CClash/Program.cs index 0b178c8..fbcfd84 100644 --- a/CClash/Program.cs +++ b/CClash/Program.cs @@ -42,7 +42,7 @@ public static int Main(string[] args) if (args.Contains("--cclash-server")) { - var server = new CClashServer(); + if (args.Contains("--attempt-pdb")) { Environment.SetEnvironmentVariable("CCLASH_ATTEMPT_PDB_CACHE", "yes"); @@ -52,15 +52,34 @@ public static int Main(string[] args) Environment.SetEnvironmentVariable("CCLASH_Z7_OBJ", "yes"); } + if (Settings.DebugEnabled) + { + if (Settings.DebugFile != null) + { + Settings.DebugFile += ".serv"; + } + } + if (args.Contains("--debug")) { if (Settings.DebugFile == null) { Settings.DebugFile = "Console"; Settings.DebugEnabled = true; } } - Server = server; - server.Listen(Settings.CacheDirectory); - return 0; + + Logging.Emit("starting in server mode"); + Server = new CClashServer(); + if (Server.Preflight(Settings.CacheDirectory)) + { + Logging.Emit("server created"); + Server.Listen(Settings.CacheDirectory); + return 0; + } + else + { + Logging.Emit("another server is running.. quitting"); + return 1; + } } if (args.Contains("--cclash")) @@ -144,12 +163,12 @@ public static int Main(string[] args) static void AppendStderr(string str) { - MainStdErr.AppendLine(str); + MainStdErr.AppendLine(str.TrimEnd('\n', '\r')); } static void AppendStdout(string str) { - MainStdOut.AppendLine(str); + MainStdOut.AppendLine(str.TrimEnd('\n', '\r')); } private static int RunBuild(string[] args, DateTime start, Action stdout, Action stderr) diff --git a/Installer/Installer/Express/DVD-5/DiskImages/DISK1/CClash.msi b/Installer/Installer/Express/DVD-5/DiskImages/DISK1/CClash.msi index 3cebabf..3eb04ed 100644 Binary files a/Installer/Installer/Express/DVD-5/DiskImages/DISK1/CClash.msi and b/Installer/Installer/Express/DVD-5/DiskImages/DISK1/CClash.msi differ diff --git a/Installer/Installer/Express/DVD-5/DiskImages/DISK1/Setup.ini b/Installer/Installer/Express/DVD-5/DiskImages/DISK1/Setup.ini index 9c3ed71..10f349d 100644 Binary files a/Installer/Installer/Express/DVD-5/DiskImages/DISK1/Setup.ini and b/Installer/Installer/Express/DVD-5/DiskImages/DISK1/Setup.ini differ diff --git a/cclash.v11.suo b/cclash.v11.suo index eeffef3..d3bcb9c 100644 Binary files a/cclash.v11.suo and b/cclash.v11.suo differ