-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* A better GetAllGlobs implementation Resolves #1795 GlobResult needs to offer a globbing object that CPS can match arbitrary strings against. The glob needed to include all the globs from a project item element's include attribute, and exclude all the itemspec fragments from the corresponding Exclude and all subsequent Remove elements that apply to that include. This required changing GetAllGlobs such that it incorporates information from Removes and constructs MSBuildGlobWithGaps objects for each include operation with globs. In addition, there should be one glob result aggregating the information per item project element. * CompositeGlob ctor clones input in ImmutableArray CompositeGlob needs to be immutable, so entering objects need to be cloned / immutable. Immutable arrays because they are fast to iterate and don't add a wrapping object. * ItemSpec knows how to convert itself to IMSBuildGlob
- Loading branch information
Showing
11 changed files
with
568 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
//----------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
using Microsoft.Build.Collections; | ||
using Microsoft.Build.Execution; | ||
using Microsoft.Build.UnitTests.BackEnd; | ||
using Xunit; | ||
using ProjectInstanceItemSpec = | ||
Microsoft.Build.Evaluation.ItemSpec<Microsoft.Build.Execution.ProjectPropertyInstance, Microsoft.Build.Execution.ProjectItemInstance>; | ||
using ProjectInstanceExpander = | ||
Microsoft.Build.Evaluation.Expander<Microsoft.Build.Execution.ProjectPropertyInstance, Microsoft.Build.Execution.ProjectItemInstance>; | ||
|
||
namespace Microsoft.Build.UnitTests.OM.Evaluation | ||
{ | ||
public class ItemSpec_Tests | ||
{ | ||
[Fact] | ||
public void EachFragmentTypeShouldContributeToItemSpecGlob() | ||
{ | ||
var itemSpec = CreateItemSpecFrom("a;b*;c*;@(foo)", CreateExpander(new Dictionary<string, string[]> {{"foo", new[] {"d", "e"}}})); | ||
|
||
var itemSpecGlob = itemSpec.ToMSBuildGlob(); | ||
|
||
Assert.True(itemSpecGlob.IsMatch("a")); | ||
Assert.True(itemSpecGlob.IsMatch("bar")); | ||
Assert.True(itemSpecGlob.IsMatch("car")); | ||
Assert.True(itemSpecGlob.IsMatch("d")); | ||
Assert.True(itemSpecGlob.IsMatch("e")); | ||
} | ||
|
||
[Fact] | ||
public void FragmentGlobsWorkAfterStateIsPartiallyInitializedByOtherOperations() | ||
{ | ||
var itemSpec = CreateItemSpecFrom("a;b*;c*;@(foo)", CreateExpander(new Dictionary<string, string[]> {{"foo", new[] {"d", "e"}}})); | ||
|
||
int matches; | ||
// cause partial Lazy state to initialize in the ItemExpressionFragment | ||
itemSpec.FragmentsMatchingItem("e", out matches); | ||
|
||
Assert.Equal(1, matches); | ||
|
||
var itemSpecGlob = itemSpec.ToMSBuildGlob(); | ||
|
||
Assert.True(itemSpecGlob.IsMatch("a")); | ||
Assert.True(itemSpecGlob.IsMatch("bar")); | ||
Assert.True(itemSpecGlob.IsMatch("car")); | ||
Assert.True(itemSpecGlob.IsMatch("d")); | ||
Assert.True(itemSpecGlob.IsMatch("e")); | ||
} | ||
|
||
private ProjectInstanceItemSpec CreateItemSpecFrom(string itemSpec, ProjectInstanceExpander expander) | ||
{ | ||
return new ProjectInstanceItemSpec(itemSpec, expander, MockElementLocation.Instance); | ||
} | ||
|
||
private ProjectInstanceExpander CreateExpander(Dictionary<string, string[]> items) | ||
{ | ||
var itemDictionary = ToItemDictionary(items); | ||
|
||
return new ProjectInstanceExpander(new PropertyDictionary<ProjectPropertyInstance>(), itemDictionary); | ||
} | ||
|
||
private static ItemDictionary<ProjectItemInstance> ToItemDictionary(Dictionary<string, string[]> itemTypes) | ||
{ | ||
var itemDictionary = new ItemDictionary<ProjectItemInstance>(); | ||
|
||
var dummyProject = ProjectHelpers.CreateEmptyProjectInstance(); | ||
|
||
foreach (var itemType in itemTypes) | ||
{ | ||
foreach (var item in itemType.Value) | ||
{ | ||
itemDictionary.Add(new ProjectItemInstance(dummyProject, itemType.Key, item, dummyProject.FullPath)); | ||
} | ||
} | ||
|
||
return itemDictionary; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.