Portfile parsing
Joshua Root
jmr at macports.org
Wed Nov 26 05:35:44 PST 2014
On 2014-11-27 00:12 , Artur Szostak wrote:
> Dear MacPorts developers,
>
> I want to extract various information from Portfiles, such as names, versions, revisions, dependencies etc. I want to do so without writing another parser. Is there a reasonably stable API I could use? or, since Portfiles are partial Tcl scripts, what set of "package require" statements would I need to successfully parse the Portfile in tclsh?
A lot of this is available from the command line, e.g.
port info --version <someport>
(you can use --index too to make it fast at the expense of not taking
variants into account)
If you need something that isn't available this way, you first have to
look up the port:
$ port-tclsh
% package require macports
1.0
% mportinit
% set entry [mportlookup postfix]
postfix {variants {pcre tls sasl ldap mysql5 mysql51 mysql55 mysql56
mariadb percona postgresql83 postgresql84 postgresql90 postgresql91
postgresql92 dovecot_sasl universal} portdir mail/postfix description
{Fast and robust mail transfer agent} homepage http://www.postfix.org/
epoch 0 platforms darwin name postfix long_description {Postfix attempts
to be fast, easy to administer, and secure, while at the same time being
sendmail-compatible enough to not upset existing users. It also offers
QMQP and VERP support to let Postfix act as delivery daemon for
ezmlm-idx.} maintainers {jmr openmaintainer} license IBMPL-1 categories
mail version 2.11.3 revision 0 porturl
file:///Users/josh/Coding/dports-dev/svn/dports/mail/postfix}
% array set portinfo [lindex $entry 1]
% array names portinfo
porturl variants portdir description homepage epoch platforms name
long_description maintainers license categories version revision
% puts $portinfo(version)
2.11.3
0
If the info you need is in the index, that's all you need to do. If not,
you have to open the portfile. Here I'll open postfix with the tls
variant, which adds an openssl dependency. (There are no dependencies
listed in the index in this case because it only has info about the port
with its default variants selected.)
% set mport [mportopen $portinfo(porturl) [list] [list tls +]]
ditem_1
% array unset portinfo
% array set portinfo [mportinfo $mport]
% array names portinfo
variants canonical_active_variants active_variants variant_desc
description homepage epoch platforms depends_lib name notes vinfo
long_description maintainers license categories version revision
% puts $portinfo(depends_lib)
port:openssl
0
If what you need isn't provided by mportinfo either, you can use _mportkey:
% _mportkey $mport patchfiles
patch-sys_defs.h patch-mail_params.h patch-postfix-install patch-makedefs
You may have to double quote variable names that contain characters that
require quoting:
% _mportkey $mport {{configure.compiler}}
clang
- Josh
More information about the macports-dev
mailing list