Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/upload-art…
Browse files Browse the repository at this point in the history
…ifact-4
  • Loading branch information
kumaS-nu authored Jan 4, 2024
2 parents 188ccb7 + 2cee0a8 commit f713411
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/NuGetImporterForUnity/[Bb]uilds/
/NuGetImporterForUnity/[Ll]ogs/
/NuGetImporterForUnity/[Mm]emoryCaptures/
/NuGetImporterForUnity/[Uu]ser[Ss]ettings/
/Packager/[Ll]ibrary/
/Packager/[Tt]emp/
/Packager/[Oo]bj/
Expand Down Expand Up @@ -89,4 +90,10 @@ crashlytics-build.properties
/NuGetImporterForUnity/[Nn]u[Gg]et/

/NuGetImporterForUnity/[Pp]ackages/*/
!/NuGetImporterForUnity/[Pp]ackages/[Nn]u[Gg]et [Ii]mporter/
!/NuGetImporterForUnity/[Pp]ackages/[Nn]u[Gg]et [Ii]mporter/

# MacOS attribute file
.DS_Store

# VS Code meta files
.vscode
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kumaS.NuGetImporter.Editor.DataClasses
{
Expand Down Expand Up @@ -54,25 +55,41 @@ public class NativePlatform
public NativePlatform(string directoryPath)
{
Path = directoryPath;
var directoryName = System.IO.Path.GetFileName(directoryPath).ToLowerInvariant();
(OS, OSPriority) = GetOSInfo(directoryName);
Architecture = GetArchInfo(directoryName);
// https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
var rid = GetRidFrom(directoryPath);
(OS, OSPriority) = GetOSInfo(rid);
Architecture = GetArchInfo(rid);
}

private (string os, int priority) GetOSInfo(string directoryName)
private static string GetRidFrom(string path)
{ // https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders
// assumes right path is like "Packages/project/runtimes/RID/native/..." or somthing
path = path.Replace('\\', '/'); // in case of '\'(windows)
var pattern = "/?runtimes/(.+?)/?";
var matched = Regex.Match(
path,
pattern,
RegexOptions.RightToLeft | // to choose last
RegexOptions.IgnoreCase);
if (!matched.Success)
return string.Empty; // failed to find
return matched.Groups[1].Value.Split('/')[0];
}

private (string os, int priority) GetOSInfo(string rid)
{
var matchedPriority = PriorityTable.Where(table => directoryName.StartsWith(table.Item1.ToLowerInvariant()));
var matchedPriority = PriorityTable.Where(table => rid.StartsWith(table.Item1.ToLowerInvariant()));
if (matchedPriority.Any())
{
return matchedPriority.First();
}

return (directoryName.Split('-')[0], int.MaxValue);
return (rid.Split('-')[0], int.MaxValue);
}

private string GetArchInfo(string directoryName)
private string GetArchInfo(string rid)
{
var matchedArch = Enum.GetNames(typeof(ArchitectureType)).Where(table => directoryName.EndsWith(table.ToLowerInvariant()));
var matchedArch = Enum.GetNames(typeof(ArchitectureType)).Where(table => rid.EndsWith(table.ToLowerInvariant()));
if (matchedArch.Any())
{
return matchedArch.First();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,9 @@ string pluginPath
BuildTarget target = BuildTarget.NoTarget;
var architecture = "";
var enableOnEditor = false;
var platformPath = pluginPath;
while (platformPath!.Contains("native"))
{
platformPath = Path.GetDirectoryName(platformPath);
}

var platform = new NativePlatform(platformPath);
var directoryPath = Path.GetDirectoryName(pluginPath);
var platform = new NativePlatform(directoryPath);
architecture = platform.Architecture switch
{
nameof(ArchitectureType.X64) => platform.OS == nameof(OSType.IOS) ? "X64" : "x86_64",
Expand Down

0 comments on commit f713411

Please sign in to comment.