Bug 168159 - Mk/bsd.python.mk: CMake python detection gets confused if multiple python versions are installed
Summary: Mk/bsd.python.mk: CMake python detection gets confused if multiple python ver...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Max Brazhnikov
URL:
Keywords: needs-patch, patch
Depends on:
Blocks: 199685 200518
  Show dependency treegraph
 
Reported: 2012-05-20 09:50 UTC by Marcus von Appen
Modified: 2015-06-10 09:26 UTC (History)
3 users (show)

See Also:
antoine: maintainer-feedback+
koobs: exp-run+


Attachments
Enforce default Python provided by the ports tree (670 bytes, patch)
2015-05-31 19:47 UTC, Max Brazhnikov
no flags Details | Diff
Enforce the version required by the port or the default (671 bytes, patch)
2015-06-02 10:52 UTC, Max Brazhnikov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus von Appen freebsd_committer freebsd_triage 2012-05-20 09:50:01 UTC
        If multiple Python versions are installed, cmake's
        find_host_package(PythonInterp) and
        find_host_package(PythonLibs) statements may return different
        Python versions, causing cmake to try to detect and link
        against the wrong Python default version

Fix: 

I'm not entirely sure, if that should be fixed in the related
        cmake files

        /usr/local/share/cmake/Modules/FindPythonInterp.cmake
        /usr/local/share/cmake/Modules/FindPythonLibs.cmake

        by adjusting the search/find order or go into the relevant Mk
        files. Below is a patch for bsd.python.mk, which explicitly sets
        the Python version to be used in bsd.python.mk, based on the
        detected PYTHON_VER.

 Index: Mk/bsd.python.mk
 ===================================================================
 RCS file: /home/pcvs/ports/Mk/bsd.python.mk,v
 retrieving revision 1.143
 diff -u -r1.143 bsd.python.mk
 --- Mk/bsd.python.mk	11 Apr 2012 12:52:16 -0000	1.143
 +++ Mk/bsd.python.mk	20 May 2012 08:31:02 -0000
 @@ -674,6 +674,11 @@
 
  .endif # defined(USE_TWISTED)
 
 +.if defined(USE_CMAKE)
 +CMAKE_ARGS+=	-DPythonLibs_FIND_VERSION:STRING="${PYTHON_VER}" \
 +		-DPythonInterp_FIND_VERSIN:STRING="${PYTHON_VER}"
 +.endif
 +
  # XXX Hm, should I export some of the variables above to *_ENV?
 
  .endif		# !defined(_POSTMKINCLUDED) &&
  !defined(Python_Pre_Include)
How-To-Repeat: 
        Install lang/python27, lang/python31, lang/python
        Try to configure and build graphics/py-opencv:

        [...]
root@medusa:/usr/ports/graphics/py-opencv # make configure
===>  License BSD accepted by the user
===>  Extracting for py27-opencv-2.3.1_3
=> SHA256 Checksum OK for OpenCV-2.3.1a.tar.bz2.
===>  Patching for py27-opencv-2.3.1_3
===>  Applying extra patch /usr/ports/graphics/py-opencv/../opencv/files/extra-patch-opencv-python
===>  Applying FreeBSD patches for py27-opencv-2.3.1_3
===>   py27-opencv-2.3.1_3 depends on file: /usr/local/lib/python2.7/site-packages/numpy/core/numeric.py - found
===>   py27-opencv-2.3.1_3 depends on file: /usr/local/bin/python2.7 - found
===>   py27-opencv-2.3.1_3 depends on executable: pkg-config - found
===>   py27-opencv-2.3.1_3 depends on file: /usr/local/bin/cmake - found
===>   py27-opencv-2.3.1_3 depends on shared library: opencv_legacy.2 - found
===>  Configuring for py27-opencv-2.3.1_3
[...]
-- Looking for pthread.h - found
-- Found PythonInterp: /usr/local/bin/python (found version "2.7.3")
-- Found PythonLibs: /usr/local/lib/libpython3.1.so (found version "3.1.5")
--     Use NumPy headers from: /usr/local/lib/python2.7/site-packages/numpy/core/include
--     Found Sphinx 1.1.2: /usr/local/bin/sphinx-build
-- Parsing 'cvconfig.h.cmake'
Comment 1 Marcus von Appen freebsd_committer freebsd_triage 2012-06-03 22:47:58 UTC
Responsible Changed
From-To: freebsd-ports-bugs->freebsd-python

That's a Python PR
Comment 2 dfilter service freebsd_committer 2012-06-19 18:18:24 UTC
mva         2012-06-19 17:18:13 UTC

  FreeBSD ports repository

  Modified files:
    Mk                   bsd.python.mk 
  Log:
  - Force cmake to use PYTHON_VER as version to detect, so that it uses
    the same Python version for the interpreter and library linking, if
    multiple Python versions are installed.
  
  PR:             ports/168159
  On behalf of:   python@
  
  Revision  Changes    Path
  1.148     +12 -1     ports/Mk/bsd.python.mk
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 3 Marcus von Appen freebsd_committer freebsd_triage 2012-06-19 18:18:53 UTC
State Changed
From-To: open->closed

Committed. Thanks!
Comment 4 Max Brazhnikov freebsd_committer 2015-05-31 19:47:04 UTC
Created attachment 157311 [details]
Enforce default Python provided by the ports tree

While this bug was resolved with the update of CMake to 3.0.1 in r366996, the workaround was still useful: by default CMake picks up the highest available version of Python package, while we want to use the default version provided by the ports framework. The attached patch fixes build issues reported in https://bugs.freebsd.org/199685 and https://bugs.freebsd.org/200518.
Comment 5 Max Brazhnikov freebsd_committer 2015-05-31 19:54:14 UTC
Reopen and request maintainer approval.
Comment 6 Antoine Brodin freebsd_committer 2015-06-01 07:29:47 UTC
Take for exp-run
Comment 7 Antoine Brodin freebsd_committer 2015-06-02 05:51:26 UTC
Exp-run results:

http://package18.nyi.freebsd.org/build.html?mastername=101amd64-default-D2704PR168169&build=2015-06-01_08h27m15s

The 1 new failure is not related to this change,  patch approved.
Comment 8 Marcus von Appen freebsd_committer freebsd_triage 2015-06-02 08:55:34 UTC
Just a minor change to be done:
  "Enforce the default version provided by the ports tree."
should be
  "Enforce the version required by the port or the default."
Comment 9 Marcus von Appen freebsd_committer freebsd_triage 2015-06-02 09:24:01 UTC
And while here: should not be CMAKE_ARGS+= only be set, if USES contains cmake? Just to keep the set environment clean?
Comment 10 Max Brazhnikov freebsd_committer 2015-06-02 09:45:10 UTC
(In reply to Marcus von Appen from comment #9)
> And while here: should not be CMAKE_ARGS+= only be set, if USES contains
> cmake? Just to keep the set environment clean?

Seems like overcomplication for me, besides two lines above the CONFIGURE_ENV is set unconditionally.
Comment 11 Max Brazhnikov freebsd_committer 2015-06-02 09:45:50 UTC
(In reply to Marcus von Appen from comment #8)
> Just a minor change to be done:
>   "Enforce the default version provided by the ports tree."
> should be
>   "Enforce the version required by the port or the default."

Absolutely. Will you commit the patch or you want me to do it?
Comment 12 Marcus von Appen freebsd_committer freebsd_triage 2015-06-02 10:05:41 UTC
(In reply to Max Brazhnikov from comment #11)
> (In reply to Marcus von Appen from comment #8)
> > Just a minor change to be done:
> >   "Enforce the default version provided by the ports tree."
> > should be
> >   "Enforce the version required by the port or the default."
> 
> Absolutely. Will you commit the patch or you want me to do it?

A change prior to the commit should be sufficient. No need for a separate patch in my opinion.
Comment 13 Max Brazhnikov freebsd_committer 2015-06-02 10:52:27 UTC
Created attachment 157371 [details]
Enforce the version required by the port or the default
Comment 14 Max Brazhnikov freebsd_committer 2015-06-02 10:54:27 UTC
(In reply to Marcus von Appen from comment #12)
> (In reply to Max Brazhnikov from comment #11)
> > (In reply to Marcus von Appen from comment #8)
> > > Just a minor change to be done:
> > >   "Enforce the default version provided by the ports tree."
> > > should be
> > >   "Enforce the version required by the port or the default."
> > 
> > Absolutely. Will you commit the patch or you want me to do it?
> 
> A change prior to the commit should be sufficient. No need for a separate
> patch in my opinion.

Sorry for not being clear, I was talking about the final version of the patch.
Comment 15 commit-hook freebsd_committer 2015-06-10 09:24:46 UTC
A commit references this bug:

Author: makc
Date: Wed Jun 10 09:23:54 UTC 2015
New revision: 389024
URL: https://svnweb.freebsd.org/changeset/ports/389024

Log:
  Pass the default Python version (or the version required by port)
  for CMake based ports.  By default CMake picks up the highest
  available version of Python package, therefore ports which use CMake
  may fail to build or link to different Python library than one could
  expect (e.g. bugs 199685, 200518).
  In essence this commit reverts r366996.

  PR:		168159
  Exp-run by:	antoine
  Approved by:	mva

Changes:
  head/Mk/Uses/python.mk