This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Remove duplicated logic to find Python when doing a standalone build
ClosedPublic

Authored by JDevlieghere on Jul 16 2019, 2:24 PM.

Details

Summary

I'm pretty sure there's no need to have this logic living in LLDBStandalone. We always go through LLDBConfig.cmake which has the canonical way to find the Python libs and interpreter.

Diff Detail

Repository
rL LLVM

Event Timeline

JDevlieghere created this revision.Jul 16 2019, 2:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 16 2019, 2:24 PM
Herald added a subscriber: mgorny. · View Herald Transcript

Actually, right now I'm trying to figure out where the interpreter is found because cmake is finding different, incompatible versions of the interpreter (2.7) and the libs (3.6).

On Windows, it looks like LLDBConfig.cmake doesn't explicitly look for the interpreter, only the libs. By the time find_python_libs_windows runs, the interpreter is already set to the wrong version.

Actually, right now I'm trying to figure out where the interpreter is found because cmake is finding different, incompatible versions of the interpreter (2.7) and the libs (3.6).

On Windows, it looks like LLDBConfig.cmake doesn't explicitly look for the interpreter, only the libs. By the time find_python_libs_windows runs, the interpreter is already set to the wrong version.

For an in-tree build I assume it would be LLVM setting the interpreter. Maybe we should we unset the variables here so we can start clean?

Indeed, the culprit appears to be https://github.com/llvm/llvm-project/blob/master/llvm/CMakeLists.txt#L645, which prefer Python 3 over Python 2.

I'm pretty sure there's no need to have this logic living in LLDBStandalone. We always go through LLDBConfig.cmake which has the canonical way to find the Python libs and interpreter.

LLDBStandalone is supposed to act like a polyfill for whatever LLVM would usually do, so LLDBConfig (and ideally everything else) can ignore in-tree vs. standalone. Thus, the Python logic here should always behave like its LLVM counterpart. If it turns out to be incorrect, we should either adapt LLDBConfig or change both LLVM and LLDBStandalone.

Indeed, the culprit appears to be https://github.com/llvm/llvm-project/blob/master/llvm/CMakeLists.txt#L645, which prefer Python 3 over Python 2.

This changed quite recently https://reviews.llvm.org/D64443

lldb/cmake/modules/LLDBStandalone.cmake
101 ↗(On Diff #210177)

The actual difference to https://github.com/llvm/llvm-project/blob/c23bc97e85f6/llvm/CMakeLists.txt#L645 is the condition on PYTHON_EXECUTABLE.

sgraenitz accepted this revision.Jul 17 2019, 12:08 PM

Jonas is right, that there is nothing wrong with this code, but that it's just redundant as we'll do all of this in LLDBConfig anyway. Removing it means adding a potential difference for standalone builds, but in the end it should be fine.

This revision is now accepted and ready to land.Jul 17 2019, 12:08 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2019, 12:36 PM