Skip to content

Commit

Permalink
Make all internal types in Common internal OR public (dotnet#1759)
Browse files Browse the repository at this point in the history
This cleans up a few dependency issues between the bindings and the common project. The classes marked internal (including the Interop classes) are now public when building Common.csproj but still internal for the final assembly. This removes the need to link to individual source files outside their binding folders, which causes build problems when they're used from multiple places.
  • Loading branch information
pgrawehr authored Feb 20, 2022
1 parent 1baac46 commit 2db2f02
Show file tree
Hide file tree
Showing 126 changed files with 1,119 additions and 975 deletions.
3 changes: 3 additions & 0 deletions src/Iot.Device.Bindings/Iot.Device.Bindings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage)</TargetsForTfmSpecificContentInPackage>
<!--Partial elements should declare access modifier: Disabled for this project to simplify handling in common project. See also there.
If we disable this here, the warning is still emmited for the individual projects.-->
<NoWarn>$(NoWarn);SA1205</NoWarn>
<!--Disabling default items so samples source won't get build by the main library-->
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion src/devices/Ads1115/Ads1115.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\System\Device\DelayHelper.cs" Link="DelayHelper.cs" />
<Compile Include="I2cAddress.cs" />
<Compile Include="ComparatorLatching.cs" />
<Compile Include="ComparatorMode.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/devices/Arduino/Arduino.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Board\Board.csproj" />
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
<PackageReference Include="System.IO.Ports" Version="$(SystemIOPortsPackageVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Arduino/Arduino.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mcp3xxx", "..\Mcp3xxx\Mcp3x
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CharacterLcd", "..\CharacterLcd\CharacterLcd.csproj", "{D47A6627-4041-4CEA-8903-A6C67C6993CF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{CD593083-8E94-4B60-86BF-DF3FB7873893}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{CD593083-8E94-4B60-86BF-DF3FB7873893}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{9E5A25ED-9839-4C1A-9B27-993437D1CB31}"
EndProject
Expand Down
1 change: 0 additions & 1 deletion src/devices/Arduino/samples/Arduino.Monitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<ProjectReference Include="..\..\Bmxx80\Bmxx80.csproj" />
<ProjectReference Include="..\..\Button\Button.csproj" />
<ProjectReference Include="..\..\CharacterLcd\CharacterLcd.csproj" />
<ProjectReference Include="..\..\Common\CommonHelpers.csproj" />
<ProjectReference Include="..\..\HardwareMonitor\HardwareMonitor.csproj" />
<ProjectReference Include="..\..\Mcp3xxx\Mcp3xxx.csproj" />
<ProjectReference Include="..\Arduino.csproj" />
Expand Down
1 change: 0 additions & 1 deletion src/devices/Arduino/samples/Arduino.sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Bmxx80\Bmxx80.csproj" />
<ProjectReference Include="..\..\Common\CommonHelpers.csproj" />
<ProjectReference Include="..\..\Mcp3xxx\Mcp3xxx.csproj" />
<ProjectReference Include="..\Arduino.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/devices/Bh1745/Bh1745.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
<ItemGroup>
<Compile Include="*.cs" />
<None Include="README.md" />
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/devices/Bh1745/Bh1745.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745CustomConfiguration.S
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bh1745", "Bh1745.csproj", "{C572C86D-5BB2-4610-84EA-768257758933}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{195588CF-3E28-4CCA-B529-123708FAD880}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{195588CF-3E28-4CCA-B529-123708FAD880}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 0 additions & 1 deletion src/devices/Bmp180/Bmp180.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<Compile Include="CalibrationData.cs" />
<Compile Include="Register.cs" />
<Compile Include="Sampling.cs" />
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
<None Include="README.md" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/devices/Bmxx80/Bmxx80.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<Compile Include="Register\Bme280Register.cs" />
<Compile Include="Sampling.cs" />
<Compile Include="StandbyTime.cs" />
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="README.md" />
Expand Down
1 change: 0 additions & 1 deletion src/devices/Board/Board.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="*.cs" />
<Compile Include="..\Interop\Windows\WinUser.cs" Link="WinUser.cs" />
</ItemGroup>
<!-- Make the internal classes visible to the unit test assembly -->
<ItemGroup>
Expand Down
18 changes: 16 additions & 2 deletions src/devices/Board/Board.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30002.166
# Visual Studio Version 17
VisualStudioVersion = 17.0.32002.185
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E3BCE30D-56D7-422C-B77A-6C47739C6EC2}"
EndProject
Expand All @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mcp3xxx", "..\Mcp3xxx\Mcp3x
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4D8428C9-F577-4427-8272-748347076B0A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{B5716002-E727-4D8B-9AE8-BE734FC04002}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,6 +89,18 @@ Global
{B4856CA0-4620-4EA9-ABA4-966B748331A6}.Release|x64.Build.0 = Release|Any CPU
{B4856CA0-4620-4EA9-ABA4-966B748331A6}.Release|x86.ActiveCfg = Release|Any CPU
{B4856CA0-4620-4EA9-ABA4-966B748331A6}.Release|x86.Build.0 = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|x64.ActiveCfg = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|x64.Build.0 = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|x86.ActiveCfg = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Debug|x86.Build.0 = Debug|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|Any CPU.Build.0 = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|x64.ActiveCfg = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|x64.Build.0 = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|x86.ActiveCfg = Release|Any CPU
{B5716002-E727-4D8B-9AE8-BE734FC04002}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 0 additions & 4 deletions src/devices/BoardLed/BoardLed.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@
<Compile Include="BoardLed.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/devices/BoardLed/BoardLed.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BoardLed.Sample", "samples\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BoardLed", "BoardLed.csproj", "{3A4798D1-FC49-46C0-8774-0519EB7987C2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{FF04E59C-5C7E-44C7-B322-D11DFDEBC769}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{FF04E59C-5C7E-44C7-B322-D11DFDEBC769}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 0 additions & 1 deletion src/devices/BrickPi3/BrickPi3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BrickPi3/BrickPi3.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrickPi3.samples", "samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BrickPi3", "BrickPi3.csproj", "{AFEC6FF8-C770-4F7A-B2A3-7BA82466E91F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{CD70B1FE-53D8-48DB-AEBA-C3995A373144}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{CD70B1FE-53D8-48DB-AEBA-C3995A373144}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
5 changes: 0 additions & 5 deletions src/devices/BuildHat/BuildHat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,4 @@
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Common\CommonHelpers.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/devices/Card/Card.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CreditCardProcessing", "Cre
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mifare", "Mifare\Mifare.csproj", "{81A964D2-BA4B-4769-A630-084D8C4BEBDA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "..\Common\CommonHelpers.csproj", "{03F9B2A3-4B73-4D39-872B-BB0D81F3593E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "..\Common\Common.csproj", "{03F9B2A3-4B73-4D39-872B-BB0D81F3593E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 0 additions & 2 deletions src/devices/Card/CreditCard/CreditCardProcessing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

<ItemGroup>
<PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" />
<Compile Include="..\..\Common\Iot\Device\Common\NumberHelper.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Common\CommonHelpers.csproj" />
<ProjectReference Include="..\CardRfid.csproj" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion src/devices/Card/Mifare/Mifare.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Common\CommonHelpers.csproj" />
<ProjectReference Include="..\CardRfid.csproj" />
<ProjectReference Include="..\Ndef\Ndef.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/devices/Card/Ultralight/Ultralight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Common\CommonHelpers.csproj" />
<ProjectReference Include="..\CardRfid.csproj" />
<ProjectReference Include="..\Ndef\Ndef.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/devices/Ccs811/Ccs811.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\System\Device\DelayHelper.cs" Link="DelayHelper.cs" />
<Compile Include="*.cs" />
</ItemGroup>
</Project>
2 changes: 0 additions & 2 deletions src/devices/CharacterLcd/CharacterLcd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Common\System\Device\DelayHelper.cs" Link="DelayHelper.cs" />
<Compile Include="Flags.cs" />
<Compile Include="Hd44780.cs" />
<Compile Include="ICharacterLcd.cs" />
Expand All @@ -23,7 +22,6 @@
<Compile Include="Registers.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../Common/CommonHelpers.csproj" />
<ProjectReference Include="../ShiftRegister/ShiftRegister.csproj" />
<None Include="README.md" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/devices/Charlieplex/Charlieplex.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Common/CommonHelpers.csproj" />
<Compile Include="CharlieplexSegment.cs" />
<Compile Include="CharlieplexSegmentNode.cs" />
</ItemGroup>
Expand Down
77 changes: 77 additions & 0 deletions src/devices/Common/ClassVisibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

#pragma warning disable SA1403 // File may only contain a single namespace

// These instructions make the classes public for building the individual projects.
// The default visibility is "internal" so they stay hidden if this section is removed for the final library build.
#if !BUILDING_IOT_DEVICE_BINDINGS

public partial class Interop
{
}

namespace Iot.Device.Common
{
public partial class NumberHelper
{
}
}

namespace System.Device
{
public partial class DelayHelper
{
}
}

namespace System.Device.Gpio
{
public partial struct PinVector32
{
}

public partial struct PinVector64
{
}
}

#else

internal partial class Interop
{
}

namespace Iot.Device.Common
{
internal partial class NumberHelper
{
}
}

namespace System.Device
{
internal partial class DelayHelper
{
}
}

namespace System.Device.Gpio
{
internal partial struct PinVector32
{
}

internal partial struct PinVector64
{
}
}


#endif
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(DefaultBindingTfms)</TargetFrameworks>
<EnableDefaultItems>false</EnableDefaultItems>
<RootNamespace>
</RootNamespace>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!-- SA1205: Partial elements should declare access modifier (allows adjusting class visibility in a single source file)-->
<NoWarn>$(NoWarn);SA1205;</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="ClassVisibility.cs" />
<Compile Include="MathExtensions.cs" />
<Compile Include="Iot/Device/Common/*.cs" />
<Compile Include="Iot/Device/Graphics/*.cs" />
Expand All @@ -16,6 +19,7 @@
<Compile Include="System/Device/Gpio/*.cs" />
<Compile Include="System/Device/Analog/*.cs" />
<Compile Include="System/Device/Spi/*.cs" />
<Compile Include="Interop/**/*.cs" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingPackageVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Common/Common.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{A15AFC2C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common.Tests", "tests\Common.Tests.csproj", "{BF1A594E-CEE3-4629-9F95-56D40F7F00E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonHelpers", "CommonHelpers.csproj", "{1B521F66-CECB-4FA6-9FC4-FA70F24F8C60}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Common", "Common.csproj", "{1B521F66-CECB-4FA6-9FC4-FA70F24F8C60}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{CAED1B3A-81A5-419E-86D9-96F8D9EB2F29}"
EndProject
Expand Down
5 changes: 4 additions & 1 deletion src/devices/Common/FrameworkCompatibilityExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

internal partial class Interop
/// <summary>
/// Interop methods for Windows and Unix (P/Invoke call declarations)
/// This class is internal by default, but gets promoted to public within the device binding projects
/// </summary>
partial class Interop
{
private const string LibcLibrary = "libc";
private const string AlsaLibrary = "libasound";
Expand Down
Loading

0 comments on commit 2db2f02

Please sign in to comment.