Skip to content

Commit 60cf294

Browse files
committed
avoid error with PathTooLongException: the TaskItem contains a list of all source files of a package separated by '|' which can lead to very long items. Reimplement FinishBuild() to split the list first before normalizing paths.
1 parent 3a513e7 commit 60cf294

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

msbuild/dbuild/MultiToolTaskVisualD.cs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ protected int PrepareTasksPerPackage(ITaskItem[] sources)
182182
int compilationPackageCount = 0;
183183
foreach(var source in sources)
184184
{
185-
string package = GetPackageName(source);
186-
185+
string package = GetPackageName(source);
186+
187187
List<List<ITaskItem>> taskItemsPerPackage;
188188
if (!tasksPerPackage.TryGetValue(package, out taskItemsPerPackage))
189189
{
@@ -219,7 +219,7 @@ protected int PrepareTasksPerPackage(ITaskItem[] sources)
219219
taskItemsPerPackage.Add(itemList);
220220
++compilationPackageCount;
221221
}
222-
}
222+
}
223223
return compilationPackageCount;
224224
}
225225

@@ -604,7 +604,7 @@ protected int ProcessTasks()
604604
}
605605
if (!cts.IsCancellationRequested)
606606
{
607-
FinishBuild(0);
607+
_FinishBuild(0);
608608
}
609609
}
610610
else
@@ -689,8 +689,40 @@ select v.Trim())
689689
}
690690
}
691691
return propertiesSet;
692-
}
693-
692+
}
693+
694+
public override void Cancel()
695+
{
696+
cts.Cancel();
697+
_FinishBuild(0);
698+
}
699+
700+
static string _FormatRootingMarker(string sources)
701+
{
702+
string[] splitSources = sources.Split('|');
703+
List<string> stringList = new List<string>(splitSources.Length);
704+
foreach (string source in splitSources)
705+
stringList.Add(Path.GetFullPath(source).ToUpperInvariant());
706+
stringList.Sort((IComparer<string>)StringComparer.OrdinalIgnoreCase);
707+
return string.Join("|", (IEnumerable<string>)stringList);
708+
}
709+
710+
// to replace super.FinishBuild
711+
protected int _FinishBuild(int exitCode)
712+
{
713+
if (PostBuildTrackingCleanup)
714+
exitCode = PostExecuteTool(exitCode);
715+
if (sourcesToCommandLines != null)
716+
{
717+
foreach (var allTask in taskScheduler.GetAllTasks())
718+
// original causes PathTooLongException for long list of files used as ITaskItem.itemSpec
719+
//sourcesToCommandLines.Remove(FileTracker.FormatRootingMarker((ITaskItem)new TaskItem(allTask.Key)));
720+
sourcesToCommandLines.Remove(_FormatRootingMarker(allTask.Key));
721+
WriteSourcesToCommandLinesTable(sourcesToCommandLines);
722+
}
723+
return exitCode;
724+
}
725+
694726
protected override int PostExecuteTool(int exitCode)
695727
{
696728
// need to call PostExecuteTool per package
@@ -702,9 +734,9 @@ protected override int PostExecuteTool(int exitCode)
702734
foreach (var package in tasksPerPackage)
703735
{
704736
foreach (var taskItems in package.Value)
705-
{
706-
SourcesCompiled = Enumerable.Intersect(srcsCompiled, taskItems).ToArray();
707-
trackedInputFiles = taskItems.ToArray();
737+
{
738+
SourcesCompiled = Enumerable.Intersect(srcsCompiled, taskItems).ToArray();
739+
trackedInputFiles = taskItems.ToArray();
708740
exitCode = base.PostExecuteTool(exitCode);
709741
}
710742
}

0 commit comments

Comments
 (0)