Пример #1
0
        private int BuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            if (dotnetTestParams.NoBuild)
            {
                return 0;
            }

            return DoBuildTestProject(projectContext, dotnetTestParams, workspace);
        }
Пример #2
0
 public BuildProjectCommand(
     Project project,
     string buildBasePath,
     string configuration,
     BuildWorkspace workspace)
 {
     _project = project;
     _buildBasePath = buildBasePath;
     _configuration = configuration;
     _workspace = workspace;
 }
Пример #3
0
        public CompilerIOManager(string configuration,
            string outputPath,
            string buildBasePath,
            IEnumerable<string> runtimes,
            BuildWorkspace workspace)
        {
            _configuration = configuration;
            _outputPath = outputPath;
            _buildBasePath = buildBasePath;
            _runtimes = runtimes.ToList();
            _workspace = workspace;

            _cache = new ConcurrentDictionary<ProjectContextIdentity, CompilerIO>();
        }
Пример #4
0
        public BuildCommandApp(string name, string fullName, string description, BuildWorkspace workspace)
        {
            Workspace = workspace;
            _app = new CommandLineApplication
            {
                Name = name,
                FullName = fullName,
                Description = description
            };

            baseClassOptions = new Dictionary<string, CommandOption>();

            AddCompileParameters();
        }
        public GivenACompilationDriverController()
        {
            _projectJson =
                Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestAppWithLibrary", "TestApp", "project.json");
            _managedCompilerMock = new Mock<ICompiler>();
            _managedCompilerMock.Setup(c => c
                .Compile(It.IsAny<ProjectContext>(), It.IsAny<BuildCommandApp>()))
                .Returns(true);
            _nativeCompilerMock = new Mock<ICompiler>();
            _nativeCompilerMock.Setup(c => c
                .Compile(It.IsAny<ProjectContext>(), It.IsAny<BuildCommandApp>()))
                .Returns(true);

            _workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());
            _contexts = new List<ProjectContext>
            {
                _workspace.GetProjectContext(_projectJson, NuGetFramework.Parse("netcoreapp1.0"))
            };

            _args = new BuildCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform", _workspace);
        }
Пример #6
0
        public static int Run(string[] args, BuildWorkspace workspace)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            try
            {
                var app = new BuildCommandApp(
                    "dotnet build",
                    ".NET Builder",
                    "Builder for the .NET Platform. It performs incremental compilation if it's safe to do so. Otherwise it delegates to dotnet-compile which performs non-incremental compilation",
                    workspace);
                return app.Execute(OnExecute, args);
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.Error.WriteLine(ex);
#else
                Console.Error.WriteLine(ex.Message);
#endif
                return 1;
            }
        }
Пример #7
0
        private int DoBuildTestProject(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var strings = new List<string>
            {
                $"--configuration",
                dotnetTestParams.Config,
                $"{dotnetTestParams.ProjectPath}"
            };

            // Build the test specifically for the target framework \ rid of the ProjectContext. This avoids building the project
            // for tfms that the user did not request.
            strings.Add("--framework");
            strings.Add(projectContext.TargetFramework.ToString());

            if (!string.IsNullOrEmpty(dotnetTestParams.BuildBasePath))
            {
                strings.Add("--build-base-path");
                strings.Add(dotnetTestParams.BuildBasePath);
            }

            if (!string.IsNullOrEmpty(dotnetTestParams.Output))
            {
                strings.Add("--output");
                strings.Add(dotnetTestParams.Output);
            }

            if (!string.IsNullOrEmpty(projectContext.RuntimeIdentifier))
            {
                strings.Add("--runtime");
                strings.Add(projectContext.RuntimeIdentifier);
            }

            var result = Build.BuildCommand.Run(strings.ToArray(), workspace);

            return result;
        }
Пример #8
0
        public int DoRun(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var dotnetTestParams = new DotnetTestParams();

            try
            {
                dotnetTestParams.Parse(args);
            
                if (dotnetTestParams.Help)
                {
                    return 0;
                }

                // Register for parent process's exit event
                if (dotnetTestParams.ParentProcessId.HasValue)
                {
                    RegisterForParentProcessExit(dotnetTestParams.ParentProcessId.Value);
                }

                var projectPath = GetProjectPath(dotnetTestParams.ProjectPath);
                var runtimeIdentifiers = !string.IsNullOrEmpty(dotnetTestParams.Runtime) ?
                    new[] { dotnetTestParams.Runtime } :
                    RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers();
                var exitCode = 0;

                // Create a workspace
                var workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

                if (dotnetTestParams.Framework != null)
                {
                    var projectContext = workspace.GetProjectContext(projectPath, dotnetTestParams.Framework);
                    if (projectContext == null)
                    {
                        Reporter.Error.WriteLine($"Project '{projectPath}' does not support framework: {dotnetTestParams.UnparsedFramework}");
                        return 1;
                    }
                    projectContext = workspace.GetRuntimeContext(projectContext, runtimeIdentifiers);

                    exitCode = RunTest(projectContext, dotnetTestParams, workspace);
                }
                else
                {
                    var summary = new Summary();
                    var projectContexts = workspace.GetProjectContextCollection(projectPath)
                        .EnsureValid(projectPath)
                        .FrameworkOnlyContexts
                        .Select(c => workspace.GetRuntimeContext(c, runtimeIdentifiers))
                        .ToList();

                    // Execute for all TFMs the project targets.
                    foreach (var projectContext in projectContexts)
                    {
                        var result = RunTest(projectContext, dotnetTestParams, workspace);
                        if (result == 0)
                        {
                            summary.Passed++;
                        }
                        else
                        {
                            summary.Failed++;
                            if (exitCode == 0)
                            {
                                // If tests fail in more than one TFM, we'll have it use the result of the first one
                                // as the exit code.
                                exitCode = result;
                            }
                        }
                    }

                    summary.Print();
                }

                return exitCode;
            }
            catch (InvalidOperationException ex)
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -1;
            }
            catch (Exception ex) when (!(ex is GracefulException))
            {
                TestHostTracing.Source.TraceEvent(TraceEventType.Error, 0, ex.ToString());
                return -2;
            }
        }
Пример #9
0
 private int RunTest(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
 {
     var testRunner = projectContext.ProjectFile.TestRunner;
     var dotnetTestRunner = _dotnetTestRunnerFactory.Create(dotnetTestParams.Port);
     return dotnetTestRunner.RunTests(projectContext, dotnetTestParams, workspace);
 }
Пример #10
0
        public int RunTests(ProjectContext projectContext, DotnetTestParams dotnetTestParams, BuildWorkspace workspace)
        {
            var result = BuildTestProject(projectContext, dotnetTestParams, workspace);

            return result == 0 ? DoRunTests(projectContext, dotnetTestParams) : result;
        }
Пример #11
0
        private int RunExecutable()
        {
            // Set up the workspace
            _workspace = new BuildWorkspace(ProjectReaderSettings.ReadFromEnvironment());

            CalculateDefaultsForNonAssigned();

            // Compile to that directory
            var result = Build.BuildCommand.Run(new[]
            {
                $"--framework",
                $"{_context.TargetFramework}",
                $"--configuration",
                Configuration,
                $"{_context.ProjectFile.ProjectDirectory}"
            }, _workspace);

            if (result != 0)
            {
                return result;
            }

            List<string> hostArgs = new List<string>();
            if (!_context.TargetFramework.IsDesktop())
            {
                // Add Nuget Packages Probing Path
                var nugetPackagesRoot = _context.PackagesDirectory;
                var probingPathArg = "--additionalprobingpath";
                hostArgs.Insert(0, nugetPackagesRoot);
                hostArgs.Insert(0, probingPathArg);
            }

            // Now launch the output and give it the results
            var outputPaths = _context.GetOutputPaths(Configuration);
            var outputName = outputPaths.RuntimeFiles.Executable;

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if (_context.TargetFramework.IsDesktop())
                {
                    // Run mono if we're running a desktop target on non windows
                    _args.Insert(0, outputName);

                    if (string.Equals(Configuration, "Debug", StringComparison.OrdinalIgnoreCase))
                    {
                        // If we're compiling for the debug configuration then add the --debug flag
                        // other options may be passed using the MONO_OPTIONS env var
                        _args.Insert(0, "--debug");
                    }

                    outputName = "mono";
                }
            }

            ICommand command;
            if (outputName.EndsWith(FileNameSuffixes.DotNet.DynamicLib, StringComparison.OrdinalIgnoreCase))
            {
                // The executable is a ".dll", we need to call it through dotnet.exe
                var muxer = new Muxer();

                command = _commandFactory.Create(muxer.MuxerPath, Enumerable.Concat(
                            Enumerable.Concat(new string[] { "exec" }, hostArgs),
                            Enumerable.Concat(new string[] { outputName }, _args)));
            }
            else
            {
                command = _commandFactory.Create(outputName, Enumerable.Concat(hostArgs, _args));
            }

            result = command
                .Execute()
                .ExitCode;

            return result;
        }
Пример #12
0
        public int Execute(OnExecute execute, string[] args)
        {
            _app.OnExecute(() =>
            {
                if (_outputOption.HasValue() && !_frameworkOption.HasValue())
                {
                    Reporter.Error.WriteLine("When the '--output' option is provided, the '--framework' option must also be provided.");
                    return 1;
                }

                OutputValue = _outputOption.Value();
                BuildBasePathValue = PathUtility.GetFullPath(_buildBasePath.Value());
                ConfigValue = _configurationOption.Value() ?? Constants.DefaultConfiguration;
                RuntimeValue = _runtimeOption.Value();
                VersionSuffixValue = _versionSuffixOption.Value();
                ShouldPrintIncrementalPreconditions = _shouldPrintIncrementalPreconditionsArgument.HasValue();
                ShouldNotUseIncrementality = _shouldNotUseIncrementalityArgument.HasValue();
                ShouldSkipDependencies = _shouldSkipDependenciesArgument.HasValue();

                // Set defaults based on the environment
                if (Workspace == null)
                {
                    Workspace = BuildWorkspace.Create(VersionSuffixValue);
                }

                var files = new ProjectGlobbingResolver().Resolve(_projectArgument.Values);
                IEnumerable<NuGetFramework> frameworks = null;
                if (_frameworkOption.HasValue())
                {
                    frameworks = new[] { NuGetFramework.Parse(_frameworkOption.Value()) };
                }
                var success = execute(files, frameworks, this);

                return success ? 0 : 1;
            });

            return _app.Execute(args);
        }