Skip to content

Commit 8dcd7d5

Browse files
committed
qt-build-utils: create a QtInstallation but don't use it
This is just to test what we can do still with the old API
1 parent a89e9fa commit 8dcd7d5

File tree

1 file changed

+23
-7
lines changed
  • crates/qt-build-utils/src

1 file changed

+23
-7
lines changed

crates/qt-build-utils/src/lib.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum QtBuildError {
4444
/// The value of the qmake environment variable when the error occurred
4545
qmake_env_var: String,
4646
/// The inner [QtBuildError] that occurred
47-
error: Box<QtBuildError>,
47+
error: Box<anyhow::Error>,
4848
},
4949
/// Qt was not found
5050
#[error("Could not find Qt")]
@@ -233,6 +233,7 @@ pub struct QmlModuleRegistrationFiles {
233233
/// let qtbuild = qt_build_utils::QtBuild::new(qt_modules).expect("Could not find Qt installation");
234234
/// ```
235235
pub struct QtBuild {
236+
qt_installation: Box<dyn QtInstallation>,
236237
version: SemVer,
237238
qmake_executable: String,
238239
moc_executable: Option<String>,
@@ -281,10 +282,16 @@ impl QtBuild {
281282
/// WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
282283
/// )
283284
/// ```
284-
pub fn new(mut qt_modules: Vec<String>) -> Result<Self, QtBuildError> {
285+
pub fn new(mut qt_modules: Vec<String>) -> anyhow::Result<Self> {
285286
if qt_modules.is_empty() {
286287
qt_modules.push("Core".to_string());
287288
}
289+
290+
#[cfg(feature = "qmake")]
291+
let qt_installation = Box::new(QtInstallationQMake::new()?);
292+
#[cfg(not(feature = "qmake"))]
293+
unsupported!("Only qmake feature is supported");
294+
288295
println!("cargo::rerun-if-env-changed=QMAKE");
289296
println!("cargo::rerun-if-env-changed=QT_VERSION_MAJOR");
290297
fn verify_candidate(candidate: &str) -> Result<(&str, versions::SemVer), QtBuildError> {
@@ -338,6 +345,7 @@ impl QtBuild {
338345
match verify_candidate(qmake_env_var.trim()) {
339346
Ok((executable_name, version)) => {
340347
return Ok(Self {
348+
qt_installation,
341349
qmake_executable: executable_name.to_string(),
342350
moc_executable: None,
343351
qmltyperegistrar_executable: None,
@@ -350,8 +358,9 @@ impl QtBuild {
350358
Err(e) => {
351359
return Err(QtBuildError::QMakeSetQtMissing {
352360
qmake_env_var,
353-
error: Box::new(e),
354-
})
361+
error: Box::new(e.into()),
362+
}
363+
.into())
355364
}
356365
}
357366
}
@@ -362,6 +371,7 @@ impl QtBuild {
362371
match verify_candidate(executable_name) {
363372
Ok((executable_name, version)) => {
364373
return Ok(Self {
374+
qt_installation,
365375
qmake_executable: executable_name.to_string(),
366376
moc_executable: None,
367377
qmltyperegistrar_executable: None,
@@ -383,17 +393,18 @@ impl QtBuild {
383393
return Err(QtBuildError::QtVersionMajorDoesNotMatch {
384394
qmake_version,
385395
qt_version_major,
386-
});
396+
}
397+
.into());
387398
}
388399
eprintln!("Candidate qmake executable `{executable_name}` is for Qt{qmake_version} but QT_VERSION_MAJOR environment variable specified as {qt_version_major}. Trying next candidate executable name `{}`...", candidate_executable_names[index + 1]);
389400
continue;
390401
}
391402
Err(QtBuildError::QtMissing) => continue,
392-
Err(e) => return Err(e),
403+
Err(e) => return Err(e.into()),
393404
}
394405
}
395406

396-
Err(QtBuildError::QtMissing)
407+
Err(QtBuildError::QtMissing.into())
397408
}
398409

399410
/// Get the output of running `qmake -query var_name`
@@ -620,6 +631,7 @@ impl QtBuild {
620631

621632
/// Version of the detected Qt installation
622633
pub fn version(&self) -> &SemVer {
634+
let _ = self.qt_installation.version();
623635
&self.version
624636
}
625637

@@ -683,6 +695,9 @@ impl QtBuild {
683695
/// as well as the path to the generated metatypes.json file, which can be passed to [register_qml_module](Self::register_qml_module).
684696
///
685697
pub fn moc(&mut self, input_file: impl AsRef<Path>, arguments: MocArguments) -> MocProducts {
698+
let _ = self
699+
.qt_installation
700+
.moc(input_file.as_ref(), arguments.clone());
686701
if self.moc_executable.is_none() {
687702
self.moc_executable = Some(self.get_qt_tool("moc").expect("Could not find moc"));
688703
}
@@ -1073,6 +1088,7 @@ Q_IMPORT_PLUGIN({plugin_class_name});
10731088
/// the `+whole-archive` flag is used, or the initializer function is called by the
10741089
/// application.
10751090
pub fn qrc(&mut self, input_file: &impl AsRef<Path>) -> Initializer {
1091+
let _ = self.qt_installation.qrc(input_file.as_ref());
10761092
if self.rcc_executable.is_none() {
10771093
self.rcc_executable = Some(self.get_qt_tool("rcc").expect("Could not find rcc"));
10781094
}

0 commit comments

Comments
 (0)