[PATCH] D62558: [Driver] Search the toolchain dir with -print-file-name

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 28 16:51:32 PDT 2019


phosek created this revision.
phosek added reviewers: mcgrathr, echristo.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is useful when looking for directories or files relative to the
toolchain root, e.g. include/c++/v1. This change also adds a test
to make sure this functionality doesn't regress in the future.


Repository:
  rC Clang

https://reviews.llvm.org/D62558

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/print-file-name.c


Index: clang/test/Driver/print-file-name.c
===================================================================
--- /dev/null
+++ clang/test/Driver/print-file-name.c
@@ -0,0 +1,19 @@
+// Test that -print-file-name finds the correct file.
+
+// RUN: %clang -print-file-name=share/asan_blacklist.txt 2>&1 \
+// RUN:     -resource-dir=%S/Inputs/resource_dir \
+// RUN:     --target=x86_64-linux-gnu \
+// RUN:   | FileCheck --check-prefix=CHECK-RESOURCE-DIR %s
+// CHECK-RESOURCE-DIR: resource_dir{{/|\\\\}}share{{/|\\\\}}asan_blacklist.txt
+
+// RUN: %clang -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:     --target=x86_64-linux-gnu \
+// RUN:   | FileCheck --check-prefix=CHECK-COMPILER-RT %s
+// CHECK-COMPILER-RT: resource_dir_with_per_target_subdir{{/|\\\\}}lib{{/|\\\\}}x86_64-linux-gnu{{/|\\\\}}libclang_rt.builtins.a
+
+// RUN: %clang -print-file-name=include/c++/v1 2>&1 \
+// RUN:     -ccc-install-dir %S/Inputs/basic_linux_libcxx_tree/usr/bin \
+// RUN:     --target=x86_64-linux-gnu \
+// RUN:   | FileCheck --check-prefix=CHECK-INSTALL-DIR %s
+// CHECK-INSTALL-DIR: basic_linux_libcxx_tree{{/|\\\\}}usr{{/|\\\\}}bin{{/|\\\\}}..{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}v1
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4427,6 +4427,11 @@
   if (auto P = SearchPaths(PrefixDirs))
     return *P;
 
+  SmallString<128> D(Dir);
+  llvm::sys::path::append(D, "..", Name);
+  if (llvm::sys::fs::exists(Twine(D)))
+    return D.str();
+
   SmallString<128> R(ResourceDir);
   llvm::sys::path::append(R, Name);
   if (llvm::sys::fs::exists(Twine(R)))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62558.201788.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190528/d68ff205/attachment.bin>


More information about the cfe-commits mailing list