55using System . Linq ;
66using System . Text . RegularExpressions ;
77using CppSharp ;
8- using CppSharp . Parser ;
9- using ClangParser = CppSharp . Parser . ClangParser ;
108
119namespace QtSharp . CLI
1210{
@@ -43,32 +41,15 @@ static int ParseArgs(string[] args, out string qmake, out string make, out bool
4341 return 0 ;
4442 }
4543
46- class QtVersion
47- {
48- public int MajorVersion ;
49- public int MinorVersion ;
50- public string Path ;
51- public string Target ;
52- public string Docs ;
53- public string QMake ;
54- public string Make ;
55- public string Bins ;
56- public string Libs ;
57- public string Headers ;
58- public IEnumerable < string > LibFiles ;
59- public IEnumerable < string > SystemIncludeDirs ;
60- public IEnumerable < string > FrameworkDirs ;
61- }
62-
63- static List < QtVersion > FindQt ( )
44+ static List < QtInfo > FindQt ( )
6445 {
6546 var home = Environment . GetFolderPath ( Environment . SpecialFolder . Personal ) ;
66- var qts = new List < QtVersion > ( ) ;
47+ var qts = new List < QtInfo > ( ) ;
6748
6849 var qtPath = Path . Combine ( home , "Qt" ) ;
6950 if ( ! Directory . Exists ( qtPath ) )
7051 {
71- return new List < QtVersion > ( ) ;
52+ return new List < QtInfo > ( ) ;
7253 }
7354
7455 foreach ( var path in Directory . EnumerateDirectories ( qtPath ) )
@@ -77,7 +58,7 @@ static List<QtVersion> FindQt()
7758 bool isNumber = dir . All ( c => char . IsDigit ( c ) || c == '.' ) ;
7859 if ( ! isNumber )
7960 continue ;
80- var qt = new QtVersion { Path = path } ;
61+ var qt = new QtInfo { Path = path } ;
8162 var match = Regex . Match ( dir , @"([0-9]+)\.([0-9]+)" ) ;
8263 if ( ! match . Success )
8364 continue ;
@@ -89,7 +70,7 @@ static List<QtVersion> FindQt()
8970 return qts ;
9071 }
9172
92- static bool QueryQt ( QtVersion qt , bool debug )
73+ static bool QueryQt ( QtInfo qt , bool debug )
9374 {
9475 // check for OS X
9576 if ( string . IsNullOrWhiteSpace ( qt . QMake ) )
@@ -167,37 +148,6 @@ static bool QueryQt(QtVersion qt, bool debug)
167148 return true ;
168149 }
169150
170- static Dictionary < string , IList < string > > GetDependencies ( QtVersion qt )
171- {
172- var dependencies = new Dictionary < string , IList < string > > ( ) ;
173-
174- var parserOptions = new ParserOptions ( ) ;
175- parserOptions . addLibraryDirs ( Platform . IsWindows ? qt . Bins : qt . Libs ) ;
176- if ( Platform . IsMacOS )
177- {
178- var libsInfo = new DirectoryInfo ( qt . Libs ) ;
179- foreach ( var frameworkDir in libsInfo . EnumerateDirectories ( "*.framework" ) . Select ( d => d . FullName ) )
180- parserOptions . addLibraryDirs ( Path . Combine ( frameworkDir ) ) ;
181- }
182-
183- foreach ( var libFile in qt . LibFiles )
184- {
185- dependencies [ libFile ] = Enumerable . Empty < string > ( ) . ToList ( ) ;
186-
187- parserOptions . FileName = libFile ;
188- using ( var parserResult = ClangParser . ParseLibrary ( parserOptions ) )
189- {
190- if ( parserResult . Kind == ParserResultKind . Success )
191- {
192- dependencies [ libFile ] = CppSharp . ClangParser . ConvertLibrary ( parserResult . Library ) . Dependencies ;
193- parserResult . Library . Dispose ( ) ;
194- }
195- }
196- }
197-
198- return dependencies ;
199- }
200-
201151 static void ProcessGeneratedInlines ( )
202152 {
203153 if ( ! Platform . IsWindows )
@@ -221,11 +171,11 @@ public static int Main(string[] args)
221171 var qts = FindQt ( ) ;
222172 bool found = qts . Count != 0 ;
223173 bool debug = false ;
224- QtVersion qt ;
174+ QtInfo qt ;
225175
226176 if ( ! found )
227177 {
228- qt = new QtVersion ( ) ;
178+ qt = new QtInfo ( ) ;
229179
230180 var result = ParseArgs ( args , out qt . QMake , out qt . Make , out debug ) ;
231181 if ( result != 0 )
@@ -245,27 +195,25 @@ public static int Main(string[] args)
245195 if ( ! QueryQt ( qt , debug ) )
246196 return 1 ;
247197
248- var dependencies = GetDependencies ( qt ) ;
249-
250198 var modules = new List < string >
251199 {
252- "Qt5Core " ,
253- "Qt5Gui " ,
254- "Qt5Widgets " ,
255- "Qt5Xml " ,
256- "Qt5Designer " ,
257- "Qt5Network " ,
258- "Qt5Qml " ,
259- "Qt5Nfc " ,
260- "Qt5OpenGL " ,
261- "Qt5ScriptTools " ,
262- "Qt5Sensors " ,
263- "Qt5SerialPort " ,
264- "Qt5Svg " ,
265- "Qt5Multimedia " ,
266- "Qt5MultimediaWidgets " ,
267- "Qt5Quick " ,
268- "Qt5QuickWidgets "
200+ "QtCore " ,
201+ "QtGui " ,
202+ "QtWidgets " ,
203+ "QtXml " ,
204+ "QtDesigner " ,
205+ "QtNetwork " ,
206+ "QtQml " ,
207+ "QtNfc " ,
208+ "QtOpenGL " ,
209+ "QtScriptTools " ,
210+ "QtSensors " ,
211+ "QtSerialPort " ,
212+ "QtSvg " ,
213+ "QtMultimedia " ,
214+ "QtMultimediaWidgets " ,
215+ "QtQuick " ,
216+ "QtQuickWidgets "
269217 } ;
270218 if ( debug )
271219 {
@@ -274,33 +222,16 @@ public static int Main(string[] args)
274222 modules [ i ] += "d" ;
275223 }
276224 }
277- qt . LibFiles = qt . LibFiles . ToList ( ) . TopologicalSort ( l => dependencies . ContainsKey ( l ) ? dependencies [ l ] : Enumerable . Empty < string > ( ) ) ;
278- var wrappedModules = new List < KeyValuePair < string , string > > ( modules . Count ) ;
279- foreach ( var libFile in qt . LibFiles )
225+ for ( int i = qt . LibFiles . Count - 1 ; i >= 0 ; i -- )
280226 {
281- string lib = Path . GetFileNameWithoutExtension ( libFile ) ;
282- if ( ! Platform . IsWindows )
283- lib = lib . Replace ( "Qt" , "Qt5" ) ;
284-
285- if ( modules . All ( m => m != Path . GetFileNameWithoutExtension ( lib ) ) )
286- continue ;
287-
288- if ( log )
227+ if ( ! modules . Contains ( QtSharp . GetModuleNameFromLibFile ( qt . LibFiles [ i ] ) ) )
289228 {
290- logredirect . SetLogFile ( lib + "Log.txt" ) ;
291- logredirect . Start ( ) ;
229+ qt . LibFiles . RemoveAt ( i ) ;
292230 }
293-
294- var qtSharp = new QtSharp ( new QtModuleInfo ( qt . QMake , qt . Make , qt . Headers , Platform . IsWindows ? qt . Bins : qt . Libs ,
295- libFile , qt . Target , qt . SystemIncludeDirs , qt . FrameworkDirs , qt . Docs ) ) ;
296- ConsoleDriver . Run ( qtSharp ) ;
297-
298- if ( File . Exists ( qtSharp . LibraryName ) && File . Exists ( qtSharp . InlinesLibraryPath ) )
299- wrappedModules . Add ( new KeyValuePair < string , string > ( qtSharp . LibraryName , qtSharp . InlinesLibraryPath ) ) ;
300-
301- if ( log )
302- logredirect . Stop ( ) ;
303231 }
232+ var qtSharp = new QtSharp ( qt ) ;
233+ ConsoleDriver . Run ( qtSharp ) ;
234+ var wrappedModules = qtSharp . GetVerifiedWrappedModules ( ) ;
304235
305236 ProcessGeneratedInlines ( ) ;
306237
0 commit comments