diff --git a/.gitignore b/.gitignore index feff5d3..f71c797 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ [Bb]uild/ *.sln.ide/ /src/.vs +/src/.idea # Build related tools/** diff --git a/nuspec/nuget/Cake.Unity.nuspec b/nuspec/nuget/Cake.Unity.nuspec index 2bf49ad..7c7fab9 100644 --- a/nuspec/nuget/Cake.Unity.nuspec +++ b/nuspec/nuget/Cake.Unity.nuspec @@ -19,8 +19,5 @@ - - - diff --git a/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj b/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj index fd8a399..463cf0f 100644 --- a/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj +++ b/src/Cake.Unity.FSharp.Tests/Cake.Unity.FSharp.Tests.fsproj @@ -4,10 +4,12 @@ netcoreapp3.1 false true + Cake.Unity.Tests + @@ -18,6 +20,7 @@ + diff --git a/src/Cake.Unity.FSharp.Tests/OSXSeekerOfEditorsTests.fs b/src/Cake.Unity.FSharp.Tests/OSXSeekerOfEditorsTests.fs new file mode 100644 index 0000000..5a79be9 --- /dev/null +++ b/src/Cake.Unity.FSharp.Tests/OSXSeekerOfEditorsTests.fs @@ -0,0 +1,28 @@ +module Cake.Unity.Tests.OSXSeekerOfEditorsTests + +open Cake.Core +open Cake.Core.IO +open NUnit.Framework +open Cake.Unity.SeekersOfEditors +open Cake.Testing +open System.Runtime.InteropServices + +let seek (seeker : OSXSeekerOfEditors) = seeker.Seek () +let runningOnWindows = RuntimeInformation.IsOSPlatform OSPlatform.Windows + +[] +let ``seek should not fail on real file system`` () = + + if runningOnWindows then + Assert.Inconclusive () + + else + let environment = FakeEnvironment PlatformFamily.OSX + let fileSystem = FileSystem () + let globber = Globber (fileSystem, environment) + let log = FakeLog () + + (environment, globber, log, fileSystem) + |> OSXSeekerOfEditors + |> seek + |> ignore diff --git a/src/Cake.Unity.sln.DotSettings b/src/Cake.Unity.sln.DotSettings new file mode 100644 index 0000000..bed39ec --- /dev/null +++ b/src/Cake.Unity.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/src/Cake.Unity/AssemblyAttributes.cs b/src/Cake.Unity/AssemblyAttributes.cs new file mode 100644 index 0000000..528a117 --- /dev/null +++ b/src/Cake.Unity/AssemblyAttributes.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Cake.Unity.FSharp.Tests")] diff --git a/src/Cake.Unity/Cake.Unity.csproj b/src/Cake.Unity/Cake.Unity.csproj index ab8680e..5573335 100644 --- a/src/Cake.Unity/Cake.Unity.csproj +++ b/src/Cake.Unity/Cake.Unity.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net46 + netstandard2.0 true true 1591;1573 diff --git a/src/Cake.Unity/SeekersOfEditors/LinuxSeekerOfEditors.cs b/src/Cake.Unity/SeekersOfEditors/LinuxSeekerOfEditors.cs new file mode 100644 index 0000000..72d6468 --- /dev/null +++ b/src/Cake.Unity/SeekersOfEditors/LinuxSeekerOfEditors.cs @@ -0,0 +1,48 @@ +using Cake.Core; +using Cake.Core.Diagnostics; +using Cake.Core.IO; +using Cake.Unity.Version; +using System.Text.RegularExpressions; + +namespace Cake.Unity.SeekersOfEditors +{ + internal class LinuxSeekerOfEditors : SeekerOfEditors + { + private readonly IFileSystem fileSystem; + private readonly Regex VersionRegex = new Regex("(?\\d+)\\.(?\\d+)\\.(?\\d+)(?\\w)(?\\d+)"); + + public LinuxSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeLog log, IFileSystem fileSystem) + : base(environment, globber, log) + { + this.fileSystem = fileSystem; + } + + protected override string[] SearchPatterns => new[] { + "/home/*/Unity/Hub/Editor/*/Editor/Unity" + }; + + protected override UnityVersion DetermineVersion(FilePath editorPath) + { + log.Debug($"Determining version of Unity Editor at path {editorPath}..."); + + var versionMatch = VersionRegex.Match(editorPath.FullPath); + + if(!versionMatch.Success) + { + log.Debug($"Can't find UnityVersion for {editorPath}"); + return null; + } + + var major = int.Parse(versionMatch.Groups["major"].Value); + var minor = int.Parse(versionMatch.Groups["minor"].Value); + var patch = int.Parse(versionMatch.Groups["patch"].Value); + var branch = char.Parse(versionMatch.Groups["branch"].Value); + var build = int.Parse(versionMatch.Groups["build"].Value); + + var unityVersion = new UnityVersion(major, minor, patch, branch, build); + + log.Debug($"Result Unity Editor version (full): {unityVersion}"); + return unityVersion; + } + } +} diff --git a/src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs b/src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs index d2be108..8adfbcc 100644 --- a/src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs +++ b/src/Cake.Unity/SeekersOfEditors/OSXSeekerOfEditors.cs @@ -1,13 +1,11 @@ using System.IO; using System.Linq; -using System.Runtime.CompilerServices; using System.Xml.Linq; using Cake.Core; using Cake.Core.Diagnostics; using Cake.Core.IO; using Cake.Unity.Version; -[assembly: InternalsVisibleTo("Cake.Unity.FSharp.Tests")] namespace Cake.Unity.SeekersOfEditors { internal class OSXSeekerOfEditors : SeekerOfEditors @@ -20,7 +18,7 @@ public OSXSeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeL this.fileSystem = fileSystem; } - protected override string[] SearchPatterns => new[] {"/Applications/**/Unity*.app/Contents/MacOS/Unity"}; + protected override string[] SearchPatterns => new[] {"/Applications/Unity/Hub/Editor/*/Unity.app/Contents/MacOS/Unity"}; protected override UnityVersion DetermineVersion(FilePath editorPath) { diff --git a/src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs b/src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs index 944847e..0871197 100644 --- a/src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs +++ b/src/Cake.Unity/SeekersOfEditors/SeekerOfEditors.cs @@ -22,7 +22,10 @@ public static SeekerOfEditors GetSeeker(ICakeEnvironment environment, IGlobber g if (environment.Platform.Family == PlatformFamily.OSX) return new OSXSeekerOfEditors(environment, globber, log, fileSystem); - throw new NotSupportedException("Cannot locate Unity Editors. Only Windows and OSX platform is supported."); + if (environment.Platform.Family == PlatformFamily.Linux) + return new LinuxSeekerOfEditors(environment, globber, log, fileSystem); + + throw new NotSupportedException("Cannot locate Unity Editors. Only Windows, OSX and Linux is supported."); } protected SeekerOfEditors(ICakeEnvironment environment, IGlobber globber, ICakeLog log)