Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'python2 --version' sends output to stderr, redirect to stdout to cat… #20979

Closed
wants to merge 9 commits into from
2 changes: 1 addition & 1 deletion recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
# In any case, check its actual version for compatibility
from six import StringIO # Python 2 and 3 compatible
mybuf = StringIO()
cmd_v = f"\"{python_exe}\" --version"
cmd_v = f"\"{python_exe}\" --version 2>&1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work on Windows - You might need to use subprocess to execute the command directly and get stderr from there

I'll look into allowing Conan's run method to also output stderr just like what is done with stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Ruben,

Thanks for reviewing.
Before submitting I tested the "python --version 2>&1" command in a Windows command prompt and it worked.
A colleague of mine is currently building qt 5.15.11 on Windows and with the above patched he has no errors yet. Before the patch the build would quit almost immediately because of the broken Python2 version check.
So I am quite confident this solution will work also on Windows.

Of course it would still be nice if stderr could be re-directed as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wdobbe Please, let's avoid workarounds and follow Ruben's approach, the subprocess is specially designed for this case, it's cross-platform compatibly, has fine-grained control over pipes, is more secure (avoids injections), and much better for error handling in case of an exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed as requested and tested with Conan 2.13.0 on Linux x86_64 with:
conan create . --version=5.15.11 -o qt/*:qtwebengine=True -o sqlite3/*:shared=True -o qt/*:shared=True -o qt/*:gui=True -o qt/*:qtdeclarative=True -o qt/*:qtlocation=True -o qt/*:qtwebchannel=True --build=missing

self.run(cmd_v, mybuf)
verstr = mybuf.getvalue().strip().split("Python ")[1]
if verstr.endswith("+"):
Expand Down Expand Up @@ -922,7 +922,7 @@
filecontents += 'set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_GADGET_EXPORT" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")\n'
save(self, os.path.join(self.package_folder, self._cmake_core_extras_file), filecontents)

def _create_private_module(module, dependencies=[]):

Check warning on line 925 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Dangerous default value [] as argument
if "Core" not in dependencies:
dependencies.append("Core")
dependencies_string = ';'.join(f'Qt5::{dependency}' for dependency in dependencies)
Expand Down Expand Up @@ -991,7 +991,7 @@
reqs.append(corrected_req)
return reqs

def _create_module(module, requires=[], has_include_dir=True):

Check warning on line 994 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Dangerous default value [] as argument
componentname = f"qt{module}"
assert componentname not in self.cpp_info.components, f"Module {module} already present in self.cpp_info.components"
self.cpp_info.components[componentname].set_property("cmake_target_name", f"Qt5::{module}")
Expand Down