-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable P2P's to determine their own compilation RID #828
Enable P2P's to determine their own compilation RID #828
Conversation
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<RuntimeIdentifiers>osx.10.11-x64</RuntimeIdentifiers> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be a problem for CI? Should you have RuntimeIdentifiers with Win and Ubuntu? the ones used by the SDK CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will expand to cover all CI flavors. Until the MSBuild fix is available, CI will be red anyways. I wanted to show a single instance of the test for the time being and will cross-target once we decide we're happy with the approach and have merge approval.
public class GivenThatWeWantToBuildASelfContainedAppWithRid : SdkTest | ||
{ | ||
[Fact] | ||
public void It_builds_a_runnable_output() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this describes the scenario enough.
Should this be It_builds_a_runnable_output_when_depending_on_both_rid_and_ridless_libraries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:D Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the name a bit. The TestAssetsManager in this repo actually checks for long-file-paths and so I had to trim it down a bit. We should think about that feature in CLI!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass in a value to CopyTestAsset
which it will use for the folder path, so you can have a long and descriptive test method name, but the path on disk will still be short enough. Here's an example:
var testAsset = _testAssetsManager.CreateTestProject(testProject, "DeduplicatePackage_Reference") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, @dsplaisted! Another feature to integrate over :)
I'm pretty happy with the naming after update, but if folks want it to be different I'll take advantage of this feature.
|
||
<PropertyGroup> | ||
<!-- If this project is not RID-specific, specify that an empty RuntimeIdentifier should be passed. Otherwise, pass through the dependant's RuntimeIdentifier --> | ||
<NearestRuntimeIdentifier>$(ReferringRuntimeIdentifier)</NearestRuntimeIdentifier> | ||
<NearestRuntimeIdentifier Condition=" '$(RuntimeIdentifier)' == '' and $(RuntimeIdentifiers) == '' "></NearestRuntimeIdentifier> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are missing single quotes on $(RuntimeIdentifiers)
. It should be '$(RuntimeIdentifiers'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I'll add another csproj to test that branch as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@livarcocc I added the test, but it did not identify the bug. I decided to see if this was a test bug by writing the following .proj file:
<Project DefaultTargets="Default">
<Target Name="Default">
<Message Condition="$(foo) == ''" Text="empty == ''" Importance="High" />
</Target>
</Project>
The Message did, in fact, print. So it looks like putting single-quotes around a property is more a convention than a rule. That said, the test is in place.
|
||
<PropertyGroup> | ||
<!-- If this project is not RID-specific, specify that an empty RuntimeIdentifier should be passed. Otherwise, pass through the dependant's RuntimeIdentifier --> | ||
<NearestRuntimeIdentifier>$(ReferringRuntimeIdentifier)</NearestRuntimeIdentifier> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about if both are RID-specific, are compatible, but do not match: A (win10-x86) -> B (win7-x86)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also confused by the term 'dependant' in this context. I'd say 'referrer' to match the variable used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Nick, I 'll change the naming.
As to non-matching RIDs, for the moment I'm considering that to be a subsequent feature. The mechanics introduced here enable folks to add RIDs to their projects and get into a working state. RID equivalence mapping seems like a different feature, and a much more risky one.
If you feel that this feature is not useful in the current state please let me know and I'll take a deeper look, but I think that this is a reasonable feature scoping decision.
{ | ||
static void Main(string[] args) | ||
{ | ||
var valueFromNativeDependency = Library.NativeCode.InvokeNativeCodeAndReturnAString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this LibraryWithRid would be a bit clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
3a80358
to
27b7e0e
Compare
@nguerrera I've made some updates to this, and the corresponding MSBuild, PR. Here is the state of affairs: Scenarios
Details of updateThis PR now includes an SDK ability to detect if the RuntimeIdentifier is passed globally. This is a workaround for an MSBuild feature request. If we detect that the RuntimeIdentifier is not set globaly then execution continues as it does today. If it IS set globaly then we give the referenced project an opportunity to override the RuntimeIdentifier passed to it during the Build phase. |
|
||
<!-- If the RuntimeIdentifier was set globally, pass it to GetTargetFrameworkProperties. --> | ||
<PropertyGroup Condition=" '$(GlobalRuntimeIdentifier)' != '' "> | ||
<AdditionalPropertiesForGetTargetFrameworkProperties>;ReferringRuntimeIdentifier=$(GlobalRuntimeIdentifier)</AdditionalPropertiesForGetTargetFrameworkProperties> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is AdditionalPropertiesForGetTargetFrameworkProperties
consumed? I don't see it in the MSBuild side of this PR or here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to push my local changes to the MSBuild change.
|
||
<PropertyGroup> | ||
<!-- If this project is not RID-specific, specify that an empty RuntimeIdentifier should be passed. --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually want to pass an empty RID or is this now just like ProjectHasSingleTargetFramework
where it should instead be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing it would certainly be better. If there is a clean way to do this, I'm happy to make the change. let's chat.
27b7e0e
to
1f18bea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 A couple of nits, but looks good and I think combining this with the RID path default change, all of my previous major concerns are now addressed. :)
I'm assuming you have a local setup with fully up-to-date msbuild + your changes where tests are passing. In other words: don't start the merge dance until we are certain that the end result will be green.
|
||
<PropertyGroup> | ||
<!-- If this project is not RID-specific, specify that an empty RuntimeIdentifier should be passed. --> | ||
<ProjectIsRidAgnostic>false</ProjectIsRidAgnostic> | ||
<ProjectIsRidAgnostic Condition=" '$(RuntimeIdentifier)' == '' and '$(RuntimeIdentifiers)' == '' ">true</ProjectIsRidAgnostic> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inconsistency in naming of single-target framework vs rid-agnostic. I suggest _IsRidAgnostic
to continue the nearby pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit 2: comment is not quite up to date with code changes here and in msbuild. How about something like "indicate to caller that project is RID agnostic so that a global property RuntimeIdentifier value can be removed" or something?
Tagging @MattGertz for approval. |
From now on, all submissions need graph paper diagrams. :-) |
1f18bea
to
3768b8f
Compare
96062c9
to
46f63c5
Compare
Nits addressed, as well as x-plat test issues. This is ready to go once approved. Whoever merges, please squash :D |
@@ -164,6 +164,7 @@ | |||
DestinationFolder="$(TestsDirectory)" | |||
/> | |||
|
|||
<Message Text="$(DotNetTool) "$(TestsDirectory)\xunit.console.netcore.exe" "@(TestAssembly, '" "')" -xml "@(XmlTestFile)"" Importance="High" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to check this in? I like it, but the formatting is off and it would be nice not to duplicate the command in Message and Exec.
…0190801.3 (dotnet#828) - Microsoft.AspNetCore.Mvc.Analyzers - 5.0.0-alpha1.19401.3 - Microsoft.AspNetCore.Mvc.Api.Analyzers - 5.0.0-alpha1.19401.3 - Microsoft.AspNetCore.Analyzers - 5.0.0-alpha1.19401.3 - Microsoft.AspNetCore.Components.Analyzers - 5.0.0-alpha1.19401.3
Fixes the RID P2P component of #696
This is part of a two-part PR. The second part is dotnet/msbuild#1674.
What
These PRs, together, enable the following class of projects:
With this fix in place, one can:
dotnet restore App.csproj
dotnet build -r osx.10.11-x64 App.csproj
Without the fix, Library.csproj will not build because the
osx.10.11-x64
runtime identifier will be passed through as a global property, forcing it to build for a target that does not exist in the NuGet assets file.How
The MSBuild portion of the fix adds
RuntimeIdentifier
to the list ofRemoveProperties
passed to the P2P in_GetProjectReferenceTargetFrameworkProperties
. It also passes along the value ofRuntimeIdentifier
asReferringRuntimeIdentifier
so that the dependency can decide how it wants to interpret that Runtime Identifier. The model used is identical to that used for TargetFramework.The SDK portion of the fix expands the
GetTargetFrameworkProperties
target to also account for RuntimeIdentifiers. The logic is as follows:RuntimeIdentifier
orRuntimeIdentifiers
set then use the ReferringRuntimeIdentifier''
as the RuntimeIdentifierThe effect is that RID-specific projects will attempt to build with the RID passed to the root project. Portable projects will be built without a RID specified.
Testing
The PR includes a thorough test for the scenario in question, building a RID-specific project that references both a RID-specific and Portable library. Both libraries are proven to compile successfuly through runtime invocation. The RID-specific library both invokes a RID-specific native dependency AND inspects its own RID via an overloaded AssemblyInfo Description attribute.
The feature was enabled without impacting any existing SDK tests.
The combination of these changes was tested on my local machine by manually editing
Microsoft.Common.CurrentVersion.targets
in the Stage0dotnet
directory.Risk
This feature requires augmenting
Microsoft.Common.CurrentVersion.targets
. Despite this being a central target, there are mitigating circumstances:Merge Strategy
Due to the codeflow for these fixes, the following will need to happen in order:
/cc @srivatsn @DustinCampbell @livarcocc @jonsequitur @rainersigwald @AndyGerlicher @nguerrera @dsplaisted