Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 157357

Summary: [PATCH] Add an option to portageq to provide packages that satisfy a virtual
Product: Portage Development Reporter: Petteri Räty (RETIRED) <betelgeuse>
Component: Core - External InteractionAssignee: Portage team <dev-portage>
Status: RESOLVED FIXED    
Severity: normal CC: esigra, java
Priority: High Keywords: InVCS
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 155723, 174675, 358927    
Attachments: expand new-style virtuals with `portageq match`
virtuals.py
combinations.py
combinations.py
combinations.py
use expand_new_virt function from bug 364673

Description Petteri Räty (RETIRED) gentoo-dev 2006-12-06 11:21:38 UTC
We have same java packages that provide the same API. We would like to choose from these package at merge time. Currently we hard code in implementation. If portageq provides the necessary information, our eclasses can do the rest with prioritising and all.
Comment 1 Marius Mauch (RETIRED) gentoo-dev 2006-12-06 16:26:52 UTC
Details/usage examples might help (porttree vs. vdb, old-stlye vs. new-stlye virtuals, ...)
Comment 2 Zac Medico gentoo-dev 2006-12-06 17:02:14 UTC
Maybe we can extend the portageq "match" function so that it does what you want.

Here's an example of current behavior:

$ portageq match / virtual/jdk
virtual/jdk-1.5.0
virtual/jdk-1.4.2

If we make it do a call to portage.dep_check(), and then match the results against installed package, you you get something like this instead:

dev-java/sun-jdk-1.5.0.10
virtual/jdk-1.5.0
dev-java/blackdown-jdk-1.4.2.03-r12
virtual/jdk-1.4.2

Would satisfy your needs?
Comment 3 Zac Medico gentoo-dev 2006-12-06 18:55:50 UTC
Created attachment 103508 [details, diff]
expand new-style virtuals with `portageq match`

This implements expansion of new-style virtuals as described in Comment #2.  Here are some samples of the output:

$ portageq match / virtual/jdk
virtual/jdk-1.5.0
dev-java/sun-jdk-1.5.0.10
virtual/jdk-1.4.2
dev-java/blackdown-jdk-1.4.2.03-r12

$ portageq match / virtual/jdk:1.5
virtual/jdk-1.5.0
dev-java/sun-jdk-1.5.0.10

$ portageq match / virtual/jre
virtual/jre-1.5.0
virtual/jdk-1.5.0
dev-java/sun-jdk-1.5.0.10
virtual/jre-1.4.2
virtual/jdk-1.4.2
dev-java/blackdown-jdk-1.4.2.03-r12

$ portageq match / virtual/jre:1.5
virtual/jre-1.5.0
virtual/jdk-1.5.0
dev-java/sun-jdk-1.5.0.10
Comment 4 Zac Medico gentoo-dev 2006-12-06 19:15:24 UTC
Just so that we don't change the old "match" behavior too much, I suppose we could call this one "expand_match" or something.  The only way that it should deviate from old "match" behavior is in the expansion of new-style virtuals.
Comment 5 Petteri Räty (RETIRED) gentoo-dev 2006-12-16 12:31:51 UTC
(In reply to comment #3)
> Created an attachment (id=103508) [edit]
> expand new-style virtuals with `portageq match`
> 
> This implements expansion of new-style virtuals as described in Comment #2. 
> Here are some samples of the output:
> 

Looks like I should be able to make it work with this. There's no hurry to commit this stuff until we have something working so the code is tested in practice.
Comment 6 Marius Mauch (RETIRED) gentoo-dev 2006-12-20 22:58:32 UTC
Any reason why this code should be in portageq instead of dbapi? IMO portageq should be just an API wrapper and not implement additional logic itself.
Comment 7 Zac Medico gentoo-dev 2006-12-20 23:15:17 UTC
(In reply to comment #6)
> Any reason why this code should be in portageq instead of dbapi? IMO portageq
> should be just an API wrapper and not implement additional logic itself.

I think it's fine if we make this part of the api but I don't think we should embed it into the dbapi classes.  Actually, the new portageq function that I've implemented is mostly just a wrapper around portage.dep_check() but it has a little bit of greed atoms logic too so that it behaves more like the original match function.  I think of the dbapi classes as simple package databases and I don't think logic for higher level conceptual things like virtuals should be embedded in them.  The dbapi.match() functions do support expansion of old-style viruals, but I think that was a mistake.  That feature isn't even used by portage internals, since both old and new-style virtuals are expanded internally by portage.dep_check().
Comment 8 Petteri Räty (RETIRED) gentoo-dev 2007-01-16 18:13:27 UTC
The patch does not apply to ~x86 portage any more.
Comment 9 Petteri Räty (RETIRED) gentoo-dev 2007-03-07 12:53:04 UTC
Created attachment 112401 [details]
virtuals.py

Ok. I started experimenting with this as an individual program and it does not do what I need:

betelgeuse@pena ~/python $ python virtual.py / virtual/jdk
dev-java/sun-jdk-1.4.2.13-r1
dev-java/sun-jdk-1.5.0.11
dev-java/sun-jdk-1.6.0-r1

betelgeuse@pena ~/python $ java-config -L
The following VMs are available for generation-2:
1)      IBM JDK 1.5.0.3 [ibm-jdk-bin-1.5]
2)      JamVM 1.4.5 [jamvm]
3)      Sun JDK 1.4.2.13 [sun-jdk-1.4]
*)      Sun JDK 1.5.0.11 [sun-jdk-1.5]
5)      Sun JDK 1.6.0 [sun-jdk-1.6]

There should be ibm-jdk-bin-1.5 in the output (jamvm is just a virtual/jre). I want this to list every possible thing that matches the rules.
Comment 10 Zac Medico gentoo-dev 2007-03-07 18:07:35 UTC
Unfortunately the current behavior of the dep_check() function will not satisfy your needs since it does not support greedy matching internally.  It's only designed to select a single combination of atoms, while you want all possible combinations.  I'll work on a version of virtuals.py that returns all possible combinations.
Comment 11 Zac Medico gentoo-dev 2007-03-11 06:38:52 UTC
Created attachment 112894 [details, diff]
combinations.py

This script will show all possible combinations of installed packages that satisfy a given dependency string.  I know this is a lot of code for what seems like a simple task.  In the future the portage api should include features that make a task like this much simpler.

Example results:

$ ./combinations.py virtual/jre:1.4
dev-java/blackdown-jdk-1.4.2.03-r13
dev-java/kaffe-1.1.7-r5
$ ./combinations.py virtual/jre
dev-java/sun-jdk-1.6.0-r1
dev-java/sun-jdk-1.5.0.11
dev-java/blackdown-jdk-1.4.2.03-r13
dev-java/kaffe-1.1.7-r5
Comment 12 Zac Medico gentoo-dev 2007-03-11 08:04:51 UTC
Created attachment 112907 [details]
combinations.py

This version fixes a bug in the combinations logic and adds a --test option to verify that various depstrings produce the correct number of combinations.
Comment 13 Zac Medico gentoo-dev 2007-04-03 20:39:02 UTC
Created attachment 115387 [details]
combinations.py

This version shows slot atoms instead of specific versions.
Comment 14 Zac Medico gentoo-dev 2011-05-23 08:07:26 UTC
Created attachment 274367 [details, diff]
use expand_new_virt function from bug 364673

Since bug 364673, there's an expand_new_virt() function that may be useful here. This patch uses the function to expand virtual atoms to non-virtual atoms as follows:

   portageq expand_virtual <root> <atom>
      Returns a \n separated list of atoms expanded from a
      given virtual atom, excluding blocker atoms. Satisfied
      virtual atoms are not included in the output, since
      they are expanded to real atoms which are displayed.
      Unsatisfied virtual atoms are displayed without
      any expansion. The "match" command can be used to
      resolve the returned atoms to specific installed
      packages.

Example input/output:

$ portageq expand_virtual / virtual/jre
=dev-java/sun-jdk-1.6.0*

$ portageq expand_virtual / virtual/jre:1.5
dev-java/gcj-jdk
Comment 15 Zac Medico gentoo-dev 2011-06-02 13:07:53 UTC
(In reply to comment #14)
> Created attachment 274367 [details, diff]
> use expand_new_virt function from bug 364673

This is in git now:

http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1edf9e3bd37fede61a21d3b6a84542d29d8f3021
Comment 16 Zac Medico gentoo-dev 2011-06-06 13:00:38 UTC
This is fixed in 2.1.10 and 2.2.0_alpha38.