Exemplo n.º 1
0
        internal static string Build(ITestOutputHelper testOutputHelper, Options options, out string absoluteSourceDir)
        {
            var sourceFile = options.MakeAbsolute(options.SourceFile);

            var compilerPath = options.GetCompilerAbsolutePath(ToolsRoot);

            Assert.True(File.Exists(compilerPath), string.Format("Can't find compiler at '{0}'", compilerPath));

            var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ReferencesFramework));
            var sourcedir            = absoluteSourceDir = Path.GetDirectoryName(sourceFile);

            var outputdir  = Path.Combine(Path.Combine(sourcedir, "bin"), options.CompilerPath);
            var extension  = options.UseExe ? ".exe" : ".dll";
            var targetKind = options.UseExe ? "exe" : "library";

            var targetfile = Path.Combine(outputdir, options.TestName + extension);

            // add Microsoft.Contracts reference if needed
            if (options.IsV35)
            {
                options.References.Add("Microsoft.Contracts.dll");
            }

            var oldCwd = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = sourcedir;

                var resolvedReferences = ResolveReferences(options);
                var referenceString    = ReferenceOptions(resolvedReferences);

                if (!Directory.Exists(outputdir))
                {
                    Directory.CreateDirectory(outputdir);
                }

                string arguments = String.Format("/t:{4} /out:{0} {3} {2} {1}", targetfile, sourceFile, referenceString, options.FinalCompilerOptions, targetKind);

                if (!options.ReleaseMode)
                {
                    if (options.PdbOnly)
                    {
                        arguments = "/debug:pdbonly " + arguments;
                    }
                    else
                    {
                        arguments = "/debug:full " + arguments;
                    }
                }

                if (options.Optimize)
                {
                    arguments = "/optimize " + arguments;
                }

                var exitCode = RunProcess(testOutputHelper, sourcedir, compilerPath, arguments, true);

                if (exitCode != 0)
                {
                    return(null);
                }

                // add reference to Microsoft.Contracts.dll if not already done because of transitive closure issues
                if (!options.References.Contains("Microsoft.Contracts.dll"))
                {
                    options.References.Add("Microsoft.Contracts.dll");

                    // recompute resolvedReferences
                    resolvedReferences = ResolveReferences(options);
                }

                CopyReferenceAssemblies(resolvedReferences, outputdir);

                return(targetfile);
            }
            finally
            {
                Environment.CurrentDirectory = oldCwd;
            }
        }
Exemplo n.º 2
0
        internal static string Build(Options options, out string absoluteSourceDir)
        {
            var sourceFile = options.MakeAbsolute(options.SourceFile);

            var compilerPath = options.GetCompilerAbsolutePath(ToolsRoot);
            Assert.IsTrue(File.Exists(compilerPath), string.Format("Can't find compiler at '{0}'", compilerPath));

            var contractreferencedir = options.MakeAbsolute(Path.Combine(ContractReferenceDirRoot, options.ReferencesFramework));
            var sourcedir = absoluteSourceDir = Path.GetDirectoryName(sourceFile);

            var outputdir = Path.Combine(Path.Combine(sourcedir, "bin"), options.CompilerPath);
            var extension = options.UseExe ? ".exe" : ".dll";
            var targetKind = options.UseExe ? "exe" : "library";

            var targetfile = Path.Combine(outputdir, options.TestName + extension);

            // add Microsoft.Contracts reference if needed
            if (options.IsV35)
            {
                options.References.Add("Microsoft.Contracts.dll");
            }

            var oldCwd = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = sourcedir;

                var resolvedReferences = ResolveReferences(options);
                var referenceString = ReferenceOptions(resolvedReferences);

                if (!Directory.Exists(outputdir))
                {
                    Directory.CreateDirectory(outputdir);
                }

                string arguments = String.Format("/t:{4} /out:{0} {3} {2} {1}", targetfile, sourceFile, referenceString, options.FinalCompilerOptions, targetKind);

                if (!options.ReleaseMode)
                {
                    arguments = "/debug " + arguments;
                }

                var exitCode = RunProcess(sourcedir, compilerPath, arguments, true);

                if (exitCode != 0)
                {
                    return null;
                }

                // add reference to Microsoft.Contracts.dll if not already done because of transitive closure issues
                if (!options.References.Contains("Microsoft.Contracts.dll"))
                {
                    options.References.Add("Microsoft.Contracts.dll");

                    // recompute resolvedReferences
                    resolvedReferences = ResolveReferences(options);
                }

                CopyReferenceAssemblies(resolvedReferences, outputdir);

                return targetfile;
            }
            finally
            {
                Environment.CurrentDirectory = oldCwd;
            }
        }