public DotNetProjectBuilder(BuildCommandApp args) : base(args.ShouldSkipDependencies) { _args = args; _preconditionManager = new IncrementalPreconditionManager( args.ShouldPrintIncrementalPreconditions, args.ShouldNotUseIncrementality, args.ShouldSkipDependencies); _compilerIOManager = new CompilerIOManager( args.ConfigValue, args.OutputValue, args.BuildBasePathValue, args.GetRuntimes(), args.Workspace ); _incrementalManager = new IncrementalManager( this, _compilerIOManager, _preconditionManager, _args.ShouldSkipDependencies, _args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue, BuildIncrementalArgumentList(_args) ); _scriptRunner = new ScriptRunner(); _commandFactory = new DotNetCommandFactory(); }
private static IEnumerable <ProjectContext> ResolveRootContexts( IEnumerable <string> files, IEnumerable <NuGetFramework> frameworks, BuildCommandApp args) { List <Task <ProjectContext> > tasks = new List <Task <ProjectContext> >(); foreach (var file in files) { Project project; using (PerfTrace.Current.CaptureTiming(file, "Loading project.json")) { project = args.Workspace.GetProject(file); } var projectFrameworks = project.GetTargetFrameworks().Select(f => f.FrameworkName); if (!projectFrameworks.Any()) { throw new InvalidOperationException( $"Project '{file}' does not have any frameworks listed in the 'frameworks' section."); } IEnumerable <NuGetFramework> selectedFrameworks; if (frameworks != null) { var unsupportedByProject = frameworks.Where(f => !projectFrameworks.Contains(f)); if (unsupportedByProject.Any()) { throw new InvalidOperationException( $"Project \'{file}\' does not support framework: {string.Join(", ", unsupportedByProject.Select(fx => fx.DotNetFrameworkName))}."); } selectedFrameworks = frameworks; } else { selectedFrameworks = projectFrameworks; } foreach (var framework in selectedFrameworks) { tasks.Add(Task.Run(() => args.Workspace.GetProjectContext(file, framework))); } } using (PerfTrace.Current.CaptureTiming(string.Empty, "Waiting for project contexts to finish loading")) { return(Task.WhenAll(tasks).GetAwaiter().GetResult()); } }
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); }
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); }
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); } }
private ScriptVariablesFixture(string rid) { var projectJson = Path.Combine(TestAssetPath, "project.json"); var command = new Mock <ICommand>(); command.Setup(c => c.Execute()).Returns(new CommandResult()); command.Setup(c => c.WorkingDirectory(It.IsAny <string>())).Returns(() => command.Object); command.Setup(c => c.OnErrorLine(It.IsAny <Action <string> >())).Returns(() => command.Object); command.Setup(c => c.OnOutputLine(It.IsAny <Action <string> >())).Returns(() => command.Object); var commandFactory = new Mock <ICommandFactory>(); commandFactory.Setup(c => c .Create( It.IsAny <string>(), It.IsAny <IEnumerable <string> >(), It.IsAny <NuGetFramework>(), It.IsAny <string>())) .Returns(command.Object); var _args = new BuildCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform", new BuildWorkspace(new ProjectReaderSettings())); _args.ConfigValue = ConfigValue; PreCompileScriptVariables = new Dictionary <string, string>(); PostCompileScriptVariables = new Dictionary <string, string>(); var _scriptRunner = new Mock <IScriptRunner>(); _scriptRunner.Setup( s => s.RunScripts(It.IsAny <ProjectContext>(), It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .Callback <ProjectContext, string, Dictionary <string, string> >((p, n, v) => { if (n.Equals(ScriptNames.PreCompile)) { PreCompileScriptVariables = v; } if (n.Equals(ScriptNames.PostCompile)) { PostCompileScriptVariables = v; } }); var managedCompiler = new ManagedCompiler(_scriptRunner.Object, commandFactory.Object); var rids = new List <string>(); if (!string.IsNullOrEmpty(rid)) { rids.Add(rid); } var workspace = new BuildWorkspace(new ProjectReaderSettings()); var context = workspace.GetRuntimeContext(workspace.GetProjectContext(projectJson, TestAssetFramework), rids); context = workspace.GetRuntimeContext(context, rids); managedCompiler.Compile(context, _args); RuntimeOutputDir = Path.Combine(OutputPath, rid); }
private static IDictionary <string, string> BuildIncrementalArgumentList(BuildCommandApp args) => new Dictionary <string, string>() { ["version-suffix"] = args.VersionSuffixValue };
private static bool OnExecute(IEnumerable <string> files, IEnumerable <NuGetFramework> frameworks, BuildCommandApp args) { var builderCommandApp = args; var graphCollector = new ProjectGraphCollector( !builderCommandApp.ShouldSkipDependencies, (project, target) => args.Workspace.GetProjectContext(project, target)); IEnumerable <ProjectContext> contexts; using (PerfTrace.Current.CaptureTiming(string.Empty, nameof(ResolveRootContexts))) { contexts = ResolveRootContexts(files, frameworks, args); } ProjectGraphNode[] graph; using (PerfTrace.Current.CaptureTiming(string.Empty, "Collect graph")) { graph = graphCollector.Collect(contexts).ToArray(); } var builder = new DotNetProjectBuilder(builderCommandApp); return(builder.Build(graph).ToArray().All(r => r != CompilationResult.Failure)); }