From c49a2d6cd24d1f993b17d6caaacce87492d0b667 Mon Sep 17 00:00:00 2001 From: grbd Date: Wed, 21 Mar 2018 00:42:32 +0000 Subject: [PATCH 1/6] moved some code into QtInfo, and added a line to .gitignore --- .gitignore | 3 + QtSharp.CLI/Program.cs | 147 +-------------------------------------- QtSharp/QtInfo.cs | 154 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 158 insertions(+), 146 deletions(-) diff --git a/.gitignore b/.gitignore index 3eb5a821..2515b681 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ $tf*/ #Nuget downloaded files packages/ deps/ + +# Visual Studio 2017 Solution files +.vs/ diff --git a/QtSharp.CLI/Program.cs b/QtSharp.CLI/Program.cs index d183a2dc..74cc42b6 100644 --- a/QtSharp.CLI/Program.cs +++ b/QtSharp.CLI/Program.cs @@ -1,19 +1,15 @@ using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; -using System.Reflection; -using System.Text.RegularExpressions; using CppSharp; -using CppSharp.Utils; namespace QtSharp.CLI { public class Program { - static int ParseArgs(string[] args, out string qmake, out string make, out bool debug) + private static int ParseArgs(string[] args, out string qmake, out string make, out bool debug) { qmake = null; make = null; @@ -44,117 +40,10 @@ static int ParseArgs(string[] args, out string qmake, out string make, out bool return 0; } - static List FindQt() - { - var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal); - var qts = new List(); - - var qtPath = Path.Combine(home, "Qt"); - if (!Directory.Exists(qtPath)) - { - return new List(); - } - - foreach (var path in Directory.EnumerateDirectories(qtPath)) - { - var dir = Path.GetFileName(path); - bool isNumber = dir.All(c => char.IsDigit(c) || c == '.'); - if (!isNumber) - continue; - var qt = new QtInfo { Path = path }; - var match = Regex.Match(dir, @"([0-9]+)\.([0-9]+)"); - if (!match.Success) - continue; - qt.MajorVersion = int.Parse(match.Groups[1].Value); - qt.MinorVersion = int.Parse(match.Groups[2].Value); - qts.Add(qt); - } - - return qts; - } - - static bool QueryQt(QtInfo qt, bool debug) - { - // check for OS X - if (string.IsNullOrWhiteSpace(qt.QMake)) - { - qt.QMake = Path.Combine(qt.Path, "clang_64/bin/qmake"); - } - if (string.IsNullOrWhiteSpace(qt.Make)) - { - qt.Make = "/usr/bin/make"; - } - - string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine); - path = Path.GetDirectoryName(qt.Make) + Path.PathSeparator + path; - Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Process); - - int error; - string errorMessage; - qt.Bins = ProcessHelper.Run(qt.QMake, "-query QT_INSTALL_BINS", out error, out errorMessage); - if (!string.IsNullOrEmpty(errorMessage)) - { - Console.WriteLine(errorMessage); - return false; - } - - qt.Libs = ProcessHelper.Run(qt.QMake, "-query QT_INSTALL_LIBS", out error, out errorMessage); - if (!string.IsNullOrEmpty(errorMessage)) - { - Console.WriteLine(errorMessage); - return false; - } - - DirectoryInfo libsInfo = new DirectoryInfo(Platform.IsWindows ? qt.Bins : qt.Libs); - if (!libsInfo.Exists) - { - Console.WriteLine( - "The directory \"{0}\" that qmake returned as the lib directory of the Qt installation, does not exist.", - libsInfo.Name); - return false; - } - qt.LibFiles = GetLibFiles(libsInfo, debug); - qt.Headers = ProcessHelper.Run(qt.QMake, "-query QT_INSTALL_HEADERS", out error, out errorMessage); - if (!string.IsNullOrEmpty(errorMessage)) - { - Console.WriteLine(errorMessage); - return false; - } - DirectoryInfo headersInfo = new DirectoryInfo(qt.Headers); - if (!headersInfo.Exists) - { - Console.WriteLine( - "The directory \"{0}\" that qmake returned as the header direcory of the Qt installation, does not exist.", - headersInfo.Name); - return false; - } - qt.Docs = ProcessHelper.Run(qt.QMake, "-query QT_INSTALL_DOCS", out error, out errorMessage); - - string emptyFile = Platform.IsWindows ? "NUL" : "/dev/null"; - string output; - ProcessHelper.Run("gcc", $"-v -E -x c++ {emptyFile}", out error, out output); - qt.Target = Regex.Match(output, @"Target:\s*(?[^\r\n]+)").Groups["target"].Value; - - const string includeDirsRegex = @"#include <\.\.\.> search starts here:(?.+)End of search list"; - string allIncludes = Regex.Match(output, includeDirsRegex, RegexOptions.Singleline).Groups["includes"].Value; - var includeDirs = allIncludes.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) - .Select(s => s.Trim()).ToList(); - - const string frameworkDirectory = "(framework directory)"; - qt.SystemIncludeDirs = includeDirs.Where(s => !s.Contains(frameworkDirectory)) - .Select(Path.GetFullPath); - - if (Platform.IsMacOS) - qt.FrameworkDirs = includeDirs.Where(s => s.Contains(frameworkDirectory)) - .Select(s => s.Replace(frameworkDirectory, string.Empty).Trim()).Select(Path.GetFullPath); - - return true; - } - public static int Main(string[] args) { Stopwatch s = Stopwatch.StartNew(); - var qts = FindQt(); + var qts = QtInfo.FindQt(); bool found = qts.Count != 0; bool debug = false; QtInfo qt; @@ -178,7 +67,7 @@ public static int Main(string[] args) if (logredirect != null) logredirect.CreateLogDirectory(); - if (!QueryQt(qt, debug)) + if (!qt.Query(debug)) return 1; for (int i = qt.LibFiles.Count - 1; i >= 0; i--) @@ -224,35 +113,5 @@ public static int Main(string[] args) Console.WriteLine("Done in: " + s.Elapsed); return 0; } - - private static IList GetLibFiles(DirectoryInfo libsInfo, bool debug) - { - List modules; - - if (Platform.IsMacOS) - { - modules = libsInfo.EnumerateDirectories("*.framework").Select(dir => Path.GetFileNameWithoutExtension(dir.Name)).ToList(); - } - else - { - modules = (from file in libsInfo.EnumerateFiles() - where Regex.IsMatch(file.Name, @"^Qt\d?\w+\.\w+$") - select file.Name).ToList(); - } - - for (var i = modules.Count - 1; i >= 0; i--) - { - var module = Path.GetFileNameWithoutExtension(modules[i]); - if (debug && module != null && !module.EndsWith("d", StringComparison.Ordinal)) - { - modules.Remove(module + Path.GetExtension(modules[i])); - } - else - { - modules.Remove(module + "d" + Path.GetExtension(modules[i])); - } - } - return modules; - } } } diff --git a/QtSharp/QtInfo.cs b/QtSharp/QtInfo.cs index 265311d1..e1860e6d 100644 --- a/QtSharp/QtInfo.cs +++ b/QtSharp/QtInfo.cs @@ -1,12 +1,19 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.RegularExpressions; +using System.Linq; +using CppSharp.Utils; +using CppSharp; namespace QtSharp { + /// Information about QT. public class QtInfo { public int MajorVersion; public int MinorVersion; - public string Path; + public string QtPath; public string Target; public string Docs; public string QMake; @@ -17,5 +24,148 @@ public class QtInfo public IList LibFiles; public IEnumerable SystemIncludeDirs; public IEnumerable FrameworkDirs; + + /// Searches for QT on the system. + /// List of found QT installs. + public static List FindQt() + { + var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + var qts = new List(); + + var qtPath = Path.Combine(home, "Qt"); + if (!Directory.Exists(qtPath)) + { + return new List(); + } + + foreach (var path in Directory.EnumerateDirectories(qtPath)) + { + var dir = Path.GetFileName(path); + var isNumber = dir.All(c => char.IsDigit(c) || c == '.'); + if (!isNumber) + continue; + var qt = new QtInfo { QtPath = path }; + var match = Regex.Match(dir, @"([0-9]+)\.([0-9]+)"); + if (!match.Success) + continue; + qt.MajorVersion = int.Parse(match.Groups[1].Value); + qt.MinorVersion = int.Parse(match.Groups[2].Value); + qts.Add(qt); + } + + return qts; + } + + /// Queries information about a given QT install + /// True to debug. + /// True if it succeeds, false if it fails. + public bool Query(bool debug) + { + // check for OS X + if (string.IsNullOrWhiteSpace(QMake)) + { + QMake = Path.Combine(QtPath, "clang_64/bin/qmake"); + } + if (string.IsNullOrWhiteSpace(Make)) + { + Make = "/usr/bin/make"; + } + + string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine); + path = Path.GetDirectoryName(Make) + Path.PathSeparator + path; + Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Process); + + Bins = ProcessHelper.Run(QMake, "-query QT_INSTALL_BINS", out var error, out var errorMessage); + if (!string.IsNullOrEmpty(errorMessage)) + { + Console.WriteLine(errorMessage); + return false; + } + + Libs = ProcessHelper.Run(QMake, "-query QT_INSTALL_LIBS", out error, out errorMessage); + if (!string.IsNullOrEmpty(errorMessage)) + { + Console.WriteLine(errorMessage); + return false; + } + + DirectoryInfo libsInfo = new DirectoryInfo(Platform.IsWindows ? Bins : Libs); + if (!libsInfo.Exists) + { + Console.WriteLine( + "The directory \"{0}\" that qmake returned as the lib directory of the Qt installation, does not exist.", + libsInfo.Name); + return false; + } + LibFiles = GetLibFiles(libsInfo, debug); + Headers = ProcessHelper.Run(QMake, "-query QT_INSTALL_HEADERS", out error, out errorMessage); + if (!string.IsNullOrEmpty(errorMessage)) + { + Console.WriteLine(errorMessage); + return false; + } + DirectoryInfo headersInfo = new DirectoryInfo(Headers); + if (!headersInfo.Exists) + { + Console.WriteLine( + "The directory \"{0}\" that qmake returned as the header direcory of the Qt installation, does not exist.", + headersInfo.Name); + return false; + } + Docs = ProcessHelper.Run(QMake, "-query QT_INSTALL_DOCS", out error, out errorMessage); + + string emptyFile = Platform.IsWindows ? "NUL" : "/dev/null"; + ProcessHelper.Run("gcc", $"-v -E -x c++ {emptyFile}", out error, out var output); + Target = Regex.Match(output, @"Target:\s*(?[^\r\n]+)").Groups["target"].Value; + + const string includeDirsRegex = @"#include <\.\.\.> search starts here:(?.+)End of search list"; + string allIncludes = Regex.Match(output, includeDirsRegex, RegexOptions.Singleline).Groups["includes"].Value; + var includeDirs = allIncludes.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) + .Select(s => s.Trim()).ToList(); + + const string frameworkDirectory = "(framework directory)"; + SystemIncludeDirs = includeDirs.Where(s => !s.Contains(frameworkDirectory)) + .Select(Path.GetFullPath); + + if (Platform.IsMacOS) + FrameworkDirs = includeDirs.Where(s => s.Contains(frameworkDirectory)) + .Select(s => s.Replace(frameworkDirectory, string.Empty).Trim()).Select(Path.GetFullPath); + + return true; + } + + /// Gets library files. + /// Information describing the library directory. + /// True to debug. + /// List of the library files. + private static IList GetLibFiles(DirectoryInfo libsInfo, bool debug) + { + List modules; + + if (Platform.IsMacOS) + { + modules = libsInfo.EnumerateDirectories("*.framework").Select(dir => Path.GetFileNameWithoutExtension(dir.Name)).ToList(); + } + else + { + modules = (from file in libsInfo.EnumerateFiles() + where Regex.IsMatch(file.Name, @"^Qt\d?\w+\.\w+$") + select file.Name).ToList(); + } + + for (var i = modules.Count - 1; i >= 0; i--) + { + var module = Path.GetFileNameWithoutExtension(modules[i]); + if (debug && module != null && !module.EndsWith("d", StringComparison.Ordinal)) + { + modules.Remove(module + Path.GetExtension(modules[i])); + } + else + { + modules.Remove(module + "d" + Path.GetExtension(modules[i])); + } + } + return modules; + } } } From a537cb00a7d347e996794deca281f2f5394a4af1 Mon Sep 17 00:00:00 2001 From: grbd Date: Thu, 22 Mar 2018 01:22:13 +0000 Subject: [PATCH 2/6] Updated some of the referenced nuget packages --- QtSharp.CLI/QtSharp.CLI.csproj | 24 ++++++++++-------------- QtSharp.CLI/packages.config | 4 ++-- QtSharp/QtSharp.csproj | 28 ++++++++++++---------------- QtSharp/packages.config | 6 +++--- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/QtSharp.CLI/QtSharp.CLI.csproj b/QtSharp.CLI/QtSharp.CLI.csproj index a8ddd595..ae4e2939 100644 --- a/QtSharp.CLI/QtSharp.CLI.csproj +++ b/QtSharp.CLI/QtSharp.CLI.csproj @@ -80,21 +80,17 @@ ..\packages\CppSharp.0.8.14\lib\CppSharp.Runtime.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll - True + + ..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll - True + + ..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Mdb.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll - True + + ..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Pdb.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll - True + + ..\packages\Mono.Cecil.0.10.0\lib\net40\Mono.Cecil.Rocks.dll @@ -121,12 +117,12 @@ - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - +