Programmatically set variants from a list

Joshua Root jmr at macports.org
Wed May 8 12:31:53 UTC 2019


On 2019-5-8 22:10 , Ruben Di Battista wrote:
> Hello, 
> I’m trying to set paraview python variants programmatically (each of
> them conflicts with the others). I’m not a TCL ninja so I came out with
> the code below, but I’m getting error of the type: "Warning: Variant
> python27 conflicts with non-existing variant python35 python36 python37”
> for all the variant combinations. How do I set variants programmatically?
>  
> 
> ```
> # Supported pythons
> set python_versions {27 35 36 37}
> 
> foreach pyver ${python_versions} {
>     # Conflicting python versions
>     set other_python_versions {}
>     foreach other_pyver ${python_versions} {
>         if {${other_pyver} ne ${pyver}} {
>             if {${other_pyver} ni ${other_python_versions}} {

This check shouldn't be needed.

>                 lappend other_python_versions python${other_pyver}
>                 }
>             }
>     }
> 
>     # Get python branch
>     set python_branch {[string range ${pyver} 0 end-1].[string index
> ${pyver} end]}
> 
>     variant python${pyver} conflicts [join ${other_python_versions} " "]
> description {Add Python ${python_branch} support.} {

Two things: the result of [join ${other_python_versions} " "] is a
single string, and it is being passed to the 'variant' command as a
single argument. That is, you're saying that e.g. the python27 variant
conflicts with a single variant called "python35 python36 python37". You
need to use the {*} operator to split the list in
${other_python_versions} into multiple args.

Also, you need to use double quotes, not braces, around the variant body
and description, because braces disable substitution and you want
${pyver} and ${python_branch} to be substituted.

variant python${pyver} conflicts {*}${other_python_versions} description
"Add Python ${python_branch} support" "

>             depends_lib-append port:py${pyver}-matplotlib
>             configure.args-append \
>                 -DPARAVIEW_ENABLE_PYTHON:BOOL=ON \
>                 -DPYTHON_EXECUTABLE=${prefix}/bin/python${python_branch} \
>                
> -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/${python_branch}/Headers/
> \
>                
> -DPYTHON_LIBRARY=${prefix}/lib/libpython${python_branch}.dylib
> 
>             if {[mpi_variant_isset]} {
>                 depends_lib-append port:py${pyver}-mpi4py
>                 configure.args-append \
>                     -DVTK_USE_SYSTEM_MPI4PY:BOOL=ON
>             }
>     }

^ Needs to be the closing double quote, naturally.

>     
> }

There are a number of ports that do this sort of thing that you can look
at as examples. gdb is one that I know of.

 - Josh


More information about the macports-dev mailing list