Add a facility to get system cache directory and use it in clangd
authorVojtěch Štěpančík <vojtechstepancik@outlook.com>
Tue, 28 Apr 2020 20:03:30 +0000 (22:03 +0200)
committerSam McCall <sam.mccall@gmail.com>
Tue, 28 Apr 2020 21:18:31 +0000 (23:18 +0200)
commitad38f4b371bdca214e3a3cda9a76ec2213215c68
treece22fb31565eda9684fea884d09094894a954f89
parent178a0c80baabed805449c23c2c0af2b993cfcbd4
Add a facility to get system cache directory and use it in clangd

Summary:
This patch adds a function that is similar to `llvm::sys::path::home_directory`, but provides access to the system cache directory.

For Windows, that is %LOCALAPPDATA%, and applications should put their files under %LOCALAPPDATA%\Organization\Product\.

For *nixes, it adheres to the XDG Base Directory Specification, so it first looks at the XDG_CACHE_HOME environment variable and falls back to ~/.cache/.

Subsequently, the Clangd Index storage leverages this new API to put index files somewhere else than the users home directory.

Fixes https://github.com/clangd/clangd/issues/341

Reviewers: sammccall, chandlerc, Bigcheese

Reviewed By: sammccall

Subscribers: hiraditya, ilya-biryukov, MaskRay, jkorous, dexonsmith, arphaman, kadircet, ormris, usaxena95, cfe-commits, llvm-commits

Tags: #clang-tools-extra, #clang, #llvm

Differential Revision: https://reviews.llvm.org/D78501
clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
llvm/include/llvm/Support/Path.h
llvm/lib/Support/Unix/Path.inc
llvm/lib/Support/Windows/Path.inc
llvm/unittests/Support/Path.cpp