Example #1
0
        protected async Task SetupHelloWorldProject(string dotNetExePath, string intermediateOutputDir, bool useExistingSetup, ITestOutputHelper output)
        {
            string helloWorldProjectDir = Path.Combine(intermediateOutputDir, "helloworld");

            //the 'exePath' gets passed as an argument to dotnet.exe
            //in this case it isn't an executable at all, its a CLI command
            //a little cheap, but it works
            ExePath        = "build";
            WorkingDirPath = helloWorldProjectDir;

            // This disables using the shared build server. I was told using it interferes with the ability to delete folders after the
            // test is complete though I haven't encountered that particular issue myself. I imagine this meaningfully changes the
            // performance of this benchmark, so if we ever want to do real perf testing on the shared scenario we have to resolve this
            // issue another way.
            EnvironmentVariables["UseSharedCompilation"] = "false";

            if (!useExistingSetup)
            {
                FileTasks.DeleteDirectory(helloWorldProjectDir, output);
                FileTasks.CreateDirectory(helloWorldProjectDir, output);
                await new ProcessRunner(dotNetExePath, "new console")
                .WithWorkingDirectory(helloWorldProjectDir)
                .WithLog(output)
                .Run();
            }
        }
Example #2
0
        private async Task <string> Publish(DotNetInstallation dotNetInstall, string outputDir, ITestOutputHelper output)
        {
            string tfm        = DotNetSetup.GetTargetFrameworkMonikerForFrameworkVersion(dotNetInstall.FrameworkVersion);
            string publishDir = GetWord2VecNetPublishDirectory(dotNetInstall, outputDir, tfm);

            if (publishDir != null)
            {
                FileTasks.DeleteDirectory(publishDir, output);
            }
            string dotNetExePath = dotNetInstall.DotNetExe;

            await new ProcessRunner(dotNetExePath, $"publish -c Release -f {tfm}")
            .WithWorkingDirectory(GetWord2VecNetSrcDirectory(outputDir))
            .WithEnvironmentVariable("DOTNET_MULTILEVEL_LOOKUP", "0")
            .WithEnvironmentVariable("WORD2VEC_FRAMEWORK_VERSION", dotNetInstall.FrameworkVersion)
            .WithEnvironmentVariable("UseSharedCompilation", "false")
            .WithLog(output)
            .Run();

            publishDir = GetWord2VecNetPublishDirectory(dotNetInstall, outputDir, tfm);
            if (publishDir == null)
            {
                throw new DirectoryNotFoundException("Could not find 'publish' directory");
            }
            return(publishDir);
        }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        protected override async Task SetupSourceToCompile(string intermediateOutputDir, string runtimeDirPath, bool useExistingSetup, ITestOutputHelper output)
#pragma warning restore CS1998
        {
            string helloWorldDir            = Path.Combine(intermediateOutputDir, "helloWorldSource");
            string helloWorldPath           = Path.Combine(helloWorldDir, "hello.cs");
            string systemPrivateCoreLibPath = Path.Combine(runtimeDirPath, "System.Private.CoreLib.dll");
            string systemRuntimePath        = Path.Combine(runtimeDirPath, "System.Runtime.dll");
            string systemConsolePath        = Path.Combine(runtimeDirPath, "System.Console.dll");

            CommandLineArguments = "hello.cs /nostdlib /r:" + systemPrivateCoreLibPath + " /r:" + systemRuntimePath + " /r:" + systemConsolePath;
            WorkingDirPath       = helloWorldDir;
            if (useExistingSetup)
            {
                return;
            }

            FileTasks.DeleteDirectory(helloWorldDir, output);
            FileTasks.CreateDirectory(helloWorldDir, output);
            File.WriteAllLines(helloWorldPath, new string[]
            {
                "using System;",
                "public static class Program",
                "{",
                "    public static void Main(string[] args)",
                "    {",
                "        Console.WriteLine(\"Hello World!\");",
                "    }",
                "}"
            });
        }
Example #4
0
        async Task CloneWord2VecNetRepo(string outputDir, ITestOutputHelper output)
        {
            // If the repo already exists, we delete it and extract it again.
            string word2VecNetRepoRootDir = GetWord2VecNetRepoRootDir(outputDir);

            FileTasks.DeleteDirectory(word2VecNetRepoRootDir, output);

            await GitTasks.Clone(Word2VecNetRepoUrl, word2VecNetRepoRootDir, output);

            await GitTasks.Checkout(Word2VecNetCommitSha1Id, output, word2VecNetRepoRootDir);
        }
        async public Task <DotNetInstallation> Run(ITestOutputHelper output)
        {
            using (var acquireOutput = new IndentedTestOutputHelper("Acquiring DotNet", output))
            {
                string remoteSdkPath = GetSDKDownloadLink();
                if (remoteSdkPath != null)
                {
                    await FileTasks.DownloadAndUnzip(remoteSdkPath, DotNetDirPath, acquireOutput);
                }
                string remoteRuntimePath = GetFrameworkDownloadLink();
                if (remoteRuntimePath != null)
                {
                    await FileTasks.DownloadAndUnzip(remoteRuntimePath, DotNetDirPath, acquireOutput);

                    // the SDK may have included another runtime version, but to help prevent mistakes
                    // where a test might run against a different version than we intended all other
                    // versions will be deleted.
                    string mnappDirPath = Path.Combine(DotNetDirPath, "shared", "Microsoft.NETCore.App");
                    foreach (string dir in Directory.GetDirectories(mnappDirPath))
                    {
                        string versionDir = Path.GetFileName(dir);
                        if (versionDir != FrameworkVersion)
                        {
                            FileTasks.DeleteDirectory(dir, acquireOutput);
                        }
                    }
                }
                string actualFrameworkVersion = FrameworkVersion;
                if (actualFrameworkVersion == null)
                {
                    //if Framework version is being infered from an SDK then snoop the filesystem to see what got installed
                    foreach (string dirPath in Directory.EnumerateDirectories(Path.Combine(DotNetDirPath, "shared", "Microsoft.NETCore.App")))
                    {
                        actualFrameworkVersion = Path.GetFileName(dirPath);
                        break;
                    }
                }


                DotNetInstallation result = new DotNetInstallation(DotNetDirPath, actualFrameworkVersion, SdkVersion, Architecture);
                acquireOutput.WriteLine("Dotnet path: " + result.DotNetExe);
                if (!File.Exists(result.DotNetExe))
                {
                    throw new FileNotFoundException(result.DotNetExe + " not found");
                }
                if (result.SdkVersion != null)
                {
                    if (!Directory.Exists(result.SdkDir))
                    {
                        throw new DirectoryNotFoundException("Sdk directory " + result.SdkDir + " not found");
                    }
                }
                if (result.FrameworkVersion != null)
                {
                    if (!Directory.Exists(result.FrameworkDir))
                    {
                        throw new DirectoryNotFoundException("Framework directory " + result.FrameworkDir + " not found");
                    }

                    //overlay private binaries if needed
                    if (PrivateRuntimeBinaryDirPath != null)
                    {
                        foreach (string fileName in GetPrivateRuntimeOverlayBinaryNames(OS))
                        {
                            string backupPath     = Path.Combine(result.FrameworkDir, fileName + ".original");
                            string overwritePath  = Path.Combine(result.FrameworkDir, fileName);
                            string privateBinPath = Path.Combine(PrivateRuntimeBinaryDirPath, fileName);
                            if (!File.Exists(backupPath))
                            {
                                File.Copy(overwritePath, backupPath);
                            }
                            if (!File.Exists(privateBinPath))
                            {
                                throw new FileNotFoundException("Private binary " + privateBinPath + " not found");
                            }
                            File.Copy(privateBinPath, overwritePath, true);
                        }
                    }
                }
                return(result);
            }
        }