I am writing a Perl version of Gentoo Linux's Portage package management tool just for the heck of it (and I think I can do it better (yes, I am full of myself ;) )). I already have a good portion of the program done except for the main part: building the dependency tree.
My program can currently:
* read Portage's configuration files and environment variables
* parse an ebuild (file that describes the way a package is built and installed) to get the dependency information
* parse the dependency string taking into account USE flags (determine which optional components get built for certain packages)
* take a dependency string such as 'x11-base/xfree', '>=net-fs/samba-2.3', etc. and return a list of candidate versions in the Portage tree (directory structure containing ~80,000 ebuilds taking into account masked packages
* determine the highest version of a particular package from a list of available package versions
* determine if a certain version of a certain package is already installed
I plan on writing a function that will get the dependency information for a certain package, check the dependencies for those dependencies, and so on down the line. I'd have a structure like:
mainpackage-1.0
|--dependency1-1.3
| ---dep1_of_dep1
|--dependency2-2.3
| ---dep1_of_dep2
| ---dep2_of_dep2
| ---dep3_of_dep2
|--dependency3
where each dependency is a string in the form of 'x11-base/xfree', '>=net-fs/samba-2.3', etc. What I can't figure out is how to take that structure and turn it into a list that looks something like:
dep1_of_dep1
dependency1-1.3
dep1_of_dep2
dep2_of_dep2
dep3_of_dep2
dependency2-2.3
dependency3
mainpackage-1.0
Generating the above would be pretty simple, but it isn't so simple to take into account packages that have dependencies on different version ranges than another package (one package having '>somepackage-3.4' and another '<somepackage-4.5') and all that other fun dependency stuff. Can anyone give me a few pointers?