qt_build_utils/tool/
qtpaths.rs1use std::{path::PathBuf, process::Command};
7
8use crate::{utils, QtInstallation, QtTool};
9
10#[derive(Default)]
12pub struct QtPathsQueryArguments {
13 query: Option<String>,
14 qtconf: Option<String>,
15 }
17
18impl QtPathsQueryArguments {
19 pub fn query(mut self, query: &str) -> Self {
21 self.query = Some(query.to_string());
22 self
23 }
24
25 pub fn qtconf(mut self, qtconf: &str) -> Self {
27 self.qtconf = Some(qtconf.to_string());
28 self
29 }
30}
31
32impl From<&str> for QtPathsQueryArguments {
33 fn from(value: &str) -> Self {
34 Self::default().query(value)
35 }
36}
37
38pub struct QtToolQtPaths {
40 executable: PathBuf,
41}
42
43impl QtToolQtPaths {
44 pub fn new(qt_installation: &dyn QtInstallation) -> Self {
46 let executable = qt_installation
47 .try_find_tool(QtTool::QtPaths)
48 .expect("Could not find qtpaths");
49
50 utils::check_executable_help(&executable).unwrap();
52
53 Self { executable }
54 }
55
56 pub fn query(&self, query_args: impl Into<QtPathsQueryArguments>) -> Option<String> {
62 let query_args = query_args.into();
63 let mut args = vec![];
64
65 if let Some(query) = &query_args.query {
67 args.extend(["--query", query]);
68 } else {
69 args.push("--query")
70 }
71
72 if let Some(qtconf) = &query_args.qtconf {
74 args.extend(["--qtconf", qtconf]);
75 }
76
77 let output = Command::new(&self.executable)
79 .args(args)
80 .env_clear()
83 .output()
85 .ok()?
86 .stdout;
87 Some(String::from_utf8_lossy(&output).trim().to_owned())
88 }
89}
90
91#[cfg(feature = "qt_minimal")]
92impl QtToolQtPaths {
93 pub(crate) fn from_path_buf(executable: PathBuf) -> Self {
95 utils::check_executable_help(&executable).unwrap();
97
98 Self { executable }
99 }
100}