Skip to content

Commit e1ecb56

Browse files
WIP add directory walk to find qt artifacts
1 parent e010614 commit e1ecb56

File tree

7 files changed

+102
-3
lines changed

7 files changed

+102
-3
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: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

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

1011
#[derive(Debug, Serialize, Deserialize)]
@@ -29,7 +30,7 @@ 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().timeout(None).build().expect("Http client failed to build");
3334
let temp_dir = tempfile::TempDir::new().expect("Could not create temporary directory");
3435
let archive_path =
3536
super::download::download_from_url(&self.url, &self.sha256, &temp_dir, &http_client)
@@ -46,6 +47,18 @@ impl ParsedQtArtifact {
4647
target_path.to_path_buf()
4748
}
4849

50+
pub fn new(version: Version, arch: String, os: String, url: String, content_type: String) -> Self {
51+
Self {
52+
version,
53+
arch,
54+
os,
55+
url,
56+
sha256: "".to_string(),
57+
content: vec![content_type],
58+
}
59+
}
60+
61+
4962
/// Assert that the hashes are the same, from bytes
5063
pub fn verify(&self, hash: &[u8]) -> anyhow::Result<()> {
5164
let mut hash_string = String::new();

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod extract;
1111
use std::path::PathBuf;
1212

1313
use crate::{QtBuildError, QtInstallation};
14+
use crate::installation::qt_minimal::artifact::ParsedQtArtifact;
1415

1516
/// A implementation of [QtInstallation] using qtminimal
1617
pub struct QtInstallationQtMinimal {
@@ -148,4 +149,48 @@ impl QtInstallationQtMinimal {
148149

149150
path
150151
}
152+
153+
/// Get a collection of the locally installed Qt artifacts
154+
pub fn local_artifacts() {
155+
// pub fn local_artifacts() -> Vec<artifact::ParsedQtArtifact> {
156+
let base_dir = Self::qt_minimal_root();
157+
158+
let mut artifacts = vec![];
159+
160+
// Iterate versions
161+
for version in base_dir.read_dir().unwrap() {
162+
let path = version.unwrap();
163+
let semver = semver::Version::parse(path.file_name().to_str().unwrap()).expect("Could not parse semver from directory name");
164+
165+
for os in path.path().read_dir().unwrap() {
166+
let path = os.unwrap();
167+
let os = path.file_name().to_str().unwrap().to_string();
168+
169+
for arch in path.path().read_dir().unwrap() {
170+
// Ugly code, this can surely be better
171+
// Expects to find valid directories
172+
let path = arch.unwrap();
173+
let dir_entries = path.path().read_dir().unwrap()
174+
.filter(|d| d.is_ok())
175+
.map(|dir| dir.unwrap())
176+
.collect::<Vec<_>>();
177+
178+
// Expects one qt dir
179+
let qt_dir_path = dir_entries.iter().filter(|dir| dir.file_name() == "qt").last().expect("Expected to find a Qt dir in this folder");
180+
181+
let qt_folders = qt_dir_path.path().read_dir().unwrap();
182+
for dir in qt_folders {
183+
let filename = dir.unwrap().file_name();
184+
if filename == "bin" {
185+
artifacts.append(ParsedQtArtifact::new(semver.clone(), path.file_name().to_str().unwrap().to_string().clone(), os.clone(), "dummy/url/not/finished".to_string(), "bin".to_string()))
186+
} else if filename == "include" {
187+
artifacts.append(ParsedQtArtifact::new(semver.clone(), path.file_name().to_str().unwrap().to_string().clone(), os.clone(), "dummy/url/not/finished".to_string(), "bin".to_string()))
188+
}
189+
}
190+
}
191+
}
192+
}
193+
194+
artifacts
195+
}
151196
}

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
QtInstallationQtMinimal::local_artifacts();
14+
}

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)