Skip to content

Commit

Permalink
Merge pull request #9609 from drewnoakes/futdc-tidying
Browse files Browse the repository at this point in the history
FUTDC tidying
  • Loading branch information
drewnoakes authored Dec 5, 2024
2 parents 5983ea9 + b14bdd8 commit fa5feb1
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void ApplyProjectEvaluation(IWorkspaceProjectContext context, IComparable
if (!difference.AnyChanges)
return;

difference = HandlerServices.NormalizeRenames(difference);
difference = difference.NormalizeRenames();

EnqueueProjectEvaluation();

Expand All @@ -100,7 +100,7 @@ public void ApplyProjectBuild(IWorkspaceProjectContext context, IComparable vers
if (!difference.AnyChanges)
return;

difference = HandlerServices.NormalizeRenames(difference);
difference = difference.NormalizeRenames();
difference = ResolveProjectBuildConflicts(version, difference);

ApplyChangesToContext(context, difference, ImmutableStringDictionary<IImmutableDictionary<string, string>>.EmptyOrdinal, ImmutableStringDictionary<IImmutableDictionary<string, string>>.EmptyOrdinal, isActiveContext, logger, evaluation: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Handle(IWorkspaceProjectContext context, IImmutableDictionary<string
if (!projectChange.Difference.AnyChanges)
continue;

IProjectChangeDiff difference = HandlerServices.NormalizeRenames(projectChange.Difference);
IProjectChangeDiff difference = projectChange.Difference.NormalizeRenames();

foreach (string includePath in difference.RemovedItems)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe

foreach (string output in outputs)
{
System.Diagnostics.Debug.Assert(Path.IsPathRooted(output), "Output path must be rooted", output);

token.ThrowIfCancellationRequested();

log.VerboseLiteral(output);

DateTime? outputTime = timestampCache.GetTimestampUtc(output);

if (outputTime is null)
Expand Down Expand Up @@ -266,8 +270,12 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe

foreach ((string input, string? itemType, bool isRequired) in inputs)
{
System.Diagnostics.Debug.Assert(Path.IsPathRooted(input), "Output path must be rooted", input);

token.ThrowIfCancellationRequested();

log.VerboseLiteral(input);

DateTime? inputTime = timestampCache.GetTimestampUtc(input);

if (inputTime is null)
Expand Down Expand Up @@ -321,10 +329,7 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe
if (state.NewestImportInput is not null)
{
log.Verbose(nameof(VSResources.FUTD_AddingNewestImportInput));
using (log.IndentScope())
{
log.VerboseLiteral(state.NewestImportInput);
}
using Log.Scope _ = log.IndentScope();
yield return (Path: state.NewestImportInput, ItemType: null, IsRequired: true);
}

Expand All @@ -337,7 +342,6 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe
foreach (string item in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(item);
log.VerboseLiteral(absolutePath);
yield return (Path: absolutePath, itemType, IsRequired: true);
}
}
Expand All @@ -351,7 +355,6 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe
foreach (string path in state.ResolvedAnalyzerReferencePaths)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return (Path: absolutePath, ItemType: ResolvedAnalyzerReference.SchemaName, IsRequired: true);
}
}
Expand All @@ -365,7 +368,6 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe
foreach (string path in state.ResolvedCompilationReferencePaths)
{
System.Diagnostics.Debug.Assert(Path.IsPathRooted(path), "ResolvedCompilationReference path should be rooted");
log.VerboseLiteral(path);
yield return (Path: path, ItemType: ResolvedCompilationReference.SchemaName, IsRequired: true);
}
}
Expand All @@ -388,7 +390,6 @@ bool CheckInputsAndOutputs(IEnumerable<(string Path, string? ItemType, bool IsRe
foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return (Path: absolutePath, ItemType: UpToDateCheckInput.SchemaName, IsRequired: true);
}
}
Expand All @@ -415,9 +416,7 @@ IEnumerable<string> CollectDefaultOutputs()

foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return absolutePath;
yield return _configuredProject.UnconfiguredProject.MakeRooted(path);
}
}
}
Expand All @@ -440,9 +439,7 @@ IEnumerable<string> CollectDefaultOutputs()

foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return absolutePath;
yield return _configuredProject.UnconfiguredProject.MakeRooted(path);
}
}
}
Expand All @@ -469,7 +466,6 @@ IEnumerable<string> CollectDefaultOutputs()
foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return (Path: absolutePath, ItemType: UpToDateCheckInput.SchemaName, IsRequired: true);
}
}
Expand All @@ -496,9 +492,7 @@ IEnumerable<string> CollectSetOutputs(string setName)

foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return absolutePath;
yield return _configuredProject.UnconfiguredProject.MakeRooted(path);
}
}
}
Expand All @@ -521,9 +515,7 @@ IEnumerable<string> CollectSetOutputs(string setName)

foreach (string path in items)
{
string absolutePath = _configuredProject.UnconfiguredProject.MakeRooted(path);
log.VerboseLiteral(absolutePath);
yield return absolutePath;
yield return _configuredProject.UnconfiguredProject.MakeRooted(path);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ public static UpToDateCheckImplicitConfiguredInput CreateDisabled(ProjectConfigu
newestImportInput: null,
isDisabled: true,
isBuildAccelerationEnabled: false,
inputSourceItemTypes: ImmutableArray<string>.Empty,
inputSourceItemTypes: [],
inputSourceItemsByItemType: ImmutableDictionary<string, ImmutableArray<string>>.Empty,
upToDateCheckInputItemsByKindBySetName: ImmutableDictionary<string, ImmutableDictionary<string, ImmutableArray<string>>>.Empty,
upToDateCheckOutputItemsByKindBySetName: ImmutableDictionary<string, ImmutableDictionary<string, ImmutableArray<string>>>.Empty,
upToDateCheckBuiltItemsByKindBySetName: ImmutableDictionary<string, ImmutableDictionary<string, ImmutableArray<string>>>.Empty,
buildFromInputFileItems: ImmutableArray<(string DestinationRelative, string SourceRelative)>.Empty,
resolvedAnalyzerReferencePaths: ImmutableArray<string>.Empty,
resolvedCompilationReferencePaths: ImmutableArray<string>.Empty,
copyReferenceInputs: ImmutableArray<string>.Empty,
presentBuildAccelerationIncompatiblePackages: ImmutableArray<string>.Empty,
buildFromInputFileItems: [],
resolvedAnalyzerReferencePaths: [],
resolvedCompilationReferencePaths: [],
copyReferenceInputs: [],
presentBuildAccelerationIncompatiblePackages: [],
lastItemsChangedAtUtc: null,
lastItemChanges: ImmutableArray<(bool IsAdd, string ItemType, string)>.Empty,
lastItemChanges: [],
itemHash: null,
projectCopyData: default);
}
Expand Down Expand Up @@ -232,20 +232,20 @@ private UpToDateCheckImplicitConfiguredInput(ProjectConfiguration projectConfigu

ProjectConfiguration = projectConfiguration;
LastItemsChangedAtUtc = null;
InputSourceItemTypes = ImmutableArray<string>.Empty;
InputSourceItemTypes = [];
InputSourceItemsByItemType = ImmutableDictionary.Create<string, ImmutableArray<string>>(StringComparers.ItemTypes);
SetNames = ImmutableArray<string>.Empty;
KindNames = ImmutableArray<string>.Empty;
SetNames = [];
KindNames = [];
UpToDateCheckInputItemsByKindBySetName = emptyItemBySetName;
UpToDateCheckOutputItemsByKindBySetName = emptyItemBySetName;
UpToDateCheckBuiltItemsByKindBySetName = emptyItemBySetName;
BuiltFromInputFileItems = ImmutableArray<(string DestinationRelative, string SourceRelative)>.Empty;
ResolvedAnalyzerReferencePaths = ImmutableArray<string>.Empty;
ResolvedCompilationReferencePaths = ImmutableArray<string>.Empty;
CopyReferenceInputs = ImmutableArray<string>.Empty;
PresentBuildAccelerationIncompatiblePackages = ImmutableArray<string>.Empty;
LastItemChanges = ImmutableArray<(bool IsAdd, string ItemType, string)>.Empty;
ProjectCopyData = new(null, "", false, ImmutableArray<CopyItem>.Empty, ImmutableArray<string>.Empty);
BuiltFromInputFileItems = [];
ResolvedAnalyzerReferencePaths = [];
ResolvedCompilationReferencePaths = [];
CopyReferenceInputs = [];
PresentBuildAccelerationIncompatiblePackages = [];
LastItemChanges = [];
ProjectCopyData = new(null, "", false, [], []);
}

private UpToDateCheckImplicitConfiguredInput(
Expand Down Expand Up @@ -370,7 +370,7 @@ public UpToDateCheckImplicitConfiguredInput Update(

bool itemTypesChanged = false;

List<(bool IsAdd, string ItemType, string)> lastItemChanges = new();
List<(bool IsAdd, string ItemType, string ItemSpec)> lastItemChanges = [];

// If an item type was removed, remove all items of that type
foreach (string removedItemType in itemTypeDiff.Removed)
Expand Down Expand Up @@ -403,7 +403,9 @@ public UpToDateCheckImplicitConfiguredInput Update(
// Rule name (schema name) is usually the same as its item type, but not always (eg: auto-generated rules)
string? itemType = null;
if (projectCatalogSnapshot.NamedCatalogs.TryGetValue(PropertyPageContexts.File, out IPropertyPagesCatalog? fileCatalog))
{
itemType = fileCatalog.GetSchema(schemaName)?.DataSource.ItemType;
}

if (itemType is null || !inputSourceItemTypes.Contains(itemType))
{
Expand All @@ -412,13 +414,13 @@ public UpToDateCheckImplicitConfiguredInput Update(

if (!inputSourceItemsByItemTypeBuilder.TryGetValue(itemType, out ImmutableArray<string> before))
{
before = ImmutableArray<string>.Empty;
before = [];
}

projectFileClassifier ??= BuildClassifier();

var after = projectChange.After.Items
.Select(item => item.Key)
.Select(pair => pair.Key)
.Where(path => !projectFileClassifier.IsNonModifiable(path))
.ToHashSet(StringComparers.Paths);

Expand Down Expand Up @@ -601,7 +603,7 @@ ImmutableArray<string> UpdatePresentBuildAccelerationIncompatiblePackages()
}

return builder is null
? ImmutableArray<string>.Empty
? []
: builder.Capacity == builder.Count
? builder.MoveToImmutable()
: builder.ToImmutable();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
PageTemplate="generic"
PropertyPagesHidden="true"
xmlns="http://schemas.microsoft.com/build/2009/properties">

<Rule.DataSource>
<DataSource HasConfigurationCondition="false"
ItemType="Compile"
Persistence="ProjectFile"
SourceOfDefaultValue="AfterContext" />
</Rule.DataSource>

<BoolProperty Name="ExcludeFromCurrentConfiguration"
Visible="False" />

<DynamicEnumProperty Name="{}{ItemType}"
EnumProvider="ItemTypes" />

Expand Down Expand Up @@ -53,6 +51,9 @@
<BoolProperty Name="DesignTimeSharedInput"
Visible="false" />

<BoolProperty Name="ExcludeFromCurrentConfiguration"
Visible="False" />

<StringProperty Name="Generator" />

<StringProperty Name="LastGenOutput"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Microsoft.VisualStudio.ProjectSystem;

internal static class ProjectChangeDiffExtensions
{
/// <summary>
/// Normalizes <see cref="IProjectChangeDiff.RenamedItems"/> to <see cref="IProjectChangeDiff.AddedItems"/>
/// and <see cref="IProjectChangeDiff.RemovedItems"/>.
/// </summary>
public static IProjectChangeDiff NormalizeRenames(this IProjectChangeDiff difference)
{
// Optimize for common case
if (difference.RenamedItems.Count == 0)
{
return difference;
}

// Treat renamed items as just as an Add and Remove, makes finding conflicts easier
IEnumerable<string> renamedNewNames = difference.RenamedItems.Select(r => r.Value);
IEnumerable<string> renamedOldNames = difference.RenamedItems.Select(e => e.Key);

IImmutableSet<string> added = difference.AddedItems.Union(renamedNewNames);
IImmutableSet<string> removed = difference.RemovedItems.Union(renamedOldNames);

return new ProjectChangeDiff(added, removed, difference.ChangedItems);
}
}

0 comments on commit fa5feb1

Please sign in to comment.