qt_build_utils/tool/
mod.rs

1// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
2// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
3//
4// SPDX-License-Identifier: MIT OR Apache-2.0
5
6use std::{env, path::PathBuf};
7
8mod moc;
9pub use moc::{MocArguments, MocProducts, QtToolMoc};
10
11mod qmlcachegen;
12pub use qmlcachegen::{QmlCacheArguments, QmlCacheProducts, QtToolQmlCacheGen};
13
14mod qmltyperegistrar;
15pub use qmltyperegistrar::QtToolQmlTypeRegistrar;
16
17mod rcc;
18pub use rcc::QtToolRcc;
19
20/// An enum representing known Qt tools
21#[non_exhaustive]
22#[derive(Eq, Hash, PartialEq)]
23pub enum QtTool {
24    /// Moc
25    Moc,
26    /// Rcc (Qt resources)
27    Rcc,
28    /// Qml cachegen
29    QmlCacheGen,
30    /// Qml Type Registrar
31    QmlTypeRegistrar,
32    // TODO: could add a Custom(&str) thing here
33}
34
35impl QtTool {
36    pub(crate) fn binary_name(&self) -> &str {
37        match self {
38            Self::Moc => "moc",
39            Self::Rcc => "rcc",
40            Self::QmlCacheGen => "qmlcachegen",
41            Self::QmlTypeRegistrar => "qmltyperegistrar",
42        }
43    }
44
45    /// Return a directory where files can be written by this tool
46    ///
47    /// Note the location might not exist yet
48    pub(crate) fn writable_path(&self) -> PathBuf {
49        PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR was not set")).join(self.binary_name())
50    }
51}