Exemplo n.º 1
0
        public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
        {
            string extraArguments = DotNetCliGenerator.GetCustomArguments(buildPartition.RepresentativeBenchmarkCase, buildPartition.Resolver);

            var restoreResult = DotNetCliCommandExecutor.ExecuteCommand(
                CustomDotNetCliPath,
                $"{RestoreCommand} {extraArguments}",
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                logger);

            if (!restoreResult.IsSuccess)
            {
                return(BuildResult.Failure(generateResult, new Exception(restoreResult.ProblemDescription)));
            }

            var buildResult = Build(generateResult, buildPartition.BuildConfiguration, extraArguments, logger);

            if (!buildResult.IsSuccess)
            {
                // dotnet cli could have successfully built 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, new Exception(buildResult.ProblemDescription)));
            }

            return(BuildResult.Success(generateResult));
        }
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark, IResolver resolver)
        {
            var extraArguments = DotNetCliGenerator.GetCustomArguments(benchmark, resolver);

            if (!string.IsNullOrEmpty(RestoreCommand))
            {
                var restoreResult = DotNetCliCommandExecutor.ExecuteCommand(
                    CustomDotNetCliPath,
                    $"{RestoreCommand} {extraArguments}",
                    generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath);

                logger.WriteLineInfo($"// dotnet restore took {restoreResult.ExecutionTime.TotalSeconds:0.##}s");

                if (!restoreResult.IsSuccess)
                {
                    return(BuildResult.Failure(generateResult, new Exception(restoreResult.ProblemDescription)));
                }
            }

            var buildResult = Build(
                generateResult,
                benchmark.Job.ResolveValue(InfrastructureMode.BuildConfigurationCharacteristic, resolver),
                extraArguments);

            logger.WriteLineInfo($"// dotnet build/publish took {buildResult.ExecutionTime.TotalSeconds:0.##}s");

            if (!buildResult.IsSuccess)
            {
                // 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, new Exception(buildResult.ProblemDescription)));
            }

            return(BuildResult.Success(generateResult));
        }