Skip to content

Conversation

@nanorkyo
Copy link
Contributor

This PR adds support for evaluating complex attributes (multiline variables like dependencies, categories, etc.) within the pkg query -e evaluation strings.

Previously, it was not possible to filter packages based on list-type attributes directly in the query evaluation. This change allows users to perform queries such as finding packages that depend on a specific library or belong to a certain category.

Changes

  • src/query.c: Implemented SQL subquery generation using EXISTS / NOT EXISTS operators to support list attributes.
  • docs/pkg-query.8: Updated documentation to describe the new "Multiline variables" in the Evaluation Format section, including examples.
  • tests/frontend/query.sh: Added regression tests for dependency query evaluation (= and !=).

Supported Attributes

The following attributes are now supported in evaluation strings:

  • %d[nov]: Dependencies (Name, Origin, Version)
  • %r[nov]: Reverse dependencies (Name, Origin, Version)
  • %C: Categories
  • %L: Licenses
  • %B: Required shared libraries
  • %b: Provided shared libraries
  • %A[tv]: Annotations (Tag, Value)

Example Usage

List packages that depend on python312:
pkg query -e '%dn = "python312"' %o

List packages that do not depend on curl:
pkg query -e '%dn != "curl"' %o

Note

The following attributes were intentionally omitted as their use cases in evaluation strings are unclear:

  • Files (%F)
  • Directories (%S, %D)
  • Options (%O)
  • Users/Groups (%U, %G)

Add support for querying complex attributes (lists) in the evaluation
string mechanism. This includes:

- %d[nov]: Dependencies (Name, Origin, Version)
- %r[nov]: Reverse dependencies (Name, Origin, Version)
- %C: Categories
- %L: Licenses
- %B: Shared libraries required
- %b: Shared libraries provided
- %A[tv]: Annotations (Tag, Value)

These are implemented by generating subqueries using EXISTS/NOT EXISTS
operators in the resulting SQL.

The following fields are not implemented as their use cases are unclear:
- %F[psugmftl]: the list of files
- %S[pugmf]: the list of (sub-)directories
- %O[kvdD]: the list of options
- %U: the list of users needed
- %G: the list of groups needed
Add regression tests to verify the behavior of evaluating dependency
attributes (%dn) in query expressions.
- Test exact match (=)
- Test inequality (!=)
Update pkg-query(8) to include documentation for the newly supported
multiline variables in evaluation expressions.
- Split variables into 'Normal Variables' and 'Multiline variables'
- Add description and example for multiline variable evaluation (e.g., %dn)
- List supported multiline variables: %d, %r, %C, %L, %B, %b, %A
@bapt
Copy link
Member

bapt commented Jan 16, 2026

it does not help me burry the sql deep down in the libpkg, but it is a nice feature ! thank you I'll review ASAP.

@bapt bapt merged commit 485013e into freebsd:main Jan 16, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants