Skip to content

Commit

Permalink
[xtro] The right platform for macOS is 'macos', not 'osx'. (#2677)
Browse files Browse the repository at this point in the history
The platform name is used to filter availability attributes, and if we use the
wrong platform, we'll incorrectly skip all availability attributes.

The net result in unclassified entries: https://gist.github.com/rolfbjarne/a4474bc2a40c49a85cad495b51bb514f
  • Loading branch information
rolfbjarne authored and spouliot committed Sep 13, 2017
1 parent 989f5f9 commit a6d9781
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 13 additions & 4 deletions tests/xtro-sharpie/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ public static string ReplaceFirstInstance (this string source, string find, stri
return index < 0 ? source : source.Substring (0, index) + replace + source.Substring (index + find.Length);
}

public static string Platform { get; set; }
public enum Platforms
{
macOS,
iOS,
watchOS,
tvOS,
}

public static Platforms Platform { get; set; }

public static bool IsAvailable (this Decl decl)
{
Expand All @@ -103,13 +111,14 @@ public static bool IsAvailable (this Decl decl)

// but right now most frameworks consider tvOS and watchOS like iOS unless
// decorated otherwise so we must check again if we do not get a definitve answer
if ((result == null) && ((Platform == "tvos") || (Platform == "watchos")))
result = decl.IsAvailable ("ios");
if ((result == null) && ((Platform == Platforms.tvOS) || (Platform == Platforms.watchOS)))
result = decl.IsAvailable (Platforms.iOS);
return !result.HasValue ? true : result.Value;
}

static bool? IsAvailable (this Decl decl, string platform)
static bool? IsAvailable (this Decl decl, Platforms platform_value)
{
var platform = platform_value.ToString ().ToLowerInvariant ();
bool? result = null;
foreach (var attr in decl.Attrs) {
// NS_UNAVAILABLE
Expand Down
10 changes: 5 additions & 5 deletions tests/xtro-sharpie/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public void Execute (string pchFile, IEnumerable<string> assemblyNames)
foreach (var assemblyName in assemblyNames) {
var name = Path.GetFileNameWithoutExtension (assemblyName);
if (name.EndsWith (".iOS", StringComparison.Ordinal))
Helpers.Platform = "ios";
Helpers.Platform = Helpers.Platforms.iOS;
else if (name.EndsWith (".Mac", StringComparison.Ordinal))
Helpers.Platform = "osx";
Helpers.Platform = Helpers.Platforms.macOS;
else if (name.EndsWith (".WatchOS", StringComparison.Ordinal))
Helpers.Platform = "watchos";
Helpers.Platform = Helpers.Platforms.watchOS;
else if (name.EndsWith (".TVOS", StringComparison.Ordinal))
Helpers.Platform = "tvos";
Helpers.Platform = Helpers.Platforms.tvOS;
managed_reader.Load (assemblyName);
}

Expand Down Expand Up @@ -75,7 +75,7 @@ static IEnumerable<string> ExclusionList {
get {
if (_exclusionList == null) {
switch (Helpers.Platform) {
case "osx":
case Helpers.Platforms.macOS:
_exclusionList = macOSXExclusionList;
break;
default:
Expand Down

0 comments on commit a6d9781

Please sign in to comment.