inconsistency in basedir spec install in $datadir, search elsewhere

Jan Tojnar jtojnar at gmail.com
Wed Aug 28 05:32:36 UTC 2024


On Tue, 2024-08-27 at 23:27 +0200, Patrice Dumas wrote:
> Hello,

Hi,


> As a consequence, if
>  - $XDG_DATA_DIRS is set
>                          and $datadir is not in $XDG_DATA_DIRS
>  - or $XDG_DATA_DIRS is unset
>                          and $datadir is not /usr/local/share/
>                          nor /usr/share/
> a search for the file installed in the specified $datadir directory
> will
> necessarily fail.
> 
> I find that difference between the datadir specified for the
> installation
> and the directories used for the search strikingly weird.

Yes, since `$datadir` can be set by user to an arbitrary path
(typically by passing a `--datadir` flag to `./configure`), it can
indeed happen that the project will be installed to a location that is
not on `XDG_DATA_DIRS` and thus, for example, its desktop files will
not be found by the environment. [1]

But, in the end, I agreee with John that the selection of installation
paths and environment variables and ensuring consistency (if desired)
is the responsibility of the environment (e.g. a Linux distribution).

In fact, it is somewhat common in Linux distros that the installation
of a project during the creation of a package is performed to a
location that is **not** on global `XDG_DATA_DIRS` path. Typically,
package creation employs some kind of `chroot`-like mechanism or
`DESTDIR` environment variable to install the project into an isolated
prefix, and then records the output files. Ensuring that the package
data can be actually found is then only done when the package is
installed to the system by a package manager.

Cheers,

Jan

[1]: If execution of a program installed in such inconsistent
environments is anticipated (e.g. for development), it might be a good
idea for the project to hardcode `$datadir` path at build time, so
that, at runtime, it can search for its data there in addition to
`$XDG_DATA_DIRS`. Alternately, the development environment may want to
provide a task runner command that sets environment variables
appropriately (e.g. `make run-uninstalled` or `meson devenv`).



More information about the xdg mailing list