declaring variants/subports in loops and loop variables
René J.V. Bertin
rjvbertin at gmail.com
Wed Dec 7 17:42:57 CET 2016
On Thursday December 08 2016 04:04:57 Joshua Root wrote:
> This is almost exactly the same situation as:
>
> foreach foo {bar baz} {
> proc p_$foo {} {
> puts $foo
> }
> }
> p_bar
> p_baz
Huh? This complains about foo not being known, I think there should be a `global foo` in that procedure?
> (Variants are slightly different only in that they
> automagically bring all global variables into scope. Thus you get pv
> with its current value instead of a "no such variable" error.)
I was expecting something like that but apparently this is not achieved via uplevel in `proc variant`?
Josh, I think you're the in-house Tcl guru. Out of curiosity, would it be feasible to write a foreach wrapper that makes limits the lifetime of the loop variable and all newly declared variables to the loop scope (like in C/C++)? And would such a wrapper be useful in the kind of context at hand (or would it have too many unwanted side-effects)?
> That sounds overly complicated (there should be almost no reason to use
> eval, ever.) Quotes instead of braces would allow variable substitution
> in the variant body.
I also spoke too soon that it did the trick. I'm using configure.args-{delete,replace,append} in the variant, and this doesn't work properly.
Still referring to the opencv Portfile from the referenced trac ticket, if I do
{{{
eval [subst {
variant python${pv} conflicts ${conflist} description "Add bindings for Python ${pdv}" {
patchfiles-delete patch-modules_python_CMakeLists.txt.diff
configure.args-delete \
-DINSTALL_PYTHON_EXAMPLES=OFF \
-DBUILD_opencv_python3=OFF
depends_lib-append port:python${pv} \
port:py${pv}-numpy
if {![variant_isset python27]} {
configure.args-replace \
-DPYTHON_EXECUTABLE=OFF \
-DPYTHON_EXECUTABLE=${prefix}/bin/python${pdv}
}
configure.args-append \
-DINSTALL_PYTHON_EXAMPLES=ON \
-DPYTHON3_EXECUTABLE=${prefix}/bin/python${pdv} \
-DPYTHON3_LIBRARY=${frameworks_dir}/Python.framework/Versions/${pdv}/lib/libpython${pdv}.dylib \
-DPYTHON3_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/${pdv}/Headers \
-DPYTHON3_PACKAGES_PATH=${frameworks_dir}/Python.framework/Versions/${pdv}/lib/python${pdv}/site-packages
ui_msg "${configure.args}"
}
}]
}}}
I get
{{{
%> port info opencv +python34
-DCMAKE_BUILD_TYPE=MacPorts -DWITH_1394=OFF -DWITH_CARBON=OFF -DWITH_VTK=OFF -DWITH_CUDA=OFF -DWITH_CUFFT=OFF -DWITH_CUBLAS=OFF -DWITH_EIGEN=OFF -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_IPP=OFF -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_WEBP=ON -DWITH_OPENEXR=ON -DWITH_OPENGL=ON -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DWITH_PNG=ON -DWITH_PVAPI=OFF -DWITH_GIGEAPI=OFF -DWITH_QT=OFF -DWITH_QUICKTIME=OFF -DWITH_TBB=OFF -DWITH_OPENMP=OFF -DWITH_CSTRIPES=OFF -DWITH_PTHREADS_PF=OFF -DWITH_TIFF=ON -DWITH_UNICAP=OFF -DWITH_V4L=OFF -DWITH_LIBV4L=OFF -DWITH_XIMEA=OFF -DWITH_XINE=OFF -DWITH_CLP=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_INTELPERC=OFF -DWITH_IPP_A=OFF -DWITH_VA=OFF -DWITH_VA_INTEL=OFF -DWITH_GDAL=OFF -DWITH_GPHOTO2=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_opencv_apps=ON -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_WITH_DYNAMIC_IPP=OFF -DBUILD_ZLIB=OFF -DBUILD_TIFF=OFF -DBUILD_JASPER=OFF -DBUILD_JPEG=OFF -DBUILD_PNG=OFF -DBUILD_OPENEXR=OFF -DBUILD_TBB=OFF -DPYTHON_EXECUTABLE=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DENABLE_PRECOMPILED_HEADERS=ON -DENABLE_SSSE3=ON -DWITH_AVFOUNDATION=ON -DZLIB_LIBRARY=/opt/local/lib/libz.dylib -DBZIP2_LIBRARIES=/opt/local/lib/libbz2.dylib
opencv @3.1.0_5 (graphics, science)
Variants: avx, avx2, contrib, dc1394, debug, eigen, gdal, java, opencl, openni, python27, +python34, python35, qt4, qt5,
tbb, universal, vtk
Description: OpenCV is a library that is mainly aimed at real time computer vision. Some example areas would be
Human-Computer Interaction (HCI), Object Identification, Segmentation and Recognition, Face Recognition,
Gesture Recognition, Motion Tracking, Ego Motion, Motion Understanding, Structure From Motion (SFM), and
Mobile Robotics.
Homepage: http://opencv.org
Extract Dependencies: unzip
Build Dependencies: cmake, pkgconfig
Library Dependencies: zlib, bzip2, libpng, jpeg, jasper, tiff, webp, ilmbase, openexr, ffmpeg, python34, py34-numpy
Platforms: darwin
License: BSD
Maintainers: Email: stromnov at macports.org
Policy: openmaintainer
}}}
I should be seeing this argument list:
{{{
-DCMAKE_BUILD_TYPE=MacPorts -DWITH_1394=OFF -DWITH_CARBON=OFF -DWITH_VTK=OFF -DWITH_CUDA=OFF -DWITH_CUFFT=OFF -DWITH_CUBLAS=OFF -DWITH_EIGEN=OFF -DWITH_FFMPEG=ON -DWITH_GSTREAMER=OFF -DWITH_GTK=OFF -DWITH_IPP=OFF -DWITH_JASPER=ON -DWITH_JPEG=ON -DWITH_WEBP=ON -DWITH_OPENEXR=ON -DWITH_OPENGL=ON -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DWITH_PNG=ON -DWITH_PVAPI=OFF -DWITH_GIGEAPI=OFF -DWITH_QT=OFF -DWITH_QUICKTIME=OFF -DWITH_TBB=OFF -DWITH_OPENMP=OFF -DWITH_CSTRIPES=OFF -DWITH_PTHREADS_PF=OFF -DWITH_TIFF=ON -DWITH_UNICAP=OFF -DWITH_V4L=OFF -DWITH_LIBV4L=OFF -DWITH_XIMEA=OFF -DWITH_XINE=OFF -DWITH_CLP=OFF -DWITH_OPENCL=OFF -DWITH_OPENCL_SVM=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_INTELPERC=OFF -DWITH_IPP_A=OFF -DWITH_VA=OFF -DWITH_VA_INTEL=OFF -DWITH_GDAL=OFF -DWITH_GPHOTO2=OFF -DBUILD_SHARED_LIBS=ON -DBUILD_opencv_apps=ON -DBUILD_DOCS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PACKAGE=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_WITH_DYNAMIC_IPP=OFF -DBUILD_ZLIB=OFF -DBUILD_TIFF=OFF -DBUILD_JASPER=OFF -DBUILD_JPEG=OFF -DBUILD_PNG=OFF -DBUILD_OPENEXR=OFF -DBUILD_TBB=OFF -DPYTHON_EXECUTABLE=/opt/local/bin/python3.4 -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DENABLE_PRECOMPILED_HEADERS=ON -DENABLE_SSSE3=ON -DWITH_AVFOUNDATION=ON -DZLIB_LIBRARY=/opt/local/lib/libz.dylib -DBZIP2_LIBRARIES=/opt/local/lib/libbz2.dylib -DINSTALL_PYTHON_EXAMPLES=ON -DPYTHON3_EXECUTABLE=/opt/local/bin/python3.4 -DPYTHON3_LIBRARY=/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4.dylib -DPYTHON3_INCLUDE_DIR=/opt/local/Library/Frameworks/Python.framework/Versions/3.4/Headers -DPYTHON3_PACKAGES_PATH=/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
}}}
So, back to simply using
{{{
variant python${pv} conflicts ${conflist} description "Add bindings for Python ${pdv}" {
patchfiles-delete patch-modules_python_CMakeLists.txt.diff
configure.args-delete \
-DINSTALL_PYTHON_EXAMPLES=OFF \
-DBUILD_opencv_python3=OFF
}
# settings that depend on loop variables must be set in an appropriate if, not in the
# variant declaration scope.
if {[variant_isset python${pv}]} {
depends_lib-append port:python${pv} \
port:py${pv}-numpy
# snip
}}}
R.
More information about the macports-dev
mailing list