Portfile parsing

Ryan Schmidt ryandesign at macports.org
Wed Nov 26 05:30:25 PST 2014


On Nov 26, 2014, at 7:12 AM, Artur Szostak wrote:

> 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?

"port info" can be used to obtain some information from a port, and flags can be used to affect how the output is presented; some outputs lend themselves to be fed to other tools.

Examples:


$ port info --name --version --revision --depends libpng
depends_build: 
version: 1.6.15
depends_run: 
revision: 0
depends_fetch: 
depends_lib: port:zlib
depends_extract: bin:xz:xz
name: libpng


$ port -q info --name --version --revision --depends libpng

1.6.15

0

port:zlib
bin:xz:xz
libpng


$ port info --line --name --version --revision --depends libpng
	1.6.15		0		port:zlib	bin:xz:xz	libpng


If that's not enough, take a look at the PortIndex2MySQL.tcl script we use to get port information into the database that powers our web site.



More information about the macports-dev mailing list