Author: cbieneman Date: Wed Nov 2 12:19:23 2016 New Revision: 285838 URL: http://llvm.org/viewvc/llvm-project?rev=285838&view=rev Log: Find clang resource directory via *nix-style lookup
Summary: This patch allows the Darwin build to fall back to to Posix-style lookups for the clang resource directory if the debugger library isn't inside a framework. The patch also includes a bit of refactoring and cleanup around the *nix resolution of the binary and lib directories to reuse the code instead of duplicating it. With this patch Darwin builds that don't build a framework only have 3 failing tests on my system (TestExec.py). Reviewers: zturner, labath, spyffe, tfiala Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D26170 Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm lldb/trunk/source/Host/posix/HostInfoPosix.cpp Modified: lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h?rev=285838&r1=285837&r2=285838&view=diff ============================================================================== --- lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h (original) +++ lldb/trunk/include/lldb/Host/posix/HostInfoPosix.h Wed Nov 2 12:19:23 2016 @@ -37,6 +37,9 @@ protected: static bool ComputeSupportExeDirectory(FileSpec &file_spec); static bool ComputeHeaderDirectory(FileSpec &file_spec); static bool ComputePythonDirectory(FileSpec &file_spec); + static bool ComputeClangDirectory(FileSpec &file_spec); + static bool ComputePathRelativeToLibrary(FileSpec &file_spec, + llvm::StringRef dir); }; } Modified: lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm?rev=285838&r1=285837&r2=285838&view=diff ============================================================================== --- lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm (original) +++ lldb/trunk/source/Host/macosx/HostInfoMacOSX.mm Wed Nov 2 12:19:23 2016 @@ -233,11 +233,13 @@ bool HostInfoMacOSX::ComputeClangDirecto std::string raw_path = lldb_file_spec.GetPath(); size_t framework_pos = raw_path.find("LLDB.framework"); - if (framework_pos != std::string::npos) { - framework_pos += strlen("LLDB.framework"); - raw_path.resize(framework_pos); - raw_path.append("/Resources/Clang"); - } + if (framework_pos == std::string::npos) + return HostInfoPosix::ComputeClangDirectory(file_spec); + + framework_pos += strlen("LLDB.framework"); + raw_path.resize(framework_pos); + raw_path.append("/Resources/Clang"); + file_spec.SetFile(raw_path.c_str(), true); return true; } Modified: lldb/trunk/source/Host/posix/HostInfoPosix.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/HostInfoPosix.cpp?rev=285838&r1=285837&r2=285838&view=diff ============================================================================== --- lldb/trunk/source/Host/posix/HostInfoPosix.cpp (original) +++ lldb/trunk/source/Host/posix/HostInfoPosix.cpp Wed Nov 2 12:19:23 2016 @@ -14,7 +14,11 @@ #include "lldb/Core/Log.h" #include "lldb/Host/posix/HostInfoPosix.h" +#include "clang/Basic/Version.h" +#include "clang/Config/config.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" #include <grp.h> @@ -124,44 +128,54 @@ uint32_t HostInfoPosix::GetEffectiveGrou FileSpec HostInfoPosix::GetDefaultShell() { return FileSpec("/bin/sh", false); } -bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) { +bool HostInfoPosix::ComputePathRelativeToLibrary(FileSpec &file_spec, + llvm::StringRef dir) { Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST); FileSpec lldb_file_spec; if (!GetLLDBPath(lldb::ePathTypeLLDBShlibDir, lldb_file_spec)) return false; - char raw_path[PATH_MAX]; - lldb_file_spec.GetPath(raw_path, sizeof(raw_path)); + std::string raw_path = lldb_file_spec.GetPath(); + // drop library directory + llvm::StringRef parent_path = llvm::sys::path::parent_path(raw_path); // Most Posix systems (e.g. Linux/*BSD) will attempt to replace a */lib with - // */bin as the base - // directory for helper exe programs. This will fail if the /lib and /bin - // directories are - // rooted in entirely different trees. + // */bin as the base directory for helper exe programs. This will fail if the + // /lib and /bin directories are rooted in entirely different trees. if (log) - log->Printf("HostInfoPosix::ComputeSupportExeDirectory() attempting to " - "derive the bin path (ePathTypeSupportExecutableDir) from " - "this path: %s", - raw_path); - char *lib_pos = ::strstr(raw_path, "/lib"); - if (lib_pos != nullptr) { + log->Printf("HostInfoPosix::ComputePathRelativeToLibrary() attempting to " + "derive the %s path from this path: %s", + dir.data(), raw_path.c_str()); + + if (!parent_path.empty()) { // Now write in bin in place of lib. - ::snprintf(lib_pos, PATH_MAX - (lib_pos - raw_path), "/bin"); + raw_path = (parent_path + dir).str(); if (log) log->Printf("Host::%s() derived the bin path as: %s", __FUNCTION__, - raw_path); + raw_path.c_str()); } else { if (log) log->Printf("Host::%s() failed to find /lib/liblldb within the shared " "lib path, bailing on bin path construction", __FUNCTION__); } - file_spec.GetDirectory().SetCString(raw_path); + file_spec.GetDirectory().SetString(raw_path); return (bool)file_spec.GetDirectory(); } +bool HostInfoPosix::ComputeSupportExeDirectory(FileSpec &file_spec) { + return ComputePathRelativeToLibrary(file_spec, "/bin"); +} + +bool HostInfoPosix::ComputeClangDirectory(FileSpec &file_spec) { + return ComputePathRelativeToLibrary( + file_spec, (llvm::Twine("/lib") + CLANG_LIBDIR_SUFFIX + "/clang/" + + CLANG_VERSION_STRING) + .str()); +} + bool HostInfoPosix::ComputeHeaderDirectory(FileSpec &file_spec) { FileSpec temp_file("/opt/local/include/lldb", false); file_spec.GetDirectory().SetCString(temp_file.GetPath().c_str()); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits