r361903 - [Driver] Search the toolchain dir with -print-file-name
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Tue May 28 17:01:05 PDT 2019
Author: phosek
Date: Tue May 28 17:01:05 2019
New Revision: 361903
URL: http://llvm.org/viewvc/llvm-project?rev=361903&view=rev
Log:
[Driver] Search the toolchain dir with -print-file-name
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.
Differential Revision: https://reviews.llvm.org/D62558
Added:
cfe/trunk/test/Driver/print-file-name.c
Modified:
cfe/trunk/lib/Driver/Driver.cpp
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=361903&r1=361902&r2=361903&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue May 28 17:01:05 2019
@@ -4437,6 +4437,11 @@ std::string Driver::GetFilePath(StringRe
if (llvm::sys::fs::exists(Twine(P)))
return P.str();
+ SmallString<128> D(Dir);
+ llvm::sys::path::append(D, "..", Name);
+ if (llvm::sys::fs::exists(Twine(D)))
+ return D.str();
+
if (auto P = SearchPaths(TC.getLibraryPaths()))
return *P;
Added: cfe/trunk/test/Driver/print-file-name.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-file-name.c?rev=361903&view=auto
==============================================================================
--- cfe/trunk/test/Driver/print-file-name.c (added)
+++ cfe/trunk/test/Driver/print-file-name.c Tue May 28 17:01:05 2019
@@ -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
More information about the cfe-commits
mailing list