Programmatically finding dependencies for a Portfile

Joshua Root jmr at macports.org
Thu May 28 07:02:31 PDT 2015


On 2015-5-28 22:44 , Artur Szostak wrote:
> Hi,
> 
> Given a Portfile, I am trying to programmatically find all of its direct dependencies. My approach is to execute an appropriate TcL script in port-tclsh to produce a listing of such dependencies. I am able to handle Portfiles with the example script indicated below, but only for Portfiles that do not have any subports. It is not clear to me how to handle dependencies for subports. The structure returned by mportinfo seems to only have a list of subport names, not their dependencies.
> _______________________________________________________
> package require macports
> mportinit
> set mport [mportopen "file:///tmp/testport" [list] [list]]
> array unset portinfo
> array set portinfo [mportinfo $mport]
> mportclose $mport
> array set depsdict {depends_build build depends_lib lib depends_run run}
> foreach deptype [array names depsdict] {
>     if {[info exists portinfo($deptype)] && \
>         [string length $portinfo($deptype)] > 0} \
>     {
>         foreach dependency $portinfo($deptype) {
>             puts "$depsdict($deptype) $dependency"
>         }
>     }
> }
> _______________________________________________________
> 
> How can I access the dependencies for the subports?

<https://trac.macports.org/browser/trunk/base/src/port/port.tcl#L2935>

If you must find the list of subports that exist directly from the
Portfile (rather than use the index), you need to first open it under
the top-level name and look at $portinfo(subports).

- Josh


More information about the macports-dev mailing list