public static int Main(string[] args) { Stopwatch s = Stopwatch.StartNew(); var qts = FindQt(); bool found = qts.Count != 0; bool debug = false; QtInfo qt; if (!found) { qt = new QtInfo(); var result = ParseArgs(args, out qt.QMake, out qt.Make, out debug); if (result != 0) { return(result); } } else { // TODO: Only for OSX for now, generalize for all platforms. qt = qts.Last(); } bool log = false; ConsoleLogger logredirect = log ? new ConsoleLogger() : null; if (logredirect != null) { logredirect.CreateLogDirectory(); } if (!QueryQt(qt, debug)) { return(1); } for (int i = qt.LibFiles.Count - 1; i >= 0; i--) { var libFile = qt.LibFiles[i]; var libFileName = Path.GetFileNameWithoutExtension(libFile); if (Path.GetExtension(libFile) == ".exe" || // QtDeclarative is obsolete and at the same time its headers cause conflicts with its successor of QtQuick libFileName == "QtDeclarative" || libFileName == "Qt5Declarative" || // QtQuickTest is a QML module but has 3 main C++ functions and is not auto-ignored libFileName == "QtQuickTest" || libFileName == "Qt5QuickTest") { qt.LibFiles.RemoveAt(i); } } var qtSharp = new QtSharp(qt); ConsoleDriver.Run(qtSharp); var wrappedModules = qtSharp.GetVerifiedWrappedModules(); ProcessGeneratedInlines(); if (wrappedModules.Count == 0) { Console.WriteLine("Generation failed."); return(1); } const string qtSharpZip = "QtSharp.zip"; if (File.Exists(qtSharpZip)) { File.Delete(qtSharpZip); } using (var zip = File.Create(qtSharpZip)) { using (var zipArchive = new ZipArchive(zip, ZipArchiveMode.Create)) { foreach (var wrappedModule in wrappedModules) { zipArchive.CreateEntryFromFile(wrappedModule.Key, wrappedModule.Key); var documentation = Path.ChangeExtension(wrappedModule.Key, "xml"); zipArchive.CreateEntryFromFile(documentation, documentation); zipArchive.CreateEntryFromFile(wrappedModule.Value, Path.GetFileName(wrappedModule.Value)); } zipArchive.CreateEntryFromFile("CppSharp.Runtime.dll", "CppSharp.Runtime.dll"); } } Console.WriteLine("Done in: " + s.Elapsed); return(0); }
public static int Main(string[] args) { Stopwatch s = Stopwatch.StartNew(); var qts = FindQt(); bool found = qts.Count != 0; bool debug = false; QtInfo qt; if (!found) { qt = new QtInfo(); var result = ParseArgs(args, out qt.QMake, out qt.Make, out debug); if (result != 0) return result; } else { // TODO: Only for OSX for now, generalize for all platforms. qt = qts.Last(); } bool log = false; ConsoleLogger logredirect = log ? new ConsoleLogger() : null; if (logredirect != null) logredirect.CreateLogDirectory(); if (!QueryQt(qt, debug)) return 1; for (int i = qt.LibFiles.Count - 1; i >= 0; i--) { var libFile = qt.LibFiles[i]; var libFileName = Path.GetFileNameWithoutExtension(libFile); if (Path.GetExtension(libFile) == ".exe" || // QtDeclarative is obsolete and at the same time its headers cause conflicts with its successor of QtQuick libFileName == "QtDeclarative" || libFileName == "Qt5Declarative" || // QtQuickTest is a QML module but has 3 main C++ functions and is not auto-ignored libFileName == "QtQuickTest" || libFileName == "Qt5QuickTest") { qt.LibFiles.RemoveAt(i); } } var qtSharp = new QtSharp(qt); ConsoleDriver.Run(qtSharp); var wrappedModules = qtSharp.GetVerifiedWrappedModules(); ProcessGeneratedInlines(); if (wrappedModules.Count == 0) { Console.WriteLine("Generation failed."); return 1; } const string qtSharpZip = "QtSharp.zip"; if (File.Exists(qtSharpZip)) { File.Delete(qtSharpZip); } using (var zip = File.Create(qtSharpZip)) { using (var zipArchive = new ZipArchive(zip, ZipArchiveMode.Create)) { foreach (var wrappedModule in wrappedModules) { zipArchive.CreateEntryFromFile(wrappedModule.Key, wrappedModule.Key); var documentation = Path.ChangeExtension(wrappedModule.Key, "xml"); zipArchive.CreateEntryFromFile(documentation, documentation); zipArchive.CreateEntryFromFile(wrappedModule.Value, Path.GetFileName(wrappedModule.Value)); } zipArchive.CreateEntryFromFile("CppSharp.Runtime.dll", "CppSharp.Runtime.dll"); } } Console.WriteLine("Done in: " + s.Elapsed); return 0; }
public static int Main(string[] args) { if (args.Length < 2) { Console.WriteLine("Please enter the paths to qmake and make."); return 0; } string qmake = args[0]; if (!File.Exists(qmake)) { Console.WriteLine("The specified qmake does not exist."); return 1; } string make = args[1]; if (!File.Exists(make)) { Console.WriteLine("The specified make does not exist."); return 1; } var debug = args.Length > 2 && (args[2] == "d" || args[2] == "debug"); ConsoleLogger logredirect = new ConsoleLogger(); logredirect.CreateLogDirectory(); string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine); path = Path.GetDirectoryName(make) + Path.PathSeparator + path; Environment.SetEnvironmentVariable("Path", path, EnvironmentVariableTarget.Process); string error; string libs = ProcessHelper.Run(qmake, "-query QT_INSTALL_BINS", out error); if (!string.IsNullOrEmpty(error)) { Console.WriteLine(error); return 1; } DirectoryInfo libsInfo = new DirectoryInfo(libs); if (!libsInfo.Exists) { Console.WriteLine( "The directory \"{0}\" that qmake returned as the lib direcory of the Qt installation, does not exist.", libsInfo.Name); return 1; } ICollection<string> libFiles = GetLibFiles(libsInfo, debug); string headers = ProcessHelper.Run(qmake, "-query QT_INSTALL_HEADERS", out error); if (!string.IsNullOrEmpty(error)) { Console.WriteLine(error); return 1; } 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 1; } string docs = ProcessHelper.Run(qmake, "-query QT_INSTALL_DOCS", out error); string emptyFile = Environment.OSVersion.Platform == PlatformID.Win32NT ? "NUL" : "/dev/null"; string output; ProcessHelper.Run("gcc", string.Format("-v -E -x c++ {0}", emptyFile), out output); string target = Regex.Match(output, @"Target:\s*(?<target>[^\r\n]+)").Groups["target"].Value; const string includeDirsRegex = @"#include <\.\.\.> search starts here:(?<includes>.+)End of search list"; string allIncludes = Regex.Match(output, includeDirsRegex, RegexOptions.Singleline).Groups["includes"].Value; var systemIncludeDirs = allIncludes.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Select(Path.GetFullPath); Dictionary<string, IEnumerable<string>> dependencies = new Dictionary<string, IEnumerable<string>>(); var parserOptions = new ParserOptions(); parserOptions.addLibraryDirs(libs); foreach (var libFile in libFiles) { parserOptions.FileName = libFile; var parserResult = ClangParser.ParseLibrary(parserOptions); if (parserResult.Kind == ParserResultKind.Success) { dependencies[libFile] = CppSharp.ClangParser.ConvertLibrary(parserResult.Library).Dependencies; } else { dependencies[libFile] = Enumerable.Empty<string>(); } } var modules = new List<string> { "Qt5Core", "Qt5Gui", "Qt5Widgets", "Qt5Xml", "Qt5Designer" }; if (debug) { for (var i = 0; i < modules.Count; i++) { modules[i] += "d"; } } libFiles = libFiles.TopologicalSort(l => dependencies.ContainsKey(l) ? dependencies[l] : Enumerable.Empty<string>()); var wrappedModules = new List<KeyValuePair<string, string>>(modules.Count); var astContexts = new List<ASTContext>(libFiles.Count); foreach (var libFile in libFiles.Where(l => modules.Any(m => m == Path.GetFileNameWithoutExtension(l)))) { logredirect.SetLogFile(libFile.Replace(".dll", "") + "Log.txt"); logredirect.Start(); var qtSharp = new QtSharp(new QtModuleInfo(qmake, make, headers, libs, libFile, target, systemIncludeDirs, docs), astContexts); ConsoleDriver.Run(qtSharp); astContexts.Add(qtSharp.AST); if (File.Exists(qtSharp.LibraryName) && File.Exists(Path.Combine("release", qtSharp.InlinesLibraryName))) { wrappedModules.Add(new KeyValuePair<string, string>(qtSharp.LibraryName, qtSharp.InlinesLibraryName)); } logredirect.Stop(); } #if DEBUG if (File.Exists("../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll")) { File.Delete("../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll"); } File.Copy("release/QtCore-inlines.dll", "../../../QtSharp.Tests/bin/Debug/QtCore-inlines.dll"); #else if (File.Exists("../../../QtSharp.Tests/bin/Release/QtCore-inlines.dll")) { File.Delete("../../../QtSharp.Tests/bin/Release/QtCore-inlines.dll"); } System.IO.File.Copy("release/QtCore-inlines.dll", "../../../QtSharp.Tests/bin/Release/QtCore-inlines.dll"); #endif if (wrappedModules.Count == 0) { Console.WriteLine("Generation failed."); return 1; } var qtSharpZip = "QtSharp.zip"; if (File.Exists(qtSharpZip)) { File.Delete(qtSharpZip); } using (var zip = File.Create(qtSharpZip)) { using (var zipArchive = new ZipArchive(zip, ZipArchiveMode.Create)) { foreach (var wrappedModule in wrappedModules) { zipArchive.CreateEntryFromFile(wrappedModule.Key, wrappedModule.Key); var documentation = Path.ChangeExtension(wrappedModule.Key, "xml"); zipArchive.CreateEntryFromFile(documentation, documentation); zipArchive.CreateEntryFromFile(Path.Combine("release", wrappedModule.Value), wrappedModule.Value); } zipArchive.CreateEntryFromFile("CppSharp.Runtime.dll", "CppSharp.Runtime.dll"); } } return 0; }