Skip to content
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

[generator] Disable [SupportedOSPlatform] until we can build with .NET 5/6. #781

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ("");
//}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\")]");
}
}
}