Browse Source

Extract platform detection logic into its own file.

pull/499/head
triton 10 years ago
parent
commit
27e537c59b
  1. 45
      src/CppParser/Bindings/ParserGen.cs
  2. 2
      src/CppParser/Bindings/premake4.lua
  3. 24
      src/Generator.Tests/GeneratorTest.cs

45
src/CppParser/Bindings/ParserGen.cs

@ -2,7 +2,6 @@ @@ -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 @@ -111,7 +110,7 @@ namespace CppSharp
options.MicrosoftMode = false;
options.NoBuiltinIncludes = true;
if (IsMacOS)
if (Platform.IsMacOS)
{
var headersPaths = new List<string> {
Path.Combine(GetSourceDirectory("deps"), "llvm/tools/clang/lib/Headers"),
@ -151,47 +150,9 @@ namespace CppSharp @@ -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 @@ -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",

2
src/CppParser/Bindings/premake4.lua

@ -6,7 +6,7 @@ project "CppSharp.Parser.Gen" @@ -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()

24
src/Generator.Tests/GeneratorTest.cs

@ -50,7 +50,7 @@ namespace CppSharp.Utils @@ -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 @@ -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
}

Loading…
Cancel
Save