Skip to content

Commit

Permalink
Subtract instead of building the cartesian product in targets (#65123)
Browse files Browse the repository at this point in the history
* Subtract instead of cartesian product in targets

See #64000 (comment). These targets were quite expensive and noticeable in no-op builds. Instead of building the cartesian product via item batching, using subtraction which avoids unnecessary items to be computed.

* Update resolveContract.targets

* Update targetingpacks.targets

* Update resolveContract.targets

* Update resolveContract.targets
  • Loading branch information
ViktorHofer authored Feb 11, 2022
1 parent 49fea67 commit 9293aab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
12 changes: 7 additions & 5 deletions eng/references.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
Condition="'$(DisableTransitiveProjectReferences)' != 'true' and
'@(DefaultReferenceExclusion)' != ''">
<ItemGroup>
<_transitiveProjectReferenceWithExclusion Include="@(ProjectReference)">
<Exclusion>%(DefaultReferenceExclusion.Identity)</Exclusion>
</_transitiveProjectReferenceWithExclusion>
<ProjectReference Remove="@(_transitiveProjectReferenceWithExclusion)"
Condition="'%(_transitiveProjectReferenceWithExclusion.NuGetPackageId)' == '%(_transitiveProjectReferenceWithExclusion.Exclusion)'" />
<_transitiveProjectReferenceWithProjectName Include="@(ProjectReference->Metadata('NuGetPackageId'))"
OriginalIdentity="%(Identity)" />
<_transitiveIncludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
Exclude="@(DefaultReferenceExclusion)" />
<_transitiveExcludedProjectReferenceWithProjectName Include="@(_transitiveProjectReferenceWithProjectName)"
Exclude="@(_transitiveIncludedProjectReferenceWithProjectName)" />
<ProjectReference Remove="@(_transitiveExcludedProjectReferenceWithProjectName->Metadata('OriginalIdentity'))" />
</ItemGroup>
</Target>

Expand Down
10 changes: 4 additions & 6 deletions eng/resolveContract.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
</PropertyGroup>
<!-- Clear the ReferenceAssembly attribute on resolved P2Ps that set SkipUseReferenceAssembly to true. -->
<ItemGroup>
<_resolvedP2PFiltered Include="@(ProjectReference)">
<ProjectReferenceItemSpec>$([System.IO.Path]::GetFullPath('%(ProjectReference.Identity)'))</ProjectReferenceItemSpec>
<SkipUseReferenceAssembly>%(ProjectReference.SkipUseReferenceAssembly)</SkipUseReferenceAssembly>
</_resolvedP2PFiltered>
<_ResolvedProjectReferencePaths Update="@(_resolvedP2PFiltered)"
Condition="'%(_resolvedP2PFiltered.ProjectReferenceItemSpec)' == '%(_resolvedP2PFiltered.MSBuildSourceProjectFile)' and
<_resolvedP2PFiltered Include="@(ProjectReference)"
ProjectReferenceItemSpec="$([System.IO.Path]::GetFullPath('%(ProjectReference.Identity)'))"
SkipUseReferenceAssembly="%(ProjectReference.SkipUseReferenceAssembly)" />
<_ResolvedProjectReferencePaths Condition="'%(_resolvedP2PFiltered.ProjectReferenceItemSpec)' == '%(_resolvedP2PFiltered.MSBuildSourceProjectFile)' and
'%(_resolvedP2PFiltered.SkipUseReferenceAssembly)' == 'true'"
ReferenceAssembly="" />
</ItemGroup>
Expand Down
14 changes: 8 additions & 6 deletions eng/targetingpacks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@
AfterTargets="ResolveTargetingPackAssets">
<ItemGroup>
<_targetingPackReferenceExclusion Include="$(TargetName)" />
<_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->'%(Filename)')" />
<_targetingPackReferenceExclusion Include="@(_ResolvedProjectReferencePaths->Metadata('Filename'))" />
<_targetingPackReferenceExclusion Include="@(DefaultReferenceExclusion)" />
</ItemGroup>

<ItemGroup>
<_targetingPackReferenceWithExclusion Include="@(Reference)">
<Exclusion>%(_targetingPackReferenceExclusion.Identity)</Exclusion>
</_targetingPackReferenceWithExclusion>
<Reference Remove="@(_targetingPackReferenceWithExclusion)"
Condition="'%(_targetingPackReferenceWithExclusion.ExternallyResolved)' == 'true' and '%(_targetingPackReferenceWithExclusion.Filename)' == '%(_targetingPackReferenceWithExclusion.Exclusion)'" />
<_targetingPackReferenceWithProjectName Include="@(Reference->WithMetadataValue('ExternallyResolved', 'true')->Metadata('Filename'))"
OriginalIdentity="%(Identity)" />
<_targetingPackIncludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
Exclude="@(_targetingPackReferenceExclusion)" />
<_targetingPackExcludedReferenceWithProjectName Include="@(_targetingPackReferenceWithProjectName)"
Exclude="@(_targetingPackIncludedReferenceWithProjectName)" />
<Reference Remove="@(_targetingPackExcludedReferenceWithProjectName->Metadata('OriginalIdentity'))" />
</ItemGroup>
</Target>
</Project>

0 comments on commit 9293aab

Please sign in to comment.