Skip to content

Commit d178c52

Browse files
committed
qt-build-utils: ensure that Command has clean environment
Otherwise when executing Qt binaries if LD_LIBRARY_PATH is set collisions can occur with differing Qt binary and libraries.
1 parent 45594bf commit d178c52

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

crates/qt-build-utils/src/installation/qmake.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ impl TryFrom<PathBuf> for QtInstallationQMake {
118118
// Attempt to read the QT_VERSION from qmake
119119
let qmake_version = match Command::new(&qmake_path)
120120
.args(["-query", "QT_VERSION"])
121+
// Binaries should work without environment and this prevents
122+
// LD_LIBRARY_PATH from causing different Qt version clashes
123+
.env_clear()
121124
.output()
122125
{
123126
Err(e) if e.kind() == ErrorKind::NotFound => Err(QtBuildError::QtMissing),
@@ -211,6 +214,9 @@ impl QtInstallationQMake {
211214
String::from_utf8_lossy(
212215
&Command::new(&self.qmake_path)
213216
.args(["-query", var_name])
217+
// Binaries should work without environment and this prevents
218+
// LD_LIBRARY_PATH from causing different Qt version clashes
219+
.env_clear()
214220
.output()
215221
.unwrap()
216222
.stdout,
@@ -267,7 +273,12 @@ impl QtInstallationQMake {
267273
// Find the first valid executable path
268274
.find_map(|qmake_query_var| {
269275
let executable_path = PathBuf::from(self.qmake_query(qmake_query_var)).join(tool_name);
270-
let test_output = Command::new(&executable_path).args(["-help"]).output();
276+
let test_output = Command::new(&executable_path)
277+
.args(["-help"])
278+
// Binaries should work without environment and this prevents
279+
// LD_LIBRARY_PATH from causing different Qt version clashes
280+
.env_clear()
281+
.output();
271282
match test_output {
272283
Err(_err) => {
273284
failed_paths.push(executable_path);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ impl QtToolMoc {
123123
.arg(output_path.to_str().unwrap())
124124
.arg("--output-json");
125125
let cmd = cmd
126+
// Binaries should work without environment and this prevents
127+
// LD_LIBRARY_PATH from causing different Qt version clashes
128+
.env_clear()
126129
.output()
127130
.unwrap_or_else(|_| panic!("moc failed for {}", input_path.display()));
128131

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ impl QtToolQmlCacheGen {
8383

8484
let cmd = Command::new(&self.executable)
8585
.args(common_args.iter().chain(&specific_args))
86+
// Binaries should work without environment and this prevents
87+
// LD_LIBRARY_PATH from causing different Qt version clashes
88+
.env_clear()
8689
.output()
8790
.unwrap_or_else(|_| {
8891
panic!(
@@ -140,6 +143,9 @@ impl QtToolQmlCacheGen {
140143
.chain(&specific_args)
141144
.chain(qml_resource_paths),
142145
)
146+
// Binaries should work without environment and this prevents
147+
// LD_LIBRARY_PATH from causing different Qt version clashes
148+
.env_clear()
143149
.output()
144150
.unwrap_or_else(|_| panic!("qmlcachegen failed for QML module {uri}"));
145151
if !cmd.status.success() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl QtToolQmlTypeRegistrar {
7272
args.extend(metatypes_json);
7373
let cmd = Command::new(&self.executable)
7474
.args(args)
75+
// Binaries should work without environment and this prevents
76+
// LD_LIBRARY_PATH from causing different Qt version clashes
77+
.env_clear()
7578
.output()
7679
.unwrap_or_else(|_| panic!("qmltyperegistrar failed for {uri}"));
7780
if !cmd.status.success() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ impl QtToolQtPaths {
7474
// Run the qtpaths command and trim the output
7575
let output = Command::new(&self.executable)
7676
.args(args)
77+
// Binaries should work without environment and this prevents
78+
// LD_LIBRARY_PATH from causing different Qt version clashes
79+
.env_clear()
7780
// NOTE: Qt 5 will fail as there is no -query parameter
7881
.output()
7982
.ok()?

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl QtToolRcc {
7272
args.extend(self.custom_args.iter().cloned());
7373

7474
let cmd = Command::new(&self.executable)
75+
// Binaries should work without environment and this prevents
76+
// LD_LIBRARY_PATH from causing different Qt version clashes
77+
.env_clear()
7578
.args(args)
7679
.output()
7780
.unwrap_or_else(|_| panic!("rcc failed for {}", input_path.display()));
@@ -104,6 +107,9 @@ impl QtToolRcc {
104107
let input_path = input_file.as_ref();
105108
let cmd_list = Command::new(&self.executable)
106109
.args(["--list", input_path.to_str().unwrap()])
110+
// Binaries should work without environment and this prevents
111+
// LD_LIBRARY_PATH from causing different Qt version clashes
112+
.env_clear()
107113
.output()
108114
.unwrap_or_else(|_| panic!("rcc --list failed for {}", input_path.display()));
109115

0 commit comments

Comments
 (0)