public void ParseSupportedArgs(params string[] argv) { var c = new Compiler(); c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); var sbo = new StringBuilder(); var sbe = new StringBuilder(); Assert.IsTrue(c.ProcessArguments(argv)); Assert.IsFalse(c.Linking); Assert.IsTrue(c.SingleSource); Assert.IsNotNullOrEmpty(c.ObjectTarget); Assert.IsFalse(c.PrecompiledHeaders); Assert.AreNotEqual(c.SingleSourceFile, c.ObjectTarget); EnsureDeleted(c.ObjectTarget); EnsureDeleted(c.PdbFile); c.CompilerExe = CompilerPath; c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); var ec = c.InvokeCompiler( c.CommandLine, Console.Error.WriteLine, Console.Error.WriteLine, false, null); Assert.AreEqual(0, ec); Assert.IsTrue(File.Exists(c.ObjectTarget)); }
public ICompiler SetCompiler(string compiler, string workdir, System.Collections.Generic.Dictionary<string,string> envs ) { if (string.IsNullOrEmpty(compiler)) throw new ArgumentNullException("compiler"); if (string.IsNullOrEmpty(workdir)) throw new ArgumentNullException("workdir"); environment = envs; workingdir = workdir; compilerPath = System.IO.Path.GetFullPath(compiler); try { Connect(); } catch (CClashServerNotReadyException) { var c = new Compiler() { CompilerExe = compiler }; c.SetWorkingDirectory(workdir); c.SetEnvironment(envs); return c; } return null; }
public void CompileObjectTest(params string[] argv) { var c = new Compiler() { CompilerExe = CompilerPath }; c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); Assert.IsTrue(c.ProcessArguments(argv)); Assert.AreEqual(1, c.CliIncludePaths.Count); Assert.AreEqual( Path.Combine(InitialDir, "test-sources\\inc with spaces"), c.CliIncludePaths[0]); Assert.AreEqual( Path.Combine(InitialDir, "test-sources\\hello.c"), c.SingleSourceFile); var stderr = new StringBuilder(); var stdout = new StringBuilder(); var rv = c.InvokeCompiler(c.CommandLine, x => stderr.Append(x), x => stdout.Append(x), false, null); Assert.AreEqual(0, rv); }
public void DetectNotSupported(params string[] argv) { var c = new Compiler() { CompilerExe = CompilerPath }; c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); Assert.IsFalse(c.ProcessArguments(argv)); }
public void IncludeFileTest(params string[] argv) { var c = new Compiler() { CompilerExe = CompilerPath }; var hv = new List<string>(); c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); Assert.IsTrue(c.ProcessArguments(argv)); hv.Add(Path.GetFullPath(c.SingleSourceFile)); List<string> incfiles = new List<string>(); var rv = c.InvokeCompiler(argv, Console.Error.Write, Console.Out.Write, true, incfiles); hv.AddRange(incfiles); Assert.AreEqual(0, rv); Assert.IsTrue(hv.Count > 0); }
public void PreprocessorTest(params string[] argv) { var c = new Compiler() { CompilerExe = CompilerPath }; c.SetWorkingDirectory(InitialDir); c.SetEnvironment(Compiler.GetEnvironmentDictionary()); var supported = c.ProcessArguments(argv); Assert.IsTrue(supported); Assert.AreEqual(1, c.CliIncludePaths.Count); Assert.AreEqual( Path.Combine(InitialDir, "test-sources\\inc with spaces"), c.CliIncludePaths[0]); Assert.AreEqual( Path.Combine(InitialDir, "test-sources\\hello.c"), c.SingleSourceFile); using (var sw = new StreamWriter(new MemoryStream())) { var rv = c.InvokePreprocessor(sw); Assert.AreEqual(0, rv); } }
public void ParseUnSupportedArgs(params string[] argv) { var c = new Compiler(); c.SetWorkingDirectory(InitialDir); Assert.IsFalse(c.ProcessArguments(argv)); }
public void ParseSupportedDebugArgs(params string[] argv) { var c = new Compiler(); c.SetWorkingDirectory(InitialDir); c.CompilerExe = CompilerPath; Assert.IsTrue(c.ProcessArguments(argv)); Assert.IsFalse(c.GeneratePdb); }
public void ParseSupportedPdbArgs(params string[] argv) { Assert.IsFalse(Settings.AttemptPDBCaching); var c = new Compiler(); c.SetWorkingDirectory(InitialDir); c.CompilerExe = CompilerPath; Assert.IsFalse(c.ProcessArguments(argv)); }
public ICompiler SetCompiler(string compiler, string workdir, Dictionary<string,string> envs) { if (string.IsNullOrEmpty(compiler)) throw new ArgumentNullException("compiler"); compilerPath = System.IO.Path.GetFullPath(compiler); var comp = new Compiler() { CompilerExe = compilerPath }; comp.SetWorkingDirectory(workdir); comp.SetEnvironment(envs); return comp; }
private static int RunBuild(string[] args, DateTime start, Action<string> stdout, Action<string> stderr) { Logging.Emit("client mode = {0}", Settings.ServiceMode); try { if (!Settings.Disabled) { string compiler = Compiler.Find(); if (compiler == null) throw new System.IO.FileNotFoundException("cant find real cl compiler"); var cachedir = Settings.CacheDirectory; Logging.Emit("compiler: {0}", compiler); ICompiler comp; using (ICompilerCache cc = CompilerCacheFactory.Get(Settings.DirectMode, cachedir, compiler, Environment.CurrentDirectory, Compiler.GetEnvironmentDictionary(), out comp)) { if (comp != null) spawnServer = true; cc.SetCaptureCallback(comp, stdout, stderr); return cc.CompileOrCache(comp, args); } } else { Logging.Emit("disabled by environment"); } } catch (CClashWarningException e) { Logging.Warning(e.Message); } catch (Exception e) { Logging.Emit("{0} after {1} ms", e.GetType().Name, DateTime.Now.Subtract(start).TotalMilliseconds); Logging.Emit("{0} {1}", e.GetType().Name + " message: " + e.Message); #if DEBUG Logging.Error("Exception from cacher {0}!!!", e); #endif } int rv = -1; try { var c = new Compiler() { CompilerExe = Compiler.Find(), }; c.SetEnvironment(Compiler.GetEnvironmentDictionary()); c.SetWorkingDirectory(Environment.CurrentDirectory); rv = c.InvokeCompiler(args, stderr, stdout, false, null); Logging.Emit("exit {0} after {1} ms", rv, DateTime.Now.Subtract(start).TotalMilliseconds); } catch (CClashErrorException e) { Logging.Error(e.Message); throw; } catch (CClashWarningException e) { Logging.Warning(e.Message); } return rv; }