registry.db and depends

Bradley Giesbrecht pixilla at macports.org
Sun Sep 16 14:29:06 PDT 2012


Sharing Clemens nice reply with the dev list.

On Sep 15, 2012, at 2:11 PM, Clemens Lang wrote:

>> Do you know how port keeps track of non-port dependencies like path:,
>> lib: or bin:?
>> 
>> Example: depends_lib path:bin/mysql_config5:mysql5
>> 
>> Looking in regiestry.db I see the dependencies table has the name
>> field of the dependent port.
>> 
>> $ mp-sqlite-registry "select t2.name from ports t1 join dependencies
>> t2 on t1.id = t2.id where t1.state = 'installed' and t1.name =
>> 'p5.12-dbd-mysql';"
>> perl5.12
>> p5.12-dbi
>> mysql5
>> 
>> Does port translate path:bin/mysql_config5 to something like "port
>> provides bin/mysql_config5" and register that?
> 
> Yes, all non-port-style dependencies are resolved at install time and
> recoded with the port currently resolving the dependency into the
> registry. So, when depending on path:bin/mysql_config5:mysql5 the
> installation of the port might actually depend on mysql55.
> 
>> I was wanting to experiment with depending on files in
>> prefix/var/macports/software.
>> 
>> My interest is improving the methods for testing if a port is active
>> with required archs and variants.
>> 
>> If things have not changed; currently we find a file only installed by
>> a variant and use the archcheck portgroup.
> 
> I think the architecture part should be already correctly handled if the
> dependency is in depends_build or depends_lib and not in the list
> variable depends_skip_archcheck. To check whether a specific port is
> installed with some variant it might be better to use the registry
> interface available in the portfile, e.g.
> 
> # registry_active comes from a list of aliased procedures in
> # macports1.0/macports.tcl, line 1238 - 1303.
> #
> # It actually calls registry::active, which is defined in
> # registry2.0/registry.tcl, line 173 and does some error handling plus
> # passing the call to the appropriate registry backend (flat file or
> # sqlite).
> #
> # In the SQLite case the call goes to registry2.0/receipt_sqlite.tcl,
> # line 45, proc active, which in turn calls registry::entry installed
> # $name, which comes from registry2.0/entry.c, line 387. I won't dig
> # deeper than that, since that's as far as we need to go to handle this
> # correctly.
> #
> # When looking at registry2.0/receipt_sqlite.tcl, line 53 and following,
> # we can see the structure returned by this call: it's a list of
> # registry entries (in the case of active, there can only be one, since
> # there can never be multiple versions of the same port active at the
> # same time). This explains the [lindex $active_list 0] in the following
> # block.
> if {[catch {set installed [lindex [registry_active port-to-check-against] 0]}] == 0} {
> 	# In this list, we have, in order: name, version, revision,
> 	# variants, a boolean indicating whether the port is installed and
> 	# the epoch. So, we're interested in the field at offset 3.
> 	set installed_variants [lindex $installed 3]
> 
> 	# From what I see, the variants are put into the database in a
> 	# canonical format, i.e. no negative variants and in alphabetic
> 	# order (and even if they were not, there's canonicalize_variants in
> 	# port1.0/portutil.tcl, line 1921 we could call). So all we need to
> 	# do now, is check whether a specific variant is in this list. You
> 	# can have a look at port1.0/portutil.tcl, line 1816, proc
> 	# check_statefile_variants that does similar variant handling (it
> 	# compares all variants, you'd probably only want to check for the
> 	# presence of a single variant).
> }
> 
> Ideally, you could turn this into a portgroup for easier use, e.g.,
> 
> PortGroup active_with_variants 1.0
> 
> if {[active_with_variants portname {python27 debug}]} {
> 	# execute this if portname is active with +python27+debug
> }
> 
> P.S.: Feel free to repost this to the list, it might be useful to
> someone.
> 
> HTH,
> -- 
> Clemens

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2763 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macports-dev/attachments/20120916/b413c07a/attachment.p7s>


More information about the macports-dev mailing list