[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 22:39:08 PDT 2022


paperchalice updated this revision to Diff 471717.
paperchalice added a comment.

Add test on Unix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136940/new/

https://reviews.llvm.org/D136940

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c


Index: clang/test/Driver/config-file3.c
===================================================================
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -221,3 +221,8 @@
 //
 // RUN: rm %t/testdmode/clang-g++.cfg
 // RUN: %t/testdmode/x86_64-unknown-linux-gnu-clang-g++ --config-system-dir= --config-user-dir= -no-canonical-prefixes --version 2>&1 | FileCheck %s -check-prefix NO-CONFIG
+
+//--- Tilde expansion in user configuration file directory
+//
+// RUN: HOME=%S/Inputs/config %clang --config-user-dir=~ -v 2>&1 | FileCheck %s -check-prefix CHECK-TILDE
+// CHECK-TILDE: User configuration file directory: {{.*}}/Inputs/config
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -220,7 +220,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.
@@ -999,8 +1003,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() || getVFS().makeAbsolute(CfgDir))
         UserConfigDir.clear();
       else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136940.471717.patch
Type: text/x-patch
Size: 1649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221029/85d9e5a5/attachment-0001.bin>


More information about the cfe-commits mailing list