@@ -8,8 +8,10 @@ mod checksum;
88mod download;
99mod extract;
1010
11- use std:: path:: PathBuf ;
11+ use std:: fs:: DirEntry ;
12+ use std:: path:: { Path , PathBuf } ;
1213
14+ use crate :: installation:: qt_minimal:: artifact:: ParsedQtArtifact ;
1315use crate :: { QtBuildError , QtInstallation } ;
1416
1517/// A implementation of [QtInstallation] using qtminimal
@@ -84,7 +86,7 @@ impl TryFrom<semver::Version> for QtInstallationQtMinimal {
8486 let os = target_parts
8587 . get ( 2 )
8688 . expect ( "TARGET to have a <sys> component" ) ;
87- let artifacts: Vec < artifact :: ParsedQtArtifact > = manifest
89+ let artifacts: Vec < ParsedQtArtifact > = manifest
8890 . artifacts
8991 . into_iter ( )
9092 . filter ( |artifact| {
@@ -185,4 +187,74 @@ impl QtInstallationQtMinimal {
185187
186188 path
187189 }
190+
191+ /// Get a collection of the locally installed Qt artifacts
192+ fn local_artifacts ( ) -> anyhow:: Result < Vec < ParsedQtArtifact > > {
193+ let base_dir = Self :: qt_minimal_root ( ) ;
194+
195+ // Expects folder structure like:
196+ // version/os/arch/qt/{bin, include}
197+ // e.g. will find an artifact at 6.10.0/linux/x86_64/qt/bin
198+ let mut artifacts = vec ! [ ] ;
199+
200+ // Iterate versions
201+ for version in list_dirs ( & base_dir) {
202+ let path = version;
203+ // TODO: Later skip unknown folders,
204+ // this will error if a directory exists which isn't a version number
205+ let semver = semver:: Version :: parse ( path. file_name ( ) . to_str ( ) . unwrap ( ) )
206+ . expect ( "Could not parse semver from directory name" ) ;
207+
208+ for os in list_dirs ( & path. path ( ) ) {
209+ let path = os;
210+ let os = path. file_name ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
211+
212+ for arch in list_dirs ( & path. path ( ) ) {
213+ let path = arch;
214+ let dir_entries = list_dirs ( & path. path ( ) ) ;
215+
216+ // Expects one qt dir
217+ let qt_dir_path = dir_entries
218+ . iter ( )
219+ . filter ( |dir| dir. file_name ( ) == "qt" )
220+ . last ( )
221+ . expect ( "Expected to find a Qt dir in this folder" ) ;
222+
223+ let qt_folders = list_dirs ( & qt_dir_path. path ( ) ) ;
224+ for dir in qt_folders {
225+ let filename = dir. file_name ( ) ;
226+ // Will be set if bin or include dirs are found
227+ let mut artifact_type = None ;
228+
229+ if filename == "bin" {
230+ artifact_type = Some ( "bin" ) ;
231+ } else if filename == "include" {
232+ artifact_type = Some ( "include" ) ;
233+ }
234+
235+ if let Some ( artifact_type) = artifact_type {
236+ artifacts. push ( ParsedQtArtifact :: new (
237+ semver. clone ( ) ,
238+ path. file_name ( ) . to_string_lossy ( ) . to_string ( ) ,
239+ os. clone ( ) ,
240+ qt_dir_path. path ( ) . to_string_lossy ( ) . to_string ( ) ,
241+ artifact_type. to_string ( ) ,
242+ ) )
243+ }
244+ }
245+ }
246+ }
247+ }
248+
249+ Ok ( artifacts)
250+ }
251+ }
252+
253+ /// Get all valid directories in path bufs, ignoring errors
254+ fn list_dirs ( path : & PathBuf ) -> Vec < DirEntry > {
255+ path. read_dir ( )
256+ . unwrap ( )
257+ . filter ( |d| d. is_ok ( ) )
258+ . map ( |d| d. unwrap ( ) )
259+ . collect ( )
188260}
0 commit comments