From 27e537c59b3f256c82449edded08a84ab33f4ee3 Mon Sep 17 00:00:00 2001 From: triton Date: Thu, 25 Jun 2015 15:36:51 +0100 Subject: [PATCH] Extract platform detection logic into its own file. --- src/CppParser/Bindings/ParserGen.cs | 45 ++-------------------------- src/CppParser/Bindings/premake4.lua | 2 +- src/Generator.Tests/GeneratorTest.cs | 24 +-------------- 3 files changed, 5 insertions(+), 66 deletions(-) diff --git a/src/CppParser/Bindings/ParserGen.cs b/src/CppParser/Bindings/ParserGen.cs index dfd390c0..9c337a4a 100644 --- a/src/CppParser/Bindings/ParserGen.cs +++ b/src/CppParser/Bindings/ParserGen.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using CppSharp.AST; using CppSharp.Generators; using CppSharp.Passes; @@ -111,7 +110,7 @@ namespace CppSharp options.MicrosoftMode = false; options.NoBuiltinIncludes = true; - if (IsMacOS) + if (Platform.IsMacOS) { var headersPaths = new List { Path.Combine(GetSourceDirectory("deps"), "llvm/tools/clang/lib/Headers"), @@ -151,47 +150,9 @@ namespace CppSharp { } - public static bool IsWindows - { - get { - switch (Environment.OSVersion.Platform) - { - case PlatformID.Win32NT: - case PlatformID.Win32S: - case PlatformID.Win32Windows: - case PlatformID.WinCE: - return true; - } - - return false; - } - } - - [DllImport ("libc")] - static extern int uname (IntPtr buf); - - public static bool IsMacOS { - get { - if (Environment.OSVersion.Platform != PlatformID.Unix) - return false; - - IntPtr buf = Marshal.AllocHGlobal (8192); - if (uname (buf) == 0) { - string os = Marshal.PtrToStringAnsi (buf); - switch (os) { - case "Darwin": - return true; - } - } - Marshal.FreeHGlobal (buf); - - return false; - } - } - public static void Main(string[] args) { - if (IsWindows) + if (Platform.IsWindows) { Console.WriteLine("Generating the C++/CLI parser bindings for Windows..."); ConsoleDriver.Run(new ParserGen(GeneratorKind.CLI, "i686-pc-win32-msvc", @@ -205,7 +166,7 @@ namespace CppSharp } var osxHeadersPath = Path.Combine(GetSourceDirectory("build"), @"headers\osx"); - if (Directory.Exists(osxHeadersPath) || IsMacOS) + if (Directory.Exists(osxHeadersPath) || Platform.IsMacOS) { Console.WriteLine("Generating the C# parser bindings for OSX..."); ConsoleDriver.Run(new ParserGen(GeneratorKind.CSharp, "i686-apple-darwin12.4.0", diff --git a/src/CppParser/Bindings/premake4.lua b/src/CppParser/Bindings/premake4.lua index 971a490a..56286623 100644 --- a/src/CppParser/Bindings/premake4.lua +++ b/src/CppParser/Bindings/premake4.lua @@ -6,7 +6,7 @@ project "CppSharp.Parser.Gen" debugdir "." files { "ParserGen.cs", "*.lua" } - links { "CppSharp.AST", "CppSharp.Generator", "System.Core" } + links { "CppSharp", "CppSharp.AST", "CppSharp.Generator", "System.Core" } SetupParser() diff --git a/src/Generator.Tests/GeneratorTest.cs b/src/Generator.Tests/GeneratorTest.cs index 544aeca9..2e81cb84 100644 --- a/src/Generator.Tests/GeneratorTest.cs +++ b/src/Generator.Tests/GeneratorTest.cs @@ -50,7 +50,7 @@ namespace CppSharp.Utils Path.GetFullPath(Path.Combine(path, "../../deps/llvm/tools/clang/lib/Headers")) }; - if (IsMacOS) { + if (Platform.IsMacOS) { options.SetupXcode(); } @@ -110,28 +110,6 @@ namespace CppSharp.Utils throw new Exception("Could not find tests output directory"); } - - [DllImport ("libc")] - static extern int uname (IntPtr buf); - - public static bool IsMacOS { - get { - if (Environment.OSVersion.Platform != PlatformID.Unix) - return false; - - IntPtr buf = Marshal.AllocHGlobal (8192); - if (uname (buf) == 0) { - string os = Marshal.PtrToStringAnsi (buf); - switch (os) { - case "Darwin": - return true; - } - } - Marshal.FreeHGlobal (buf); - - return false; - } - } #endregion }