Skip to content

Commit 01dc659

Browse files
committed
qt-build-utils: have a command writable path method for tools
1 parent 3ec71e8 commit 01dc659

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

crates/qt-build-utils/src/tool/moc.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use crate::{QtInstallation, QtTool};
77

88
use std::{
9-
env,
109
path::{Path, PathBuf},
1110
process::Command,
1211
};
@@ -73,10 +72,7 @@ impl QtToolMoc {
7372
pub fn compile(&self, input_file: impl AsRef<Path>, arguments: MocArguments) -> MocProducts {
7473
let input_path = input_file.as_ref();
7574
// Put all the moc files into one place, this can then be added to the include path
76-
let moc_dir = PathBuf::from(format!(
77-
"{}/qt-build-utils/moc",
78-
env::var("OUT_DIR").unwrap()
79-
));
75+
let moc_dir = QtTool::Moc.writable_path();
8076
std::fs::create_dir_all(&moc_dir).expect("Could not create moc dir");
8177
let output_path = moc_dir.join(format!(
8278
"moc_{}.cpp",

crates/qt-build-utils/src/tool/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6+
use std::{env, path::PathBuf};
7+
68
mod moc;
79
pub use moc::{MocArguments, MocProducts, QtToolMoc};
810

@@ -33,4 +35,11 @@ impl QtTool {
3335
Self::QmlTypeRegistrar => "qmltyperegistrar",
3436
}
3537
}
38+
39+
/// Return a directory where files can be written by this tool
40+
///
41+
/// Note the location might not exist yet
42+
pub(crate) fn writable_path(&self) -> PathBuf {
43+
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR was not set")).join(self.binary_name())
44+
}
3645
}

crates/qt-build-utils/src/tool/rcc.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{Initializer, QtInstallation, QtTool};
77

88
use semver::Version;
99
use std::{
10-
env,
1110
path::{Path, PathBuf},
1211
process::Command,
1312
};
@@ -41,10 +40,7 @@ impl QtToolRcc {
4140
/// application.
4241
pub fn compile(&self, input_file: impl AsRef<Path>) -> Initializer {
4342
let input_path = input_file.as_ref();
44-
let output_folder = PathBuf::from(&format!(
45-
"{}/qt-build-utils/qrc",
46-
env::var("OUT_DIR").unwrap()
47-
));
43+
let output_folder = QtTool::Rcc.writable_path();
4844
std::fs::create_dir_all(&output_folder).expect("Could not create qrc dir");
4945
let output_path = output_folder.join(format!(
5046
"{}.cpp",

0 commit comments

Comments
 (0)