public static ICompilerCache Get(bool direct, string cachedir, string compiler, string workdir, Dictionary <string, string> envs, out ICompiler comp) { comp = null; ICompilerCache rv = null; if (Settings.ServiceMode) { try { rv = new CClashServerClient(cachedir); } catch (CClashWarningException) { rv = new NullCompilerCache(cachedir); } } if (rv == null) { if (direct) { Logging.Emit("use direct mode"); rv = new DirectCompilerCache(cachedir); } else { throw new NotSupportedException("ppmode is not supported yet"); } } comp = rv.SetCompiler(compiler, workdir, envs); return(rv); }
public static string GetStatsString(string compiler, ICompilerCache cache) { var sb = new StringBuilder(); sb.WriteLine("compiler: {0}", compiler); sb.WriteLine("cachedir: {0}", Settings.CacheDirectory); if (Settings.DebugEnabled) { sb.WriteLine("debug file: {0}", Settings.DebugFile); } if (Settings.Disabled) { sb.WriteLine("disabled: yes"); } else { sb.WriteLine("disabled: no"); } if (compiler != null) { if (cache != null) { var stats = new CacheInfo(cache.OutputCache); sb.WriteLine("outputCache usage: {0} kb", (int)(stats.CacheSize / 1024)); sb.WriteLine("cached files: {0}", stats.CacheObjects); sb.WriteLine("hits: {0}", stats.CacheHits); sb.WriteLine("misses: {0}", stats.CacheMisses); sb.WriteLine("unsupported: {0}", stats.CacheUnsupported); sb.WriteLine("slow hits: {0}", stats.SlowHitCount); } } return(sb.ToString()); }
public static string GetStatsString(string compiler, ICompilerCache cache) { var sb = new StringBuilder(); sb.WriteLine("compiler: {0}", compiler); sb.WriteLine("cachedir: {0}", Settings.CacheDirectory); if (Settings.DebugEnabled) { sb.WriteLine("debug file: {0}", Settings.DebugFile); } if (Settings.Disabled) { sb.WriteLine("disabled: yes"); } else { sb.WriteLine("disabled: no"); } if (compiler != null) { if (cache != null) { var stats = new CacheInfo(cache.OutputCache); sb.WriteLine("outputCache usage: {0} kb", (int)(stats.CacheSize / 1024)); sb.WriteLine("cached files: {0}", stats.CacheObjects); sb.WriteLine("hits: {0}", stats.CacheHits); sb.WriteLine("misses: {0}", stats.CacheMisses); sb.WriteLine("unsupported: {0}", stats.CacheUnsupported); sb.WriteLine("slow hits: {0}", stats.SlowHitCount); } } return sb.ToString(); }
public SharedCompilerCacheProvider( ApplicationPartManager applicationPartManager, IRazorViewEngineFileProviderAccessor fileProviderAccessor, IEnumerable <IApplicationFeatureProvider <ViewsFeature> > viewsFeatureProviders, IHostingEnvironment env) { lock (_synLock) { if (_cache == null) { var feature = new ViewsFeature(); var featureProviders = applicationPartManager.FeatureProviders .OfType <IApplicationFeatureProvider <ViewsFeature> >() .ToList(); featureProviders.AddRange(viewsFeatureProviders); var assemblyParts = new AssemblyPart[] { new AssemblyPart(Assembly.Load(new AssemblyName(env.ApplicationName))) }; foreach (var provider in featureProviders) { provider.PopulateFeature(assemblyParts, feature); } _cache = new CompilerCache(fileProviderAccessor.FileProvider, feature.Views); } } }
public RazorAssemblyCache(ICompilerCache cache, CachePathFactory cachePathFactory, IFileProvider contentFileProvider, ILogger logger) { _cache = cache; _contentFileProvider = contentFileProvider; _logger = logger; CachePathMaker = cachePathFactory; }
public VirtualPathRazorPageFactory(ITypeActivator typeActivator, IServiceProvider serviceProvider, ICompilerCache compilerCache, IRazorFileSystemCache fileSystemCache) { _activator = typeActivator; _serviceProvider = serviceProvider; _compilerCache = compilerCache; _fileSystemCache = fileSystemCache; }
public VirtualPathRazorPageFactory(ITypeActivator typeActivator, IServiceProvider serviceProvider, ICompilerCache compilerCache, IFileInfoCache fileInfoCache, IContextAccessor <HttpContext> contextAccessor) { _activator = typeActivator; _serviceProvider = serviceProvider; _compilerCache = compilerCache; _fileInfoCache = fileInfoCache; _isInstrumentationEnabled = IsInstrumentationEnabled(contextAccessor.Value); }
public TestRunner(IProcessHelper process, ITestCaseStreamReaderFactory testCaseStreamReaderFactory, IFileProbe fileProbe, ITestContextBuilder htmlTestFileCreator, ICompilerCache compilerCache) { this.process = process; this.testCaseStreamReaderFactory = testCaseStreamReaderFactory; this.fileProbe = fileProbe; stopWatch = new Stopwatch(); testContextBuilder = htmlTestFileCreator; this.compilerCache = compilerCache; }
public TestRunner(IProcessHelper process, ITestCaseStreamReaderFactory testCaseStreamReaderFactory, IFileProbe fileProbe, IBatchCompilerService batchCompilerService, ITestHarnessBuilder testHarnessBuilder, ITestContextBuilder htmlTestFileCreator, ICompilerCache compilerCache, IChutzpahTestSettingsService testSettingsService) { this.process = process; this.testCaseStreamReaderFactory = testCaseStreamReaderFactory; this.fileProbe = fileProbe; this.batchCompilerService = batchCompilerService; this.testHarnessBuilder = testHarnessBuilder; stopWatch = new Stopwatch(); testContextBuilder = htmlTestFileCreator; this.compilerCache = compilerCache; this.testSettingsService = testSettingsService; }
public SharedCompilerCacheProvider( ApplicationPartManager applicationPartManager, IRazorViewEngineFileProviderAccessor fileProviderAccessor, IHostingEnvironment env) { lock (_synLock) { if (_cache == null) { var feature = new ViewsFeature(); // Applying ViewsFeatureProvider to gather any precompiled view new ViewsFeatureProvider().PopulateFeature( new AssemblyPart[] { new AssemblyPart(Assembly.Load(new AssemblyName(env.ApplicationName))) }, feature); _cache = new CompilerCache(fileProviderAccessor.FileProvider, feature.Views); } } }
public CachingPageFactory(Func <string, CompilationResult> compileDelegate, ICompilerCache compilerCache) { this._compileDelegate = compileDelegate; this._compilerCache = compilerCache; }
public VirtualPathRazorPageFactory(IServiceProvider serviceProvider, ICompilerCache compilerCache) { _serviceProvider = serviceProvider; _compilerCache = compilerCache; }
public CoffeeScriptFileGenerator(IFileSystemWrapper fileSystem, ICoffeeScriptEngineWrapper coffeeScriptEngine, ICompilerCache compilerCache) : base(fileSystem) { this.coffeeScriptEngine = coffeeScriptEngine; this.compilerCache = compilerCache; }
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); long last_hits = 0; if (!Settings.ServiceMode) { last_hits = cc.Stats.CacheHits; } int res = cc.CompileOrCache(comp, args, null); if (!Settings.ServiceMode) { if (last_hits < cc.Stats.CacheHits) { WasHit = true; } } return(res); } } 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); }
public static int Main(string[] args) { var start = DateTime.Now; WasHit = false; var dbg = Environment.GetEnvironmentVariable("CCLASH_DEBUG"); if (!string.IsNullOrEmpty(dbg)) { Settings.DebugFile = dbg; Settings.DebugEnabled = true; } if (Settings.DebugEnabled) { Logging.Emit("command line args:"); foreach (var a in args) { Logging.Emit("arg: {0}", a); } } if (args.Contains("--cclash-server")) { foreach (var opt in args) { switch (opt) { case "--attempt-pdb": Environment.SetEnvironmentVariable("CCLASH_ATTEMPT_PDB_CACHE", "yes"); break; case "--pdb-to-z7": Environment.SetEnvironmentVariable("CCLASH_Z7_OBJ", "yes"); break; case "--sqlite": Environment.SetEnvironmentVariable("CCLASH_CACHE_TYPE", "sqlite"); break; case "--debug": if (Settings.DebugFile == null) { Settings.DebugFile = "Console"; Settings.DebugEnabled = true; } break; default: if (opt.StartsWith("--cachedir=")) { var dir = opt.Substring(1 + opt.IndexOf('=')); dir = Path.GetFullPath(dir); Settings.CacheDirectory = dir; } break; } } if (Settings.DebugEnabled) { if (Settings.DebugFile != null && Settings.DebugFile != "Console") { Settings.DebugFile += ".serv"; } } Logging.Emit("starting in server mode"); Logging.Emit("cache dir is {0}", Settings.CacheDirectory); Logging.Emit("cache type is {0}", Settings.CacheType); if (Settings.DebugFile != "Console") { Logging.Emit("closing server console"); Console.Out.Close(); Console.Error.Close(); Console.In.Close(); } 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")) { Logging.Emit("maint mode"); Console.Error.WriteLine("cclash {0} (c) Ian Norton, April 2016", typeof(Program).Assembly.GetName().Version.ToString()); var compiler = Compiler.Find(); if (Settings.ServiceMode) { for (int i = 0; i < 3; i++) { try { var cc = new CClashServerClient(Settings.CacheDirectory); if (args.Contains("--stop")) { Console.Error.WriteLine("stopping server.."); cc.Transact(new CClashRequest() { cmd = Command.Quit }); } else { #region server commands if (args.Contains("--clear")) { cc.Transact(new CClashRequest() { cmd = Command.ClearCache }); } else if (args.Contains("--disable")) { cc.Transact(new CClashRequest() { cmd = Command.DisableCache }); } else if (args.Contains("--enable")) { cc.Transact(new CClashRequest() { cmd = Command.EnableCache }); } else if (args.Contains("--start")) { Console.Out.WriteLine("starting server"); CClashServerClient.StartBackgroundServer(); } else { var stats = cc.Transact(new CClashRequest() { cmd = Command.GetStats }); Console.Out.WriteLine(stats.stdout); } return(0); #endregion } } catch (CClashErrorException ex) { Logging.Error(ex.Message); return(-1); } catch (CClashWarningException) { System.Threading.Thread.Sleep(2000); } catch (CClashServerNotReadyException) { Logging.Emit("server not ready, try again"); return(-1); } catch (IOException ex) { Logging.Error(ex.ToString()); return(-1); } } } else { ICompiler comp; using (ICompilerCache cc = CompilerCacheFactory.Get(Settings.DirectMode, Settings.CacheDirectory, compiler, Environment.CurrentDirectory, Compiler.GetEnvironmentDictionary(), out comp)) { Console.Out.WriteLine(StatOutputs.GetStatsString(compiler, cc)); } } return(0); } var rv = RunBuild(args, start, AppendStdout, AppendStderr); if (rv != 0) { if (!Settings.NoAutoRebuild) { for (int i = 1; i < 4; i++) { MainStdErr.Clear(); MainStdOut.Clear(); rv = RunBuild(args, start, AppendStdout, AppendStderr); if (rv == 0) { break; } System.Threading.Thread.Sleep(100); } } } Console.Error.Write(MainStdErr.ToString()); Console.Out.Write(MainStdOut.ToString()); if (spawnServer) { Logging.Emit("server needs to be started"); } return(rv); }