If I have something of the form "<port>-<version>", is there a reliable way to determine the corresponding "<category>/<port>"? For example, given
Importantly, I'd like to be able to do this regardless of whether the port/package is installed, so (I think?)
It can be assumed that the only "<port>-<version>" strings that will be used as input are things that actually could be built given the current state of
I also don't need flavors taken into account. For example, it will never be asked to resolve
It seems easy to get something that will often work, by doing something like getting
pkg-1.19.1_1, I'd like to get ports-mgmt/pkg.Importantly, I'd like to be able to do this regardless of whether the port/package is installed, so (I think?)
pkg info doesn't answer the question.It can be assumed that the only "<port>-<version>" strings that will be used as input are things that actually could be built given the current state of
/usr/ports and whatnot. In fact, even beyond that, I don't really care about "<version>" at all (unless it is somehow actually needed in order to determine "<category>/<port>". That is, for example, I'd want any of pkg-1.2.1, pkg-1.19.1_1, and pkg-438.65.92_234 to all resolve to ports-mgmt/pkg.I also don't need flavors taken into account. For example, it will never be asked to resolve
py-setuptools@py39-63.1.0 (or whatever the format is); it would instead be asked to resolve py39-setuptools-63.1.0.It seems easy to get something that will often work, by doing something like getting
pkg from pkg-1.19.1_1 and then scanning /usr/ports/ for directories of the form "<category>/pkg/", but there are several problems (or at least potential problems, given my ignorance) with this:- Port names can contain hyphens, numbers, and periods, and I'm not sure that versions cannot contain (say) hyphens. Is it definitely the case that the very last hyphen is what separates <port> from <version>?
- A port can be in more than one category. Is there a concept of a "canonical" category for a port, and if so, can it be algorithmically determined which category that is? I notice that although (e.g.)
python39is in bothlangandpython, there is no/usr/ports/python/directory. However, I don't know that it is always the case that a port cannot be in more than one category having a corresponding/usr/ports/subdirectory. - Similar potential issue: Is it possible for two entirely different ports to have the same port name (in different categories)? For example,
deli/submarineandnavy/submarine? - Is it even necessarily the case that the "<port>" in "<port>-<version>" is the same as the "<port>" in the "<category>/<port>" subdirectory of
/usr/portsthat would be used to build it in the first place?