-
Notifications
You must be signed in to change notification settings - Fork 769
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
[READY] Do not rely on CMake to find Python libraries #481
Conversation
We need to clear Travis cache because the Python library from cached pyenv is not dynamic. Reviewed 7 of 7 files at r1. Comments from Reviewable |
74a83be
to
83ef584
Compare
I just cleared out all Travis caches. Thanks for doing this! Yet Another Reason to never use Python for anything of importance ever again. Review status: all files reviewed at latest revision, 2 unresolved discussions. build.py, line 44 [r1] (raw file): build.py, line 183 [r1] (raw file): Comments from Reviewable |
Review status: all files reviewed at latest revision, 3 unresolved discussions. build.py, line 213 [r1] (raw file): Comments from Reviewable |
94b6739
to
c2db194
Compare
Reviewed 1 of 1 files at r2, 1 of 1 files at r3. build.py, line 44 [r1] (raw file): build.py, line 183 [r1] (raw file): build.py, line 213 [r1] (raw file): Comments from Reviewable |
Reviewed 6 of 7 files at r1, 1 of 1 files at r2. Comments from Reviewable |
Reviewed 6 of 7 files at r1, 1 of 1 files at r3. Comments from Reviewable |
PR is ready. When this is merged, I'll send a PR to the YCM repository that updates the Travis configuration.
|
Awesome! @homu r+ |
📌 Commit 15f3d04 has been approved by |
[READY] Do not rely on CMake to find Python libraries ### Problem CMake is not able to find the Python libraries from `pyenv`. We can observe this on Travis. If we look at the build output of the Python 2.6 run on Linux, we have the following line during the CMake configuration: ```sh -- Found PythonLibs: /usr/lib/libpython2.7.so (found suitable version "2.7.3", minimum required is "2.6") ``` which, in addition to be the wrong version, is the system library instead of the `pyenv` one. We confirm this by inspecting the `ycm_core.so` library from the build: ```sh $ ldd ycm_core.so | grep python libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007f0521fa1000) ``` Same issue with the Python 2.7 and 3.3 Linux runs although the library version is correct in these cases. In the Travis configuration file, there is this comment: > This is because stupid cmake 2.8.11 has a bug preventing it from finding the pyenv pythons (ostensibly; I haven't checked, but online reports say the issue is gone with cmake 3.4). I tried with CMake 3.5.1 (3.5.2 is the last version) and it is still not working. That's not all. In some situations, CMake find the wrong Python system libraries (see [this workaround on AppVeyor](https://github.com/Valloric/ycmd/blob/master/ci/appveyor/appveyor_install.bat#L36)) or cannot find them at all (see [this post on ycm-users](https://groups.google.com/forum/#!searchin/ycm-users/windows$20cmake/ycm-users/e6K-grbeUMw/0kzwtAaYCQAJ)). ### Solution From this, it is clear that we cannot rely on CMake to find the Python libraries. We need to find them in the `build.py` script and pass the `PYTHON_LIBRARY` and `PYTHON_INCLUDE_DIR` parameters to CMake, like we already do for OS X. This is implemented by creating a `FindPythonLibraries` function for each supported platform: Linux, OS X, and Windows. For OS X, we are keeping the logic from `CustomPythonCmakeArgs` except that we are dropping support for system Python 2.6. For Linux, we need to use the `ldconfig` tool to find the system Python library on some distributions (e.g. Ubuntu) because it is not installed in its standard location. For Windows, it is straightforward. In all cases, we assume that the Python running the script is the one that will be used to build the library. This PR also fixes an important issue. When building the ycmd library with Clang support and linking it to a non-system Python libray, the dynamic linker will not be able to find the Python library: ```sh $ ldd ycm_core.so | grep python libpython3.4m.so.1.0 => not found $ objdump -x ycm_core.so | grep RPATH RPATH $ORIGIN ``` This is solved by setting the `CMAKE_INSTALL_RPATH_USE_LINK_PATH` option to true (see [this wiki page](https://cmake.org/Wiki/CMake_RPATH_handling) for details on the option): ``` > ldd ycm_core.so | grep python libpython3.4m.so.1.0 => /home/micbou/.pyenv/versions/3.4.4/lib/libpython3.4m.so.1.0 (0x00007f9fb6472000) > objdump -x ycm_core.so | grep RPATH RPATH $ORIGIN:/home/micbou/.pyenv/versions/3.4.4/lib ``` Closes #196 (we don't care about the Python interpreter when building the ycmd library). Fixes #479. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/481) <!-- Reviewable:end -->
💔 Test failed - status |
Let's retry without the cache. @homu r+
|
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 15f3d04 has been approved by |
💡 This pull request was already approved, no need to approve it again.
|
@homu retry
|
[READY] Do not rely on CMake to find Python libraries ### Problem CMake is not able to find the Python libraries from `pyenv`. We can observe this on Travis. If we look at the build output of the Python 2.6 run on Linux, we have the following line during the CMake configuration: ```sh -- Found PythonLibs: /usr/lib/libpython2.7.so (found suitable version "2.7.3", minimum required is "2.6") ``` which, in addition to be the wrong version, is the system library instead of the `pyenv` one. We confirm this by inspecting the `ycm_core.so` library from the build: ```sh $ ldd ycm_core.so | grep python libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007f0521fa1000) ``` Same issue with the Python 2.7 and 3.3 Linux runs although the library version is correct in these cases. In the Travis configuration file, there is this comment: > This is because stupid cmake 2.8.11 has a bug preventing it from finding the pyenv pythons (ostensibly; I haven't checked, but online reports say the issue is gone with cmake 3.4). I tried with CMake 3.5.1 (3.5.2 is the last version) and it is still not working. That's not all. In some situations, CMake find the wrong Python system libraries (see [this workaround on AppVeyor](https://github.com/Valloric/ycmd/blob/master/ci/appveyor/appveyor_install.bat#L36)) or cannot find them at all (see [this post on ycm-users](https://groups.google.com/forum/#!searchin/ycm-users/windows$20cmake/ycm-users/e6K-grbeUMw/0kzwtAaYCQAJ)). ### Solution From this, it is clear that we cannot rely on CMake to find the Python libraries. We need to find them in the `build.py` script and pass the `PYTHON_LIBRARY` and `PYTHON_INCLUDE_DIR` parameters to CMake, like we already do for OS X. This is implemented by creating a `FindPythonLibraries` function for each supported platform: Linux, OS X, and Windows. For OS X, we are keeping the logic from `CustomPythonCmakeArgs` except that we are dropping support for system Python 2.6. For Linux, we need to use the `ldconfig` tool to find the system Python library on some distributions (e.g. Ubuntu) because it is not installed in its standard location. For Windows, it is straightforward. In all cases, we assume that the Python running the script is the one that will be used to build the library. This PR also fixes an important issue. When building the ycmd library with Clang support and linking it to a non-system Python libray, the dynamic linker will not be able to find the Python library: ```sh $ ldd ycm_core.so | grep python libpython3.4m.so.1.0 => not found $ objdump -x ycm_core.so | grep RPATH RPATH $ORIGIN ``` This is solved by setting the `CMAKE_INSTALL_RPATH_USE_LINK_PATH` option to true (see [this wiki page](https://cmake.org/Wiki/CMake_RPATH_handling) for details on the option): ``` > ldd ycm_core.so | grep python libpython3.4m.so.1.0 => /home/micbou/.pyenv/versions/3.4.4/lib/libpython3.4m.so.1.0 (0x00007f9fb6472000) > objdump -x ycm_core.so | grep RPATH RPATH $ORIGIN:/home/micbou/.pyenv/versions/3.4.4/lib ``` Closes #196 (we don't care about the Python interpreter when building the ycmd library). Fixes #479. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/481) <!-- Reviewable:end -->
☀️ Test successful - status |
[READY] Remove architecture option in scripts With the changes from PR #481, the `--arch` option cannot be used anymore to specify the architecture on Windows because the architecture of the Python library is now the same as the Python interpreter running the `build.py` script and this architecture must match the one used to compile ycmd. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/484) <!-- Reviewable:end -->
[READY] Update Travis configuration Update ycmd to include PR ycm-core/ycmd#481 and update Travis configuration according to this PR. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2157) <!-- Reviewable:end -->
[READY] Update Travis configuration Update ycmd to include PR ycm-core/ycmd#481 and update Travis configuration according to this PR. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2157) <!-- Reviewable:end -->
Thanks for the heads up. We'll take care of that in the next iteration. |
Problem
CMake is not able to find the Python libraries from
pyenv
. We can observe this on Travis. If we look at the build output of the Python 2.6 run on Linux, we have the following line during the CMake configuration:which, in addition to be the wrong version, is the system library instead of the
pyenv
one. We confirm this by inspecting theycm_core.so
library from the build:Same issue with the Python 2.7 and 3.3 Linux runs although the library version is correct in these cases.
In the Travis configuration file, there is this comment:
I tried with CMake 3.5.1 (3.5.2 is the last version) and it is still not working.
That's not all. In some situations, CMake find the wrong Python system libraries (see this workaround on AppVeyor) or cannot find them at all (see this post on ycm-users).
Solution
From this, it is clear that we cannot rely on CMake to find the Python libraries. We need to find them in the
build.py
script and pass thePYTHON_LIBRARY
andPYTHON_INCLUDE_DIR
parameters to CMake, like we already do for OS X.This is implemented by creating a
FindPythonLibraries
function for each supported platform: Linux, OS X, and Windows. For OS X, we are keeping the logic fromCustomPythonCmakeArgs
except that we are dropping support for system Python 2.6. For Linux, we need to use theldconfig
tool to find the system Python library on some distributions (e.g. Ubuntu) because it is not installed in its standard location. For Windows, it is straightforward. In all cases, we assume that the Python running the script is the one that will be used to build the library.This PR also fixes an important issue. When building the ycmd library with Clang support and linking it to a non-system Python libray, the dynamic linker will not be able to find the Python library:
This is solved by setting the
CMAKE_INSTALL_RPATH_USE_LINK_PATH
option to true (see this wiki page for details on the option):Closes #196 (we don't care about the Python interpreter when building the ycmd library).
Fixes #479.
This change is