Page MenuHomeFreeBSD

pkgconf: determine the default paths dynamically
AcceptedPublic

Authored by khorben on Tue, May 26, 1:59 PM.
Tags
None
Referenced Files
F160320963: D57246.diff
Tue, Jun 23, 6:13 AM
F160297494: D57246.id179062.diff
Tue, Jun 23, 1:07 AM
Unknown Object (File)
Sat, Jun 20, 9:21 PM
Unknown Object (File)
Tue, Jun 9, 1:07 PM
Unknown Object (File)
Tue, Jun 9, 1:03 PM
Unknown Object (File)
Tue, Jun 9, 7:28 AM
Unknown Object (File)
Tue, Jun 9, 7:24 AM
Unknown Object (File)
Tue, Jun 9, 4:19 AM
Subscribers

Details

Summary

This computes the correct LOCALBASE from the environment or from the "user.localbase" sysctl, in this order.

Sponsored by: The FreeBSD Foundation

Test Plan

Tested as follows:

$ sysctl user.localbase
user.localbase: /usr/local
$ pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /usr/local/libdata/pkgconfig:/usr/libdata/pkgconfig:/usr/local/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib
$ LOCALBASE=/opt/vendor pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /opt/vendor/libdata/pkgconfig:/usr/libdata/pkgconfig:/opt/vendor/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib
$ sudo sysctl -w user.localbase=/opt/vendor2
user.localbase: /usr/local -> /opt/vendor2
$ pkgconf --dump-personality
Triplet: default
DefaultSearchPaths: /opt/vendor2/libdata/pkgconfig:/usr/libdata/pkgconfig:/opt/vendor2/share/pkgconfig
SystemIncludePaths: /usr/include
SystemLibraryPaths: /usr/lib

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

contrib/pkgconf/libpkgconf/personality.c
109

Reading this again, I think this code will never be reached, so we wouldn't even need -DLOCALBASE=... in CFLAGS.

This update takes care of PERSONALITY_PATH in addition to PKG_DEFAULT_PATH.

khorben edited the test plan for this revision. (Show Details)
contrib/pkgconf/libpkgconf/personality.c
96

Just use a stack buffer. The result will never be longer than MAXPATHLEN including the terminating null character.

117

It seems odd to use err() here, how does the rest of pkgconf deal with string handling failures?

Use a stack buffer of MAXPATHLEN for localbase, as suggested by @des.

contrib/pkgconf/libpkgconf/personality.c
117

Interestingly, I just identified two similar functions that use malloc(), check for errors, and report them: bool pkgconf_buffer_append_fmt() and bool pkgconf_buffer_append_vfmt() (true is success, false is error). But then when called from build_default_search_path() (the same place we are patching) possible errors are ignored, and the result inconsistent. I don't think there's much risk there so we could probably do the same... 🤔

contrib/pkgconf/libpkgconf/personality.c
96

this snprintf() is pointless, I would do the reverse: add str = localbase; to the other branch and pass str to pkgconf_buffer_append() below. You may want to rename localbase to buf and str to localbase.

Simplified the code obtaining LOCALBASE as per @des' suggestion. (Thanks!)

contrib/pkgconf/libpkgconf/personality.c
96
99

redundant braces

393
396

redundant braces

des requested changes to this revision.Fri, May 29, 10:00 PM

please mark obsolete comments as done and fix the remaining four issues

contrib/pkgconf/libpkgconf/personality.c
99

redundant

396

redundant

This revision now requires changes to proceed.Fri, May 29, 10:00 PM
khorben edited the summary of this revision. (Show Details)

Remove redundant code, as suggested by des@. (Thanks!)

khorben marked 6 inline comments as done and an inline comment as not done.Mon, Jun 1, 4:04 PM
khorben marked 2 inline comments as done.
This revision is now accepted and ready to land.Tue, Jun 2, 8:34 AM