Skip to content

Commit

Permalink
Major per-RuntimeIdentifier build refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-boyarshin committed Mar 28, 2020
1 parent 4405b31 commit aa54aab
Showing 1 changed file with 122 additions and 91 deletions.
213 changes: 122 additions & 91 deletions Source/MSBuild.Sdk.Extras/Build/RIDs.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<MSBuildAllProjects Condition=" '$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' &lt; '16.0' ">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<ExtrasIncludeDefaultProjectBuildOutputInPackTarget Condition="'$(ExtrasIncludeDefaultProjectBuildOutputInPackTarget)' == ''">_SdkIncludeDefaultProjectBuildOutputInPackImpl</ExtrasIncludeDefaultProjectBuildOutputInPackTarget>
</PropertyGroup>

<Target Name="_SdkGetRidsPerTargetFramework" Returns="@(_SdkRuntimeId)">
Expand All @@ -11,134 +12,129 @@
</PropertyGroup>

<ItemGroup>
<_SdkRuntimeIds Include="$(RuntimeIdentifiers)" Condition="'$(RuntimeIdentifiers)' != '' and '$(ExtrasBuildEachRuntimeIdentifier)' == 'true' " TargetFramework="$(TargetFramework)" />
<_SdkRuntimeIds Include="$(RuntimeIdentifiers)" Condition="'$(RuntimeIdentifiers)' != '' and '$(ExtrasBuildEachRuntimeIdentifier)' == 'true' " TargetFramework="$(TargetFramework)" />

<_SdkRuntimeId Include="@(_SdkRuntimeIds->'%(TargetFramework)')" Rid="%(_SdkRuntimeIds.Identity)" />
<_SdkRuntimeId Include="$(TargetFramework)" Condition="'$(ExtrasBuildEachRuntimeIdentifier)' == 'false'" />
<_SdkRuntimeId Include="@(_SdkRuntimeIds->'%(TargetFramework)')" Rid="%(_SdkRuntimeIds.Identity)" />
<_SdkRuntimeId Include="$(TargetFramework)" Condition="'$(ExtrasBuildEachRuntimeIdentifier)' == 'false'" />
</ItemGroup>
</Target>

</Target>


<Target Name="_ComputeTargetFrameworkItems" Returns="@(InnerOutput)">
<!-- Microsoft.Common.CrossTargeting.targets -> _ComputeTargetFrameworkItems -->
<!-- One intentional diff in target signature: removal of Returns="@(InnerOutput)" -->
<!-- Rationale: it's not produced by _ComputeTargetFrameworkItems, most likely a result of copy-paste -->
<Target Name="_ComputeTargetFrameworkItemsCore">
<ItemGroup>
<_TargetFramework Include="$(TargetFrameworks)" />
<!-- Make normalization explicit: Trim; Deduplicate by keeping first occurrence, case insensitive -->
<_TargetFrameworkNormalized Include="@(_TargetFramework->Trim()->Distinct())" />
<_InnerBuildProjects Include="$(MSBuildProjectFile)">
<AdditionalProperties>TargetFramework=%(_TargetFrameworkNormalized.Identity)</AdditionalProperties>
</_InnerBuildProjects>
</ItemGroup>
</Target>


<Target Name="_SdkPrepareProjectFlavorMatrix"
DependsOnTargets="_ComputeTargetFrameworkItemsCore;$(_SdkPrepareProjectFlavorMatrixDependsOn)">

<ItemGroup>
<_InnerBuildProjects Include="$(MSBuildProjectFile)">
<AdditionalProperties>TargetFramework=%(_TargetFramework.Identity)</AdditionalProperties>
</_InnerBuildProjects>
<_SdkProjectFlavorMatrixItem Include="$(MSBuildProjectFullPath)">
<SetTargetFramework>TargetFramework=%(_TargetFrameworkNormalized.Identity)</SetTargetFramework>
<SetRuntimeIdentifier />
</_SdkProjectFlavorMatrixItem>
</ItemGroup>

<MSBuild Projects="@(_InnerBuildProjects)"
<MSBuild Projects="@(_SdkProjectFlavorMatrixItem)"
BuildInParallel="$(BuildInParallel)"
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework)"
Targets="_SdkGetRidsPerTargetFramework">
<Output ItemName="_SdkTargetsWithRids" TaskParameter="TargetOutputs" />
<Output ItemName="_SdkProjectFlavorMatrixItemStaging" TaskParameter="TargetOutputs" />
</MSBuild>

<ItemGroup>
<_SdkProjectFlavorMatrixItem Remove="@(_SdkProjectFlavorMatrixItem)" />
<_SdkProjectFlavorMatrixItem Include="@(_SdkProjectFlavorMatrixItemStaging->'%(OriginalItemSpec)')" KeepMetadata="TargetFramework;SetTargetFramework;Rid;SetRuntimeIdentifier" />
<_SdkProjectFlavorMatrixItemStaging Remove="@(_SdkProjectFlavorMatrixItemStaging)" />
<_SdkProjectFlavorMatrixItem Update="@(_SdkProjectFlavorMatrixItem->HasMetadata('Rid'))">
<SetRuntimeIdentifier Condition="'%(Rid)' != ''">RuntimeIdentifier=%(Rid)</SetRuntimeIdentifier>
</_SdkProjectFlavorMatrixItem>
</ItemGroup>

</Target>


<!-- One intentional diff in target signature: removal of Returns="@(InnerOutput)" -->
<Target Name="_ComputeTargetFrameworkItems" DependsOnTargets="_SdkPrepareProjectFlavorMatrix">

<ItemGroup>
<_InnerBuildProjects Remove="@(_InnerBuildProjects)" />
<_InnerBuildProjects Include="$(MSBuildProjectFile)">
<AdditionalProperties Condition="'%(_SdkTargetsWithRids.Rid)' != ''" >TargetFramework=%(_SdkTargetsWithRids.Identity);RuntimeIdentifier=%(_SdkTargetsWithRids.Rid)</AdditionalProperties>
<AdditionalProperties Condition="'%(_SdkTargetsWithRids.Rid)' == ''" >TargetFramework=%(_SdkTargetsWithRids.Identity)</AdditionalProperties>
<_InnerBuildProjects Include="@(_SdkProjectFlavorMatrixItem)" KeepMetadata="FakeProperty">
<AdditionalProperties Condition="'%(SetRuntimeIdentifier)' != ''">%(SetTargetFramework);%(SetRuntimeIdentifier)</AdditionalProperties>
<AdditionalProperties Condition="'%(SetRuntimeIdentifier)' == ''">%(SetTargetFramework)</AdditionalProperties>
</_InnerBuildProjects>
</ItemGroup>

</Target>


<Target Name="_WalkEachTargetPerFrameworkCore"
DependsOnTargets="_SdkPrepareProjectFlavorMatrix;$(_WalkEachTargetPerFrameworkCoreDependsOn)">

<Target Name="_WalkEachTargetPerFramework">
<MSBuild Projects="$(MSBuildProjectFile)"
BuildInParallel="$(BuildInParallel)"
Properties="TargetFramework=%(_TargetFrameworks.Identity)"
Targets="_SdkGetRidsPerTargetFramework">
<Output ItemName="_SdkTargetsWithRids" TaskParameter="TargetOutputs" />
</MSBuild>
<PropertyGroup>
<ExtrasDisableRidSpecificOutputMetadataReleaseOptimization Condition="'$(ExtrasDisableRidSpecificOutputMetadataReleaseOptimization)' == ''">false</ExtrasDisableRidSpecificOutputMetadataReleaseOptimization>
<ExtrasRidSpecificOutputKeepMetadata Condition="'$(ExtrasRidSpecificOutputKeepMetadata)' == '' and '$(ExtrasDisableRidSpecificOutputMetadataReleaseOptimization)' == 'false'">TargetFramework;Rid</ExtrasRidSpecificOutputKeepMetadata>
</PropertyGroup>

<MSBuild
Condition="'$(IncludeBuildOutput)' == 'true' and '%(_SdkTargetsWithRids.Rid)' != ''"
Projects="$(MSBuildProjectFullPath)"
Condition="'$(IncludeBuildOutput)' == 'true'"
Projects="@(_SdkProjectFlavorMatrixItem)"
Targets="_SdkGetBuildOutputFilesWithTfm"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);RuntimeIdentifier=%(_SdkTargetsWithRids.Rid)">

<Output
TaskParameter="TargetOutputs"
ItemName="_BuildOutputInPackageWithRid" />
</MSBuild>

<MSBuild
Condition="'$(IncludeBuildOutput)' == 'true' and '%(_SdkTargetsWithRids.Rid)' == ''"
Projects="$(MSBuildProjectFullPath)"
Targets="_GetBuildOutputFilesWithTfm"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); %(_SdkProjectFlavorMatrixItem.SetRuntimeIdentifier)">

<Output
TaskParameter="TargetOutputs"
ItemName="_BuildOutputInPackage" />
</MSBuild>

<MSBuild
Condition="'$(TargetsForTfmSpecificContentInPackage)' != '' and '%(_SdkTargetsWithRids.Rid)' != ''"
Projects="$(MSBuildProjectFullPath)"
Condition="'$(TargetsForTfmSpecificContentInPackage)' != ''"
Projects="@(_SdkProjectFlavorMatrixItem)"
Targets="_GetTfmSpecificContentForPackage"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);RuntimeIdentifier=%(_SdkTargetsWithRids.Rid)">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); %(_SdkProjectFlavorMatrixItem.SetRuntimeIdentifier)">

<Output
TaskParameter="TargetOutputs"
ItemName="_PackageFiles"/>
</MSBuild>

<MSBuild
Condition="'$(TargetsForTfmSpecificContentInPackage)' != '' and '%(_SdkTargetsWithRids.Rid)' == ''"
Projects="$(MSBuildProjectFullPath)"
Targets="_GetTfmSpecificContentForPackage"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);">

<Output
TaskParameter="TargetOutputs"
ItemName="_PackageFiles"/>
</MSBuild>

<MSBuild
Condition="'$(IncludeBuildOutput)' == 'true' and '%(_SdkTargetsWithRids.Rid)' != ''"
Projects="$(MSBuildProjectFullPath)"
Condition="'$(IncludeBuildOutput)' == 'true'"
Projects="@(_SdkProjectFlavorMatrixItem)"
Targets="_SdkGetDebugSymbolsWithTfm"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);RuntimeIdentifier=%(_SdkTargetsWithRids.Rid)">

<Output
TaskParameter="TargetOutputs"
ItemName="_TargetPathsToSymbolsWithRid" />
</MSBuild>

<MSBuild
Condition="'$(IncludeBuildOutput)' == 'true' and '%(_SdkTargetsWithRids.Rid)' == ''"
Projects="$(MSBuildProjectFullPath)"
Targets="_GetDebugSymbolsWithTfm"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); %(_SdkProjectFlavorMatrixItem.SetRuntimeIdentifier)">

<Output
TaskParameter="TargetOutputs"
ItemName="_TargetPathsToSymbols" />
</MSBuild>

<MSBuild
Condition="'$(IncludeSource)' == 'true' and '%(_SdkTargetsWithRids.Rid)' == ''"
Projects="$(MSBuildProjectFullPath)"
Condition="'$(IncludeSource)' == 'true' and '%(_SdkProjectFlavorMatrixItem.Rid)' == ''"
Projects="@(_SdkProjectFlavorMatrixItem)"
Targets="SourceFilesProjectOutputGroup"
Properties="TargetFramework=%(_SdkTargetsWithRids.Identity);
BuildProjectReferences=false;">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); BuildProjectReferences=false">

<Output
TaskParameter="TargetOutputs"
ItemName="_SourceFiles" />
</MSBuild>

<MSBuild
Projects="$(MSBuildProjectFullPath)"
Projects="@(_SdkProjectFlavorMatrixItem)"
Targets="_GetFrameworkAssemblyReferences"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
BuildProjectReferences=false;">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); BuildProjectReferences=false">

<Output
TaskParameter="TargetOutputs"
Expand All @@ -150,52 +146,87 @@
</PropertyGroup>

<MSBuild
Projects="$(MSBuildProjectFullPath)" Condition="'$([System.Version]::Parse($(_SdkNETCoreSdkVersion)).CompareTo($([System.Version]::Parse($(_SdkMinVersionWithDependencyTarget)))))' &gt;= '0' "
Projects="@(_SdkProjectFlavorMatrixItem)"
Condition="'$([System.Version]::Parse($(_SdkNETCoreSdkVersion)).CompareTo($([System.Version]::Parse($(_SdkMinVersionWithDependencyTarget)))))' &gt;= '0' "
Targets="_GetFrameworksWithSuppressedDependencies"
Properties="TargetFramework=%(_TargetFrameworks.Identity);
BuildProjectReferences=false;">
Properties="%(_SdkProjectFlavorMatrixItem.SetTargetFramework); BuildProjectReferences=false">

<Output
TaskParameter="TargetOutputs"
ItemName="_FrameworksWithSuppressedDependencies" />
</MSBuild>

<ItemGroup>
<_BuildOutputInPackageWithRid Include="@(_BuildOutputInPackage->HasMetadata('Rid'))" />
<_TargetPathsToSymbolsWithRid Include="@(_TargetPathsToSymbols->HasMetadata('Rid'))" />
<_BuildOutputInPackageWithRid Remove="@(_BuildOutputInPackageWithRid)" Condition="'%(Rid)' == ''" />
<_TargetPathsToSymbolsWithRid Remove="@(_TargetPathsToSymbolsWithRid)" Condition="'%(Rid)' == ''" />
<_BuildOutputInPackage Remove="@(_BuildOutputInPackageWithRid)" />
<_TargetPathsToSymbols Remove="@(_TargetPathsToSymbolsWithRid)" />
</ItemGroup>

<ItemGroup Condition="'$(ExtrasDisableRidSpecificOutputMetadataReleaseOptimization)' == 'false'">
<RidSpecificOutput Include="@(_BuildOutputInPackageWithRid->'%(FinalOutputPath)')" KeepDuplicates="false" KeepMetadata="$(ExtrasRidSpecificOutputKeepMetadata)" />
<RidSpecificOutput Include="@(_TargetPathsToSymbolsWithRid->'%(FinalOutputPath)')" KeepDuplicates="false" KeepMetadata="$(ExtrasRidSpecificOutputKeepMetadata)" />
</ItemGroup>
<ItemGroup Condition="'$(ExtrasDisableRidSpecificOutputMetadataReleaseOptimization)' != 'false'">
<RidSpecificOutput Include="@(_BuildOutputInPackageWithRid->'%(FinalOutputPath)')" />
<RidSpecificOutput Include="@(_TargetPathsToSymbolsWithRid->'%(FinalOutputPath)')" />
</ItemGroup>

<!-- Include the runtimes files -->
<None Include="@(_BuildOutputInPackageWithRid)" PackagePath="runtimes/%(_BuildOutputInPackageWithRid.Rid)/lib/%(_BuildOutputInPackageWithRid.TargetFramework)" Pack="true" />
<None Include="@(_TargetPathsToSymbolsWithRid)" PackagePath="runtimes/%(_TargetPathsToSymbolsWithRid.Rid)/lib/%(_TargetPathsToSymbolsWithRid.TargetFramework)" Pack="true" />
</ItemGroup>

</Target>


<Target Name="_SdkGetBuildOutputFilesWithTfm" DependsOnTargets="_GetBuildOutputFilesWithTfm" Returns="@(BuildOutputInPackage)">
<Target Name="_WalkEachTargetPerFramework"
DependsOnTargets="_WalkEachTargetPerFrameworkCore;$(ExtrasIncludeDefaultProjectBuildOutputInPackTarget);$(_WalkEachTargetPerFrameworkDependsOn)">

<ItemGroup>
<BuildOutputInPackage Update="@(BuildOutputInPackage)" Rid="$(RuntimeIdentifier)" />
<PropertyGroup>
<ExtrasDisableRidSpecificOutputReleaseOptimization Condition="'$(ExtrasDisableRidSpecificOutputReleaseOptimization)' == ''">false</ExtrasDisableRidSpecificOutputReleaseOptimization>
</PropertyGroup>

<!-- Optional: release references -->
<ItemGroup Condition="'$(ExtrasDisableRidSpecificOutputReleaseOptimization)' == 'false'">
<RidSpecificOutput Remove="@(RidSpecificOutput)" />
<_BuildOutputInPackageWithRid Remove="@(_BuildOutputInPackageWithRid)" />
<_TargetPathsToSymbolsWithRid Remove="@(_TargetPathsToSymbolsWithRid)" />
</ItemGroup>

</Target>

<Target Name="_SdkGetDebugSymbolsWithTfm" DependsOnTargets="_GetDebugSymbolsWithTfm" Returns="@(_TargetPathsToSymbolsWithTfm)">
<Target Name="_SdkIncludeDefaultProjectBuildOutputInPackImpl" Condition="'$(ExtrasIncludeDefaultProjectBuildOutputInPack)' != 'false'">

<ItemGroup>
<_TargetPathsToSymbolsWithTfm Update="@(_TargetPathsToSymbolsWithTfm)" Rid="$(RuntimeIdentifier)" />
<PropertyGroup>
<ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization Condition="'$(ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization)' == ''">false</ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization>

<ExtrasNoneRidSpecificOutputKeepMetadata Condition="'$(ExtrasNoneRidSpecificOutputKeepMetadata)' == '' and '$(ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization)' != 'false'"></ExtrasNoneRidSpecificOutputKeepMetadata>
<!-- Ideally should be empty, but that disables KeepMetadata property -->
<ExtrasNoneRidSpecificOutputKeepMetadata Condition="'$(ExtrasNoneRidSpecificOutputKeepMetadata)' == '' and '$(ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization)' == 'false'">Pack</ExtrasNoneRidSpecificOutputKeepMetadata>
</PropertyGroup>

<!-- Include the runtimes files -->
<ItemGroup Condition="'$(ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization)' == 'false'">
<None Include="@(RidSpecificOutput->'%(Identity)')" PackagePath="runtimes/%(Rid)/lib/%(TargetFramework)" Pack="true" KeepMetadata="$(ExtrasNoneRidSpecificOutputKeepMetadata)" />
</ItemGroup>
<ItemGroup Condition="'$(ExtrasDisableNoneRidSpecificOutputKeepMetadataOptimization)' != 'false'">
<None Include="@(RidSpecificOutput)" PackagePath="runtimes/%(Rid)/lib/%(TargetFramework)" Pack="true" />
</ItemGroup>

</Target>


<Target Name="_ExtrasPackageRuntimeFiles" BeforeTargets="_GetPackageFiles" >
<Target Name="_SdkGetBuildOutputFilesWithTfm" DependsOnTargets="_GetBuildOutputFilesWithTfm" Returns="@(BuildOutputInPackage)">

<MSBuild Projects="$(MSBuildProjectFile)"
BuildInParallel="$(BuildInParallel)"
Properties="TargetFramework=%(_TargetFramework.Identity)"
Targets="_SdkGetRidsPerTargetFramework">
<Output ItemName="_SdkTargetsWithRids" TaskParameter="TargetOutputs" />
</MSBuild>

<ItemGroup Condition="'$(RuntimeIdentifier)' != ''">
<BuildOutputInPackage Update="@(BuildOutputInPackage)" Rid="$(RuntimeIdentifier)" />
</ItemGroup>

</Target>

<Target Name="_SdkGetDebugSymbolsWithTfm" DependsOnTargets="_GetDebugSymbolsWithTfm" Returns="@(_TargetPathsToSymbolsWithTfm)">

<ItemGroup Condition="'$(RuntimeIdentifier)' != ''">
<_TargetPathsToSymbolsWithTfm Update="@(_TargetPathsToSymbolsWithTfm)" Rid="$(RuntimeIdentifier)" />
</ItemGroup>

</Target>

Expand Down

0 comments on commit aa54aab

Please sign in to comment.