X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FMicrosoft.Build.Engine%2FMicrosoft.Build.BuildEngine%2FEngine.cs;h=5674cbaed389b987e995f3a36f728710844ed049;hb=92c12ba52450f7cc14bd4fd09eaf450157715b00;hp=fd675a7d752d458c50f863623c82bd77ec00af54;hpb=315d6800df2ae11dc533456d8fc73118ab087759;p=mono.git diff --git a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs index fd675a7d752..5674cbaed38 100644 --- a/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs +++ b/mcs/class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine/Engine.cs @@ -31,6 +31,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Mono.XBuild.Utilities; @@ -44,7 +45,7 @@ namespace Microsoft.Build.BuildEngine { const string defaultTasksProjectName = "Microsoft.Common.tasks"; EventSource eventSource; bool buildStarted; - ToolsetDefinitionLocations toolsetLocations; + //ToolsetDefinitionLocations toolsetLocations; BuildPropertyGroup global_properties; //IDictionary importedProjects; List loggers; @@ -72,7 +73,7 @@ namespace Microsoft.Build.BuildEngine { public Engine (ToolsetDefinitionLocations locations) : this (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)) { - toolsetLocations = locations; + //toolsetLocations = locations; } public Engine (BuildPropertyGroup globalProperties) @@ -85,7 +86,7 @@ namespace Microsoft.Build.BuildEngine { : this (ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20)) { this.global_properties = globalProperties; - toolsetLocations = locations; + //toolsetLocations = locations; } // engine should be invoked with path where binary files are @@ -126,6 +127,7 @@ namespace Microsoft.Build.BuildEngine { { if (project == null) throw new ArgumentException ("project"); + builtTargetsOutputByName.Clear (); return project.Build (); } @@ -164,6 +166,9 @@ namespace Microsoft.Build.BuildEngine { if (targetNames == null) return false; + if ((buildFlags & BuildSettings.DoNotResetPreviouslyBuiltTargets) != BuildSettings.DoNotResetPreviouslyBuiltTargets) + builtTargetsOutputByName.Clear (); + if (defaultToolsVersion != null) // it has been explicitly set, xbuild does this.. project.ToolsVersion = defaultToolsVersion; @@ -224,6 +229,34 @@ namespace Microsoft.Build.BuildEngine { IDictionary targetOutputs, BuildSettings buildFlags, string toolsVersion) { + bool result = false; + try { + StartEngineBuild (); + result = BuildProjectFileInternal (projectFile, targetNames, globalProperties, targetOutputs, buildFlags, toolsVersion); + return result; + } catch (InvalidProjectFileException ie) { + this.LogError (projectFile, ie.Message); + this.LogMessage (MessageImportance.Low, String.Format ("{0}: {1}", projectFile, ie.ToString ())); + return false; + } catch (Exception e) { + this.LogError (projectFile, e.Message); + this.LogMessage (MessageImportance.Low, String.Format ("{0}: {1}", projectFile, e.ToString ())); + return false; + } finally { + EndEngineBuild (result); + } + } + + bool BuildProjectFileInternal (string projectFile, + string[] targetNames, + BuildPropertyGroup globalProperties, + IDictionary targetOutputs, + BuildSettings buildFlags, string toolsVersion) + { + + if ((buildFlags & BuildSettings.DoNotResetPreviouslyBuiltTargets) != BuildSettings.DoNotResetPreviouslyBuiltTargets) + builtTargetsOutputByName.Clear (); + Project project; bool newProject = false; @@ -301,8 +334,10 @@ namespace Microsoft.Build.BuildEngine { internal void RemoveLoadedProject (Project p) { - if (p.FullFileName != String.Empty) + if (!String.IsNullOrEmpty (p.FullFileName)) { + ClearBuiltTargetsForProject (p); projects.Remove (p.FullFileName); + } } internal void AddLoadedProject (Project p) @@ -321,8 +356,7 @@ namespace Microsoft.Build.BuildEngine { project.CheckUnloaded (); - if (project.FullFileName != String.Empty) - projects.Remove (project.FullFileName); + RemoveLoadedProject (project); project.Unload (); } @@ -357,12 +391,25 @@ namespace Microsoft.Build.BuildEngine { loggers.Clear (); } - internal void StartProjectBuild (Project project, string [] target_names) + void StartEngineBuild () { if (!buildStarted) { LogBuildStarted (); buildStarted = true; } + } + + void EndEngineBuild (bool succeeded) + { + if (buildStarted && currentlyBuildingProjectsStack.Count == 0) { + LogBuildFinished (succeeded); + buildStarted = false; + } + } + + internal void StartProjectBuild (Project project, string [] target_names) + { + StartEngineBuild (); if (currentlyBuildingProjectsStack.Count == 0 || String.Compare (currentlyBuildingProjectsStack.Peek ().FullFileName, project.FullFileName) != 0) @@ -388,10 +435,15 @@ namespace Microsoft.Build.BuildEngine { String.Compare (top_project.FullFileName, currentlyBuildingProjectsStack.Peek ().FullFileName) != 0) LogProjectFinished (top_project, succeeded); - if (currentlyBuildingProjectsStack.Count == 0) { - LogBuildFinished (succeeded); - buildStarted = false; - } + EndEngineBuild (succeeded); + } + + internal void ClearBuiltTargetsForProject (Project project) + { + string project_key = project.GetKeyForTarget (String.Empty, false); + var to_remove_keys = BuiltTargetsOutputByName.Keys.Where (key => key.StartsWith (project_key)).ToList (); + foreach (string to_remove_key in to_remove_keys) + BuiltTargetsOutputByName.Remove (to_remove_key); } void LogProjectStarted (Project project, string [] target_names) @@ -501,16 +553,14 @@ namespace Microsoft.Build.BuildEngine { public string DefaultToolsVersion { get { - if (String.IsNullOrEmpty (defaultToolsVersion)) -#if NET_4_0 - return "4.0"; -#elif NET_3_5 - return "3.5"; -#else - return "2.0"; -#endif - - return defaultToolsVersion; + // This is used as the fall back version if the + // project can't find a version to use + // Hard-coded to 2.0, so it allows even vs2005 projects + // to build correctly, as they won't have a ToolsVersion + // set! + return String.IsNullOrEmpty (defaultToolsVersion) + ? "2.0" + : defaultToolsVersion; } set { if (Toolsets [value] == null)