예제 #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));
        }
예제 #2
0
        /// <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)
        {
            var restoreResult = DotNetCliCommandExecutor.ExecuteCommand(
                RestoreCommand,
                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);

            logger.WriteLineInfo($"// dotnet build 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));
        }
예제 #3
0
        /// <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));
        }
예제 #4
0
        /// <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)));
        }
        public DotNetCliCommandResult AddPackages()
        {
            var executionTime = new TimeSpan(0);
            var stdOutput     = new StringBuilder();

            foreach (var cmd in GetAddPackagesCommands(BuildPartition))
            {
                var result = DotNetCliCommandExecutor.Execute(WithArguments(cmd));
                if (!result.IsSuccess)
                {
                    return(result);
                }
                executionTime += result.ExecutionTime;
                stdOutput.Append(result.StandardOutput);
            }
            return(DotNetCliCommandResult.Success(executionTime, stdOutput.ToString()));
        }
예제 #6
0
        private DotNetCliCommandExecutor.CommandResult Build(GenerateResult generateResult)
        {
            var withoutDependencies = DotNetCliCommandExecutor.ExecuteCommand(
                GetBuildCommand(TargetFrameworkMoniker, justTheProjectItself: true),
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath);

            // at first we try to build the project without it's dependencies to save a LOT of time
            // in 99% of the cases it will work (the host process is running so it must be compiled!)
            if (withoutDependencies.IsSuccess)
            {
                return(withoutDependencies);
            }

            // but the host process might have different runtime or was build in Debug, not Release,
            // which requires all dependencies to be build anyway
            return(DotNetCliCommandExecutor.ExecuteCommand(
                       GetBuildCommand(TargetFrameworkMoniker, justTheProjectItself: false),
                       generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath));
        }
        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));
        }
예제 #8
0
        private DotNetCliCommandExecutor.CommandResult Build(GenerateResult generateResult, string configuration, string extraArguments, ILogger logger)
        {
            var withoutDependencies = DotNetCliCommandExecutor.ExecuteCommand(
                CustomDotNetCliPath,
                $"{GetBuildCommand(TargetFrameworkMoniker, true, configuration)} {extraArguments}",
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                logger);

            // at first we try to build the project without it's dependencies to save a LOT of time
            // in 99% of the cases it will work (the host process is running so it must be compiled!)
            if (withoutDependencies.IsSuccess)
            {
                return(withoutDependencies);
            }

            // but the host process might have different runtime or was build in Debug, not Release,
            // which requires all dependencies to be build anyway
            var withDependencies = DotNetCliCommandExecutor.ExecuteCommand(
                CustomDotNetCliPath,
                $"{GetBuildCommand(TargetFrameworkMoniker, false, configuration)} {extraArguments}",
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                logger);

            if (withDependencies.IsSuccess)
            {
                return(withDependencies);
            }

            // there are some crazy edge-cases, where executing dotnet build --no-restore AFTER dotnet restore will fail
            // an example: ML.NET has default values like Configuration = Debug in Directory.Build.props file
            // when we run dotnet restore for it, it restores for Debug. When we run dotnet build -c Release --no-restore, it fails because it can't find project.assets.json file
            // The problem is that dotnet cli does not allow to set the configuration from console arguments
            // But when we run dotnet build -c Release (without --no-restore) it's going to restore the right things for us ;)
            return(DotNetCliCommandExecutor.ExecuteCommand(
                       CustomDotNetCliPath,
                       $"{GetBuildCommand(TargetFrameworkMoniker, false, configuration)} {extraArguments}".Replace(" --no-restore", string.Empty),
                       generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                       logger));
        }
예제 #9
0
        private ExecuteResult Execute(Benchmark benchmark, ILogger logger, ArtifactsPaths artifactsPaths, IDiagnoser diagnoser, string executableName, IConfig config)
        {
            using (var process = new Process
            {
                StartInfo = DotNetCliCommandExecutor.BuildStartInfo(
                    artifactsPaths.BinariesDirectoryPath,
                    BuildArgs(diagnoser, executableName))
            })
            {
                var loggerWithDiagnoser = new SynchronousProcessOutputLoggerWithDiagnoser(logger, process, diagnoser, benchmark, config);

                ConsoleHandler.Instance.SetProcess(process);

                process.Start();

                process.EnsureHighPriority(logger);
                if (benchmark.Job.Env.HasValue(EnvMode.AffinityCharacteristic))
                {
                    process.EnsureProcessorAffinity(benchmark.Job.Env.Affinity);
                }

                loggerWithDiagnoser.ProcessInput();
                string standardError = process.StandardError.ReadToEnd();

                process.WaitForExit(); // should we add timeout here?

                if (process.ExitCode == 0)
                {
                    return(new ExecuteResult(true, process.ExitCode, loggerWithDiagnoser.LinesWithResults, loggerWithDiagnoser.LinesWithExtraOutput));
                }

                if (!string.IsNullOrEmpty(standardError))
                {
                    logger.WriteError(standardError);
                }

                return(new ExecuteResult(true, process.ExitCode, Array.Empty <string>(), Array.Empty <string>()));
            }
        }
예제 #10
0
        private DotNetCliCommandExecutor.CommandResult Build(GenerateResult generateResult, string configuration, string extraArguments, ILogger logger)
        {
            var withoutDependencies = DotNetCliCommandExecutor.ExecuteCommand(
                CustomDotNetCliPath,
                $"{GetBuildCommand(TargetFrameworkMoniker, true, configuration)} {extraArguments}",
                generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                logger);

            // at first we try to build the project without it's dependencies to save a LOT of time
            // in 99% of the cases it will work (the host process is running so it must be compiled!)
            if (withoutDependencies.IsSuccess)
            {
                return(withoutDependencies);
            }

            // but the host process might have different runtime or was build in Debug, not Release,
            // which requires all dependencies to be build anyway
            return(DotNetCliCommandExecutor.ExecuteCommand(
                       CustomDotNetCliPath,
                       $"{GetBuildCommand(TargetFrameworkMoniker, false, configuration)} {extraArguments}",
                       generateResult.ArtifactsPaths.BuildArtifactsDirectoryPath,
                       logger));
        }
예제 #11
0
 public DotNetCliCommandResult Publish()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetPublishCommand(BuildPartition, Arguments)));
예제 #12
0
 public DotNetCliCommandResult BuildNoDependencies()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetBuildCommand(BuildPartition, $"{Arguments} --no-dependencies")));
예제 #13
0
 public DotNetCliCommandResult Restore()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetRestoreCommand(GenerateResult.ArtifactsPaths, BuildPartition, Arguments)));
 public DotNetCliCommandResult PublishNoBuildAndNoRestore()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetPublishCommand(BuildPartition, $"{Arguments} --no-build --no-restore")));
 public DotNetCliCommandResult BuildNoRestore()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetBuildCommand(BuildPartition, $"{Arguments} --no-restore")));
 public DotNetCliCommandResult BuildNoRestoreNoDependencies()
 => DotNetCliCommandExecutor.Execute(WithArguments(
                                         GetBuildCommand(GenerateResult.ArtifactsPaths, BuildPartition, $"{Arguments} --no-restore --no-dependencies")));