From bf36cac0c36ad674d443e333d9168032c4a5915f Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Thu, 14 Jan 2021 16:14:41 -0600 Subject: [PATCH] [generator] Disable [SupportedOSPlatform] until we can build with .NET 5/6. --- .../Unit-Tests/CodeGeneratorTests.cs | 22 ++++++++-------- .../NamespaceMapping.cs | 25 ++++++++++--------- .../Attributes/SupportedOSPlatformAttr.cs | 3 ++- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs index 2eb6fa968..95ba940f7 100644 --- a/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs +++ b/tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs @@ -236,18 +236,20 @@ class XAJavaInteropCodeGeneratorTests : CodeGeneratorTests { protected override CodeGenerationTarget Target => CodeGenerationTarget.XAJavaInterop1; - [Test] - public void SupportedOSPlatform () - { - var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options); - klass.ApiAvailableSince = 30; - generator.Context.ContextTypes.Push (klass); - generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly")); - generator.Context.ContextTypes.Pop (); + // Disabled until we can properly build .NET 5/6 assemblies in our XA tree. + //[Test] + //public void SupportedOSPlatform () + //{ + // var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options); + // klass.ApiAvailableSince = 30; - StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!"); - } + // generator.Context.ContextTypes.Push (klass); + // generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly")); + // generator.Context.ContextTypes.Pop (); + + // StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!"); + //} } [TestFixture] diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs index 96026d0eb..5ba0742fd 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs @@ -32,20 +32,21 @@ public void Generate (CodeGenerationOptions opt, GenerationInfo gen_info) foreach (var jni in opt.GetJniMarshalDelegates ()) sw.WriteLine ($"delegate {FromJniType (jni[jni.Length - 1])} {jni} (IntPtr jnienv, IntPtr klass{GetDelegateParameters (jni)});"); + // Disabled until we can properly build .NET 5/6 assemblies in our XA tree. // [SupportedOSPlatform] only exists in .NET 5.0+, so we need to generate a // dummy one so earlier frameworks can compile. - if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) { - sw.WriteLine ("#if !NET"); - sw.WriteLine ("namespace System.Runtime.Versioning {"); - sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]"); - sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]"); - sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {"); - sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }"); - sw.WriteLine (" }"); - sw.WriteLine ("}"); - sw.WriteLine ("#endif"); - sw.WriteLine (""); - } + //if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) { + // sw.WriteLine ("#if !NET"); + // sw.WriteLine ("namespace System.Runtime.Versioning {"); + // sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]"); + // sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]"); + // sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {"); + // sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }"); + // sw.WriteLine (" }"); + // sw.WriteLine ("}"); + // sw.WriteLine ("#endif"); + // sw.WriteLine (""); + //} } } diff --git a/tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs b/tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs index f2f5021e2..f7f9b38d5 100644 --- a/tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs +++ b/tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs @@ -15,7 +15,8 @@ public class SupportedOSPlatformAttr : AttributeWriter public override void WriteAttribute (CodeWriter writer) { - writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]"); + // Disabled until we can properly build .NET 5/6 assemblies in our XA tree. + //writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]"); } } }