Conan: Follow XDG Base Directory Specification

Created on 26 Feb 2018  路  7Comments  路  Source: conan-io/conan

conan shouldn't create a $HOME/.conan directory and use $XDG_CONFIG_HOME/conan instead, following the XDG Base Directory Specification. This can nicely be applied to Windows too.

This avoids cluttering $HOME, is friendly to other operating systems, and allows backup and synchronization systems to just work if they look at the standard locations.

Using conan 1.0.4 on Ubuntu 14.04.

  • [X] I've read the CONTRIBUTING guide.
  • [X] I've specified the Conan version, operating system version and any tool that can be relevant.
  • [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.
medium medium queue feature

Most helpful comment

Actually, Git does follow XDG dir spec. It used to _not_ follow it, because git itself is older then the spec. Because of that, it first tries to load its global configuration from $XDG_CONFIG_HOME/git/config (falling back to $HOME/.config/git/config, then from ~/.gitconfig. Something like that could be implemented for Conan.

Note, that in order to actually conform to the spec, Conan will have to store only _static_ configuration in $XDG_CONFIG_HOME/conan/. All files that normally get changed by the program itself should go into $XDG_DATA_HOME/conan or other similar directories. For example:

  • $XDG_CONFIG_HOME/conan/cacert.pem
  • $XDG_CONFIG_HOME/conan/conan.conf
  • $XDG_CONFIG_HOME/conan/settings.yml
  • $XDG_CONFIG_HOME/conan/profiles/

  • $XDG_DATA_HOME/conan/registry.txt

  • $XDG_DATA_HOME/conan/version.txt
  • $XDG_DATA_HOME/conan/data/

  • $XDG_RUNTIME_DIR/conan/registry.lock

All 7 comments

Sorry my ignorance, it is the first time I heard about the XDG specification. And I am afraid that the majority of conan users might be the same as me. The fact that you can define custom env-vars in Windows to follow that specification, doesn't mean that most conan users in Windows will follow it.

In any case, it is just a default, you can easily change that and put whenever you want with CONAN_USER_HOME env var.

I have checked my current HOME folder and I have folders for CLion, VirtualBox, git, eclipse, vim, VS code, just to name a few... So I wouldn't say that conan is not aligned with the current leaders practices, and I strongly think that conan should do the same as them.

Thanks very much for your suggestion anyway!

$ ls -1 ~/.config
compiz-1
dconf
enchant
eog
evince
evolution
gedit
gnome-session
gnote
goa-1.0
gtg
gtk-2.0
gtk-3.0
htop
ibus
Kitware
libaccounts-glib
libreoffice
menus
nautilus
pdfmod
pulse
qi
QtProject.conf
software-center
totem
tracker
Trolltech.conf
unity
update-notifier
upstart
user-dirs.dirs
user-dirs.locale
VirtualBox
yelp

Vim does not follow it for historical reasons, as it predates the standard. This is a freedesktop standard, not something made out of the blue.
You'll notice that Virtualbox follows the XDG spec however, as well as other cross-platform tools, like gtk, qt, libreoffice, cmake (well, almost, they should use cmake instead of Kitware as a directory name), and pip (try running a pip install --user conan).

I totally understand if you don't want to implement this, but being able to find projects that don't follow the standard misses the point of why that standard was created and is useful.

It is an interesting standard, I am not saying that it is not, or it doesn't have value. Just that I didn't see it followed by the majority of mainstream C and C++ tools, specially outside of the GNU or Linux ecosystem.

If we see more support for this feature among conan users, we will be happy to reconsider. I am living this feature open and looking for further feedback from the community.

Thanks for reopening.

As a side-note, I feel your docs already are sprinkled with UNIX-ishms thet are not valid outside of GNU/Linux either. From conan's Getting Started documentation:

  • .conan/data : Dot files are hidden files from UNIX
  • <userhome>/.conan/profiles/default : userhome is the UNIX terminology (Windows equivalent would be userprofile)
  • ~/.conan/profiles/default : ~ is the equivalent to $HOME

This is already bound to UNIX-like systems. With XDG base dir spec, you can just refer to the concerned variables, and say to which directories they default on each platform, avoiding all ambiguity, and also alowing the user to choose a location that better suits his/her needs. Maybe a network share for Windows users for example, on a continous build machine ?

The spec isn't also only about config, but also defines where the cache directories should go, so a user that wants to get some disk space back can delete cache files safely.

Actually, Git does follow XDG dir spec. It used to _not_ follow it, because git itself is older then the spec. Because of that, it first tries to load its global configuration from $XDG_CONFIG_HOME/git/config (falling back to $HOME/.config/git/config, then from ~/.gitconfig. Something like that could be implemented for Conan.

Note, that in order to actually conform to the spec, Conan will have to store only _static_ configuration in $XDG_CONFIG_HOME/conan/. All files that normally get changed by the program itself should go into $XDG_DATA_HOME/conan or other similar directories. For example:

  • $XDG_CONFIG_HOME/conan/cacert.pem
  • $XDG_CONFIG_HOME/conan/conan.conf
  • $XDG_CONFIG_HOME/conan/settings.yml
  • $XDG_CONFIG_HOME/conan/profiles/

  • $XDG_DATA_HOME/conan/registry.txt

  • $XDG_DATA_HOME/conan/version.txt
  • $XDG_DATA_HOME/conan/data/

  • $XDG_RUNTIME_DIR/conan/registry.lock

Hi @grisumbras

Thanks very much for the feedback. Yes, I think this might be doable without breaking, and it makes sense.

Just a quick question, the profiles, the settings.yml, the conan.conf are for example installed via conan config install. Still should be considered config and not data, right?

Thanks!

Yes, similar to git config --global.

Was this page helpful?
0 / 5 - 0 ratings