Skip to content

Add cross-targeting support - #154

Merged
nguerrera merged 5 commits into
dotnet:masterfrom
nguerrera:cross-targeting
Sep 21, 2016
Merged

nguerrera merged 5 commits into
dotnet:masterfrom
nguerrera:cross-targeting

Conversation

@nguerrera

Copy link
Copy Markdown
Contributor

Initial implementation of cross-targeting builds.

I'm now working on automated tests, but I know a lot of folks are eager to get these bits, so starting the review now.

Fix #69
Fix #30
Fix dotnet/project-system#380

@srivatsn @eerhardt @rainersigwald @cdmihai @dotnet/project-system

@nguerrera

nguerrera commented Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

@brthor @livarcocc #Closed

<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)Microsoft.NETCore.Sdk.BeforeCommon.targets</CustomBeforeMicrosoftCommonTargets>
</PropertyGroup>

<!-- Shared properties between cross-targeting and inner build targets. -->

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) I think this section should go "above" the temporary hacks section, if possible. It makes it more readable IMO - all the "official" properties go together, and then the "hacks" at the end. #Resolved

<!--
***********************************************************************************************
Microsoft.NETCore.Sdk.targets
netstandard1.0/Microsoft.NETCore.Sdk.targets

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sort of odd to me. All the other .targets files don't have a path in this comment.

(honestly, I'm not sure why we need this name here at all...) #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just put the name without a path and I'd be fine removing the names altogether, but we can do that separately. I'm trying to follow a convention that doesn't yet exist, but that I'm proposing in dotnet/msbuild#1046 where a package puts its cross-targeting (aka "outer") build participation in build/cross/packagename.targets. But that creates two files of the same name and so I updated the comment to distinguish them. #Resolved

@@ -0,0 +1,105 @@
<!--
***********************************************************************************************
Microsoft.NETCore.TargetFrameworkInference.props

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file has .targets as an extension. Which should it be? #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be targets. Left over from earlier attempt to do this earlier in props phase. #Resolved

<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
Note that this file is only included when $(TargetFramework) is set and so we do not need to check that here.

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(TargetFramework) or $(TargetFrameworks)? #ByDesign

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(TargetFramework) is correct here. This runs in the inner build to expand individual $(TargetFramework) to $(TargetFrameworkIdentifier), $(TargetFrameworkVersion) #ByDesign

</Target>

<!--
Apply the same defaults as common targets now since we're rnning before them, but need to respect defaults

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type-o rnning #Resolved

if (nearestNuGetFramework == null)
{
// TODO: localize: https://github.com/dotnet/sdk/issues/33
Log.LogError($"Project has no no target framework compatible with '{ReferringTargetFramework}'");

@brthor brthor Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be confusing which project this error is referring to.

Looking at the code it looks like this would be one of your dependencies right? Does msbuild give you any nice output that helps clear this up? #Resolved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into getting a better error, but I think it's going to require passing in more from common targets. I've filed #155 to handle this separately.


In reply to: 79675873 [](ancestors = 79675873)

</MSBuild>
</Target>

<Target Name="Clean" DependsOnTargets="_SetCleanInnerTarget;Build" />

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the "Clean" target doesn't do a "Build". #Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the "Build" target should be renamed here, as I find it confusing reusing "Build" to do things that are not "Build".


In reply to: 79678083 [](ancestors = 79678083)

@srivatsn srivatsn Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. We should probably call it something like CallInnerBuild or something like that to distinguish it from the actual Build target. #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll factor it for clarity. I want to preserve that msbuild /p:InnerTargets=x;y;z will do the inner build of x, y, and z. I can do that without actually making build the worker though by making build use a worker too. #Resolved

Log.LogError($"Project has no no target framework compatible with '{ReferringTargetFramework}'");
}

NearestTargetFramework = PossibleTargetFrameworks[possibleNuGetFrameworks.IndexOf(nearestNuGetFramework)];

@brthor brthor Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for indexing here rather than just returning nearestNuGetFramework ? #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that we need to preserve the spelling of target framework. We guarantee that whatever spelling you use in $(TargetFrameworks) (and there can be more than 1 for same target, e.g. net45 net4.5) is what you can condition $(TargetFramework) against in your project. With that said, it may be the case the NuGetFramework.ToString() doesn't adjust or canonicalize in which case I could use that. I'll investigate and add a comment to clarify the importance of being careful here. #Resolved

@brthor brthor Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this makes sense now. #Resolved

<Import Condition="'$(TargetFramework)' != ''"
Project="$(MSBuildThisFileDirectory)Microsoft.NETCore.TargetFrameworkInference.targets" />

</Project>

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) whitespace. #Resolved

<TargetFramework Include="$(TargetFrameworks)" />
</ItemGroup>

<Target Name="Build" Returns="@(InnerOutput)">

@brthor brthor Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a comment that this is the outer build? #Resolved


<UsingTask TaskName="GetNearestTargetFramework" AssemblyFile="$(MicrosoftNETCoreBuildTasksAssembly)" />

<Target Name="GetTargetFrameworkProperties" Returns="TargetFramework=$(NearestTargetFramework)">

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this Target get invoked? I don't see it called. #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this to common targets so that any project can reference a cross-targeted project:
https://github.com/Microsoft/msbuild/blob/e7019886b3fd520b547a7353d78d106d72a4b828/src/XMakeTasks/Microsoft.Common.CurrentVersion.targets#L1494

I'll copy some comments over to make it clear when seeing it on this side too.
#Resolved

@eerhardt

Copy link
Copy Markdown
Member

:shipit:

<!-- https://github.com/dotnet/sdk/issues/145 -->
<!-- ================================================================================== -->
<ItemGroup>
<TargetFramework Include="$(TargetFrameworks)" />

@srivatsn srivatsn Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users may have items called TargetFramework. Can we name this item _TargetFramework or something like that so it's less likely to conflict? #Resolved

@srivatsn srivatsn Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should it move into the Build target to scope the item to that target? #Resolved

if (nearestNuGetFramework == null)
{
// TODO: localize: https://github.com/dotnet/sdk/issues/33
Log.LogError($"Project has no no target framework compatible with '{ReferringTargetFramework}'");

@eerhardt eerhardt Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably return "false" here instead of "true" below. #Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even worse - since nearestNuGetFramework is null, you'll get an IndexOutOfRange exception on the indexer when passing in -1.


In reply to: 79713556 [](ancestors = 79713556)

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. #Resolved

@rainersigwald rainersigwald Sep 20, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style recommendation: never return true or false from within a task. Instead, always return Log.HasLoggedErrors.

It's intensely annoying to debug builds that have failed but emitted no errors, and fairly annoying to go the other way. #Resolved

@nguerrera nguerrera Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the final return true, but the early false exits are by design and easy to prove Log.HasLoggedErrors is false. I'd like to leave that. #Resolved

@nguerrera

nguerrera commented Sep 20, 2016 •

Copy link
Copy Markdown
Contributor Author

@dotnet-bot test this please (infrastructure issue) #Closed

@srivatsn

srivatsn commented Sep 20, 2016 •

Copy link
Copy Markdown
Contributor

Also tagging @codito @sbaid since they wanted to see this PR to get an idea of how the test target would work. #Closed

@nguerrera

Copy link
Copy Markdown
Contributor Author

@Sridhar-MS I changed OnlyHaveFiles to be recursive and updated kitchen sink test to expect satellites. I needed this to be able to list outputs from more than one framework for cross-targeting. I am now seeing the files missing on Linux. Is there an issue with satellites on Linux?

@nguerrera

Copy link
Copy Markdown
Contributor Author

Looks like #146 which is adding deliberate test coverage for satellites is also failing to find them on linux.

@Sridhar-MS

Copy link
Copy Markdown
Contributor

@nguerrera Yup. I am debugging that right now. ReferenceCopyLocalPaths item group is not populated with reference project satellite assemblies on Linux.

More sophisticated scenarios involving P2P and other verbs
will require upstream changes.
@nguerrera

Copy link
Copy Markdown
Contributor Author

@Sridhar-MS OK, good luck. ;) I've worked around it by making recursive OnlyHaveFiles optional. This should also eliminate conflicts with your change.

@nguerrera
nguerrera merged commit 8b6d32b into dotnet:master Sep 21, 2016
@nguerrera
nguerrera deleted the cross-targeting branch September 21, 2016 01:27
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<Version>42.43.44.45-alpha</Version>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) spacing

.Pass();

var outputDirectory = buildCommand.GetOutputDirectory();
var targetFrameworks = new[] { "netstandard1.4", "netstandard1.5" };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable doesn't appear to be used.

@nguerrera nguerrera mentioned this pull request Sep 21, 2016
@nguerrera

nguerrera commented Sep 21, 2016 •

Copy link
Copy Markdown
Contributor Author

@eerhardt Thanks for reviewing the test. I've started #159 to fix these issues and I'll address anything else you see there. I merged optimistically (with only test changes since sign-off) so that I could get the bits over to restore3 and unblock further testing and others needing cross-targeting.

nguerrera added a commit that referenced this pull request Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants