Skip to content

Commit

Permalink
Traversal targets for cross-targeting (#1018)
Browse files Browse the repository at this point in the history
* Add initial traversal targets

* Establish protocol for P2P references to cross-targeted projects

* Remove condition which breaks rebuild

When we run during clean phase, we would skip on this
condition and then not rerun during build phase.

* Rename property to match target

* Rename Traversal to CrossTargeting
  • Loading branch information
nguerrera authored and cdmihai committed Sep 13, 2016
1 parent 4d260f7 commit 0a6e5f1
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 17 deletions.
2 changes: 2 additions & 0 deletions setup/files.swr
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ folder InstallDir:\MSBuild\15.0\Bin
file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngen=yes
file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngen=yes
file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets
file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets
file source=$(X86BinPath)Microsoft.Common.overridetasks
file source=$(X86BinPath)Microsoft.Common.targets
file source=$(X86BinPath)Microsoft.Common.tasks
Expand Down Expand Up @@ -139,6 +140,7 @@ folder InstallDir:\MSBuild\15.0\Bin\amd64
file source=$(X86BinPath)System.Threading.Tasks.Dataflow.dll vs.file.ngen=yes
file source=$(X86BinPath)System.Collections.Immutable.dll vs.file.ngen=yes
file source=$(X86BinPath)Microsoft.Common.CurrentVersion.targets
file source=$(X86BinPath)Microsoft.Common.CrossTargeting.targets
file source=$(X86BinPath)Microsoft.Common.overridetasks
file source=$(X86BinPath)Microsoft.Common.targets
file source=$(X86BinPath)Microsoft.Common.tasks
Expand Down
7 changes: 7 additions & 0 deletions src/XMakeTasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Microsoft.Common.CrossTargeting.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Microsoft.Common.targets">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -827,6 +831,9 @@
<DataFile Include="Microsoft.Common.CurrentVersion.targets">
<SubType>Designer</SubType>
</DataFile>
<DataFile Include="Microsoft.Common.CrossTargeting.targets">
<SubType>Designer</SubType>
</DataFile>
<DataFile Include="Microsoft.NETFramework.targets" />
<DataFile Include="Microsoft.NETFramework.CurrentVersion.targets" />
<DataFile Include="Microsoft.NETFramework.props">
Expand Down
14 changes: 14 additions & 0 deletions src/XMakeTasks/Microsoft.CSharp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
We are doing a cross-targeting build if there is no list of target frameworks specified
nor is there a current target framework being built individually. In that case, this import is
redirected to Microsoft.Common.CrossTargeting.targets.
-->
<PropertyGroup Condition="'$(TargetFrameworks)' != '' and '$(TargetFramework)' == ''">
<IsCrossTargetingBuild>true</IsCrossTargetingBuild>
</PropertyGroup>

<!--
In VS 2010 SP1 and VS 2012, both supported for asset compatibility, the MSBuild installed
as part of them did not enforce using the local ToolsVersion (4.0) in all cases, but instead
just used whatever ToolsVersion was in the project file if it existed on the machine, and
Expand All @@ -40,6 +49,11 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<CscToolPath Condition="'$(CscToolPath)' == '' and '$(BuildingInsideVisualStudio)' != 'true'">$(MsBuildFrameworkToolsPath)</CscToolPath>
</PropertyGroup>
</When>
<When Condition="'$(IsCrossTargetingBuild)' == 'true'">
<PropertyGroup>
<CSharpTargetsPath>$(MSBuildToolsPath)\Microsoft.Common.CrossTargeting.targets</CSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<CSharpTargetsPath>$(MSBuildToolsPath)\Microsoft.CSharp.CurrentVersion.targets</CSharpTargetsPath>
Expand Down
16 changes: 16 additions & 0 deletions src/XMakeTasks/Microsoft.Common.CrossTargeting.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
***********************************************************************************************
Microsoft.Common.CrossTargeting.targets
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(CoreCrossTargetingTargetsPath)"
Condition="'$(CoreCrossTargetingTargetsPath)' != '' and Exists('$(CoreCrossTargetingTargetsPath)')" />
</Project>
110 changes: 93 additions & 17 deletions src/XMakeTasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Target Name="BuildGenerateSources" DependsOnTargets="BuildGenerateSourcesTraverse;$(BuildGenerateSourcesAction)" />

<Target Name="BuildGenerateSourcesTraverse" DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence">
<Target Name="BuildGenerateSourcesTraverse" DependsOnTargets="PrepareProjectReferences">
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="BuildGenerateSources"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework);"
Condition="'$(BuildPassReferences)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != '' and '%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true'"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand All @@ -913,12 +913,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Target Name="BuildCompile" DependsOnTargets="BuildCompileTraverse;$(BuildCompileAction)" />

<Target Name="BuildCompileTraverse" DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence">
<Target Name="BuildCompileTraverse" DependsOnTargets="PrepareProjectReferences">
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="BuildCompile"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'$(BuildPassReferences)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != '' and '%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true'"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand All @@ -938,12 +938,12 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Target Name="BuildLink" DependsOnTargets="BuildLinkTraverse;$(BuildLinkAction)" />

<Target Name="BuildLinkTraverse" DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence" >
<Target Name="BuildLinkTraverse" DependsOnTargets="PrepareProjectReferences" >
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="BuildLink"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'$(BuildPassReferences)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '@(_MSBuildProjectReferenceExistent)' != '' and '%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true'"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand Down Expand Up @@ -1491,6 +1491,81 @@ Copyright (C) Microsoft Corporation. All rights reserved.

</Target>

<!--
====================================================================================
_GetProjectReferenceTargetFrameworkProperties
Builds the GetTargetFrameworkProperties target of all existent project references,
passing $(TargetFrameworkMoniker) as $(ReferringTargetFramework) and sets the
SetTargetFramework metadata of the project reference to the value that is returned.
This allows a cross-targeting project to select how it should be configured to
build against the most appropriate target for the referring target framework.
======================================================================================
-->
<Target Name="_GetProjectReferenceTargetFrameworkProperties" Outputs="%(_MSBuildProjectReferenceExistent.Identity)">
<MSBuild
Projects="%(_MSBuildProjectReferenceExistent.Identity)"
Targets="GetTargetFrameworkProperties"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); ReferringTargetFramework=$(TargetFrameworkMoniker)"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">

<Output TaskParameter="TargetOutputs" PropertyName="_ProjectReferenceTargetFrameworkProperties" />
</MSBuild>

<ItemGroup>
<_MSBuildProjectReferenceExistent Condition="'%(_MSBuildProjectReferenceExistent.Identity)' == '%(Identity)'">
<SetTargetFramework>$(_ProjectReferenceTargetFrameworkProperties)</SetTargetFramework>
</_MSBuildProjectReferenceExistent>
</ItemGroup>

<PropertyGroup>
<_ProjectReferenceTargetFrameworkProperties />
</PropertyGroup>
</Target>

<!--
============================================================
GetTargetFrameworkProperties
Overrridden by cross-targeting projects to return the set of
properties (in the form "key1=value1;...keyN=valueN") needed
to build it with the best target for the referring project's
target framework.
The referring project's $(TargetFrameworkMoniker) is passed
in as $(ReferringTargetFramework)
-->
<Target Name="GetTargetFrameworkProperties" />

<!--
============================================================
PrepareProjectReferences
Prepares project references for consumption by other targets.
[IN]
@(ProjectReference) - The list of project references.
[OUT]
@(ProjectReferenceWithConfiguration) - Project references with apporpriate metadata
@(_MSBuildProjectReferenceExistent) - Subset of @(ProjectReferenceWithConfiguration) that exist
with added SetTargetFramework metadata for cross-targeting
@(_MSBuildProjectReferenceNonExistent) - Subset of @(ProjectReferenceWithConfiguration) that do not exist
============================================================
-->
<PropertyGroup>
<PrepareProjectReferencesDependsOn>
AssignProjectConfiguration;
_SplitProjectReferencesByFileExistence;
_GetProjectReferenceTargetFrameworkProperties
</PrepareProjectReferencesDependsOn>
</PropertyGroup>
<Target Name="PrepareProjectReferences" DependsOnTargets="$(PrepareProjectReferencesDependsOn)" />

<!--
============================================================
ResolveProjectReferences
Expand Down Expand Up @@ -1518,7 +1593,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.

<Target
Name="ResolveProjectReferences"
DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence"
DependsOnTargets="PrepareProjectReferences"
Returns="@(_ResolvedNativeProjectReferencePaths);@(_ResolvedProjectReferencePaths)">

<!--
Expand All @@ -1533,7 +1608,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetTargetPath"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and ('$(BuildingInsideVisualStudio)' == 'true' or '$(BuildProjectReferences)' != 'true') and '$(VisualStudioVersion)' != '10.0' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand All @@ -1560,7 +1635,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="%(_MSBuildProjectReferenceExistent.Targets);GetTargetPath"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and ('$(BuildingInsideVisualStudio)' == 'true' or '$(BuildProjectReferences)' != 'true') and '$(VisualStudioVersion)' == '10.0' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="!$(BuildingProject)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand All @@ -1577,7 +1652,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="%(_MSBuildProjectReferenceExistent.Targets)"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '$(BuildingInsideVisualStudio)' != 'true' and '$(BuildProjectReferences)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="$(ContinueOnError)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand All @@ -1594,7 +1669,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetNativeManifest"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(ProjectReferenceWithConfiguration)' != '' and '$(BuildingProject)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="$(ContinueOnError)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand Down Expand Up @@ -2119,10 +2194,10 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</ItemGroup>
</Target>

<Target Name="GetReferenceTargetPlatformMonikers" DependsOnTargets="AssignProjectConfiguration;_SplitProjectReferencesByFileExistence">
<Target Name="GetReferenceTargetPlatformMonikers" DependsOnTargets="PrepareProjectReferences">
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Targets="GetTargetPathWithTargetPlatformMoniker"
BuildInParallel="$(BuildInParallel)"
ContinueOnError="!$(BuildingProject)"
Expand Down Expand Up @@ -4026,7 +4101,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<PropertyGroup>
<GetCopyToOutputDirectoryItemsDependsOn>
AssignTargetPaths;
_SplitProjectReferencesByFileExistence
_SplitProjectReferencesByFileExistence;
_GetProjectReferenceTargetFrameworkProperties
</GetCopyToOutputDirectoryItemsDependsOn>
</PropertyGroup>
<Target
Expand All @@ -4050,7 +4126,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="GetCopyToOutputDirectoryItems"
BuildInParallel="$(BuildInParallel)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
Condition="'@(_MSBuildProjectReferenceExistent)' != '' and '$(_GetChildProjectCopyToOutputDirectoryItems)' == 'true' and '%(_MSBuildProjectReferenceExistent.Private)' != 'false' and '$(UseCommonOutputDirectory)' != 'true'"
ContinueOnError="$(ContinueOnError)"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)">
Expand Down Expand Up @@ -4573,7 +4649,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
-->
<Target
Name="CleanReferencedProjects"
DependsOnTargets="AssignProjectConfiguration; _SplitProjectReferencesByFileExistence">
DependsOnTargets="PrepareProjectReferences">

<!--
When building the project directly from the command-line, clean those referenced projects
Expand All @@ -4583,7 +4659,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="Clean"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform)"
Properties="%(_MSBuildProjectReferenceExistent.SetConfiguration); %(_MSBuildProjectReferenceExistent.SetPlatform); %(_MSBuildProjectReferenceExistent.SetTargetFramework)"
BuildInParallel="$(BuildInParallel)"
Condition="'$(BuildingInsideVisualStudio)' != 'true' and '$(BuildProjectReferences)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
ContinueOnError="$(ContinueOnError)"
Expand Down
Loading

0 comments on commit 0a6e5f1

Please sign in to comment.