Skip to content

Reference leaf's src from test project #42826

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

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/workflow/building/libraries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Here is one example of a daily workflow for a developer working mainly on the li

```bat
:: From root:
git clean -xdf
:: Clean artifacts directory without removing the bootstrapped .dotnet folder.
build -clean
git pull upstream master & git push origin master
:: Build Debug libraries on top of Release runtime:
build.cmd clr+libs -rc Release
Expand All @@ -23,14 +24,15 @@ cd tests

:: Then inner loop build / test
:: (If using Visual Studio, you might run tests inside it instead)
pushd ..\src & dotnet build & popd & dotnet build /t:test
dotnet build /t:test
```

The instructions for Linux and macOS are essentially the same:

```bash
# From root:
git clean -xdf
# Clean artifacts directory without removing the bootstrapped .dotnet folder.
build -clean
git pull upstream master & git push origin master
# Build Debug libraries on top of Release runtime:
./build.sh clr+libs -rc Release
Expand All @@ -43,7 +45,7 @@ cd src/libraries/System.Text.RegularExpressions
cd tests

# Then inner loop build / test:
pushd ../src & dotnet build & popd & dotnet build /t:test
dotnet build /t:test
```

The steps above may be all you need to know to make a change. Want more details about what this means? Read on.
Expand Down
45 changes: 37 additions & 8 deletions eng/references.targets
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@
PrivateAssets="all" />
</ItemGroup>

<!-- Annotate the CoreLib P2P with required attributes. -->
<ItemGroup>
<ProjectReference Update="$(CoreLibProject)">
<Private>false</Private>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
<!-- Don't flow TargetFramework and Platform to use same inputs and outputs as the CoreLib's build as part of the runtime. -->
<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
</ProjectReference>
</ItemGroup>

<!-- Project references shouldn't be copied to the output for non test apps. -->
<ItemDefinitionGroup Condition="'$(IsTestProject)' != 'true' and '$(IsTestSupportProject)' != 'true'">
<ProjectReference>
<Private>false</Private>
</ProjectReference>
</ItemDefinitionGroup>

<!-- Disable TargetArchitectureMismatch warning when we reference CoreLib which is platform specific. -->
<Target Name="SetAssemblyWarnOnErrorOnTargetArchitectureForCoreLib"
BeforeTargets="ResolveAssemblyReferences"
Condition="'@(ProjectReference)' != '' and
@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Target>

<!-- Filter out transitive P2Ps which should be excluded. -->
<Target Name="FilterTransitiveProjectReferences"
AfterTargets="IncludeTransitiveProjectReferences"
Expand All @@ -42,17 +65,23 @@
</ItemGroup>
</Target>

<!-- Make shared framework assemblies not app-local (non private). -->
<Target Name="UpdateProjectReferencesWithPrivateAttribute"
AfterTargets="AssignProjectConfiguration"
BeforeTargets="PrepareProjectReferences"
<!--
Make shared framework assemblies not app-local (non private), don't reference them and flow
the TargetFramework-TargetOS touple to avoid tfm selection.
-->
<Target Name="UpdateSharedFrameworkProjectReferences"
BeforeTargets="ResolveP2PReferences;AssignProjectConfiguration"
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
('$(IsTestProject)' == 'true' or '$(IsTestSupportProject)' == 'true') and
'@(ProjectReferenceWithConfiguration)' != ''">
'@(ProjectReference)' != ''">
<ItemGroup>
<ProjectReferenceWithConfiguration PrivateAssets="all"
Private="false"
Condition="$(NetCoreAppLibrary.Contains('%(Filename);'))" />
<ProjectReference Condition="$(NetCoreAppLibrary.Contains('%(Filename);'))">
<PrivateAssets>all</PrivateAssets>
<Private>false</Private>
<ReferenceOutputAssembly Condition="!$(NetCoreAppLibraryNoReference.Contains('%(Filename);')) and
'%(ProjectReference.SkipUseReferenceAssembly)' != 'true'">false</ReferenceOutputAssembly>
<ReferringTargetFramework Condition="'$(TargetFrameworkSuffix)' == ''">$(TargetFramework)-$(TargetOS)</ReferringTargetFramework>
Copy link
Member

@ericstj ericstj Oct 8, 2020

Choose a reason for hiding this comment

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

This isn't handling the case when referencing project is a less specific RID than referenced. Nor does it handle the case where TFM is less specific (though we may not use this any more).

Suggested change
<ReferringTargetFramework Condition="'$(TargetFrameworkSuffix)' == ''">$(TargetFramework)-$(TargetOS)</ReferringTargetFramework>
<ReferringTargetFramework>$(BuildTargetFramework)-$(TargetOS)</ReferringTargetFramework>

Copy link
Member Author

Choose a reason for hiding this comment

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

Nor does it handle the case where TFM is less specific (though we may not use this any more).

Right, we don't care about that anymore as test projects targeting ie .NETStandard aren't supported.

This isn't handling the case when referencing project is a less specific RID than referenced.

Right, but tbh I don't understand your proposal below. BuildTargetFramework is the same as TargetFramework if the project is invoked individually (outside of a root build).

Copy link
Member Author

@ViktorHofer ViktorHofer Oct 9, 2020

Choose a reason for hiding this comment

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

This isn't handling the case when referencing project is a less specific RID than referenced.

I thought about this a bit more and I'm unsure how we would make this ever work. I'm ok with supporting a rid-less TargetFramework for the sake of less configurations but I can't get my head around how we would support less specific RIDs without loosing the ability in test projects to not support some configurations.

Maybe we should chat about this offline as this confuses me... In the meantime I adjusted the two affected test projects for the sake of getting this in.

Copy link
Member

Choose a reason for hiding this comment

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

Binplacing will still make the right decision. The purpose of the project reference here is just to make a convenient build. That convenient build shouldn't really be chosen based on the test's configuration, but what the vertical build would have put in the test runtime, which is decided by the things I suggested.

</ProjectReference>
</ItemGroup>
</Target>

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/tests/TestUtilities/TestUtilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<!-- Upgrade the NetStandard.Library transitive xunit dependency to avoid 1.x NS dependencies. -->
<PackageReference Include="NETStandard.Library" Version="$(NetStandardLibrary20Version)" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\ref\Microsoft.Win32.Registry.csproj" PrivateAssets="all" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Principal.Windows\ref\System.Security.Principal.Windows.csproj" PrivateAssets="all" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Security.Principal.Windows\src\System.Security.Principal.Windows.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
Expand Down
22 changes: 1 addition & 21 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project InitialTargets="UpdateProjectReferencesWithAttributes">

<Project>
<Import Project="..\..\Directory.Build.targets" />

<PropertyGroup>
Expand Down Expand Up @@ -167,24 +166,6 @@
<!-- Define this target to override the workaround in arcade as we don't need it for our pkgprojs -->
<Target Name="InitializeStandardNuspecProperties" />

<Target Name="UpdateProjectReferencesWithAttributes" Condition="'@(ProjectReference)' != ''">
<ItemGroup>
<ProjectReference Condition="'%(Filename)' == 'System.Private.CoreLib'">
<!-- Don't flow TargetFramework and Platform to use same inputs and outputs as the CoreLib's build as part of the runtime. -->
<UndefineProperties>$(UndefineProperties);TargetFramework;Platform</UndefineProperties>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'CoreCLR' and
'$(Configuration)' != '$(CoreCLRConfiguration)'">Configuration=$(CoreCLRConfiguration)</SetConfiguration>
<SetConfiguration Condition="'$(RuntimeFlavor)' == 'Mono' and
'$(Configuration)' != '$(MonoConfiguration)'">Configuration=$(MonoConfiguration)</SetConfiguration>
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<!-- Disable TargetArchitectureMismatch warning when we reference CoreLib which is platform specific. -->
<PropertyGroup Condition="@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Target>

<!-- Used for packaging -->
<Target Name="IsNotNetCoreAppProject" Returns="@(IsNotNetCoreAppProjectResult)">
<ItemGroup>
Expand Down Expand Up @@ -284,5 +265,4 @@
</ItemGroup>
</When>
</Choose>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
<Compile Include="UserDefinedShortCircuitOperators.cs" />
<Compile Include="VarArgsTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)'))">
<Compile Include="AccessTests.netcoreapp.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)'))">
<ProjectReference Include="..\src\Microsoft.CSharp.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Compile Include="UtilsTests.cs" />
<Compile Include="VBMathTests.cs" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('$(NetCoreAppCurrent)'))">
<ProjectReference Include="..\src\Microsoft.VisualBasic.Core.vbproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Encoding.CodePages\src\System.Text.Encoding.CodePages.csproj" />
<Reference Include="Microsoft.VisualBasic" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<ItemGroup>
<Compile Include="Win32ExceptionTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Microsoft.Win32.Primitives.csproj" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions src/libraries/NetCoreAppLibrary.props
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
System.Net.WebSockets.Client;
System.Numerics.Vectors;
System.ObjectModel;
System.Private.CoreLib;
System.Private.DataContractSerialization;
System.Private.Runtime.InteropServices.JavaScript;
System.Private.Uri;
Expand Down Expand Up @@ -149,6 +150,12 @@
Microsoft.Win32.Registry;
System.IO.FileSystem.AccessControl;
System.IO.Pipes.AccessControl;
System.Private.CoreLib;
System.Private.DataContractSerialization;
System.Private.Runtime.InteropServices.JavaScript;
System.Private.Uri;
System.Private.Xml;
System.Private.Xml.Linq;
System.Security.AccessControl;
System.Security.Cryptography.Cng;
System.Security.Cryptography.OpenSsl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<Compile Include="AppContext.Switch.cs" />
<Compile Include="AppContext.Switch.Validation.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.AppContext.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
<Compile Include="ArrayPool\UnitTests.cs" />
<Compile Include="$(CommonTestPath)System\Diagnostics\Tracing\TestEventListener.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Buffers.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@
<Compile Include="$(CommonTestPath)System\Collections\IEnumerable.Generic.Serialization.Tests.cs"
Link="Common\System\Collections\IEnumerable.Generic.Serialization.Tests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Collections.Concurrent.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@
<Compile Include="$(CommonTestPath)System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs"
Link="Common\System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Collections.NonGeneric.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@
Link="Common\System\Collections\IEnumerable.NonGeneric.Serialization.Tests.cs" />
<Compile Include="NameObjectCollectionBase\NameObjectCollectionBase.ConstructorTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Collections.Specialized.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@
<Compile Include="$(CommonTestPath)System\Collections\IDictionary.NonGeneric.Tests.netcoreapp.cs"
Link="Common\System\Collections\IDictionary.NonGeneric.Tests.netcoreapp.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Collections.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Compile Include="System\ComponentModel\DataAnnotations\ValidationResultTests.cs" />
<Compile Include="System\ComponentModel\DataAnnotations\ValidatorTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="..\src\System.ComponentModel.Annotations.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<Compile Include="BackgroundWorkerTests.cs" />
<Compile Include="TestException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.ComponentModel.EventBasedAsync.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
<Compile Include="System\ComponentModel\ReadOnlyAttributeTests.cs" />
<Compile Include="System\ComponentModel\RefreshPropertiesAttributeTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.ComponentModel.Primitives.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<Compile Include="XTypeDescriptionProviderTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.ComponentModel.TypeConverter.csproj" />
<PackageReference Include="System.ComponentModel.TypeConverter.TestData" Version="$(SystemComponentModelTypeConverterTestDataVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<Compile Include="CancelEventArgsTests.cs" />
<Compile Include="ComponentModelBasicTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.ComponentModel.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<ItemGroup>
<Compile Include="ManualTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\System.Console.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Fcntl.cs"
Link="Common\Interop\Unix\System.Native\Interop.Fcntl.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Console.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
<ProjectReference Include="..\..\System.ComponentModel.TypeConverter\src\System.ComponentModel.TypeConverter.csproj" />
<ProjectReference Include="..\..\System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\src\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.Private.Uri\src\System.Private.Uri.csproj" />
<ProjectReference Include="..\..\System.Private.Uri\src\System.Private.Uri.csproj" PrivateAssets="all" />
<Reference Include="System.Collections.Concurrent" />
<Reference Include="System.ComponentModel" />
<Reference Include="System.ComponentModel.Primitives" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
</ItemGroup>
<!-- S.D.SqlClient isn't live built anymore. -->
<ItemGroup>
<!-- S.D.SqlClient isn't live built anymore. -->
<PackageReference Include="System.Data.SqlClient" Version="$(SystemDataSqlClientVersion)" />
<ProjectReference Include="..\src\System.Data.Common.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
<Compile Include="System\Data\TypedTableBaseExtensionsTests.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Mono\testdataset1.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Mono\testdataset1.xml"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Data.DataSetExtensions.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<Compile Include="$(CommonTestPath)System\ShouldNotBeInvokedException.cs"
Link="Common\System\ShouldNotBeInvokedException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\System.Diagnostics.Contracts.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
<TestRuntime>true</TestRuntime>
</PropertyGroup>
<ItemGroup>
<DefaultReferenceExclusion Include="System.Diagnostics.Debug" />
<DefaultReferenceExclusion Include="System.Runtime.Extensions" />
<ProjectReference Include="$(CoreLibProject)" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\src\System.Runtime.csproj;
$(LibrariesProjectRoot)System.Threading\src\System.Threading.csproj"
SkipUseReferenceAssembly="true" />
</ItemGroup>
<ItemGroup>
<Compile Include="DebugTests.cs" />
<Compile Include="DebugTestsNoListeners.cs" />
Expand All @@ -26,4 +18,14 @@
<Compile Include="EmptyAttributeTests.cs" />
<Compile Include="XunitAssemblyAttributes.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CoreLibProject)" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\src\System.Runtime.csproj;
$(LibrariesProjectRoot)System.Threading\src\System.Threading.csproj"
SkipUseReferenceAssembly="true" />
<ProjectReference Include="..\src\System.Diagnostics.Debug.csproj" />
<!-- Do not reference since we build part of the source code for tests. -->
<DefaultReferenceExclusion Include="System.Diagnostics.Debug" />
<DefaultReferenceExclusion Include="System.Runtime.Extensions" />
</ItemGroup>
</Project>
Loading