-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Rgen] Use a roslyn code generator to help generate the flag parsing …
…of all attributes. (#22032)
- Loading branch information
1 parent
b50532b
commit 7df9693
Showing
11 changed files
with
569 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/rgen/Microsoft.Macios.Generator/TabbedStringBuilder.Availability.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.Macios.Generator.Availability; | ||
using Xamarin.Utils; | ||
|
||
namespace Microsoft.Macios.Generator; | ||
|
||
partial class TabbedStringBuilder { | ||
|
||
public TabbedStringBuilder AppendMemberAvailability (in SymbolAvailability allPlatformsAvailability) | ||
{ | ||
foreach (var availability in allPlatformsAvailability.PlatformAvailabilities) { | ||
var platformName = availability.Platform.AsString ().ToLower (); | ||
if (availability.SupportedVersion is not null) { | ||
var versionStr = (PlatformAvailability.IsDefaultVersion (availability.SupportedVersion)) | ||
? string.Empty | ||
: availability.SupportedVersion.ToString (); | ||
AppendLine ($"[SupportedOSPlatform (\"{platformName}{versionStr}\")]"); | ||
} | ||
|
||
// loop over the unsupported versions of the platform | ||
foreach (var (version, message) in availability.UnsupportedVersions) { | ||
var versionStr = (PlatformAvailability.IsDefaultVersion (version)) ? string.Empty : version.ToString (); | ||
if (message is null) { | ||
AppendLine ($"[UnsupportedOSPlatform (\"{platformName}{versionStr}\")]"); | ||
} else { | ||
AppendLine ($"[UnsupportedOSPlatform (\"{platformName}{versionStr}\", \"{message}\")]"); | ||
} | ||
} | ||
|
||
// loop over the obsolete versions of the platform | ||
foreach (var (version, obsoleteInfo) in availability.ObsoletedVersions) { | ||
var versionStr = (PlatformAvailability.IsDefaultVersion (version)) ? string.Empty : version.ToString (); | ||
|
||
switch (obsoleteInfo) { | ||
case (null, null): | ||
AppendLine ($"[ObsoletedOSPlatform (\"{platformName}{versionStr}\")]"); | ||
break; | ||
case (not null, null): | ||
AppendLine ($"[ObsoletedOSPlatform (\"{platformName}{versionStr}\", \"{obsoleteInfo.Message}\")]"); | ||
break; | ||
case (null, not null): | ||
AppendLine ($"[ObsoletedOSPlatform (\"{platformName}{versionStr}\", Url=\"{obsoleteInfo.Url}\")]"); | ||
break; | ||
case (not null, not null): | ||
AppendLine ( | ||
$"[ObsoletedOSPlatform (\"{platformName}{versionStr}\", \"{obsoleteInfo.Message}\", Url=\"{obsoleteInfo.Url}\")]"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ator/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<Nullable>enable</Nullable> | ||
<LangVersion>latest</LangVersion> | ||
|
||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
<IsRoslynComponent>true</IsRoslynComponent> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
|
||
<RootNamespace>Microsoft.Macios.Transformer.Generator</RootNamespace> | ||
<PackageId>Microsoft.Macios.Transformer.Generator</PackageId> | ||
<!-- There is a bug in the roslyn analyzer for roslyn analyzers.... --> | ||
<NoWarn>RS2007;RS1041;APL0003</NoWarn> | ||
|
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\..\Microsoft.Macios.Generator\TabbedStringBuilder.cs"> | ||
<Link>TabbedStringBuilder.cs</Link> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
9 changes: 9 additions & 0 deletions
9
...ansformer.Generator/Microsoft.Macios.Transformer.Generator/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"DebugRoslynSourceGenerator": { | ||
"commandName": "DebugRoslynComponent", | ||
"targetProject": "../Microsoft.Macios.Transformer.Generator.Sample/Microsoft.Macios.Transformer.Generator.Sample.csproj" | ||
} | ||
} | ||
} |
Oops, something went wrong.