Example #1
0
        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);
        }