[Generator] Move the most of the path logic out of BT. (#19429)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
This commit is contained in:
Родитель
5c1f372e81
Коммит
dd3aa9afca
|
@ -124,24 +124,24 @@ public class BindingTouch : IDisposable {
|
|||
return attributedll!;
|
||||
|
||||
if (IsDotNet)
|
||||
return Path.Combine (GetSDKRoot (), "lib", "Xamarin.Apple.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "Xamarin.Apple.BindingAttributes.dll");
|
||||
|
||||
switch (CurrentPlatform) {
|
||||
case PlatformName.iOS:
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.iOS.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.iOS.BindingAttributes.dll");
|
||||
case PlatformName.WatchOS:
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.WatchOS.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.WatchOS.BindingAttributes.dll");
|
||||
case PlatformName.TvOS:
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.TVOS.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.TVOS.BindingAttributes.dll");
|
||||
case PlatformName.MacCatalyst:
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.MacCatalyst.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.MacCatalyst.BindingAttributes.dll");
|
||||
case PlatformName.MacOSX:
|
||||
if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) {
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.Mac-full.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.Mac-full.BindingAttributes.dll");
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) {
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.Mac-full.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.Mac-full.BindingAttributes.dll");
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) {
|
||||
return Path.Combine (GetSDKRoot (), "lib", "bgen", "Xamarin.Mac-mobile.BindingAttributes.dll");
|
||||
return CurrentPlatform.GetPath ("lib", "bgen", "Xamarin.Mac-mobile.BindingAttributes.dll");
|
||||
} else {
|
||||
throw ErrorHelper.CreateError (1053, target_framework);
|
||||
}
|
||||
|
@ -155,26 +155,26 @@ public class BindingTouch : IDisposable {
|
|||
if (!IsDotNet) {
|
||||
switch (CurrentPlatform) {
|
||||
case PlatformName.iOS:
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.iOS");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "Xamarin.iOS");
|
||||
break;
|
||||
case PlatformName.WatchOS:
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.WatchOS");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "Xamarin.WatchOS");
|
||||
break;
|
||||
case PlatformName.TvOS:
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.TVOS");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "Xamarin.TVOS");
|
||||
break;
|
||||
case PlatformName.MacCatalyst:
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.MacCatalyst");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "Xamarin.MacCatalyst");
|
||||
break;
|
||||
case PlatformName.MacOSX:
|
||||
if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) {
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "reference", "full");
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5");
|
||||
yield return CurrentPlatform.GetPath ("lib", "reference", "full");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "4.5");
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) {
|
||||
yield return "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5";
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "4.5");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "4.5");
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) {
|
||||
yield return Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac");
|
||||
yield return CurrentPlatform.GetPath ("lib", "mono", "Xamarin.Mac");
|
||||
} else {
|
||||
throw ErrorHelper.CreateError (1053, target_framework);
|
||||
}
|
||||
|
@ -187,27 +187,6 @@ public class BindingTouch : IDisposable {
|
|||
yield return lib;
|
||||
}
|
||||
|
||||
string GetSDKRoot ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void SetTargetFramework (string fx)
|
||||
{
|
||||
TargetFramework tf;
|
||||
|
@ -363,40 +342,40 @@ public class BindingTouch : IDisposable {
|
|||
CurrentPlatform = PlatformName.iOS;
|
||||
nostdlib = true;
|
||||
if (string.IsNullOrEmpty (baselibdll))
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.iOS/Xamarin.iOS.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib/mono/Xamarin.iOS/Xamarin.iOS.dll");
|
||||
if (!IsDotNet) {
|
||||
references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.iOS", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/Xamarin.iOS", references);
|
||||
}
|
||||
break;
|
||||
case ApplePlatform.TVOS:
|
||||
CurrentPlatform = PlatformName.TvOS;
|
||||
nostdlib = true;
|
||||
if (string.IsNullOrEmpty (baselibdll))
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll");
|
||||
if (!IsDotNet) {
|
||||
references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.TVOS", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/Xamarin.TVOS", references);
|
||||
}
|
||||
break;
|
||||
case ApplePlatform.WatchOS:
|
||||
CurrentPlatform = PlatformName.WatchOS;
|
||||
nostdlib = true;
|
||||
if (string.IsNullOrEmpty (baselibdll))
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll");
|
||||
if (!IsDotNet) {
|
||||
references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.WatchOS", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/Xamarin.WatchOS", references);
|
||||
}
|
||||
break;
|
||||
case ApplePlatform.MacCatalyst:
|
||||
CurrentPlatform = PlatformName.MacCatalyst;
|
||||
nostdlib = true;
|
||||
if (string.IsNullOrEmpty (baselibdll))
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib/mono/Xamarin.MacCatalyst/Xamarin.MacCatalyst.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib/mono/Xamarin.MacCatalyst/Xamarin.MacCatalyst.dll");
|
||||
if (!IsDotNet) {
|
||||
// references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.MacCatalyst", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/Xamarin.MacCatalyst", references);
|
||||
}
|
||||
break;
|
||||
case ApplePlatform.MacOSX:
|
||||
|
@ -404,22 +383,22 @@ public class BindingTouch : IDisposable {
|
|||
nostdlib = true;
|
||||
if (string.IsNullOrEmpty (baselibdll)) {
|
||||
if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile)
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib", "reference", "mobile", "Xamarin.Mac.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib", "reference", "mobile", "Xamarin.Mac.dll");
|
||||
else if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full || target_framework == TargetFramework.Xamarin_Mac_4_5_System)
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib", "reference", "full", "Xamarin.Mac.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib", "reference", "full", "Xamarin.Mac.dll");
|
||||
else if (target_framework == TargetFramework.DotNet_macOS)
|
||||
baselibdll = Path.Combine (GetSDKRoot (), "lib", "mono", "Xamarin.Mac", "Xamarin.Mac.dll");
|
||||
baselibdll = CurrentPlatform.GetPath ("lib", "mono", "Xamarin.Mac", "Xamarin.Mac.dll");
|
||||
else
|
||||
throw ErrorHelper.CreateError (1053, target_framework);
|
||||
}
|
||||
if (target_framework == TargetFramework.Xamarin_Mac_2_0_Mobile) {
|
||||
skipSystemDrawing = true;
|
||||
references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/Xamarin.Mac", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/Xamarin.Mac", references);
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_4_5_Full) {
|
||||
skipSystemDrawing = true;
|
||||
references.Add ("Facades/System.Drawing.Common");
|
||||
ReferenceFixer.FixSDKReferences (GetSDKRoot (), "lib/mono/4.5", references);
|
||||
ReferenceFixer.FixSDKReferences (CurrentPlatform, "lib/mono/4.5", references);
|
||||
} else if (target_framework == TargetFramework.Xamarin_Mac_4_5_System) {
|
||||
skipSystemDrawing = false;
|
||||
ReferenceFixer.FixSDKReferences ("/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5", references, forceSystemDrawing: true);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using ObjCRuntime;
|
||||
using Xamarin.Utils;
|
||||
|
||||
|
@ -99,4 +100,33 @@ public static class PlatformNameExtensions {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ObjCRuntime;
|
||||
|
||||
#nullable enable
|
||||
|
||||
static class ReferenceFixer {
|
||||
public static void FixSDKReferences (string sdkRoot, string sdk_offset, List<string> references) => FixSDKReferences (Path.Combine (sdkRoot, sdk_offset), references);
|
||||
public static void FixSDKReferences (PlatformName sdkRoot, string sdk_offset, List<string> references) => FixSDKReferences (sdkRoot.GetPath (sdk_offset), references);
|
||||
|
||||
public static void FixSDKReferences (string sdk_path, List<string> references, bool forceSystemDrawing = false)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using ObjCRuntime;
|
||||
using Xamarin.Utils;
|
||||
|
@ -57,5 +60,33 @@ namespace GeneratorTests {
|
|||
[TestCase (PlatformName.None, ApplePlatform.None)]
|
||||
public void AsApplePlatformTest (PlatformName platformName, ApplePlatform expected)
|
||||
=> Assert.AreEqual (expected, platformName.AsApplePlatform ());
|
||||
|
||||
[TestCase (PlatformName.iOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib/mono/Xamarin.iOS/Xamarin.iOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll")]
|
||||
[TestCase (PlatformName.iOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib", "mono", "Xamarin.iOS", "Xamarin.iOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll")]
|
||||
[TestCase (PlatformName.TvOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll")]
|
||||
[TestCase (PlatformName.TvOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib", "mono", "Xamarin.TVOS", "Xamarin.TVOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.TVOS/Xamarin.TVOS.dll")]
|
||||
[TestCase (PlatformName.WatchOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll")]
|
||||
[TestCase (PlatformName.WatchOS, "MD_MTOUCH_SDK_ROOT", new [] { "lib", "mono", "Xamarin.WatchOS", "Xamarin.WatchOS.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.WatchOS/Xamarin.WatchOS.dll")]
|
||||
[TestCase (PlatformName.MacCatalyst, "MD_MTOUCH_SDK_ROOT", new [] { "lib/mono/Xamarin.MacCatalyst/Xamarin.MacCatalyst.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.MacCatalyst/Xamarin.MacCatalyst.dll")]
|
||||
[TestCase (PlatformName.MacCatalyst, "MD_MTOUCH_SDK_ROOT", new [] { "lib", "mono", "Xamarin.MacCatalyst", "Xamarin.MacCatalyst.dll" }, "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.MacCatalyst/Xamarin.MacCatalyst.dll")]
|
||||
public void GetPath (PlatformName platformName, string envVar, string [] paths, string expectedResult)
|
||||
{
|
||||
// clean the paths using the OS new line
|
||||
if (Path.DirectorySeparatorChar != '/') {
|
||||
paths = paths.Select (p => p.Replace ('/', Path.DirectorySeparatorChar)).ToArray ();
|
||||
expectedResult = expectedResult.Replace ('/', Path.DirectorySeparatorChar);
|
||||
}
|
||||
// get the env, test and reset
|
||||
var env = Environment.GetEnvironmentVariable (envVar);
|
||||
Environment.SetEnvironmentVariable (envVar, "");
|
||||
var actualResult = platformName.GetPath (paths);
|
||||
Environment.SetEnvironmentVariable (envVar, env);
|
||||
|
||||
if (Path.DirectorySeparatorChar != '/') {
|
||||
actualResult = actualResult.Replace ('/', Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
Assert.AreEqual (expectedResult, actualResult, platformName.GetPath (paths));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче