Skip to content

Commit 8b5c713

Browse files
Add directory walk to find qt artifacts
1 parent e010614 commit 8b5c713

File tree

7 files changed

+137
-7
lines changed

7 files changed

+137
-7
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ members = [
2727

2828
"tests/basic_cxx_only/rust",
2929
"tests/basic_cxx_qt/rust",
30-
"tests/qt_types_standalone/rust",
30+
"tests/qt_types_standalone/rust", "examples/qt_minimal",
3131
]
3232
resolver = "2"
3333

crates/qt-build-utils/src/installation/qt_minimal/artifact.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6-
use std::path::{Path, PathBuf};
7-
6+
use semver::Version;
87
use serde::{Deserialize, Serialize};
8+
use std::path::{Path, PathBuf};
9+
use std::time::Duration;
910

1011
#[derive(Debug, Serialize, Deserialize)]
1112
/// A Qt manifest.json file, which specifies a set of artifacts needed for installation
@@ -17,7 +18,7 @@ pub(crate) struct ParsedQtManifest {
1718
#[derive(Debug, Serialize, Deserialize, PartialEq)]
1819
/// Descriptor for a Qt artifact, included download information
1920
pub(crate) struct ParsedQtArtifact {
20-
pub(crate) version: semver::Version,
21+
pub(crate) version: Version,
2122
pub(crate) arch: String,
2223
pub(crate) os: String,
2324
pub(crate) url: String,
@@ -29,7 +30,10 @@ impl ParsedQtArtifact {
2930
/// Download the artifact and extract to the given target path
3031
pub fn download_and_extract(&self, target_path: &Path) -> PathBuf {
3132
// Download to a temporary location
32-
let http_client = reqwest::blocking::Client::new();
33+
let http_client = reqwest::blocking::Client::builder()
34+
.timeout(None)
35+
.build()
36+
.expect("Http client failed to build");
3337
let temp_dir = tempfile::TempDir::new().expect("Could not create temporary directory");
3438
let archive_path =
3539
super::download::download_from_url(&self.url, &self.sha256, &temp_dir, &http_client)
@@ -46,6 +50,23 @@ impl ParsedQtArtifact {
4650
target_path.to_path_buf()
4751
}
4852

53+
pub fn new(
54+
version: Version,
55+
arch: String,
56+
os: String,
57+
url: String,
58+
content_type: String,
59+
) -> Self {
60+
Self {
61+
version,
62+
arch,
63+
os,
64+
url,
65+
sha256: "".to_string(),
66+
content: vec![content_type],
67+
}
68+
}
69+
4970
/// Assert that the hashes are the same, from bytes
5071
pub fn verify(&self, hash: &[u8]) -> anyhow::Result<()> {
5172
let mut hash_string = String::new();

crates/qt-build-utils/src/installation/qt_minimal/mod.rs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ mod checksum;
88
mod download;
99
mod 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;
1315
use crate::{QtBuildError, QtInstallation};
1416

1517
/// A implementation of [QtInstallation] using qtminimal
@@ -42,7 +44,7 @@ impl TryFrom<semver::Version> for QtInstallationQtMinimal {
4244
let os = target_parts
4345
.get(2)
4446
.expect("TARGET to have a <sys> component");
45-
let artifacts: Vec<artifact::ParsedQtArtifact> = manifest
47+
let artifacts: Vec<ParsedQtArtifact> = manifest
4648
.artifacts
4749
.into_iter()
4850
.filter(|artifact| {
@@ -73,6 +75,8 @@ impl TryFrom<semver::Version> for QtInstallationQtMinimal {
7375
artifact_include.download_and_extract(&extract_target_dir);
7476
}
7577

78+
println!(">>>> Artefacts: {:?}", Self::local_artifacts());
79+
7680
Ok(Self {
7781
path_qt: extract_target_dir.join("qt"),
7882
version,
@@ -148,4 +152,69 @@ impl QtInstallationQtMinimal {
148152

149153
path
150154
}
155+
156+
/// Get a collection of the locally installed Qt artifacts
157+
fn local_artifacts() -> anyhow::Result<Vec<ParsedQtArtifact>> {
158+
let base_dir = Self::qt_minimal_root();
159+
160+
let mut artifacts = vec![];
161+
162+
// Iterate versions
163+
for version in list_dirs(&base_dir) {
164+
let path = version;
165+
let semver = semver::Version::parse(path.file_name().to_str().unwrap())
166+
.expect("Could not parse semver from directory name");
167+
168+
for os in list_dirs(&path.path()) {
169+
let path = os;
170+
let os = path.file_name().to_str().unwrap().to_string();
171+
172+
for arch in list_dirs(&path.path()) {
173+
let path = arch;
174+
let dir_entries = list_dirs(&path.path());
175+
176+
// Expects one qt dir
177+
let qt_dir_path = dir_entries
178+
.iter()
179+
.filter(|dir| dir.file_name() == "qt")
180+
.last()
181+
.expect("Expected to find a Qt dir in this folder");
182+
183+
let qt_folders = list_dirs(&qt_dir_path.path());
184+
for dir in qt_folders {
185+
let filename = dir.file_name();
186+
// Will be set if bin or include dirs are found
187+
let mut artifact_type = None;
188+
189+
if filename == "bin" {
190+
artifact_type = Some("bin");
191+
} else if filename == "include" {
192+
artifact_type = Some("include");
193+
}
194+
195+
if let Some(artifact_type) = artifact_type {
196+
artifacts.push(ParsedQtArtifact::new(
197+
semver.clone(),
198+
path.file_name().to_string_lossy().to_string(),
199+
os.clone(),
200+
qt_dir_path.path().to_string_lossy().to_string(),
201+
artifact_type.to_string(),
202+
))
203+
}
204+
}
205+
}
206+
}
207+
}
208+
209+
Ok(artifacts)
210+
}
211+
}
212+
213+
/// Get all valid directories in path bufs, ignoring errors
214+
fn list_dirs(path: &PathBuf) -> Vec<DirEntry> {
215+
path.read_dir()
216+
.unwrap()
217+
.filter(|d| d.is_ok())
218+
.map(|d| d.unwrap())
219+
.collect()
151220
}

examples/qt_minimal/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "qt_minimal"
3+
edition.workspace = true
4+
license.workspace = true
5+
repository.workspace = true
6+
version.workspace = true
7+
rust-version.workspace = true
8+
9+
[dependencies]
10+
11+
[build-dependencies]
12+
semver.workspace = true
13+
qt-build-utils = { workspace = true, features = ["qt_minimal"] }
14+
15+
[lints]
16+
workspace = true

examples/qt_minimal/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use qt_build_utils::{QtInstallation, QtInstallationQtMinimal};
2+
3+
fn main() {
4+
println!("qt_minimal auto download, asking for 6.10.0");
5+
let install = QtInstallationQtMinimal::try_from(semver::Version::new(6, 10, 0)).unwrap();
6+
println!("Found Qt install: {}", install.version());
7+
println!(
8+
"Discovered include path: {:?}",
9+
install.include_paths(&vec![])
10+
);
11+
let moc = install.try_find_tool(qt_build_utils::QtTool::Moc).unwrap();
12+
println!("Found moc: {}", moc.display());
13+
}

examples/qt_minimal/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)