Skip to content

Commit b47df04

Browse files
committed
Read symbols from inlines on OS X and removed the redundancies of QString.
1 parent b18a755 commit b47df04

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

QtSharp.CLI/Program.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class QtVersion
6363

6464
static List<QtVersion> FindQt()
6565
{
66-
var home = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
66+
var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
6767
var qts = new List<QtVersion>();
6868

6969
var qtPath = Path.Combine(home, "Qt");
@@ -154,7 +154,7 @@ static bool QueryQt(QtVersion qt, bool debug)
154154
const string includeDirsRegex = @"#include <\.\.\.> search starts here:(?<includes>.+)End of search list";
155155
string allIncludes = Regex.Match(output, includeDirsRegex, RegexOptions.Singleline).Groups["includes"].Value;
156156
var includeDirs = allIncludes.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
157-
.Select(s => s.Trim());
157+
.Select(s => s.Trim()).ToList();
158158

159159
const string frameworkDirectory = "(framework directory)";
160160

@@ -187,7 +187,7 @@ static IEnumerable<string> ParseDependenciesFromLibtool(string libFile)
187187

188188
var matches = Regex.Matches(libs.Groups[1].Value, @"-framework\s+(\w+)");
189189
var frameworks = matches.OfType<Match>().Select(m => m.Groups[1].Value)
190-
.Where(s => s.StartsWith("Qt"));
190+
.Where(s => s.StartsWith("Qt", StringComparison.Ordinal));
191191

192192
if (Platform.IsMacOS)
193193
frameworks = frameworks.Select(framework => framework + ".framework");
@@ -315,7 +315,7 @@ public static int Main(string[] args)
315315
if (!Platform.IsWindows)
316316
lib = lib.Replace("Qt", "Qt5");
317317

318-
if (!modules.Any(m => m == Path.GetFileNameWithoutExtension(lib)))
318+
if (modules.All(m => m != Path.GetFileNameWithoutExtension(lib)))
319319
continue;
320320

321321
if (log)
@@ -328,8 +328,8 @@ public static int Main(string[] args)
328328
libFile, qt.Target, qt.SystemIncludeDirs, qt.FrameworkDirs, qt.Docs));
329329
ConsoleDriver.Run(qtSharp);
330330

331-
if (File.Exists(qtSharp.LibraryName) && File.Exists(Path.Combine("release", qtSharp.InlinesLibraryName)))
332-
wrappedModules.Add(new KeyValuePair<string, string>(qtSharp.LibraryName, qtSharp.InlinesLibraryName));
331+
if (File.Exists(qtSharp.LibraryName) && File.Exists(qtSharp.InlinesLibraryPath))
332+
wrappedModules.Add(new KeyValuePair<string, string>(qtSharp.LibraryName, qtSharp.InlinesLibraryPath));
333333

334334
if (log)
335335
logredirect.Stop();
@@ -357,7 +357,7 @@ public static int Main(string[] args)
357357
zipArchive.CreateEntryFromFile(wrappedModule.Key, wrappedModule.Key);
358358
var documentation = Path.ChangeExtension(wrappedModule.Key, "xml");
359359
zipArchive.CreateEntryFromFile(documentation, documentation);
360-
zipArchive.CreateEntryFromFile(Path.Combine("release", wrappedModule.Value), wrappedModule.Value);
360+
zipArchive.CreateEntryFromFile(wrappedModule.Value, Path.GetFileName(wrappedModule.Value));
361361
}
362362
zipArchive.CreateEntryFromFile("CppSharp.Runtime.dll", "CppSharp.Runtime.dll");
363363
}

QtSharp/QtSharp.cs

+26-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public QtSharp(QtModuleInfo qtModuleInfo)
2929
}
3030

3131
public string LibraryName { get; set; }
32-
public string InlinesLibraryName { get; set; }
32+
public string InlinesLibraryPath { get; set; }
3333

3434
public void Preprocess(Driver driver, ASTContext lib)
3535
{
@@ -74,6 +74,18 @@ public void Preprocess(Driver driver, ASTContext lib)
7474
string[] classesWithTypeEnums = { };
7575
switch (this.module)
7676
{
77+
case "Core":
78+
// QString is type-mapped to string so we only need two methods for the conversion
79+
var qString = lib.FindCompleteClass("QString");
80+
foreach (var @class in qString.Declarations)
81+
{
82+
@class.ExplicitlyIgnore();
83+
}
84+
foreach (var method in qString.Methods.Where(m => m.OriginalName != "utf16" && m.OriginalName != "fromUtf16"))
85+
{
86+
method.ExplicitlyIgnore();
87+
}
88+
break;
7789
case "Widgets":
7890
classesWithTypeEnums = new[]
7991
{
@@ -160,6 +172,14 @@ public void Postprocess(Driver driver, ASTContext lib)
160172
.FirstOrDefault(o => o.Parameters[0].Type.IsPrimitiveType(PrimitiveType.Int));
161173
if (op != null)
162174
op.ExplicitlyIgnore();
175+
// QString is type-mapped to string so we only need two methods for the conversion
176+
// go through the methods a second time to ignore free operators moved to the class
177+
var qString = lib.FindCompleteClass("QString");
178+
foreach (var method in qString.Methods.Where(
179+
m => !m.Ignore && m.OriginalName != "utf16" && m.OriginalName != "fromUtf16"))
180+
{
181+
method.ExplicitlyIgnore();
182+
}
163183
break;
164184
}
165185
}
@@ -227,9 +247,11 @@ public void Setup(Driver driver)
227247
driver.Options.CodeFiles.Add(Path.Combine(dir, "IQQmlParserStatus.cs"));
228248
break;
229249
}
230-
var extension = Path.GetExtension(this.library);
231-
this.LibraryName = driver.Options.LibraryName + extension;
232-
this.InlinesLibraryName = driver.Options.InlinesLibraryName + extension;
250+
this.LibraryName = driver.Options.LibraryName + ".dll";
251+
var prefix = Platform.IsWindows ? string.Empty : "lib";
252+
var extension = Platform.IsWindows ? ".dll" : Platform.IsMacOS ? ".dylib" : ".so";
253+
var inlinesLibraryFile = string.Format("{0}{1}{2}", prefix, driver.Options.InlinesLibraryName, extension);
254+
this.InlinesLibraryPath = Path.Combine(driver.Options.OutputDir, Platform.IsWindows ? "release" : string.Empty, inlinesLibraryFile);
233255
}
234256

235257
public void SetupPasses(Driver driver)

0 commit comments

Comments
 (0)