2010-06-09 00:52:24 +08:00
|
|
|
//===-- FileSpec.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/RegularExpression.h"
|
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-23 01:33:23 +08:00
|
|
|
#include "lldb/Utility/TildeExpressionResolver.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2017-04-07 02:12:24 +08:00
|
|
|
#include "llvm/ADT/SmallString.h" // for SmallString
|
|
|
|
#include "llvm/ADT/SmallVector.h" // for SmallVectorTemplat...
|
2014-08-16 06:04:21 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-04-07 02:12:24 +08:00
|
|
|
#include "llvm/ADT/Triple.h" // for Triple
|
|
|
|
#include "llvm/ADT/Twine.h" // for Twine
|
|
|
|
#include "llvm/Support/ErrorOr.h" // for ErrorOr
|
2014-08-16 06:04:21 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2017-04-07 02:12:24 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h" // for raw_ostream, fs
|
|
|
|
|
|
|
|
#include <algorithm> // for replace, min, unique
|
|
|
|
#include <system_error> // for error_code
|
|
|
|
#include <vector> // for vector
|
|
|
|
|
|
|
|
#include <assert.h> // for assert
|
|
|
|
#include <stdio.h> // for size_t, NULL, snpr...
|
|
|
|
#include <string.h> // for strcmp
|
2014-08-16 06:04:21 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2015-05-29 01:02:45 +08:00
|
|
|
namespace {
|
|
|
|
|
2017-03-09 01:56:08 +08:00
|
|
|
static constexpr FileSpec::PathSyntax GetNativeSyntax() {
|
2018-04-10 21:33:45 +08:00
|
|
|
#if defined(_WIN32)
|
2017-03-09 01:56:08 +08:00
|
|
|
return FileSpec::ePathSyntaxWindows;
|
|
|
|
#else
|
|
|
|
return FileSpec::ePathSyntaxPosix;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool PathSyntaxIsPosix(FileSpec::PathSyntax syntax) {
|
|
|
|
return (syntax == FileSpec::ePathSyntaxPosix ||
|
|
|
|
(syntax == FileSpec::ePathSyntaxHostNative &&
|
2017-03-09 01:56:08 +08:00
|
|
|
GetNativeSyntax() == FileSpec::ePathSyntaxPosix));
|
2015-05-29 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *GetPathSeparators(FileSpec::PathSyntax syntax) {
|
|
|
|
return PathSyntaxIsPosix(syntax) ? "/" : "\\/";
|
2016-04-04 22:39:12 +08:00
|
|
|
}
|
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
char GetPreferredPathSeparator(FileSpec::PathSyntax syntax) {
|
2016-09-07 04:57:50 +08:00
|
|
|
return GetPathSeparators(syntax)[0];
|
2016-04-04 22:39:12 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool IsPathSeparator(char value, FileSpec::PathSyntax syntax) {
|
|
|
|
return value == '/' || (!PathSyntaxIsPosix(syntax) && value == '\\');
|
2015-05-29 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Normalize(llvm::SmallVectorImpl<char> &path, FileSpec::PathSyntax syntax) {
|
|
|
|
if (PathSyntaxIsPosix(syntax))
|
|
|
|
return;
|
2015-05-29 01:02:45 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::replace(path.begin(), path.end(), '\\', '/');
|
|
|
|
// Windows path can have \\ slashes which can be changed by replace
|
|
|
|
// call above to //. Here we remove the duplicate.
|
|
|
|
auto iter = std::unique(path.begin(), path.end(), [](char &c1, char &c2) {
|
|
|
|
return (c1 == '/' && c2 == '/');
|
|
|
|
});
|
|
|
|
path.erase(iter, path.end());
|
2015-05-29 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Denormalize(llvm::SmallVectorImpl<char> &path,
|
|
|
|
FileSpec::PathSyntax syntax) {
|
|
|
|
if (PathSyntaxIsPosix(syntax))
|
|
|
|
return;
|
2015-05-29 01:02:45 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::replace(path.begin(), path.end(), '/', '\\');
|
2015-05-29 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t FilenamePos(llvm::StringRef str, FileSpec::PathSyntax syntax) {
|
|
|
|
if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
|
|
|
|
return 0;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (str.size() > 0 && IsPathSeparator(str.back(), syntax))
|
|
|
|
return str.size() - 1;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t pos = str.find_last_of(GetPathSeparators(syntax), str.size() - 1);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!PathSyntaxIsPosix(syntax) && pos == llvm::StringRef::npos)
|
|
|
|
pos = str.find_last_of(':', str.size() - 2);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (pos == llvm::StringRef::npos ||
|
|
|
|
(pos == 1 && IsPathSeparator(str[0], syntax)))
|
|
|
|
return 0;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return pos + 1;
|
2015-05-29 01:02:45 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t RootDirStart(llvm::StringRef str, FileSpec::PathSyntax syntax) {
|
|
|
|
// case "c:/"
|
|
|
|
if (!PathSyntaxIsPosix(syntax) &&
|
|
|
|
(str.size() > 2 && str[1] == ':' && IsPathSeparator(str[2], syntax)))
|
|
|
|
return 2;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// case "//"
|
|
|
|
if (str.size() == 2 && IsPathSeparator(str[0], syntax) && str[0] == str[1])
|
|
|
|
return llvm::StringRef::npos;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// case "//net"
|
|
|
|
if (str.size() > 3 && IsPathSeparator(str[0], syntax) && str[0] == str[1] &&
|
|
|
|
!IsPathSeparator(str[2], syntax))
|
|
|
|
return str.find_first_of(GetPathSeparators(syntax), 2);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// case "/"
|
|
|
|
if (str.size() > 0 && IsPathSeparator(str[0], syntax))
|
|
|
|
return 0;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return llvm::StringRef::npos;
|
2016-04-04 22:39:12 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t ParentPathEnd(llvm::StringRef path, FileSpec::PathSyntax syntax) {
|
|
|
|
size_t end_pos = FilenamePos(path, syntax);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool filename_was_sep =
|
|
|
|
path.size() > 0 && IsPathSeparator(path[end_pos], syntax);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Skip separators except for root dir.
|
|
|
|
size_t root_dir_pos = RootDirStart(path.substr(0, end_pos), syntax);
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
while (end_pos > 0 && (end_pos - 1) != root_dir_pos &&
|
|
|
|
IsPathSeparator(path[end_pos - 1], syntax))
|
|
|
|
--end_pos;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (end_pos == 1 && root_dir_pos == 0 && filename_was_sep)
|
|
|
|
return llvm::StringRef::npos;
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return end_pos;
|
2016-04-04 22:39:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void FileSpec::Resolve(llvm::SmallVectorImpl<char> &path) {
|
|
|
|
if (path.empty())
|
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2017-03-23 01:33:23 +08:00
|
|
|
llvm::SmallString<32> Source(path.begin(), path.end());
|
|
|
|
StandardTildeExpressionResolver Resolver;
|
|
|
|
Resolver.ResolveFullPath(Source, path);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Save a copy of the original path that's passed in
|
|
|
|
llvm::SmallString<128> original_path(path.begin(), path.end());
|
2015-02-25 10:35:25 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
llvm::sys::fs::make_absolute(path);
|
|
|
|
if (!llvm::sys::fs::exists(path)) {
|
|
|
|
path.clear();
|
|
|
|
path.append(original_path.begin(), original_path.end());
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-03-09 01:56:08 +08:00
|
|
|
FileSpec::FileSpec() : m_syntax(GetNativeSyntax()) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-16 08:57:33 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Default constructor that can take an optional full path to a
|
|
|
|
// file on disk.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-28 04:48:37 +08:00
|
|
|
FileSpec::FileSpec(llvm::StringRef path, bool resolve_path, PathSyntax syntax)
|
2016-11-15 18:58:16 +08:00
|
|
|
: m_syntax(syntax) {
|
2016-09-28 04:48:37 +08:00
|
|
|
SetFile(path, resolve_path, syntax);
|
2010-09-16 08:57:33 +08:00
|
|
|
}
|
|
|
|
|
2017-03-07 07:42:44 +08:00
|
|
|
FileSpec::FileSpec(llvm::StringRef path, bool resolve_path,
|
|
|
|
const llvm::Triple &Triple)
|
|
|
|
: FileSpec{path, resolve_path,
|
|
|
|
Triple.isOSWindows() ? ePathSyntaxWindows : ePathSyntaxPosix} {}
|
2015-05-09 09:21:32 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Copy constructor
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec::FileSpec(const FileSpec &rhs)
|
|
|
|
: m_directory(rhs.m_directory), m_filename(rhs.m_filename),
|
|
|
|
m_is_resolved(rhs.m_is_resolved), m_syntax(rhs.m_syntax) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Copy constructor
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec::FileSpec(const FileSpec *rhs) : m_directory(), m_filename() {
|
|
|
|
if (rhs)
|
|
|
|
*this = *rhs;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2014-07-02 05:22:11 +08:00
|
|
|
// Virtual destructor in case anyone inherits from this class.
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec::~FileSpec() {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Assignment operator.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
const FileSpec &FileSpec::operator=(const FileSpec &rhs) {
|
|
|
|
if (this != &rhs) {
|
|
|
|
m_directory = rhs.m_directory;
|
|
|
|
m_filename = rhs.m_filename;
|
|
|
|
m_is_resolved = rhs.m_is_resolved;
|
|
|
|
m_syntax = rhs.m_syntax;
|
|
|
|
}
|
|
|
|
return *this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Update the contents of this object with a new path. The path will
|
|
|
|
// be split up into a directory and filename and stored as uniqued
|
|
|
|
// string values for quick comparison and efficient memory usage.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-28 04:48:37 +08:00
|
|
|
void FileSpec::SetFile(llvm::StringRef pathname, bool resolve,
|
|
|
|
PathSyntax syntax) {
|
|
|
|
// CLEANUP: Use StringRef for string handling. This function is kind of a
|
|
|
|
// mess and the unclear semantics of RootDirStart and ParentPathEnd make
|
|
|
|
// it very difficult to understand this function. There's no reason this
|
|
|
|
// function should be particularly complicated or difficult to understand.
|
2016-09-07 04:57:50 +08:00
|
|
|
m_filename.Clear();
|
|
|
|
m_directory.Clear();
|
|
|
|
m_is_resolved = false;
|
2017-03-09 01:56:08 +08:00
|
|
|
m_syntax = (syntax == ePathSyntaxHostNative) ? GetNativeSyntax() : syntax;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
if (pathname.empty())
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
llvm::SmallString<64> resolved(pathname);
|
2014-08-08 01:33:07 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (resolve) {
|
|
|
|
FileSpec::Resolve(resolved);
|
|
|
|
m_is_resolved = true;
|
|
|
|
}
|
2014-12-02 07:13:32 +08:00
|
|
|
|
2016-12-16 12:27:00 +08:00
|
|
|
Normalize(resolved, m_syntax);
|
2016-04-14 17:38:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
llvm::StringRef resolve_path_ref(resolved.c_str());
|
2016-12-16 12:27:00 +08:00
|
|
|
size_t dir_end = ParentPathEnd(resolve_path_ref, m_syntax);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (dir_end == 0) {
|
|
|
|
m_filename.SetString(resolve_path_ref);
|
|
|
|
return;
|
|
|
|
}
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_directory.SetString(resolve_path_ref.substr(0, dir_end));
|
2016-04-04 22:39:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t filename_begin = dir_end;
|
2016-12-16 12:27:00 +08:00
|
|
|
size_t root_dir_start = RootDirStart(resolve_path_ref, m_syntax);
|
2016-09-07 04:57:50 +08:00
|
|
|
while (filename_begin != llvm::StringRef::npos &&
|
|
|
|
filename_begin < resolve_path_ref.size() &&
|
|
|
|
filename_begin != root_dir_start &&
|
2016-12-16 12:27:00 +08:00
|
|
|
IsPathSeparator(resolve_path_ref[filename_begin], m_syntax))
|
2016-09-07 04:57:50 +08:00
|
|
|
++filename_begin;
|
|
|
|
m_filename.SetString((filename_begin == llvm::StringRef::npos ||
|
|
|
|
filename_begin >= resolve_path_ref.size())
|
|
|
|
? "."
|
|
|
|
: resolve_path_ref.substr(filename_begin));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-03-07 07:42:44 +08:00
|
|
|
void FileSpec::SetFile(llvm::StringRef path, bool resolve,
|
|
|
|
const llvm::Triple &Triple) {
|
|
|
|
return SetFile(path, resolve,
|
|
|
|
Triple.isOSWindows() ? ePathSyntaxWindows : ePathSyntaxPosix);
|
2015-05-30 03:52:37 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Convert to pointer operator. This allows code to check any FileSpec
|
|
|
|
// objects to see if they contain anything valid using code such as:
|
|
|
|
//
|
|
|
|
// if (file_spec)
|
|
|
|
// {}
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec::operator bool() const { return m_filename || m_directory; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Logical NOT operator. This allows code to check any FileSpec
|
|
|
|
// objects to see if they are invalid using code such as:
|
|
|
|
//
|
|
|
|
// if (!file_spec)
|
|
|
|
// {}
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::operator!() const { return !m_directory && !m_filename; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::DirectoryEquals(const FileSpec &rhs) const {
|
|
|
|
const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive();
|
|
|
|
return ConstString::Equals(m_directory, rhs.m_directory, case_sensitive);
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::FileEquals(const FileSpec &rhs) const {
|
|
|
|
const bool case_sensitive = IsCaseSensitive() || rhs.IsCaseSensitive();
|
|
|
|
return ConstString::Equals(m_filename, rhs.m_filename, case_sensitive);
|
Add support for reading line tables from PDB files.
PDB is Microsoft's debug information format, and although we
cannot yet generate it, we still must be able to consume it.
Reason for this is that debug information for system libraries
(e.g. kernel32, C Runtime Library, etc) only have debug info
in PDB format, so in order to be able to support debugging
of system code, we must support it.
Currently this code should compile on every platform, but on
non-Windows platforms the PDB plugin will return 0 capabilities,
meaning that for now PDB is only supported on Windows. This
may change in the future, but the API is designed in such a way
that this will require few (if any) changes on the LLDB side.
In the future we can just flip a switch and everything will
work.
This patch only adds support for line tables. It does not return
information about functions, types, global variables, or anything
else. This functionality will be added in a followup patch.
Differential Revision: http://reviews.llvm.org/D17363
Reviewed by: Greg Clayton
llvm-svn: 262528
2016-03-03 06:05:52 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Equal to operator
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::operator==(const FileSpec &rhs) const {
|
|
|
|
if (!FileEquals(rhs))
|
|
|
|
return false;
|
|
|
|
if (DirectoryEquals(rhs))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// TODO: determine if we want to keep this code in here.
|
|
|
|
// The code below was added to handle a case where we were
|
|
|
|
// trying to set a file and line breakpoint and one path
|
|
|
|
// was resolved, and the other not and the directory was
|
|
|
|
// in a mount point that resolved to a more complete path:
|
|
|
|
// "/tmp/a.c" == "/private/tmp/a.c". I might end up pulling
|
|
|
|
// this out...
|
|
|
|
if (IsResolved() && rhs.IsResolved()) {
|
|
|
|
// Both paths are resolved, no need to look further...
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec resolved_lhs(*this);
|
|
|
|
|
|
|
|
// If "this" isn't resolved, resolve it
|
|
|
|
if (!IsResolved()) {
|
|
|
|
if (resolved_lhs.ResolvePath()) {
|
|
|
|
// This path wasn't resolved but now it is. Check if the resolved
|
|
|
|
// directory is the same as our unresolved directory, and if so,
|
|
|
|
// we can mark this object as resolved to avoid more future resolves
|
|
|
|
m_is_resolved = (m_directory == resolved_lhs.m_directory);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec resolved_rhs(rhs);
|
|
|
|
if (!rhs.IsResolved()) {
|
|
|
|
if (resolved_rhs.ResolvePath()) {
|
|
|
|
// rhs's path wasn't resolved but now it is. Check if the resolved
|
|
|
|
// directory is the same as rhs's unresolved directory, and if so,
|
|
|
|
// we can mark this object as resolved to avoid more future resolves
|
|
|
|
rhs.m_is_resolved = (rhs.m_directory == resolved_rhs.m_directory);
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach this point in the code we were able to resolve both paths
|
|
|
|
// and since we only resolve the paths if the basenames are equal, then
|
|
|
|
// we can just check if both directories are equal...
|
|
|
|
return DirectoryEquals(rhs);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Not equal to operator
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::operator!=(const FileSpec &rhs) const { return !(*this == rhs); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Less than operator
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::operator<(const FileSpec &rhs) const {
|
|
|
|
return FileSpec::Compare(*this, rhs, true) < 0;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Dump a FileSpec object to a stream
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
Stream &lldb_private::operator<<(Stream &s, const FileSpec &f) {
|
|
|
|
f.Dump(&s);
|
|
|
|
return s;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Clear this object by releasing both the directory and filename
|
|
|
|
// string values and making them both the empty string.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
void FileSpec::Clear() {
|
|
|
|
m_directory.Clear();
|
|
|
|
m_filename.Clear();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Compare two FileSpec objects. If "full" is true, then both
|
|
|
|
// the directory and the filename must match. If "full" is false,
|
|
|
|
// then the directory names for "a" and "b" are only compared if
|
|
|
|
// they are both non-empty. This allows a FileSpec object to only
|
|
|
|
// contain a filename and it can match FileSpec objects that have
|
|
|
|
// matching filenames with different paths.
|
|
|
|
//
|
|
|
|
// Return -1 if the "a" is less than "b", 0 if "a" is equal to "b"
|
|
|
|
// and "1" if "a" is greater than "b".
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
int FileSpec::Compare(const FileSpec &a, const FileSpec &b, bool full) {
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
// case sensitivity of compare
|
|
|
|
const bool case_sensitive = a.IsCaseSensitive() || b.IsCaseSensitive();
|
|
|
|
|
|
|
|
// If full is true, then we must compare both the directory and filename.
|
|
|
|
|
|
|
|
// If full is false, then if either directory is empty, then we match on
|
|
|
|
// the basename only, and if both directories have valid values, we still
|
|
|
|
// do a full compare. This allows for matching when we just have a filename
|
|
|
|
// in one of the FileSpec objects.
|
|
|
|
|
|
|
|
if (full || (a.m_directory && b.m_directory)) {
|
|
|
|
result = ConstString::Compare(a.m_directory, b.m_directory, case_sensitive);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return ConstString::Compare(a.m_filename, b.m_filename, case_sensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSpec::Equal(const FileSpec &a, const FileSpec &b, bool full,
|
|
|
|
bool remove_backups) {
|
2017-03-28 03:12:25 +08:00
|
|
|
static ConstString g_dot_string(".");
|
|
|
|
static ConstString g_dot_dot_string("..");
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// case sensitivity of equality test
|
|
|
|
const bool case_sensitive = a.IsCaseSensitive() || b.IsCaseSensitive();
|
2017-03-28 03:12:25 +08:00
|
|
|
|
|
|
|
bool filenames_equal = ConstString::Equals(a.m_filename,
|
|
|
|
b.m_filename,
|
|
|
|
case_sensitive);
|
|
|
|
|
|
|
|
// The only way two FileSpecs can be equal if their filenames are
|
|
|
|
// unequal is if we are removing backups and one or the other filename
|
|
|
|
// is a backup string:
|
|
|
|
|
|
|
|
if (!filenames_equal && !remove_backups)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool last_component_is_dot = ConstString::Equals(a.m_filename, g_dot_string)
|
|
|
|
|| ConstString::Equals(a.m_filename,
|
|
|
|
g_dot_dot_string)
|
|
|
|
|| ConstString::Equals(b.m_filename,
|
|
|
|
g_dot_string)
|
|
|
|
|| ConstString::Equals(b.m_filename,
|
|
|
|
g_dot_dot_string);
|
|
|
|
|
|
|
|
if (!filenames_equal && !last_component_is_dot)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (!full && (a.GetDirectory().IsEmpty() || b.GetDirectory().IsEmpty()))
|
2017-03-28 03:12:25 +08:00
|
|
|
return filenames_equal;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
if (remove_backups == false)
|
|
|
|
return a == b;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
if (a == b)
|
|
|
|
return true;
|
2014-11-15 09:54:26 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
return Equal(a.GetNormalizedPath(), b.GetNormalizedPath(), full, false);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
FileSpec FileSpec::GetNormalizedPath() const {
|
|
|
|
// Fast path. Do nothing if the path is not interesting.
|
|
|
|
if (!m_directory.GetStringRef().contains(".") &&
|
2016-12-01 00:08:45 +08:00
|
|
|
!m_directory.GetStringRef().contains("//") &&
|
|
|
|
m_filename.GetStringRef() != ".." && m_filename.GetStringRef() != ".")
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
return *this;
|
|
|
|
|
|
|
|
llvm::SmallString<64> path, result;
|
|
|
|
const bool normalize = false;
|
|
|
|
GetPath(path, normalize);
|
|
|
|
llvm::StringRef rest(path);
|
|
|
|
|
|
|
|
// We will not go below root dir.
|
|
|
|
size_t root_dir_start = RootDirStart(path, m_syntax);
|
|
|
|
const bool absolute = root_dir_start != llvm::StringRef::npos;
|
|
|
|
if (absolute) {
|
|
|
|
result += rest.take_front(root_dir_start + 1);
|
|
|
|
rest = rest.drop_front(root_dir_start + 1);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
if (m_syntax == ePathSyntaxWindows && path.size() > 2 && path[1] == ':') {
|
|
|
|
result += rest.take_front(2);
|
|
|
|
rest = rest.drop_front(2);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
bool anything_added = false;
|
|
|
|
llvm::SmallVector<llvm::StringRef, 0> components, processed;
|
|
|
|
rest.split(components, '/', -1, false);
|
|
|
|
processed.reserve(components.size());
|
|
|
|
for (auto component : components) {
|
|
|
|
if (component == ".")
|
|
|
|
continue; // Skip these.
|
|
|
|
if (component != "..") {
|
|
|
|
processed.push_back(component);
|
|
|
|
continue; // Regular file name.
|
2014-11-15 09:54:26 +08:00
|
|
|
}
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
if (!processed.empty()) {
|
|
|
|
processed.pop_back();
|
|
|
|
continue; // Dots. Go one level up if we can.
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
if (absolute)
|
|
|
|
continue; // We're at the top level. Cannot go higher than that. Skip.
|
2014-11-15 09:54:26 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
result += component; // We're a relative path. We need to keep these.
|
|
|
|
result += '/';
|
|
|
|
anything_added = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
for (auto component : processed) {
|
|
|
|
result += component;
|
|
|
|
result += '/';
|
|
|
|
anything_added = true;
|
|
|
|
}
|
|
|
|
if (anything_added)
|
|
|
|
result.pop_back(); // Pop last '/'.
|
|
|
|
else if (result.empty())
|
|
|
|
result = ".";
|
2014-11-15 09:54:26 +08:00
|
|
|
|
Improve ".." handling in FileSpec normalization
Summary:
.. handling for windows path was completely broken because the function was
expecting \ as path separators, but we were passing it normalized file paths,
where these have been replaced by forward slashes. Apart from this, the function
was incorrect for posix paths as well in some corner cases, as well as being
generally hard to follow.
The corner cases were:
- /../bar -> should be same as /bar
- /bar/.. -> should be same as / (slightly dodgy as the former depends on /bar actually
existing, but since we're doing it in an abstract way, I think the
transformation is reasonable)
I rewrite the function to fix these corner cases and handle windows paths more
correctly. The function should now handle the posix paths (modulo symlinks, but
we cannot really do anything about that without a real filesystem). For windows
paths, there are a couple of corner cases left, mostly to do with drive letter
handling, which cannot be fixed until the rest of the class understands drive
letters better.
Reviewers: clayborg, zturner
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D26081
llvm-svn: 285593
2016-11-01 00:22:07 +08:00
|
|
|
return FileSpec(result, false, m_syntax);
|
2014-11-15 09:54:26 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Dump the object to the supplied stream. If the object contains
|
|
|
|
// a valid directory name, it will be displayed followed by a
|
|
|
|
// directory delimiter, and the filename.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
void FileSpec::Dump(Stream *s) const {
|
|
|
|
if (s) {
|
|
|
|
std::string path{GetPath(true)};
|
2016-11-03 04:34:10 +08:00
|
|
|
s->PutCString(path);
|
2016-09-28 04:48:37 +08:00
|
|
|
char path_separator = GetPreferredPathSeparator(m_syntax);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!m_filename && !path.empty() && path.back() != path_separator)
|
|
|
|
s->PutChar(path_separator);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Returns true if the file exists.
|
|
|
|
//------------------------------------------------------------------
|
2017-03-09 01:56:08 +08:00
|
|
|
bool FileSpec::Exists() const { return llvm::sys::fs::exists(GetPath()); }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
bool FileSpec::Readable() const {
|
2017-03-09 01:56:08 +08:00
|
|
|
return GetPermissions() & llvm::sys::fs::perms::all_read;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSpec::ResolveExecutableLocation() {
|
2016-09-28 04:48:37 +08:00
|
|
|
// CLEANUP: Use StringRef for string handling.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!m_directory) {
|
|
|
|
const char *file_cstr = m_filename.GetCString();
|
|
|
|
if (file_cstr) {
|
|
|
|
const std::string file_str(file_cstr);
|
|
|
|
llvm::ErrorOr<std::string> error_or_path =
|
|
|
|
llvm::sys::findProgramByName(file_str);
|
|
|
|
if (!error_or_path)
|
|
|
|
return false;
|
|
|
|
std::string path = error_or_path.get();
|
|
|
|
llvm::StringRef dir_ref = llvm::sys::path::parent_path(path);
|
|
|
|
if (!dir_ref.empty()) {
|
|
|
|
// FindProgramByName returns "." if it can't find the file.
|
|
|
|
if (strcmp(".", dir_ref.data()) == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_directory.SetCString(dir_ref.data());
|
|
|
|
if (Exists())
|
|
|
|
return true;
|
|
|
|
else {
|
|
|
|
// If FindProgramByName found the file, it returns the directory +
|
|
|
|
// filename in its return results.
|
|
|
|
// We need to separate them.
|
|
|
|
FileSpec tmp_file(dir_ref.data(), false);
|
|
|
|
if (tmp_file.Exists()) {
|
|
|
|
m_directory = tmp_file.m_directory;
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-12 08:10:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-09-12 08:10:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-09-16 08:57:33 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::ResolvePath() {
|
|
|
|
if (m_is_resolved)
|
|
|
|
return true; // We have already resolved this path
|
2010-11-08 08:28:40 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// SetFile(...) will set m_is_resolved correctly if it can resolve the path
|
2017-03-13 17:46:15 +08:00
|
|
|
SetFile(GetPath(false), true);
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_is_resolved;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint64_t FileSpec::GetByteSize() const {
|
2017-03-09 01:56:08 +08:00
|
|
|
uint64_t Size = 0;
|
|
|
|
if (llvm::sys::fs::file_size(GetPath(), Size))
|
|
|
|
return 0;
|
|
|
|
return Size;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec::PathSyntax FileSpec::GetPathSyntax() const { return m_syntax; }
|
2014-08-08 01:33:07 +08:00
|
|
|
|
2017-03-07 21:19:15 +08:00
|
|
|
uint32_t FileSpec::GetPermissions() const {
|
2017-03-09 01:56:08 +08:00
|
|
|
namespace fs = llvm::sys::fs;
|
|
|
|
fs::file_status st;
|
|
|
|
if (fs::status(GetPath(), st, false))
|
|
|
|
return fs::perms::perms_not_known;
|
|
|
|
|
|
|
|
return st.permissions();
|
2013-11-21 05:07:01 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Directory string get accessor.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
ConstString &FileSpec::GetDirectory() { return m_directory; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Directory string const get accessor.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
const ConstString &FileSpec::GetDirectory() const { return m_directory; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Filename string get accessor.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
ConstString &FileSpec::GetFilename() { return m_filename; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Filename string const get accessor.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
const ConstString &FileSpec::GetFilename() const { return m_filename; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Extract the directory and path into a fixed buffer. This is
|
|
|
|
// needed as the directory and path are stored in separate string
|
|
|
|
// values.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t FileSpec::GetPath(char *path, size_t path_max_len,
|
|
|
|
bool denormalize) const {
|
|
|
|
if (!path)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
std::string result = GetPath(denormalize);
|
|
|
|
::snprintf(path, path_max_len, "%s", result.c_str());
|
|
|
|
return std::min(path_max_len - 1, result.length());
|
2011-10-18 05:45:27 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
std::string FileSpec::GetPath(bool denormalize) const {
|
|
|
|
llvm::SmallString<64> result;
|
|
|
|
GetPath(result, denormalize);
|
|
|
|
return std::string(result.begin(), result.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *FileSpec::GetCString(bool denormalize) const {
|
|
|
|
return ConstString{GetPath(denormalize)}.AsCString(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSpec::GetPath(llvm::SmallVectorImpl<char> &path,
|
|
|
|
bool denormalize) const {
|
|
|
|
path.append(m_directory.GetStringRef().begin(),
|
|
|
|
m_directory.GetStringRef().end());
|
|
|
|
if (m_directory && m_filename &&
|
|
|
|
!IsPathSeparator(m_directory.GetStringRef().back(), m_syntax))
|
2016-09-28 04:48:37 +08:00
|
|
|
path.insert(path.end(), GetPreferredPathSeparator(m_syntax));
|
2016-09-07 04:57:50 +08:00
|
|
|
path.append(m_filename.GetStringRef().begin(),
|
|
|
|
m_filename.GetStringRef().end());
|
|
|
|
Normalize(path, m_syntax);
|
|
|
|
if (denormalize && !path.empty())
|
|
|
|
Denormalize(path, m_syntax);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString FileSpec::GetFileNameExtension() const {
|
|
|
|
if (m_filename) {
|
2011-10-18 05:45:27 +08:00
|
|
|
const char *filename = m_filename.GetCString();
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *dot_pos = strrchr(filename, '.');
|
|
|
|
if (dot_pos && dot_pos[1] != '\0')
|
|
|
|
return ConstString(dot_pos + 1);
|
|
|
|
}
|
|
|
|
return ConstString();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString FileSpec::GetFileNameStrippingExtension() const {
|
|
|
|
const char *filename = m_filename.GetCString();
|
|
|
|
if (filename == NULL)
|
|
|
|
return ConstString();
|
|
|
|
|
|
|
|
const char *dot_pos = strrchr(filename, '.');
|
|
|
|
if (dot_pos == NULL)
|
|
|
|
return m_filename;
|
|
|
|
|
|
|
|
return ConstString(filename, dot_pos - filename);
|
2011-10-18 05:45:27 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Return the size in bytes that this object takes in memory. This
|
|
|
|
// returns the size in bytes of this object, not any shared string
|
|
|
|
// values it may refer to.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t FileSpec::MemorySize() const {
|
|
|
|
return m_filename.MemorySize() + m_directory.MemorySize();
|
|
|
|
}
|
|
|
|
|
2017-03-13 10:44:39 +08:00
|
|
|
void FileSpec::EnumerateDirectory(llvm::StringRef dir_path,
|
|
|
|
bool find_directories, bool find_files,
|
|
|
|
bool find_other,
|
|
|
|
EnumerateDirectoryCallbackType callback,
|
|
|
|
void *callback_baton) {
|
|
|
|
namespace fs = llvm::sys::fs;
|
|
|
|
std::error_code EC;
|
|
|
|
fs::recursive_directory_iterator Iter(dir_path, EC);
|
|
|
|
fs::recursive_directory_iterator End;
|
|
|
|
for (; Iter != End && !EC; Iter.increment(EC)) {
|
|
|
|
const auto &Item = *Iter;
|
2017-10-11 06:19:46 +08:00
|
|
|
llvm::ErrorOr<fs::basic_file_status> Status = Item.status();
|
|
|
|
if (!Status)
|
2017-03-13 10:44:39 +08:00
|
|
|
break;
|
2017-10-11 06:19:46 +08:00
|
|
|
if (!find_files && fs::is_regular_file(*Status))
|
2017-03-13 10:44:39 +08:00
|
|
|
continue;
|
2017-10-11 06:19:46 +08:00
|
|
|
if (!find_directories && fs::is_directory(*Status))
|
2017-03-13 10:44:39 +08:00
|
|
|
continue;
|
2017-10-11 06:19:46 +08:00
|
|
|
if (!find_other && fs::is_other(*Status))
|
2017-03-13 10:44:39 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
FileSpec Spec(Item.path(), false);
|
2017-10-11 06:19:46 +08:00
|
|
|
auto Result = callback(callback_baton, Status->type(), Spec);
|
2017-03-13 10:44:39 +08:00
|
|
|
if (Result == eEnumerateDirectoryResultQuit)
|
|
|
|
return;
|
|
|
|
if (Result == eEnumerateDirectoryResultNext) {
|
|
|
|
// Default behavior is to recurse. Opt out if the callback doesn't want
|
|
|
|
// this behavior.
|
|
|
|
Iter.no_push();
|
2015-06-30 02:29:00 +08:00
|
|
|
}
|
2017-03-13 10:44:39 +08:00
|
|
|
}
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
FileSpec
|
|
|
|
FileSpec::CopyByAppendingPathComponent(llvm::StringRef component) const {
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec ret = *this;
|
2016-09-28 04:48:37 +08:00
|
|
|
ret.AppendPathComponent(component);
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSpec FileSpec::CopyByRemovingLastPathComponent() const {
|
2016-09-28 04:48:37 +08:00
|
|
|
// CLEANUP: Use StringRef for string handling.
|
2016-09-07 04:57:50 +08:00
|
|
|
const bool resolve = false;
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty())
|
|
|
|
return FileSpec("", resolve);
|
|
|
|
if (m_directory.IsEmpty())
|
|
|
|
return FileSpec("", resolve);
|
|
|
|
if (m_filename.IsEmpty()) {
|
|
|
|
const char *dir_cstr = m_directory.GetCString();
|
|
|
|
const char *last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
|
|
|
|
// check for obvious cases before doing the full thing
|
|
|
|
if (!last_slash_ptr)
|
|
|
|
return FileSpec("", resolve);
|
|
|
|
if (last_slash_ptr == dir_cstr)
|
|
|
|
return FileSpec("/", resolve);
|
|
|
|
|
|
|
|
size_t last_slash_pos = last_slash_ptr - dir_cstr + 1;
|
|
|
|
ConstString new_path(dir_cstr, last_slash_pos);
|
|
|
|
return FileSpec(new_path.GetCString(), resolve);
|
|
|
|
} else
|
|
|
|
return FileSpec(m_directory.GetCString(), resolve);
|
|
|
|
}
|
|
|
|
|
|
|
|
ConstString FileSpec::GetLastPathComponent() const {
|
2016-09-28 04:48:37 +08:00
|
|
|
// CLEANUP: Use StringRef for string handling.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_filename)
|
|
|
|
return m_filename;
|
|
|
|
if (m_directory) {
|
|
|
|
const char *dir_cstr = m_directory.GetCString();
|
|
|
|
const char *last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
if (last_slash_ptr == NULL)
|
|
|
|
return m_directory;
|
|
|
|
if (last_slash_ptr == dir_cstr) {
|
|
|
|
if (last_slash_ptr[1] == 0)
|
|
|
|
return ConstString(last_slash_ptr);
|
|
|
|
else
|
|
|
|
return ConstString(last_slash_ptr + 1);
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
if (last_slash_ptr[1] != 0)
|
|
|
|
return ConstString(last_slash_ptr + 1);
|
|
|
|
const char *penultimate_slash_ptr = last_slash_ptr;
|
|
|
|
while (*penultimate_slash_ptr) {
|
|
|
|
--penultimate_slash_ptr;
|
|
|
|
if (penultimate_slash_ptr == dir_cstr)
|
|
|
|
break;
|
|
|
|
if (*penultimate_slash_ptr == '/')
|
|
|
|
break;
|
2015-06-05 08:28:06 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
ConstString result(penultimate_slash_ptr + 1,
|
|
|
|
last_slash_ptr - penultimate_slash_ptr);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return ConstString();
|
|
|
|
}
|
2016-03-11 16:44:44 +08:00
|
|
|
|
2017-01-16 18:07:02 +08:00
|
|
|
static std::string
|
|
|
|
join_path_components(FileSpec::PathSyntax syntax,
|
|
|
|
const std::vector<llvm::StringRef> components) {
|
|
|
|
std::string result;
|
|
|
|
for (size_t i = 0; i < components.size(); ++i) {
|
|
|
|
if (components[i].empty())
|
|
|
|
continue;
|
|
|
|
result += components[i];
|
|
|
|
if (i != components.size() - 1 &&
|
|
|
|
!IsPathSeparator(components[i].back(), syntax))
|
|
|
|
result += GetPreferredPathSeparator(syntax);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
void FileSpec::PrependPathComponent(llvm::StringRef component) {
|
|
|
|
if (component.empty())
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
2016-09-28 04:48:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const bool resolve = false;
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty()) {
|
2016-09-28 04:48:37 +08:00
|
|
|
SetFile(component, resolve);
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-09-28 04:48:37 +08:00
|
|
|
|
2017-01-16 18:07:02 +08:00
|
|
|
std::string result =
|
|
|
|
join_path_components(m_syntax, {component, m_directory.GetStringRef(),
|
|
|
|
m_filename.GetStringRef()});
|
2017-01-16 20:15:42 +08:00
|
|
|
SetFile(result, resolve, m_syntax);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileSpec::PrependPathComponent(const FileSpec &new_path) {
|
|
|
|
return PrependPathComponent(new_path.GetPath(false));
|
|
|
|
}
|
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
void FileSpec::AppendPathComponent(llvm::StringRef component) {
|
|
|
|
if (component.empty())
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
component = component.drop_while(
|
|
|
|
[this](char c) { return IsPathSeparator(c, m_syntax); });
|
2016-08-24 01:13:33 +08:00
|
|
|
|
2017-01-16 18:07:02 +08:00
|
|
|
std::string result =
|
|
|
|
join_path_components(m_syntax, {m_directory.GetStringRef(),
|
|
|
|
m_filename.GetStringRef(), component});
|
2016-03-11 16:44:44 +08:00
|
|
|
|
2016-09-28 04:48:37 +08:00
|
|
|
SetFile(result, false, m_syntax);
|
2015-05-30 03:52:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void FileSpec::AppendPathComponent(const FileSpec &new_path) {
|
|
|
|
return AppendPathComponent(new_path.GetPath(false));
|
2015-06-05 08:28:06 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void FileSpec::RemoveLastPathComponent() {
|
2016-09-28 04:48:37 +08:00
|
|
|
// CLEANUP: Use StringRef for string handling.
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const bool resolve = false;
|
|
|
|
if (m_filename.IsEmpty() && m_directory.IsEmpty()) {
|
|
|
|
SetFile("", resolve);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_directory.IsEmpty()) {
|
|
|
|
SetFile("", resolve);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_filename.IsEmpty()) {
|
|
|
|
const char *dir_cstr = m_directory.GetCString();
|
|
|
|
const char *last_slash_ptr = ::strrchr(dir_cstr, '/');
|
|
|
|
|
|
|
|
// check for obvious cases before doing the full thing
|
|
|
|
if (!last_slash_ptr) {
|
|
|
|
SetFile("", resolve);
|
|
|
|
return;
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
if (last_slash_ptr == dir_cstr) {
|
|
|
|
SetFile("/", resolve);
|
|
|
|
return;
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t last_slash_pos = last_slash_ptr - dir_cstr + 1;
|
|
|
|
ConstString new_path(dir_cstr, last_slash_pos);
|
|
|
|
SetFile(new_path.GetCString(), resolve);
|
|
|
|
} else
|
|
|
|
SetFile(m_directory.GetCString(), resolve);
|
2013-08-27 07:57:52 +08:00
|
|
|
}
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-30 05:13:06 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Returns true if the filespec represents an implementation source
|
|
|
|
/// file (files with a ".c", ".cpp", ".m", ".mm" (many more)
|
|
|
|
/// extension).
|
|
|
|
///
|
|
|
|
/// @return
|
|
|
|
/// \b true if the filespec represents an implementation source
|
|
|
|
/// file, \b false otherwise.
|
|
|
|
//------------------------------------------------------------------
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::IsSourceImplementationFile() const {
|
|
|
|
ConstString extension(GetFileNameExtension());
|
2016-09-22 00:01:28 +08:00
|
|
|
if (!extension)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
static RegularExpression g_source_file_regex(llvm::StringRef(
|
|
|
|
"^([cC]|[mM]|[mM][mM]|[cC][pP][pP]|[cC]\\+\\+|[cC][xX][xX]|[cC][cC]|["
|
|
|
|
"cC][pP]|[sS]|[aA][sS][mM]|[fF]|[fF]77|[fF]90|[fF]95|[fF]03|[fF][oO]["
|
|
|
|
"rR]|[fF][tT][nN]|[fF][pP][pP]|[aA][dD][aA]|[aA][dD][bB]|[aA][dD][sS])"
|
|
|
|
"$"));
|
|
|
|
return g_source_file_regex.Execute(extension.GetStringRef());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileSpec::IsRelative() const {
|
|
|
|
const char *dir = m_directory.GetCString();
|
|
|
|
llvm::StringRef directory(dir ? dir : "");
|
|
|
|
|
|
|
|
if (directory.size() > 0) {
|
|
|
|
if (PathSyntaxIsPosix(m_syntax)) {
|
|
|
|
// If the path doesn't start with '/' or '~', return true
|
|
|
|
switch (directory[0]) {
|
|
|
|
case '/':
|
|
|
|
case '~':
|
|
|
|
return false;
|
|
|
|
default:
|
2012-10-19 00:33:33 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (directory.size() >= 2 && directory[1] == ':')
|
|
|
|
return false;
|
|
|
|
if (directory[0] == '/')
|
|
|
|
return false;
|
|
|
|
return true;
|
2012-10-19 00:33:33 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else if (m_filename) {
|
|
|
|
// No directory, just a basename, return true
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-10-19 00:33:33 +08:00
|
|
|
}
|
2015-06-10 01:54:27 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool FileSpec::IsAbsolute() const { return !FileSpec::IsRelative(); }
|
2016-12-16 12:27:00 +08:00
|
|
|
|
|
|
|
void llvm::format_provider<FileSpec>::format(const FileSpec &F,
|
|
|
|
raw_ostream &Stream,
|
|
|
|
StringRef Style) {
|
|
|
|
assert(
|
|
|
|
(Style.empty() || Style.equals_lower("F") || Style.equals_lower("D")) &&
|
|
|
|
"Invalid FileSpec style!");
|
|
|
|
|
|
|
|
StringRef dir = F.GetDirectory().GetStringRef();
|
|
|
|
StringRef file = F.GetFilename().GetStringRef();
|
|
|
|
|
|
|
|
if (dir.empty() && file.empty()) {
|
|
|
|
Stream << "(empty)";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Style.equals_lower("F")) {
|
|
|
|
Stream << (file.empty() ? "(empty)" : file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Style is either D or empty, either way we need to print the directory.
|
|
|
|
if (!dir.empty()) {
|
|
|
|
// Directory is stored in normalized form, which might be different
|
|
|
|
// than preferred form. In order to handle this, we need to cut off
|
|
|
|
// the filename, then denormalize, then write the entire denorm'ed
|
|
|
|
// directory.
|
|
|
|
llvm::SmallString<64> denormalized_dir = dir;
|
|
|
|
Denormalize(denormalized_dir, F.GetPathSyntax());
|
|
|
|
Stream << denormalized_dir;
|
|
|
|
Stream << GetPreferredPathSeparator(F.GetPathSyntax());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Style.equals_lower("D")) {
|
|
|
|
// We only want to print the directory, so now just exit.
|
|
|
|
if (dir.empty())
|
|
|
|
Stream << "(empty)";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!file.empty())
|
|
|
|
Stream << file;
|
|
|
|
}
|