Skip to content

Commit 00862ad

Browse files
authored
[generator] Disable [SupportedOSPlatform] until .NET 5/6. (#781)
Context: da12df4 Context: a33084b Context: dotnet/android#5497 (review) We cannot currently build `net5.0` or `net6.0` assemblies in our xamarin-android tree; we instead do some workaround that involves compiling with `netcoreapp3.1` while referencing the 5.0 BCL. This creates a conflict between the local `[SupportedOSPlatform]` we create in `Mono.Android.dll` built for `netcoreapp3.1` , and the real one in the 5.0 BCL. error CS0433: The type 'SupportedOSPlatformAttribute' exists in both 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' and 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [/Users/runner/work/1/s/tests/Mono.Android-Tests/Java.Interop-Tests/Java.Interop-Tests.NET.csproj] Disable generating `SupportedOSPlatformAttribute` until we can build `Mono.Android.dll` with `NET` defined, in which case it will not contain the local attribute, and we can re-enable da12df4.
1 parent a33084b commit 00862ad

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs

+12-10
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,20 @@ class XAJavaInteropCodeGeneratorTests : CodeGeneratorTests
236236
{
237237
protected override CodeGenerationTarget Target => CodeGenerationTarget.XAJavaInterop1;
238238

239-
[Test]
240-
public void SupportedOSPlatform ()
241-
{
242-
var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
243-
klass.ApiAvailableSince = 30;
244239

245-
generator.Context.ContextTypes.Push (klass);
246-
generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
247-
generator.Context.ContextTypes.Pop ();
240+
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
241+
//[Test]
242+
//public void SupportedOSPlatform ()
243+
//{
244+
// var klass = SupportTypeBuilder.CreateClass ("java.code.MyClass", options);
245+
// klass.ApiAvailableSince = 30;
248246

249-
StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
250-
}
247+
// generator.Context.ContextTypes.Push (klass);
248+
// generator.WriteType (klass, string.Empty, new GenerationInfo ("", "", "MyAssembly"));
249+
// generator.Context.ContextTypes.Pop ();
250+
251+
// StringAssert.Contains ("[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android30.0\")]", builder.ToString (), "Should contain SupportedOSPlatform!");
252+
//}
251253
}
252254

253255
[TestFixture]

tools/generator/Java.Interop.Tools.Generator.ObjectModel/NamespaceMapping.cs

+13-12
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ public void Generate (CodeGenerationOptions opt, GenerationInfo gen_info)
3232
foreach (var jni in opt.GetJniMarshalDelegates ())
3333
sw.WriteLine ($"delegate {FromJniType (jni[jni.Length - 1])} {jni} (IntPtr jnienv, IntPtr klass{GetDelegateParameters (jni)});");
3434

35+
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
3536
// [SupportedOSPlatform] only exists in .NET 5.0+, so we need to generate a
3637
// dummy one so earlier frameworks can compile.
37-
if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) {
38-
sw.WriteLine ("#if !NET");
39-
sw.WriteLine ("namespace System.Runtime.Versioning {");
40-
sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]");
41-
sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]");
42-
sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {");
43-
sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }");
44-
sw.WriteLine (" }");
45-
sw.WriteLine ("}");
46-
sw.WriteLine ("#endif");
47-
sw.WriteLine ("");
48-
}
38+
//if (opt.CodeGenerationTarget == Xamarin.Android.Binder.CodeGenerationTarget.XAJavaInterop1) {
39+
// sw.WriteLine ("#if !NET");
40+
// sw.WriteLine ("namespace System.Runtime.Versioning {");
41+
// sw.WriteLine (" [System.Diagnostics.Conditional(\"NEVER\")]");
42+
// sw.WriteLine (" [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Module | AttributeTargets.Property | AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]");
43+
// sw.WriteLine (" internal sealed class SupportedOSPlatformAttribute : Attribute {");
44+
// sw.WriteLine (" public SupportedOSPlatformAttribute (string platformName) { }");
45+
// sw.WriteLine (" }");
46+
// sw.WriteLine ("}");
47+
// sw.WriteLine ("#endif");
48+
// sw.WriteLine ("");
49+
//}
4950
}
5051
}
5152

tools/generator/SourceWriters/Attributes/SupportedOSPlatformAttr.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class SupportedOSPlatformAttr : AttributeWriter
1515

1616
public override void WriteAttribute (CodeWriter writer)
1717
{
18-
writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]");
18+
// Disabled until we can properly build .NET 5/6 assemblies in our XA tree.
19+
//writer.WriteLine ($"[global::System.Runtime.Versioning.SupportedOSPlatformAttribute (\"android{Version}.0\")]");
1920
}
2021
}
2122
}

0 commit comments

Comments
 (0)