-
Notifications
You must be signed in to change notification settings - Fork 511
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
[Rgen] Provide all the wiring to allow to emit code. #21460
Open
mandel-macaque
wants to merge
24
commits into
main
Choose a base branch
from
dev/mandel/rgen-wiring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e5b75d2
[Rgen] Provide all the wiring to allow to emit code.
mandel-macaque 1ac8974
Auto-format source code
89aef62
Fix makefile.
mandel-macaque f6f8811
Merge branch 'main' into dev/mandel/rgen-wiring
mandel-macaque c8ddb0a
Merge TryValidate and Emit since it makes the API cleaner.
mandel-macaque 56c7ed2
enuable nullable first so that emitters can add extra namespaces.
mandel-macaque ae1b14a
Fix the sample projects.
mandel-macaque d4fb40e
Fix analyzer tests.
mandel-macaque ad83462
Auto-format source code
7f32f87
Apply suggestions from code review
mandel-macaque bca5fca
Fix tab usage, add misssing closing brace
mandel-macaque 5f90c0e
Auto-format source code
d95ed58
Add AppendRaw implementation with fewer string allocations.
mandel-macaque 2e3ff80
Provide Appends that take an interpolated string.
mandel-macaque 7e96a68
Merge branch 'dev/mandel/rgen-wiring' of github.com:xamarin/xamarin-m…
mandel-macaque cc24fa9
Auto-format source code
4da5c5d
Use a better approach fro the new line in the append raw.
mandel-macaque 721b29e
Auto-format source code
1eaadfd
Update src/rgen/Microsoft.Macios.Generator.Sample/Microsoft.Macios.Ge…
mandel-macaque b6924fb
Apply suggestions from code review
mandel-macaque a208851
Apply suggestions from code review
mandel-macaque c59f13c
Fix tabbeb string build that broke after applying comments from PR.
mandel-macaque 1662432
Remove method that will be re-added in the following rgen pr.
mandel-macaque dbbdf51
Auto-format source code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -70,6 +70,6 @@ $(RSP_DIR)/dotnet/%-defines-dotnet.rsp: frameworks.sources Makefile.generator ge | |
$(Q) ./generate-defines.csharp [email protected] '$(filter-out $(DOTNET_REMOVED_$(shell echo $* | tr a-z A-Z)_FRAMEWORKS),$($(shell echo $* | tr a-z A-Z)_FRAMEWORKS))' | ||
$(Q) mv [email protected] $@ | ||
|
||
$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll: bgen/Attributes.cs Makefile.generator | $(DOTNET_BUILD_DIR) | ||
$(Q_DOTNET_BUILD) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ $< | ||
$(DOTNET_BUILD_DIR)/Xamarin.Apple.BindingAttributes.dll: bgen/Attributes.cs bgen/PlatformName.cs Makefile.generator | $(DOTNET_BUILD_DIR) | ||
$(Q_DOTNET_BUILD) $(SYSTEM_CSC) $(DOTNET_FLAGS) -out:$@ bgen/Attributes.cs bgen/PlatformName.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,74 @@ | ||
using System; | ||
using System.IO; | ||
using ObjCRuntime; | ||
using Xamarin.Utils; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
public static class PlatformNameExtensions { | ||
|
||
public static string GetApplicationClassName (this PlatformName currentPlatform) | ||
public static bool TryGetApplicationClassName (this PlatformName currentPlatform, [NotNullWhen (true)] out string? className) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.WatchOS: | ||
case PlatformName.TvOS: | ||
case PlatformName.MacCatalyst: | ||
return "UIApplication"; | ||
className = "UIApplication"; | ||
return true; | ||
case PlatformName.MacOSX: | ||
return "NSApplication"; | ||
className = "NSApplication"; | ||
return true; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
className = null; | ||
return false; | ||
} | ||
} | ||
|
||
public static int GetXamcoreVersion (this PlatformName currentPlatform) | ||
{ | ||
#if NET | ||
return 4; | ||
#else | ||
switch (currentPlatform) { | ||
case PlatformName.MacOSX: | ||
case PlatformName.iOS: | ||
return 2; | ||
case PlatformName.TvOS: | ||
case PlatformName.WatchOS: | ||
return 3; | ||
default: | ||
return 4; | ||
} | ||
#endif | ||
} | ||
|
||
public static string GetCoreImageMap (this PlatformName currentPlatform) | ||
public static bool TryGetCoreImageMap (this PlatformName currentPlatform, [NotNullWhen (true)] out string? coreImageMap) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.WatchOS: | ||
case PlatformName.TvOS: | ||
case PlatformName.MacCatalyst: | ||
return "CoreImage"; | ||
coreImageMap = "CoreImage"; | ||
return true; | ||
case PlatformName.MacOSX: | ||
return "Quartz"; | ||
coreImageMap = "Quartz"; | ||
return true; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
coreImageMap = null; | ||
return false; | ||
} | ||
} | ||
|
||
public static string GetCoreServicesMap (this PlatformName currentPlatform) | ||
public static bool TryGetCoreServicesMap (this PlatformName currentPlatform, [NotNullWhen (true)] out string? coreServicesMap) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.WatchOS: | ||
case PlatformName.TvOS: | ||
case PlatformName.MacCatalyst: | ||
return "MobileCoreServices"; | ||
case PlatformName.MacOSX: | ||
return "CoreServices"; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
} | ||
|
||
public static string GetPDFKitMap (this PlatformName currentPlatform) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.MacCatalyst: | ||
return "PDFKit"; | ||
case PlatformName.MacOSX: | ||
return "Quartz"; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
} | ||
|
||
public static ApplePlatform AsApplePlatform (this PlatformName platform) | ||
{ | ||
switch (platform) { | ||
case PlatformName.iOS: | ||
return ApplePlatform.iOS; | ||
case PlatformName.TvOS: | ||
return ApplePlatform.TVOS; | ||
case PlatformName.MacCatalyst: | ||
return ApplePlatform.MacCatalyst; | ||
coreServicesMap = "MobileCoreServices"; | ||
return true; | ||
case PlatformName.MacOSX: | ||
return ApplePlatform.MacOSX; | ||
case PlatformName.WatchOS: | ||
return ApplePlatform.WatchOS; | ||
case PlatformName.None: | ||
return ApplePlatform.None; | ||
coreServicesMap = "CoreServices"; | ||
return true; | ||
default: | ||
throw new ArgumentOutOfRangeException (nameof (platform), platform, $"Unknown platform: {platform}"); | ||
coreServicesMap = null; | ||
return false; | ||
} | ||
} | ||
|
||
static string GetSdkRoot (this PlatformName currentPlatform) | ||
public static bool TryGetPDFKitMap (this PlatformName currentPlatform, [NotNullWhen (true)] out string? pdfKitMap) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.WatchOS: | ||
case PlatformName.TvOS: | ||
case PlatformName.MacCatalyst: | ||
var sdkRoot = Environment.GetEnvironmentVariable ("MD_MTOUCH_SDK_ROOT"); | ||
if (string.IsNullOrEmpty (sdkRoot)) | ||
sdkRoot = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current"; | ||
return sdkRoot; | ||
pdfKitMap = "PDFKit"; | ||
return true; | ||
case PlatformName.MacOSX: | ||
var macSdkRoot = Environment.GetEnvironmentVariable ("XamarinMacFrameworkRoot"); | ||
if (string.IsNullOrEmpty (macSdkRoot)) | ||
macSdkRoot = "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current"; | ||
return macSdkRoot; | ||
pdfKitMap = "Quartz"; | ||
return true; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
pdfKitMap = null; | ||
return false; | ||
} | ||
} | ||
|
||
public static string GetPath (this PlatformName currentPlatform, params string [] paths) | ||
{ | ||
var fullPaths = new string [paths.Length + 1]; | ||
fullPaths [0] = currentPlatform.GetSdkRoot (); | ||
Array.Copy (paths, 0, fullPaths, 1, paths.Length); | ||
return Path.Combine (fullPaths); | ||
} | ||
} |
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,102 @@ | ||
using System; | ||
using System.IO; | ||
using Xamarin.Utils; | ||
|
||
public static class PlatformNameExtensionsBgen { | ||
|
||
// wrapper that allows us to use the same code for rgen and bgen | ||
public static string GetApplicationClassName (this PlatformName currentPlatform) | ||
{ | ||
if (currentPlatform.TryGetApplicationClassName (out var applicationClassName)) | ||
return applicationClassName; | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
|
||
public static string GetCoreImageMap (this PlatformName currentPlatform) | ||
{ | ||
if (currentPlatform.TryGetCoreImageMap (out var coreImageMap)) | ||
return coreImageMap; | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
|
||
public static string GetCoreServicesMap (this PlatformName currentPlatform) | ||
{ | ||
if (currentPlatform.TryGetCoreServicesMap (out var coreServicesMap)) | ||
return coreServicesMap; | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
|
||
public static string GetPDFKitMap (this PlatformName currentPlatform) | ||
{ | ||
if (currentPlatform.TryGetPDFKitMap (out var pdfKitMap)) | ||
return pdfKitMap; | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
|
||
public static int GetXamcoreVersion (this PlatformName currentPlatform) | ||
{ | ||
#if NET | ||
return 4; | ||
#else | ||
switch (currentPlatform) { | ||
case PlatformName.MacOSX: | ||
case PlatformName.iOS: | ||
return 2; | ||
case PlatformName.TvOS: | ||
case PlatformName.WatchOS: | ||
return 3; | ||
default: | ||
return 4; | ||
} | ||
#endif | ||
} | ||
|
||
public static ApplePlatform AsApplePlatform (this PlatformName platform) | ||
{ | ||
switch (platform) { | ||
case PlatformName.iOS: | ||
return ApplePlatform.iOS; | ||
case PlatformName.TvOS: | ||
return ApplePlatform.TVOS; | ||
case PlatformName.MacCatalyst: | ||
return ApplePlatform.MacCatalyst; | ||
case PlatformName.MacOSX: | ||
return ApplePlatform.MacOSX; | ||
case PlatformName.WatchOS: | ||
return ApplePlatform.WatchOS; | ||
case PlatformName.None: | ||
return ApplePlatform.None; | ||
default: | ||
throw new ArgumentOutOfRangeException (nameof (platform), platform, $"Unknown platform: {platform}"); | ||
} | ||
} | ||
|
||
static string GetSdkRoot (this PlatformName currentPlatform) | ||
{ | ||
switch (currentPlatform) { | ||
case PlatformName.iOS: | ||
case PlatformName.WatchOS: | ||
case PlatformName.TvOS: | ||
case PlatformName.MacCatalyst: | ||
var sdkRoot = Environment.GetEnvironmentVariable ("MD_MTOUCH_SDK_ROOT"); | ||
if (string.IsNullOrEmpty (sdkRoot)) | ||
sdkRoot = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current"; | ||
return sdkRoot; | ||
case PlatformName.MacOSX: | ||
var macSdkRoot = Environment.GetEnvironmentVariable ("XamarinMacFrameworkRoot"); | ||
if (string.IsNullOrEmpty (macSdkRoot)) | ||
macSdkRoot = "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current"; | ||
return macSdkRoot; | ||
default: | ||
throw new BindingException (1047, currentPlatform); | ||
} | ||
} | ||
|
||
public static string GetPath (this PlatformName currentPlatform, params string [] paths) | ||
{ | ||
var fullPaths = new string [paths.Length + 1]; | ||
fullPaths [0] = currentPlatform.GetSdkRoot (); | ||
Array.Copy (paths, 0, fullPaths, 1, paths.Length); | ||
return Path.Combine (fullPaths); | ||
} | ||
} |
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,8 @@ | ||
public enum PlatformName : byte { | ||
None, | ||
MacOSX, | ||
iOS, | ||
WatchOS, | ||
TvOS, | ||
MacCatalyst, | ||
} |
2 changes: 2 additions & 0 deletions
2
src/rgen/Microsoft.Macios.Bindings.Analyzer.Sample/Examples.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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Microsoft.Macios.Generator; | ||
|
||
/// <summary> | ||
/// Contains all the names of the attributes that are used by the binding generator. | ||
/// </summary> | ||
public static class AttributesNames { | ||
|
||
public static readonly string BindingAttribute = "ObjCBindings.BindingTypeAttribute"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question - would these ever have to be fully qualified?
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.
This is just a map, that will happen later in the code emitter. This class only provides helper methods that return the mapping.