SetWorkingDirectory() public method

public SetWorkingDirectory ( string path ) : void
path string
return void
Beispiel #1
0
        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));
        }
Beispiel #2
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);
        }
Beispiel #3
0
 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;
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 public void DetectNotSupported(params string[] argv)
 {
     var c = new Compiler() { 
         CompilerExe = CompilerPath };
     c.SetWorkingDirectory(InitialDir);
     c.SetEnvironment(Compiler.GetEnvironmentDictionary());
     Assert.IsFalse(c.ProcessArguments(argv));
 }
Beispiel #6
0
 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);
 }
Beispiel #7
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);
            }
        }
Beispiel #8
0
 public void ParseUnSupportedArgs(params string[] argv)
 {
     var c = new Compiler();
     c.SetWorkingDirectory(InitialDir);
     Assert.IsFalse(c.ProcessArguments(argv));
 }
Beispiel #9
0
 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);
 }
Beispiel #10
0
 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));
 }
Beispiel #11
0
        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;
        }
Beispiel #12
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);
                        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;
        }