public async Task FastCheckNeedsBuildWithContext() { string solFile = Util.GetSampleProject("fast-build-test", "FastBuildTest.sln"); Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var app = (DotNetProject)sol.Items [0]; var cs = new SolutionConfigurationSelector("Debug"); var ctx = new TargetEvaluationContext(); ctx.GlobalProperties.SetValue("Foo", "Bar"); Assert.IsTrue(app.FastCheckNeedsBuild(cs, ctx)); ctx = new TargetEvaluationContext(); ctx.GlobalProperties.SetValue("Foo", "Bar"); var res = await sol.Build(Util.GetMonitor(), cs, ctx); Assert.IsFalse(res.HasErrors); ctx = new TargetEvaluationContext(); ctx.GlobalProperties.SetValue("Foo", "Bar"); Assert.IsFalse(app.FastCheckNeedsBuild(cs, ctx)); ctx = new TargetEvaluationContext(); ctx.GlobalProperties.SetValue("Foo", "Modified"); Assert.IsTrue(app.FastCheckNeedsBuild(cs, ctx)); sol.Dispose(); }
public async Task BasicEvents() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution item = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var myLogger = new MSBuildLogger(); TargetEvaluationContext ctx = new TargetEvaluationContext(); ctx.Loggers.Add(myLogger); myLogger.EnabledEvents = MSBuildEvent.BuildStarted | MSBuildEvent.BuildFinished | MSBuildEvent.TargetStarted; int started = 0, finished = 0, targetStarted = 0; myLogger.EventRaised += (sender, e) => { switch (e.Event) { case MSBuildEvent.BuildStarted: started++; break; case MSBuildEvent.BuildFinished: finished++; break; case MSBuildEvent.TargetStarted: targetStarted++; break; default: throw new InvalidOperationException("Unexpected event: " + e.Event); } }; await item.Build(Util.GetMonitor(), "Debug", ctx); Assert.AreEqual(1, started); Assert.AreEqual(1, finished); Assert.IsTrue(targetStarted > 0); }
public async Task RunTarget() { string projFile = Util.GetSampleProject("msbuild-tests", "project-with-custom-target.csproj"); var p = (Project)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile); var ctx = new TargetEvaluationContext(); ctx.GlobalProperties.SetValue("TestProp", "has"); ctx.PropertiesToEvaluate.Add("GenProp"); ctx.PropertiesToEvaluate.Add("AssemblyName"); ctx.ItemsToEvaluate.Add("GenItem"); var res = await p.RunTarget(Util.GetMonitor(), "Test", p.Configurations [0].Selector, ctx); Assert.AreEqual(1, res.BuildResult.Errors.Count); Assert.AreEqual("Something failed: has foo bar", res.BuildResult.Errors [0].ErrorText); // Verify that properties are returned Assert.AreEqual("ConsoleProject", res.Properties.GetValue("AssemblyName")); Assert.AreEqual("foo", res.Properties.GetValue("GenProp")); // Verify that items are returned var items = res.Items.ToArray(); Assert.AreEqual(1, items.Length); Assert.AreEqual("bar", items [0].Include); Assert.AreEqual("Hello", items [0].Metadata.GetValue("MyMetadata")); Assert.AreEqual("bar", items [0].Metadata.GetValue("Filename")); Assert.AreEqual(p.ItemDirectory.Combine("bar").ToString(), items [0].Metadata.GetValue("FullPath")); p.Dispose(); }
public void RunTarget() { string projFile = Util.GetSampleProject("msbuild-tests", "project-with-custom-target.csproj"); var p = (Project)Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile); var ctx = new TargetEvaluationContext(); ctx.GlobalProperties.Add("TestProp", "has"); ctx.PropertiesToEvaluate.Add("GenProp"); ctx.PropertiesToEvaluate.Add("AssemblyName"); ctx.ItemsToEvaluate.Add("GenItem"); var res = p.RunTarget(Util.GetMonitor(), "Test", p.Configurations [0].Selector, ctx); Assert.AreEqual(1, res.BuildResult.Errors.Count); Assert.AreEqual("Something failed: has foo bar", res.BuildResult.Errors [0].ErrorText); // Verify that properties are returned Assert.AreEqual("ConsoleProject", res.Properties ["AssemblyName"]); Assert.AreEqual("foo", res.Properties ["GenProp"]); // Verify that items are returned var items = res.Items.ToArray(); Assert.AreEqual(1, items.Length); Assert.AreEqual("bar", items [0].ItemSpec); Assert.AreEqual("Hello", items [0].Metadata["MyMetadata"]); }
protected override Task<TargetEvaluationResult> OnRunTarget(ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { if (Commands.SelectActiveCompilerHandler.IsRoslynCompilerSet) { context.GlobalProperties.SetValue("CscToolExe", "csc.exe"); context.GlobalProperties.SetValue("CscToolPath", Path.Combine(Path.GetDirectoryName(typeof(ProjectExtension).Assembly.Location), "RoslynCompilerFiles")); context.GlobalProperties.SetValue("DebugType", "portable"); } return base.OnRunTarget(monitor, target, configuration, context); }
public async Task NoLog() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution item = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); TargetEvaluationContext ctx = new TargetEvaluationContext(); ctx.LogVerbosity = MSBuildVerbosity.Quiet; var mon = new StringMonitor(); await item.Build(mon, "Debug", ctx); Assert.AreEqual(string.Empty, mon.GetLogText()); }
public async Task AllEvents() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution item = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var myLogger = new MSBuildLogger(); TargetEvaluationContext ctx = new TargetEvaluationContext(); ctx.Loggers.Add(myLogger); myLogger.EnabledEvents = MSBuildEvent.All; int buildStarted = 0, buildFinished = 0, targetStarted = 0, targetFinished = 0, projectStarted = 0, projectFinished = 0, taskStarted = 0, taskFinished = 0; myLogger.EventRaised += (sender, e) => { switch (e.Event) { case MSBuildEvent.BuildStarted: buildStarted++; break; case MSBuildEvent.BuildFinished: buildFinished++; break; case MSBuildEvent.TargetStarted: targetStarted++; break; case MSBuildEvent.TargetFinished: targetFinished++; break; case MSBuildEvent.ProjectStarted: projectStarted++; break; case MSBuildEvent.ProjectFinished: projectFinished++; break; case MSBuildEvent.TaskStarted: taskStarted++; break; case MSBuildEvent.TaskFinished: taskFinished++; break; } }; var mon = new StringMonitor(); await item.Build(mon, "Debug", ctx); Assert.AreEqual(1, buildStarted); Assert.AreEqual(1, buildFinished); Assert.AreEqual(1, projectStarted); Assert.AreEqual(1, projectFinished); Assert.AreEqual(taskStarted, taskFinished); Assert.AreEqual(targetStarted, targetFinished); Assert.AreNotEqual(string.Empty, mon.GetLogText()); item.Dispose(); }
public async Task ConcurrentLongAndShortOperations() { // Tests that when a short operation is started while a long operation is in progress, // a new builder is created to execute the short operation await RemoteBuildEngineManager.RecycleAllBuilders(); Assert.AreEqual(0, RemoteBuildEngineManager.ActiveEnginesCount); FilePath solFile = Util.GetSampleProject("builder-manager-tests", "builder-manager-tests.sln"); using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { var project1 = sol.Items.FirstOrDefault(p => p.Name == "SyncBuildProject"); var project2 = (Project)sol.Items.FirstOrDefault(p => p.Name == "App"); InitBuildSyncEvent(project1); // Start the build var build1 = project1.Build(Util.GetMonitor(), sol.Configurations [0].Selector); // Wait for the build to reach the sync task await WaitForBuildSyncEvent(project1); // The build is now in progess. Start a short operation. var context = new TargetEvaluationContext { BuilderQueue = BuilderQueue.ShortOperations }; var build2 = project2.RunTarget(Util.GetMonitor(), "QuickTarget", sol.Configurations [0].Selector, context); if (await Task.WhenAny(build2, Task.Delay(5000)) != build2) { Assert.Fail("Build did not start"); } SignalBuildToContinue(project1); if (await Task.WhenAny(build1, Task.Delay(5000)) != build1) { Assert.Fail("Build did not end in time"); } Assert.AreEqual(0, build1.Result.ErrorCount); Assert.NotNull(build2.Result); } }
public async Task NoEvents() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution item = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var myLogger = new MSBuildLogger(); TargetEvaluationContext ctx = new TargetEvaluationContext(); ctx.Loggers.Add(myLogger); myLogger.EnabledEvents = MSBuildEvent.None; int events = 0; myLogger.EventRaised += (sender, e) => events++; await item.Build(Util.GetMonitor(), "Debug", ctx); Assert.AreEqual(0, events); }
public TargetEvaluationResult RunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { try { CallContext.SetData ("MonoDevelop.Projects.ProjectOperationContext", context); CallContext.SetData ("MonoDevelop.Projects.TargetEvaluationResult", null); var r = RunTarget (monitor, target, configuration); var evalRes = CallContext.GetData ("MonoDevelop.Projects.TargetEvaluationResult") as TargetEvaluationResult; if (evalRes != null) { evalRes.BuildResult = r; return evalRes; } return new TargetEvaluationResult (r); } finally { CallContext.SetData ("MonoDevelop.Projects.ProjectOperationContext", null); CallContext.SetData ("MonoDevelop.Projects.TargetEvaluationResult", null); } }
internal protected override BuildResult OnRunTarget(IProgressMonitor monitor, string target, ConfigurationSelector configuration) { var currentContext = CallContext.GetData("MonoDevelop.Projects.ProjectOperationContext") as ProjectOperationContext; ProjectOperationContext newContext = currentContext; // Collect last write times for the files generated by this project var fileTimes = new Dictionary <FilePath, DateTime> (); foreach (var f in GetOutputFiles(configuration)) { fileTimes [f] = File.GetLastWriteTime(f); } try { if (newContext == null) { newContext = new TargetEvaluationContext(); } else if (!(newContext is TargetEvaluationContext)) { newContext = new TargetEvaluationContext(newContext); } var res = OnRunTarget(monitor, target, configuration, (TargetEvaluationContext)newContext); CallContext.SetData("MonoDevelop.Projects.TargetEvaluationResult", res); return(res.BuildResult); } finally { if (newContext != currentContext) { CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", currentContext); } // If any of the project generated files changes, notify it foreach (var e in fileTimes) { if (File.GetLastWriteTime(e.Key) != e.Value) { FileService.NotifyFileChanged(e.Key); } } } }
public async Task TargetEvaluationResultTryGetPathValueForNullPropertyValue() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var p = (Project)sol.Items [0]; var ctx = new TargetEvaluationContext(); ctx.PropertiesToEvaluate.Add("MissingProperty"); var res = await p.RunTarget(Util.GetMonitor(), "Build", p.Configurations [0].Selector, ctx); Assert.IsNull(res.Properties.GetValue("MissingProperty")); FilePath path = null; bool foundProperty = res.Properties.TryGetPathValue("MissingProperty", out path); Assert.IsFalse(foundProperty); p.Dispose(); }
public async Task EvaluateUnknownPropertyDuringBuild() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var project = ((Project)sol.Items[0]); var context = new TargetEvaluationContext(); context.PropertiesToEvaluate.Add("TestUnknownPropertyToEvaluate"); var res = await project.RunTarget(Util.GetMonitor(), "Build", project.Configurations[0].Selector, context); Assert.IsNotNull(res); Assert.IsNotNull(res.BuildResult); Assert.AreEqual(0, res.BuildResult.ErrorCount); Assert.AreEqual(0, res.BuildResult.WarningCount); Assert.IsNull(res.Properties.GetValue("TestUnknownPropertyToEvaluate")); sol.Dispose(); }
public TargetEvaluationResult RunTarget(IProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var currentContext = CallContext.GetData("MonoDevelop.Projects.ProjectOperationContext"); var currentResult = CallContext.GetData("MonoDevelop.Projects.TargetEvaluationResult"); try { CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", context); CallContext.SetData("MonoDevelop.Projects.TargetEvaluationResult", null); var r = RunTarget(monitor, target, configuration); var evalRes = CallContext.GetData("MonoDevelop.Projects.TargetEvaluationResult") as TargetEvaluationResult; if (evalRes != null) { evalRes.BuildResult = r; return(evalRes); } return(new TargetEvaluationResult(r)); } finally { CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", currentContext); CallContext.SetData("MonoDevelop.Projects.TargetEvaluationResult", currentResult); } }
internal protected virtual TargetEvaluationResult OnRunTarget(IProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var currentContext = CallContext.GetData("MonoDevelop.Projects.ProjectOperationContext") as ProjectOperationContext; CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", context); try { var r = base.OnRunTarget(monitor, target, configuration); var evalRes = CallContext.GetData("MonoDevelop.Projects.TargetEvaluationResult") as TargetEvaluationResult; if (evalRes != null) { evalRes.BuildResult = r; } else { evalRes = new TargetEvaluationResult(r); } return(evalRes); } finally { CallContext.SetData("MonoDevelop.Projects.ProjectOperationContext", currentContext); } }
public async Task BuildSessionBeginEnd() { var en = new CustomSolutionItemNode <TestBuildSolutionExtension> (); var en2 = new CustomSolutionItemNode <TestBuildSolutionItemExtension> (); WorkspaceObject.RegisterCustomExtension(en); WorkspaceObject.RegisterCustomExtension(en2); int beginCount = 0, endCount = 0, projectBuildCount = 0, msbuildBeginCount = 0, msbuildEndCount = 0; TestBuildSolutionExtension.BeginBuildCalled = delegate { beginCount++; }; TestBuildSolutionExtension.EndBuildCalled = delegate { endCount++; }; TestBuildSolutionItemExtension.BuildCalled = delegate { Assert.AreEqual(1, beginCount); Assert.AreEqual(0, endCount); projectBuildCount++; }; // This logger is used to verify that the BuildStarted event is raised only once per // build, which means only one build session is started. var customLogger = new MSBuildLogger(); customLogger.EnabledEvents = MSBuildEvent.BuildStarted | MSBuildEvent.BuildFinished; customLogger.EventRaised += (sender, e) => { if (e.Event == MSBuildEvent.BuildStarted) { msbuildBeginCount++; } else if (e.Event == MSBuildEvent.BuildFinished) { msbuildEndCount++; } }; var oldPrefParallelBuild = Runtime.Preferences.ParallelBuild.Value; var oldPrefSkipUnmodified = Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value; try { Runtime.Preferences.ParallelBuild.Set(false); Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(false); FilePath solFile = Util.GetSampleProject("build-session", "build-session.sln"); var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Assert.AreEqual(0, beginCount); Assert.AreEqual(0, endCount); Assert.AreEqual(0, projectBuildCount); Assert.AreEqual(0, msbuildBeginCount); Assert.AreEqual(0, msbuildEndCount); // Test building the whole solution var context = new TargetEvaluationContext(); context.Loggers.Add(customLogger); var res = await sol.Build(Util.GetMonitor(), "Debug", context); Assert.AreEqual(1, beginCount); Assert.AreEqual(1, endCount); Assert.AreEqual(3, projectBuildCount); Assert.AreEqual(1, msbuildBeginCount); Assert.AreEqual(1, msbuildEndCount); // Test building a solution folder beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0; var folder = (SolutionFolder)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "libraries"); context = new TargetEvaluationContext(); context.Loggers.Add(customLogger); res = await folder.Build(Util.GetMonitor(), sol.Configurations["Debug|x86"].Selector, operationContext : context); Assert.AreEqual(1, beginCount); Assert.AreEqual(1, endCount); Assert.AreEqual(2, projectBuildCount); Assert.AreEqual(1, msbuildBeginCount); Assert.AreEqual(1, msbuildEndCount); // Test building a specific item and dependencies beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0; var item = (SolutionItem)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "build-session"); context = new TargetEvaluationContext(); context.Loggers.Add(customLogger); res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, true, context); Assert.AreEqual(1, beginCount); Assert.AreEqual(1, endCount); Assert.AreEqual(3, projectBuildCount); Assert.AreEqual(1, msbuildBeginCount); Assert.AreEqual(1, msbuildEndCount); // Test building a specific item but not its dependencies beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0; context = new TargetEvaluationContext(); context.Loggers.Add(customLogger); res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, false, context); Assert.AreEqual(1, beginCount); Assert.AreEqual(1, endCount); Assert.AreEqual(1, projectBuildCount); Assert.AreEqual(1, msbuildBeginCount); Assert.AreEqual(1, msbuildEndCount); sol.Dispose(); } finally { TestBuildSolutionExtension.BeginBuildCalled = null; TestBuildSolutionExtension.EndBuildCalled = null; TestBuildSolutionItemExtension.BuildCalled = null; WorkspaceObject.UnregisterCustomExtension(en); WorkspaceObject.UnregisterCustomExtension(en2); Runtime.Preferences.ParallelBuild.Set(oldPrefParallelBuild); Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(oldPrefSkipUnmodified); } }
public async Task ConcurrentShortAndBuildOperations() { // If a builder is running a short operation and a build is started, // the build operation will wait for the sort operation to finish // and will use the same builder, instead of starting a new one. // Also, the build session should not start until the short operation // is finished. await RemoteBuildEngineManager.RecycleAllBuilders(); Assert.AreEqual(0, RemoteBuildEngineManager.ActiveEnginesCount); FilePath solFile = Util.GetSampleProject("builder-manager-tests", "builder-manager-tests.sln"); using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { var project1 = (Project)sol.Items.FirstOrDefault(p => p.Name == "SyncBuildProject"); var project2 = (Project)sol.Items.FirstOrDefault(p => p.Name == "App"); InitBuildSyncEvent(project1); // Start the first target. The FileSync target will pause until signaled to continue. // Select the ShortOperations build queue. var context = new TargetEvaluationContext { BuilderQueue = BuilderQueue.ShortOperations }; var build1 = project1.RunTarget(Util.GetMonitor(), "FileSync", sol.Configurations [0].Selector, context); // Wait for the build to reach the sync task await WaitForBuildSyncEvent(project1); Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); // The build is now in progess. Run a new target. var build2 = project2.Build(Util.GetMonitor(), sol.Configurations [0].Selector); // Wait a bit. This should be enough to ensure the build has started. await Task.Delay(1000); // The RunTarget request should be queued, no new builder should be spawned Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); // Continue building the first project SignalBuildToContinue(project1); // The first build should end now if (await Task.WhenAny(build1, Task.Delay(5000)) != build1) { Assert.Fail("Build did not end in time"); } // And now the second build should end if (await Task.WhenAny(build2, Task.Delay(5000)) != build2) { Assert.Fail("Build did not end in time"); } Assert.NotNull(build1.Result); Assert.AreEqual(0, build2.Result.ErrorCount); Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); } }
internal protected virtual Task <TargetEvaluationResult> OnRunTarget(ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { return(next.OnRunTarget(monitor, target, configuration, context)); }
protected override Task<TargetEvaluationResult> OnRunTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { if (target == ProjectService.BuildTarget) target = "all"; else if (target == ProjectService.CleanTarget) target = "clean"; DotNetProjectConfiguration conf = (DotNetProjectConfiguration) Project.GetConfiguration (configuration); return Task<TargetEvaluationResult>.Factory.StartNew (delegate { using (var output = new StringWriter ()) { using (var tw = new LogTextWriter ()) { tw.ChainWriter (output); tw.ChainWriter (monitor.Log); using (ProcessWrapper proc = Runtime.ProcessService.StartProcess ("make", "PROFILE=" + conf.Id + " " + target, conf.OutputDirectory, monitor.Log, tw, null)) proc.WaitForOutput (); tw.UnchainWriter (output); tw.UnchainWriter (monitor.Log); CompilerResults cr = new CompilerResults (null); string[] lines = output.ToString ().Split ('\n'); foreach (string line in lines) { CompilerError err = CreateErrorFromString (line); if (err != null) cr.Errors.Add (err); } return new TargetEvaluationResult (new BuildResult (cr, output.ToString ())); } } }); }
private async Task<TargetEvaluationResult> RunDefinitionTarget(ProtobuildModule module, ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var project = await module.GetShadowProject(this, monitor, configuration); var value = await project.RunTarget(monitor, target, configuration, context); if (target == ProjectService.BuildTarget) { module.OnDefinitionBuilt(this); } return value; }
internal protected virtual Task<TargetEvaluationResult> OnRunTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { return next.OnRunTarget (monitor, target, configuration, context); }
internal protected override BuildResult OnRunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration) { var currentContext = CallContext.GetData ("MonoDevelop.Projects.ProjectOperationContext") as ProjectOperationContext; ProjectOperationContext newContext = currentContext; // Collect last write times for the files generated by this project var fileTimes = new Dictionary<FilePath, DateTime> (); foreach (var f in GetOutputFiles (configuration)) fileTimes [f] = File.GetLastWriteTime (f); try { if (newContext == null) newContext = new TargetEvaluationContext (); else if (!(newContext is TargetEvaluationContext)) newContext = new TargetEvaluationContext (newContext); var res = OnRunTarget (monitor, target, configuration, (TargetEvaluationContext) newContext); CallContext.SetData ("MonoDevelop.Projects.TargetEvaluationResult", res); return res.BuildResult; } finally { if (newContext != currentContext) CallContext.SetData ("MonoDevelop.Projects.ProjectOperationContext", currentContext); // If any of the project generated files changes, notify it foreach (var e in fileTimes) { if (File.GetLastWriteTime (e.Key) != e.Value) FileService.NotifyFileChanged (e.Key); } } }
internal protected virtual TargetEvaluationResult OnRunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var currentContext = CallContext.GetData ("MonoDevelop.Projects.ProjectOperationContext") as ProjectOperationContext; CallContext.SetData ("MonoDevelop.Projects.ProjectOperationContext", context); try { var r = base.OnRunTarget (monitor, target, configuration); var evalRes = CallContext.GetData ("MonoDevelop.Projects.TargetEvaluationResult") as TargetEvaluationResult; if (evalRes != null) evalRes.BuildResult = r; else evalRes = new TargetEvaluationResult (r); return evalRes; } finally { CallContext.SetData ("MonoDevelop.Projects.ProjectOperationContext", currentContext); } }
public async Task RunTarget () { string projFile = Util.GetSampleProject ("msbuild-tests", "project-with-custom-target.csproj"); var p = (Project)await Services.ProjectService.ReadSolutionItem (Util.GetMonitor (), projFile); var ctx = new TargetEvaluationContext (); ctx.GlobalProperties.SetValue ("TestProp", "has"); ctx.PropertiesToEvaluate.Add ("GenProp"); ctx.PropertiesToEvaluate.Add ("AssemblyName"); ctx.ItemsToEvaluate.Add ("GenItem"); var res = await p.RunTarget (Util.GetMonitor (), "Test", p.Configurations [0].Selector, ctx); Assert.AreEqual (1, res.BuildResult.Errors.Count); Assert.AreEqual ("Something failed: has foo bar", res.BuildResult.Errors [0].ErrorText); // Verify that properties are returned Assert.AreEqual ("ConsoleProject", res.Properties.GetValue ("AssemblyName")); Assert.AreEqual ("foo", res.Properties.GetValue ("GenProp")); // Verify that items are returned var items = res.Items.ToArray (); Assert.AreEqual (1, items.Length); Assert.AreEqual ("bar", items [0].Include); Assert.AreEqual ("Hello", items [0].Metadata.GetValue ("MyMetadata")); }
public async Task TargetEvaluationResultTryGetPathValueForNullPropertyValue () { string solFile = Util.GetSampleProject ("console-project", "ConsoleProject.sln"); Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile); var p = (Project)sol.Items [0]; var ctx = new TargetEvaluationContext (); ctx.PropertiesToEvaluate.Add ("MissingProperty"); var res = await p.RunTarget (Util.GetMonitor (), "Build", p.Configurations [0].Selector, ctx); Assert.IsNull (res.Properties.GetValue ("MissingProperty")); FilePath path = null; bool foundProperty = res.Properties.TryGetPathValue ("MissingProperty", out path); Assert.IsFalse (foundProperty); }
internal protected override TargetEvaluationContext OnConfigureTargetEvaluationContext(string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var c = base.OnConfigureTargetEvaluationContext(target, configuration, context); context.GlobalProperties.SetValue("Foo", ControlValue); return(c); }
public async Task ShortOperationsInSingleBuilder() { // Tests that targets using BuilderQueue.ShortOperations share the same builder // and don't spawn a new builder when one of them is being executed and another // one starts executing. await RemoteBuildEngineManager.RecycleAllBuilders(); Assert.AreEqual(0, RemoteBuildEngineManager.ActiveEnginesCount); FilePath solFile = Util.GetSampleProject("builder-manager-tests", "builder-manager-tests.sln"); using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { var project1 = (Project)sol.Items.FirstOrDefault(p => p.Name == "SyncBuildProject"); var project2 = (Project)sol.Items.FirstOrDefault(p => p.Name == "App"); InitBuildSyncEvent(project1); // Start the first target. The FileSync target will pause until signaled to continue. // Select the ShortOperations build queue. var context = new TargetEvaluationContext { BuilderQueue = BuilderQueue.ShortOperations }; var build1 = project1.RunTarget(Util.GetMonitor(), "FileSync", sol.Configurations [0].Selector, context); // Wait for the build to reach the sync task await WaitForBuildSyncEvent(project1); Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); // The build is now in progess. Run a new target. context = new TargetEvaluationContext { BuilderQueue = BuilderQueue.ShortOperations }; var build2 = project2.RunTarget(Util.GetMonitor(), "QuickTarget", sol.Configurations [0].Selector, context); // Wait a bit. This should be enough to ensure the build has started. await Task.Delay(1000); // The RunTarget request should be queued, not new builder should be spawned Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); // Continue building the first project SignalBuildToContinue(project1); // The first build should end now if (await Task.WhenAny(build1, Task.Delay(5000)) != build1) { Assert.Fail("Build did not end in time"); } // And now the second build should end if (await Task.WhenAny(build2, Task.Delay(5000)) != build2) { Assert.Fail("Build did not end in time"); } Assert.NotNull(build1.Result); Assert.NotNull(build2.Result); Assert.AreEqual(1, RemoteBuildEngineManager.ActiveEnginesCount); } }
/// <summary> /// Called to initialize a TargetEvaluationContext instance required by RunTarget() /// and other methods that invoke MSBuild targets /// </summary> /// <returns>The initialized evaluation context (it can be just the provided context)</returns> /// <param name="target">The MSBuild target that is going to be invoked</param> /// <param name="configuration">Build configuration</param> /// <param name="context">Execution context</param> internal protected virtual TargetEvaluationContext OnConfigureTargetEvaluationContext(string target, ConfigurationSelector configuration, TargetEvaluationContext context) { return(next.OnConfigureTargetEvaluationContext(target, configuration, context)); }
protected override Task<TargetEvaluationResult> OnRunTarget (ProgressMonitor monitor, string target, ConfigurationSelector configuration, TargetEvaluationContext context) { var module = (ProtobuildModule)ParentSolution; return RunDefinitionTarget(module, monitor, target, configuration, context); }
/// <summary> /// Checks if this project needs to be built. /// </summary> /// <returns><c>true</c>, if the project is dirty and needs to be rebuilt, <c>false</c> otherwise.</returns> /// <param name="configuration">Build configuration.</param> /// <param name="context">Evaluation context.</param> /// <remarks> /// This method can be overriden to provide custom logic for checking if a project needs to be built, either /// due to changes in the content or in the configuration. /// </remarks> internal protected virtual bool OnFastCheckNeedsBuild(ConfigurationSelector configuration, TargetEvaluationContext context) { return(next.OnFastCheckNeedsBuild(configuration, context)); }