[PATCH] D136940: [clang][Driver] allow tilde in user config dir

LJC via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 28 04:15:21 PDT 2022


paperchalice created this revision.
paperchalice added a reviewer: MaskRay.
paperchalice added a project: clang.
Herald added a subscriber: StephenFan.
Herald added a project: All.
paperchalice requested review of this revision.
Herald added a subscriber: cfe-commits.

This patch allows users to configure clang with option e.g. `-DCLANG_CONFIG_FILE_USER_DIR=~/.config/clang` or invoke clang with `--config-user-dir=~/.config/clang`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136940

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -219,7 +219,11 @@
   SystemConfigDir = CLANG_CONFIG_FILE_SYSTEM_DIR;
 #endif
 #if defined(CLANG_CONFIG_FILE_USER_DIR)
-  UserConfigDir = CLANG_CONFIG_FILE_USER_DIR;
+  {
+    SmallString<128> P;
+    llvm::sys::fs::expand_tilde(CLANG_CONFIG_FILE_USER_DIR, P);
+    UserConfigDir = static_cast<std::string>(P);
+  }
 #endif
 
   // Compute the path to the resource directory.
@@ -979,8 +983,8 @@
     }
     if (CLOptions->hasArg(options::OPT_config_user_dir_EQ)) {
       SmallString<128> CfgDir;
-      CfgDir.append(
-          CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ));
+      llvm::sys::fs::expand_tilde(
+          CLOptions->getLastArgValue(options::OPT_config_user_dir_EQ), CfgDir);
       if (!CfgDir.empty()) {
         if (llvm::sys::fs::make_absolute(CfgDir).value() != 0)
           UserConfigDir.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136940.471487.patch
Type: text/x-patch
Size: 1007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221028/2e3acc0a/attachment.bin>


More information about the cfe-commits mailing list