Skip to content

Commit

Permalink
[xbuild] Clear the built targets cache on project unload.
Browse files Browse the repository at this point in the history
Remove the entries for a project from the built targets cache, on
project unload.

* Microsoft.Build.BuildEngine/Engine.cs (ClearBuiltTargetsForProject): New.
* Microsoft.Build.BuildEngine/Project.cs (BuiltTargetKeys): Remove.
(RemoveBuiltTargets): Use Engine.ClearBuiltTargetsForProject .
* Microsoft.Build.BuildEngine/Target.cs: Track api changes.
*
  • Loading branch information
radical committed Feb 2, 2011
1 parent 7ce5ff1 commit e516b54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -311,8 +312,10 @@ public Project GetLoadedProject (string projectFullFileName)

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)
Expand All @@ -331,8 +334,7 @@ public void UnloadProject (Project project)

project.CheckUnloaded ();

if (project.FullFileName != String.Empty)
projects.Remove (project.FullFileName);
RemoveLoadedProject (project);

project.Unload ();
}
Expand Down Expand Up @@ -404,6 +406,14 @@ internal void EndProjectBuild (Project project, bool 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)
{
string targets;
Expand Down
Expand Up @@ -73,7 +73,6 @@ public class Project {
XmlDocument xmlDocument;
bool unloaded;
bool initialTargetsBuilt;
List<string> builtTargetKeys;
bool building;
BuildSettings current_settings;
Stack<Batch> batches;
Expand Down Expand Up @@ -111,7 +110,6 @@ public Project (Engine engine, string toolsVersion)

encoding = null;

builtTargetKeys = new List<string> ();
initialTargets = new List<string> ();
defaultTargets = new string [0];
batches = new Stack<Batch> ();
Expand Down Expand Up @@ -351,9 +349,16 @@ bool BuildTarget (string target_name, IDictionary targetOutputs)
}

internal string GetKeyForTarget (string target_name)
{
return GetKeyForTarget (target_name, true);
}

internal string GetKeyForTarget (string target_name, bool include_global_properties)
{
// target name is case insensitive
return fullFileName + ":" + target_name.ToLower () + ":" + GlobalPropertiesToString (GlobalProperties);
return fullFileName + ":" + target_name.ToLower () +
(include_global_properties ? (":" + GlobalPropertiesToString (GlobalProperties))
: String.Empty);
}

string GlobalPropertiesToString (BuildPropertyGroup bgp)
Expand Down Expand Up @@ -896,8 +901,7 @@ void Evaluate ()
// Removes entries of all earlier built targets for this project
void RemoveBuiltTargets ()
{
foreach (string key in builtTargetKeys)
ParentEngine.BuiltTargetsOutputByName.Remove (key);
ParentEngine.ClearBuiltTargetsForProject (this);
}

void InitializeProperties (string effective_tools_version)
Expand Down Expand Up @@ -1396,10 +1400,6 @@ internal void LogWarning (string filename, string message, params object[] messa
get; internal set;
}

internal List<string> BuiltTargetKeys {
get { return builtTargetKeys; }
}

internal Dictionary <string, BuildItemGroup> LastItemGroupContaining {
get { return last_item_group_containing; }
}
Expand Down
Expand Up @@ -165,7 +165,6 @@ bool Build (string built_targets_key, out bool executeOnErrors)
}

project.ParentEngine.BuiltTargetsOutputByName [built_targets_key] = (ITaskItem[]) Outputs.Clone ();
project.BuiltTargetKeys.Add (built_targets_key);

return result;
}
Expand Down

0 comments on commit e516b54

Please sign in to comment.