Skip to content

Commit

Permalink
Optimization neglected to include condition (#5927)
Browse files Browse the repository at this point in the history
Optimization for RemoveOperation neglected to consider condition. Fixes that and adds a test.

Fixes #5766

Introduced by #5350
  • Loading branch information
Forgind authored Dec 3, 2020
1 parent 27cef46 commit cd29721
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Build.OM.UnitTests/Definition/ProjectItem_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,17 @@ public void UpdateShouldImportMetadataFromReferencedItem()
ObjectModelHelpers.AssertItemHasMetadata(expectedMetadataC, items[4]);
}

[Fact]
public void OptimizedRemoveOperationRespectsCondition()
{
string content = @"<TheItem Include=""InitialValue"" />
<TheItem Remove=""@(TheItem)"" Condition=""false"" />
<TheItem Include=""ReplacedValue"" Condition=""false"" /> ";
IList<ProjectItem> items = ObjectModelHelpers.GetItemsFromFragment(content, true);

items[0].EvaluatedInclude.ShouldBe("InitialValue");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Build/Evaluation/LazyItemEvaluator.RemoveOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void ApplyImpl(ImmutableList<ItemData>.Builder listBuilder, I
new BuildEventFileInfo(string.Empty),
"OM_MatchOnMetadataIsRestrictedToOnlyOneReferencedItem");

if (_matchOnMetadata.IsEmpty && ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType))
if (_matchOnMetadata.IsEmpty && ItemspecContainsASingleBareItemReference(_itemSpec, _itemElement.ItemType) && _conditionResult)
{
// Perf optimization: If the Remove operation references itself (e.g. <I Remove="@(I)"/>)
// then all items are removed and matching is not necessary
Expand Down

0 comments on commit cd29721

Please sign in to comment.