Page MenuHomeFreeBSD

Mk/bsd.port.{subdir}.mk: create describe-json
ClosedPublic

Authored by fernape on Oct 9 2023, 12:49 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 25, 3:16 AM
Unknown Object (File)
Sun, Dec 1, 10:50 AM
Unknown Object (File)
Fri, Nov 29, 9:28 PM
Unknown Object (File)
Nov 25 2024, 10:05 PM
Unknown Object (File)
Nov 25 2024, 6:21 PM
Unknown Object (File)
Nov 24 2024, 12:48 AM
Unknown Object (File)
Nov 22 2024, 5:18 PM
Unknown Object (File)
Nov 21 2024, 6:54 AM
Subscribers
None

Details

Summary

Create describe-json target to get a JSON-compliant representation of the
ports tree.

It can be invoked from a single port directory, a category directory or from the
ports tree top directory.

It supports FLAVORS. E.g. It is possible to execute the following:

cd math/qalculate-qt && make describe-json-qt6

Performance-wise it is a bit slower than a simple make describe although it
offers a more complete vision of the port in an easily parseable format.

Test Plan

Apply patch and run "make describe-json", possibly redirecting to a file. A sample of such a file generated from my ports tree can be found here

Some examples assuming the output is in the describe.json file.

  • Show all ports in the "accessibility" category:
jq '.accessibility'
  • Show ports in the "accessibility" category with a USES=iconv dependency:
jq '.accessibility.[] | select(.uses | index("iconv")) | .pkgorigin' describe.json
  • Show ports in the tree that Uses=kmod:
jq '.[].[] | select(.uses | index("kmod")) | .pkgorigin' describe.json
  • Show ports having a LIB_DEPENDS on devel/binutils:
jq '.[].[] | select(.lib_depends | map(test("devel/binutils")) | any) | .pkgorigin' describe.json
  • Show ports in the "database" category which has no maintainer and are marked as deprecated:
jq '.databases.[] | select(.maintainer=="ports@FreeBSD.org" and .deprecated!="") | .pkgorigin' describe.json

Diff Detail

Repository
R11 FreeBSD ports repository
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 54028
Build 50918: arc lint + arc unit

Event Timeline

fernape created this revision.
fernape edited the test plan for this revision. (Show Details)
fernape added reviewers: bapt, portmgr.

am I missing something, I do not see the definition of SED_ARGS ?

In D42131#961439, @bapt wrote:

am I missing something, I do not see the definition of SED_ARGS ?

Damn, sorry for that. I moved all substitutions from sed(1) to make(1)'s variable modifiers and embarrassingly forgot to remove the command altogether.

Mk/bsd.port.mk
4412

each of those line will spawn a new sh process, so this won't be efficient, you should probably inline all of this, with ; \ at the end of each line,

otherwise it will ve very slow to make at the root of the ports tree a make describe-json

Address bapt@ feedback

  • Don't spawn a new sh process for every ECHO_CMD

While here:

  • Prettyfy code
  • Prefix private variables with underscore
  • Fix flavors
fernape added inline comments.
Mk/bsd.port.mk
4412

One sh with multiple echo commands, thanks!

While here, make the code more readable, prefix private variables with underscore and fix flavors.
make describe-json creates JSON-compliant output from the top of the tree, a category directory or an individual port directory.

It lacks informations about the licenses ;), but the technical part is ok, and license can be added later

This revision is now accepted and ready to land.Oct 18 2023, 7:18 AM
In D42131#964377, @bapt wrote:

It lacks informations about the licenses ;), but the technical part is ok, and license can be added later

Yup! you're right. That's important information.
I just added it as a list, since some ports have multiple licenses.
This is an example for audio/picard-plugins.

...
  "categories": [
    "audio",
    "python"
  ],
  "license": [
    "GPLv2+",
    "GPLv3+",
    "MIT",
    "WTFPL"
  ],
  "deprecated": " ",
  "broken": "",
  "distversion": "2.0.20230915",
...

It generates the whole ports tree.
If you don't say otherwise, I'll go with that version.

diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index fc02b52821ac..6b3522d559a0 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -4428,6 +4428,7 @@ describe-json:
        ${ECHO_CMD} \"pkg_depends\":[\"${PKG_DEPENDS:ts,:Q:S/,/\",\"/g}\"], ;\
        ${ECHO_CMD} \"complete_options_list\":[\"${COMPLETE_OPTIONS_LIST:ts,:S/,/\",\"/g}\"], ;\
        ${ECHO_CMD} \"categories\":[\"${CATEGORIES:ts,:S/,/\",\"/g}\"], ;\
+       ${ECHO_CMD} \"license\":[\"${LICENSE:ts,:S/,/\",\"/g}\"], ;\
        ${ECHO_CMD} \"deprecated\":\""${DEPRECATED:S/"/\\\"/g:S/\\\\*/*/g:S/\\\'/'/g}" \", ;\
        ${ECHO_CMD} \"broken\":\"${BROKEN:Q:S/"/\\\"/g:S/\\\\*/*/g:S/\\\'/'/g}\", ;\
        ${ECHO_CMD} \"distversion\":\"${DISTVERSION}\", ;\

Committed with the license info added.

Thanks for the review!