Skip to content

Commit 76931c2

Browse files
author
Stewart Miles
committed
Disable all obsolete files that are referenced by packages.
Previously, the Version Handler would only disable a file if it was determined as obsolete on a file-by-file basis. For example, a/b/c/foo-1.2.3.dll is older than a/b/c/foo-1.2.4.dll so a/b/c/foo-1.2.3.dll would be disabled and marked for deletion. However, if a file was obsolete *and* moved between package updates it would not be disabled but would be marked for deletion as the file would not exist in the most recent package manifest. This scenario is problematic if the developer doesn't clean up the old file when prompted (target builds break) or the file is loaded in the editor (editor plugins break). This change adds files that are determined obsolete by comparing differences between package manifests to the set of files to disable. Bug: 150886091 Change-Id: I49c711feef9817c79e9d36ffebc4f8503fba33ed
1 parent 0c7b662 commit 76931c2

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

source/VersionHandlerImpl/src/VersionHandlerImpl.cs

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,17 @@ public void Add(FileMetadata metadata) {
919919
/// <returns>true if any plugin metadata was modified and requires an
920920
/// AssetDatabase.Refresh(), false otherwise.</return>
921921
public bool EnableMostRecentPlugins() {
922+
return EnableMostRecentPlugins(new HashSet<string>());
923+
}
924+
925+
/// <summary>
926+
/// If this instance references a set of plugins, enable the most
927+
/// recent versions.
928+
/// </summary>
929+
/// <param name="disableFiles">Set of files in the project that should be disabled.</param>
930+
/// <returns>true if any plugin metadata was modified and requires an
931+
/// AssetDatabase.Refresh(), false otherwise.</return>
932+
public bool EnableMostRecentPlugins(HashSet<string> disableFiles) {
922933
bool modified = false;
923934
int versionIndex = 0;
924935
int numberOfVersions = metadataByVersion.Count;
@@ -970,13 +981,16 @@ public bool EnableMostRecentPlugins() {
970981
bool modifiedThisVersion = false;
971982
// Only enable the most recent plugin - SortedDictionary
972983
// orders keys in ascending order.
973-
bool obsoleteVersion = (numberOfVersions > 1 &&
974-
versionIndex < numberOfVersions);
984+
bool obsoleteVersion =
985+
(numberOfVersions > 1 && versionIndex < numberOfVersions) ||
986+
disableFiles.Contains(metadata.filename);
975987
// If this is an obsolete version.
976988
if (obsoleteVersion) {
977989
// Disable for all platforms and the editor.
978990
editorEnabled = false;
979991
selectedTargets = new HashSet<BuildTarget>();
992+
Log(String.Format("{0} is obsolete and will be disabled.", metadata.filename),
993+
verbose: true);
980994
} else {
981995
if (hasDotNetTargets) {
982996
// Determine whether this is supported by the selected .NET version.
@@ -1055,6 +1069,8 @@ public bool EnableMostRecentPlugins() {
10551069
// Therefore, force a reimport of each file touched by the
10561070
// plugin importer.
10571071
if (modifiedThisVersion) {
1072+
Log(String.Format("Metadata changed: force import of {0}", metadata.filename),
1073+
verbose: true);
10581074
AssetDatabase.ImportAsset(metadata.filename,
10591075
ImportAssetOptions.ForceUpdate);
10601076
}
@@ -1396,6 +1412,21 @@ public void ConsolidateManifests() {
13961412
/// <returns>true if any plugin metadata was modified and requires an
13971413
/// AssetDatabase.Refresh(), false otherwise.</return>
13981414
public bool EnableMostRecentPlugins(bool forceUpdate) {
1415+
return EnableMostRecentPlugins(forceUpdate, new HashSet<string>());
1416+
}
1417+
1418+
/// <summary>
1419+
/// For each plugin (DLL) referenced by this set, disable targeting
1420+
/// for all versions and re-enable platform targeting for the most
1421+
/// recent version.
1422+
/// </summary>
1423+
/// <param name="forceUpdate">Whether the update was forced by the
1424+
/// user.</param>
1425+
/// <param name="disableFiles">Set of files that should be disabled.</param>
1426+
/// <returns>true if any plugin metadata was modified and requires an
1427+
/// AssetDatabase.Refresh(), false otherwise.</return>
1428+
public bool EnableMostRecentPlugins(bool forceUpdate,
1429+
HashSet<string> disableFiles) {
13991430
bool modified = false;
14001431

14011432
// If PluginImporter isn't available it's not possible
@@ -1474,7 +1505,7 @@ public bool EnableMostRecentPlugins(bool forceUpdate) {
14741505
}
14751506

14761507
foreach (var metadataByVersion in Values) {
1477-
modified |= metadataByVersion.EnableMostRecentPlugins();
1508+
modified |= metadataByVersion.EnableMostRecentPlugins(disableFiles);
14781509
}
14791510
return modified;
14801511
}
@@ -1790,6 +1821,18 @@ public class ObsoleteFiles {
17901821
/// </summary>
17911822
public Dictionary<string, List<string>> referencedExcludingManifests;
17921823

1824+
/// <summary>
1825+
/// Get all referenced and unreferenced obsolete files.
1826+
/// </summary>
1827+
public HashSet<string> All {
1828+
get {
1829+
var all = new HashSet<string>();
1830+
all.UnionWith(unreferenced);
1831+
all.UnionWith(referenced.Keys);
1832+
return all;
1833+
}
1834+
}
1835+
17931836
/// <summary>
17941837
/// Build an ObsoleteFiles instance searching a set of
17951838
/// ManifestReferences and a FileMetadataSet for old files.
@@ -2401,15 +2444,15 @@ public static void UpdateVersionedAssets(bool forceUpdate, Action complete) {
24012444
if (!forceUpdate) {
24022445
metadataSet = FileMetadataSet.FindWithPendingUpdates(metadataSet);
24032446
}
2404-
if (metadataSet.EnableMostRecentPlugins(forceUpdate)) {
2447+
2448+
var obsoleteFiles = new ObsoleteFiles(
2449+
ManifestReferences.FindAndReadManifests(metadataSet), metadataSet);
2450+
if (metadataSet.EnableMostRecentPlugins(forceUpdate, obsoleteFiles.All)) {
24052451
analytics.Report("enablemostrecentplugins", "Enable Most Recent Plugins");
24062452
AssetDatabase.Refresh();
24072453
Refreshing = true;
24082454
}
24092455

2410-
var obsoleteFiles = new ObsoleteFiles(
2411-
ManifestReferences.FindAndReadManifests(metadataSet), metadataSet);
2412-
24132456
// Obsolete files that are no longer referenced can be safely deleted, prompt the user for
24142457
// confirmation if they have the option enabled.
24152458
var cleanupFiles = new List<KeyValuePair<string, string>>();

0 commit comments

Comments
 (0)