Skip to content

Commit

Permalink
[bgen] Add support for converting ObsoletedOSPlatform attributes. Fixes
Browse files Browse the repository at this point in the history
#18966. (#18972)

Fixes #18966.
  • Loading branch information
rolfbjarne authored Sep 11, 2023
1 parent d6eb395 commit a7e96e5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/bgen/AttributeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ Type LookupReflectionType (string fullname, ICustomAttributeProvider provider)
return typeof (System.Runtime.Versioning.SupportedOSPlatformAttribute);
case "System.Runtime.Versioning.UnsupportedOSPlatformAttribute":
return typeof (System.Runtime.Versioning.UnsupportedOSPlatformAttribute);
case "System.Runtime.Versioning.ObsoletedOSPlatformAttribute":
return typeof (System.Runtime.Versioning.ObsoletedOSPlatformAttribute);
#endif
}

Expand Down Expand Up @@ -338,6 +340,14 @@ Type ConvertTypeToMeta (System.Type type, ICustomAttributeProvider provider)
return AttributeFactory.CreateNewAttribute<UnavailableAttribute> (up).Yield ();
else
return Enumerable.Empty<System.Attribute> ();
case "ObsoletedOSPlatformAttribute":
var oarg = attribute.ConstructorArguments [0].Value as string;
(var op, var ov) = ParseOSPlatformAttribute (oarg);
// might have been available for a while...
if (ov is null)
return AttributeFactory.CreateNewAttribute<ObsoletedAttribute> (op).Yield ();
else
return AttributeFactory.CreateNewAttribute<ObsoletedAttribute> (op, ov.Major, ov.Minor).Yield ();
#endif
default:
return Enumerable.Empty<System.Attribute> ();
Expand Down
2 changes: 1 addition & 1 deletion tests/bgen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ TOP=../..
include $(TOP)/Make.config

run-tests:
$(DOTNET) test
$(DOTNET) test $(TEST_FILTER)
7 changes: 6 additions & 1 deletion tests/common/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -810,13 +810,18 @@ public static IEnumerable<string> GetBaseLibraryImplementations (ApplePlatform p
}
}


public static IEnumerable<string> GetRefLibraries ()
{
foreach (var platform in GetIncludedPlatforms (true))
yield return Path.Combine (GetRefDirectory (platform), GetBaseLibraryName (platform, true));
}


public static string GetRefLibrary (ApplePlatform platform)
{
return GetBaseLibrary (platform, true);
}

public static string GetTargetFramework (Profile profile)
{
switch (profile) {
Expand Down
15 changes: 15 additions & 0 deletions tests/generator/BGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,21 @@ public void NewerAvailabilityInInlinedProtocol (Profile profile)
Assert.That (failures, Is.Empty, "Failures");
}

#if !NET
[Ignore ("This only applies to .NET")]
#endif
[Test]
[TestCase (Profile.iOS)]
public void ObsoletedOSPlatform (Profile profile)
{
Configuration.IgnoreIfIgnoredPlatform (profile.AsPlatform ());
var bgen = new BGenTool ();
bgen.Profile = profile;
bgen.AddTestApiDefinition ("tests/obsoletedosplatform.cs");
bgen.CreateTemporaryBinding ();
bgen.AssertExecute ("build");
}

BGenTool BuildFile (Profile profile, params string [] filenames)
{
return BuildFile (profile, true, false, filenames);
Expand Down
10 changes: 10 additions & 0 deletions tests/generator/tests/obsoletedosplatform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.Versioning;
using Foundation;
using UIKit;

namespace iosbindinglib {
[Protocol, Model]
[BaseType (typeof (UIApplicationDelegate))]
public interface TestDelegate {
}
}

5 comments on commit a7e96e5

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.