/// <summary>
        /// generates project.lock.json that tells compiler where to take dlls and source from
        /// and builds executable and copies all required dll's
        /// </summary>
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            if (!ExecuteCommand("restore", generateResult.DirectoryPath, logger))
            {
                return new BuildResult(generateResult, false, new Exception("dotnet restore has failed"), null);
            }

            if (!ExecuteCommand(
                $"build --framework {Framework} --configuration {Configuration} --output {OutputDirectory}", 
                generateResult.DirectoryPath, 
                logger))
            {
                // dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
                // so we need to check whether the exe exists or not, if it does then it is OK
                var executablePath = BuildExecutablePath(generateResult, benchmark);
                if (File.Exists(executablePath))
                {
                    return new BuildResult(generateResult, true, null, executablePath);
                }

                return new BuildResult(generateResult, false, new Exception("dotnet build has failed"), null);
            }

            return new BuildResult(generateResult, true, null, BuildExecutablePath(generateResult, benchmark));
        }
        /// <summary>
        /// generates project.lock.json that tells compiler where to take dlls and source from
        /// and builds executable and copies all required dll's
        /// </summary>
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            if (!DotNetCliCommandExecutor.ExecuteCommand(
                RestoreCommand,
                generateResult.DirectoryPath,
                logger,
                DefaultTimeout))
            {
                return new BuildResult(generateResult, false, new Exception("dotnet restore has failed"), null);
            }

            if (!DotNetCliCommandExecutor.ExecuteCommand(
                GetBuildCommand(TargetFrameworkMonikerProvider(benchmark.Job.Framework)),
                generateResult.DirectoryPath,
                logger,
                DefaultTimeout))
            {
                // dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
                // so we need to check whether the exe exists or not, if it does then it is OK
                var executablePath = BuildExecutablePath(generateResult, benchmark);
                if (File.Exists(executablePath))
                {
                    return new BuildResult(generateResult, true, null, executablePath);
                }

                return new BuildResult(generateResult, false, new Exception("dotnet build has failed"), null);
            }

            return new BuildResult(generateResult, true, null, BuildExecutablePath(generateResult, benchmark));
        }
        /// <summary>
        /// generates project.lock.json that tells compiler where to take dlls and source from
        /// and builds executable and copies all required dll's
        /// </summary>
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark, IResolver resolver)
        {
            if (!DotNetCliCommandExecutor.ExecuteCommand(
                RestoreCommand, 
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, 
                logger, 
                DefaultTimeout))
            {
                return BuildResult.Failure(generateResult, new Exception("dotnet restore has failed"));
            }

            if (!DotNetCliCommandExecutor.ExecuteCommand(
                GetBuildCommand(TargetFrameworkMoniker),
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath, 
                logger,
                DefaultTimeout))
            {
                // dotnet cli could have succesfully builded the program, but returned 1 as exit code because it had some warnings
                // so we need to check whether the exe exists or not, if it does then it is OK
                if (File.Exists(generateResult.ArtifactsPaths.ExecutablePath))
                {
                    return BuildResult.Success(generateResult);
                }

                return BuildResult.Failure(generateResult);
            }

            return BuildResult.Success(generateResult);
        }
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            lock (buildLock)
            {
                var projectFileName = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".csproj");
                var exeFilePath = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".exe");
                var consoleLogger = new MsBuildConsoleLogger(logger);
                var globalProperties = new Dictionary<string, string>();
                var buildRequest = new BuildRequestData(projectFileName, globalProperties, null, new[] { "Build" }, null);
                var buildParameters = new BuildParameters(new ProjectCollection()) { DetailedSummary = false, Loggers = new Microsoft.Build.Framework.ILogger[] { consoleLogger } };
                var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(exeFilePath))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");
                    logger.WriteLineInfo("Let's try to build it via BuildBenchmark.bat!");
                    var buildProcess = new Process
                    {
                        StartInfo =
                        {
                            FileName = Path.Combine(generateResult.DirectoryPath, "BuildBenchmark.bat"),
                            WorkingDirectory = generateResult.DirectoryPath,
                            UseShellExecute = false,
                            RedirectStandardOutput = false,
                        }
                    };
                    buildProcess.Start();
                    buildProcess.WaitForExit();
                    if (File.Exists(exeFilePath))
                        return new BuildResult(generateResult, true, null, exeFilePath);
                }

                return new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success, buildResult.Exception, exeFilePath);
            }
        }
Beispiel #5
0
 public BuildResult(GenerateResult generateResult, bool isBuildSuccess, Exception buildException, string executablePath) :
     base(generateResult.DirectoryPath, generateResult.IsGenerateSuccess, generateResult.GenerateException)
 {
     IsBuildSuccess = isBuildSuccess;
     BuildException = buildException;
     ExecutablePath = executablePath;
 }
 public BenchmarkReport(
     Benchmark benchmark,
     GenerateResult generateResult,
     BuildResult buildResult,
     IReadOnlyList<ExecuteResult> executeResults,
     IReadOnlyList<Measurement> allMeasurements)
 {
     Benchmark = benchmark;
     GenerateResult = generateResult;
     BuildResult = buildResult;
     ExecuteResults = executeResults ?? new ExecuteResult[0];
     AllMeasurements = allMeasurements ?? new Measurement[0];
 }
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            logger.WriteLineInfo($"BuildScript: {generateResult.ArtifactsPaths.BuildScriptFilePath}");

            var syntaxTree = CSharpSyntaxTree.ParseText(File.ReadAllText(generateResult.ArtifactsPaths.ProgramCodePath));

            var compilationOptions = new CSharpCompilationOptions(
                 outputKind: OutputKind.ConsoleApplication,
                 optimizationLevel: OptimizationLevel.Release,
                 allowUnsafe: true,
                 platform: GetPlatform(benchmark.Job.Platform),
                 deterministic: true);

            var references = RoslynGenerator
                .GetAllReferences(benchmark)
                .Select(assembly => AssemblyMetadata.CreateFromFile(assembly.Location))
                .Concat(FrameworkAssembliesMetadata.Value)
                .Distinct()
                .Select(uniqueMetadata => uniqueMetadata.GetReference());

            var compilation = CSharpCompilation
                .Create(assemblyName: Path.GetFileName(generateResult.ArtifactsPaths.ExecutablePath))
                .AddSyntaxTrees(syntaxTree)
                .WithOptions(compilationOptions)
                .AddReferences(references);

            using (var executable = File.Create(generateResult.ArtifactsPaths.ExecutablePath))
            {
                var emitResult = compilation.Emit(executable);

                if(emitResult.Success)
                {
                    return BuildResult.Success(generateResult);
                }

                foreach (var diagnostic in emitResult.Diagnostics
                    .Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error))
                {
                    logger.WriteError($"{diagnostic.Id}: {diagnostic.GetMessage()}");
                }

                return BuildResult.Failure(generateResult);
            }
        }
        private BuildResult BuildWithBat(GenerateResult generateResult, ILogger logger, string exeFilePath)
        {
            logger.WriteLineInfo($"Let's try to build it via {GeneratorBase.BuildBenchmarkScriptFileName}!");

            var buildProcess = new Process
            {
                StartInfo =
                {
                    FileName = Path.Combine(generateResult.DirectoryPath, GeneratorBase.BuildBenchmarkScriptFileName),
                    WorkingDirectory = generateResult.DirectoryPath,
                    UseShellExecute = false,
                    RedirectStandardOutput = false,
                }
            };
            buildProcess.Start();
            buildProcess.WaitForExit();

            return new BuildResult(generateResult, File.Exists(exeFilePath), null, exeFilePath);
        }
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            var projectFilePath = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".csproj");
            var executablePath = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".exe");

            try
            {
                var buildResult = BuildWithManagedApi(logger, projectFilePath);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(executablePath))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");

                    return BuildWithBat(generateResult, logger, executablePath);
                }

                return new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success,
                    buildResult.Exception, executablePath);
            }
            catch (FileLoadException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to load {msBuildDllNotFound.FileName}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
            catch (FileNotFoundException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to find {msBuildDllNotFound.FileName}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
            catch (InvalidOperationException exception)
            {
                logger.WriteLine($"Unable to build (InvalidOperationException). More information: {exception.Message}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
        }
Beispiel #10
0
 public BuildResult(GenerateResult generateResult, bool isBuildSuccess, Exception buildException) :
     base(generateResult.DirectoryPath, generateResult.IsGenerateSuccess, generateResult.GenerateException)
 {
     IsBuildSuccess = isBuildSuccess;
     BuildException = buildException;
 }
 /// <summary>
 /// we use custom output path in order to avoid any future problems related to dotnet cli paths changing
 /// </summary>
 private string BuildExecutablePath(GenerateResult generateResult, Benchmark benchmark)
     => Path.Combine(generateResult.DirectoryPath, OutputDirectory, $"{benchmark.ShortInfo}{RuntimeInformation.ExecutableExtension}");
Beispiel #12
0
 [PublicAPI] public static BuildResult Failure(GenerateResult generateResult, Exception exception = null) => new BuildResult(generateResult, false, exception);
 public BuildResult Build(GenerateResult generateResult, ILogger logger)
 {
     logger.WriteLine("Building");
     Done = true;
     return new BuildResult(generateResult, true, null);
 }
Beispiel #14
0
 public static BuildResult Failure(GenerateResult generateResult, Exception exception)
 => new BuildResult(generateResult, false, $"Exception! {Environment.NewLine}Message: {exception.Message},{Environment.NewLine}Stack trace:{Environment.NewLine}{exception.StackTrace}");
Beispiel #15
0
 public static BuildResult Failure(GenerateResult generateResult, string errorMessage)
 => new BuildResult(generateResult, false, errorMessage);
Beispiel #16
0
 private BuildResult(GenerateResult generateResult, bool isBuildSuccess, string errorMessage)
     : base(generateResult.ArtifactsPaths, generateResult.IsGenerateSuccess, generateResult.GenerateException, generateResult.ArtifactsToCleanup)
 {
     IsBuildSuccess = isBuildSuccess;
     ErrorMessage   = errorMessage;
 }
Beispiel #17
0
 private BuildResult(GenerateResult generateResult, bool isBuildSuccess, Exception buildException)
     : base(generateResult.ArtifactsPaths, generateResult.IsGenerateSuccess, generateResult.GenerateException, generateResult.ArtifactsToCleanup)
 {
     IsBuildSuccess = isBuildSuccess;
     BuildException = buildException;
 }
Beispiel #18
0
 [PublicAPI] public static BuildResult Success(GenerateResult generateResult) => new BuildResult(generateResult, true, null);
 /// <summary>
 /// we use custom output path in order to avoid any future problems related to dotnet cli paths changing
 /// </summary>
 private string BuildExecutablePath(GenerateResult generateResult, Benchmark benchmark)
     => Path.Combine(generateResult.DirectoryPath, OutputDirectory, $"{benchmark.ShortInfo}.exe");
 public static BuildResult Failure(GenerateResult generateResult, Exception exception = null) => new BuildResult(generateResult, false, exception);
Beispiel #21
0
 public BuildResult(GenerateResult generateResult, bool isBuildSuccess, Exception buildException) :
     base(generateResult.DirectoryPath, generateResult.IsGenerateSuccess, generateResult.GenerateException)
 {
     IsBuildSuccess = isBuildSuccess;
     BuildException = buildException;
 }
 public static BuildResult Success(GenerateResult generateResult) => new BuildResult(generateResult, true, null);
 public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark, IResolver resolver)
 {
     logger.WriteLine("Building");
     Done = true;
     return BuildResult.Success(generateResult);
 }
 private BuildResult(GenerateResult generateResult, bool isBuildSuccess, Exception buildException)
     : base(generateResult.ArtifactsPaths, generateResult.IsGenerateSuccess, generateResult.GenerateException)
 {
     IsBuildSuccess = isBuildSuccess;
     BuildException = buildException;
 }
 /// <summary>
 /// we use custom output path in order to avoid any future problems related to dotnet cli paths changes
 /// </summary>
 private string BuildExecutablePath(GenerateResult generateResult, Benchmark benchmark)
 {
     return Path.Combine(
         generateResult.DirectoryPath,
         OutputDirectory,
         $"{new DirectoryInfo(generateResult.DirectoryPath).Name}{RuntimeInformation.ExecutableExtension}");
 }
 private static BuildResult Build(ILogger logger, IToolchain toolchain, GenerateResult generateResult, Benchmark benchmark)
 {
     logger.WriteLineInfo("// *** Build ***");
     var buildResult = toolchain.Builder.Build(generateResult, logger, benchmark);
     if (buildResult.IsBuildSuccess)
     {
         logger.WriteLineInfo("// Result = Success");
     }
     else
     {
         logger.WriteLineError("// Result = Failure");
         if (buildResult.BuildException != null)
             logger.WriteLineError($"// Exception: {buildResult.BuildException.Message}");
     }
     logger.WriteLine();
     return buildResult;
 }
Beispiel #27
0
 public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
 {
     logger.WriteLine("Building");
     Done = true;
     return new BuildResult(generateResult, true, null, "doesNotMatterHere");
 }