Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 0 additions & 109 deletions lib/Interpreter/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,6 @@ namespace platform {
return Lib;
}

void* DLSym(const std::string& Name, std::string* Err /* = nullptr*/) {
if (void* Self = ::dlopen(nullptr, RTLD_GLOBAL)) {
// get dlopen error if there is one
DLErr(Err);
void* Sym = ::dlsym(Self, Name.c_str());
// overwrite error if dlsym caused one
DLErr(Err);
// only get dlclose error if dlopen & dlsym haven't emited one
DLClose(Self, Err && Err->empty() ? Err : nullptr);
return Sym;
}
DLErr(Err);
return nullptr;
}

void DLClose(void* Lib, std::string* Err /* = nullptr*/) {
::dlclose(Lib);
DLErr(Err);
Expand All @@ -158,28 +143,6 @@ namespace platform {

} // namespace platform

bool ExpandEnvVars(std::string& Str, bool Path) {
std::size_t DPos = Str.find("$");
while (DPos != std::string::npos) {
std::size_t SPos = Str.find("/", DPos + 1);
std::size_t Length = Str.length();

if (SPos != std::string::npos) // if we found a "/"
Length = SPos - DPos;

std::string EnvVar = Str.substr(DPos + 1, Length -1); //"HOME"
std::string FullPath;
if (const char* Tok = GetEnv(EnvVar.c_str()))
FullPath = Tok;

Str.replace(DPos, Length, FullPath);
DPos = Str.find("$", DPos + 1); // search for next env variable
}
if (!Path)
return true;
return llvm::sys::fs::exists(Str.c_str());
}

using namespace llvm;
using namespace clang;

Expand Down Expand Up @@ -268,84 +231,12 @@ void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
incpaths.push_back("-v");
}

void DumpIncludePaths(const clang::HeaderSearchOptions& Opts,
llvm::raw_ostream& Out,
bool WithSystem, bool WithFlags) {
llvm::SmallVector<std::string, 100> IncPaths;
CopyIncludePaths(Opts, IncPaths, WithSystem, WithFlags);
// print'em all
for (unsigned i = 0; i < IncPaths.size(); ++i) {
Out << IncPaths[i] <<"\n";
}
}

void LogNonExistantDirectory(llvm::StringRef Path) {
#define DEBUG_TYPE "LogNonExistantDirectory"
LLVM_DEBUG(dbgs() << " ignoring nonexistent directory \"" << Path << "\"\n");
#undef DEBUG_TYPE
}

static void LogFileStatus(const char* Prefix, const char* FileType,
llvm::StringRef Path) {
#define DEBUG_TYPE "LogFileStatus"
LLVM_DEBUG(dbgs() << Prefix << " " << FileType << " '" << Path << "'\n";);
#undef DEBUG_TYPE
}

bool LookForFile(const std::vector<const char*>& Args, std::string& Path,
const clang::FileManager* FM, const char* FileType) {
if (llvm::sys::fs::is_regular_file(Path)) {
if (FileType)
LogFileStatus("Using", FileType, Path);
return true;
}
if (FileType)
LogFileStatus("Ignoring", FileType, Path);

SmallString<1024> FilePath;
if (FM) {
FilePath.assign(Path);
if (FM->FixupRelativePath(FilePath) &&
llvm::sys::fs::is_regular_file(FilePath)) {
if (FileType)
LogFileStatus("Using", FileType, FilePath.str());
Path = FilePath.str().str();
return true;
}
// Don't write same same log entry twice when FilePath == Path
if (FileType && FilePath.str() != Path)
LogFileStatus("Ignoring", FileType, FilePath);
}
else if (llvm::sys::path::is_absolute(Path))
return false;

for (std::vector<const char*>::const_iterator It = Args.begin(),
End = Args.end(); It < End; ++It) {
const char* Arg = *It;
// TODO: Suppport '-iquote' and MSVC equivalent
if (!::strncmp("-I", Arg, 2) || !::strncmp("/I", Arg, 2)) {
if (!Arg[2]) {
if (++It >= End)
break;
FilePath.assign(*It);
}
else
FilePath.assign(Arg + 2);

llvm::sys::path::append(FilePath, Path.c_str());
if (llvm::sys::fs::is_regular_file(FilePath)) {
if (FileType)
LogFileStatus("Using", FileType, FilePath.str());
Path = FilePath.str().str();
return true;
}
if (FileType)
LogFileStatus("Ignoring", FileType, FilePath);
}
}
return false;
}

bool SplitPaths(llvm::StringRef PathStr,
llvm::SmallVectorImpl<llvm::StringRef>& Paths,
SplitMode Mode, llvm::StringRef Delim, bool Verbose) {
Expand Down
42 changes: 0 additions & 42 deletions lib/Interpreter/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ std::string NormalizePath(const std::string& Path);
///
void* DLOpen(const std::string& Path, std::string* Err = nullptr);

void* DLSym(const std::string& Name, std::string* Err = nullptr);

///\brief Close a handle to a shared library.
///
/// \param [in] Lib - Handle to library from previous call to DLOpen
Expand All @@ -61,17 +59,6 @@ void* DLSym(const std::string& Name, std::string* Err = nullptr);
void DLClose(void* Lib, std::string* Err = nullptr);
} // namespace platform

///\brief Replace all $TOKENS in a string with environent variable values.
///
/// \param [in,out] Str - String with tokens to replace (in place)
/// \param [in] Path - Check if the result is a valid filesystem path.
///
/// \returns When Path is true, return whether Str was expanded to an
/// existing file-system object.
/// Return value has no meaning when Path is false.
///
bool ExpandEnvVars(std::string& Str, bool Path = false);

enum SplitMode {
kPruneNonExistant, ///< Don't add non-existant paths into output
kFailNonExistant, ///< Fail on any non-existant paths
Expand All @@ -96,22 +83,6 @@ bool SplitPaths(llvm::StringRef PathStr,
llvm::StringRef Delim = Cpp::utils::platform::kEnvDelim,
bool Verbose = false);

///\brief Look for given file that can be reachable from current working
/// directory or any user supplied include paths in Args. This is useful
/// to look for a file (precompiled header) before a Preprocessor instance
/// has been created.
///
/// \param [in] Args - The argv vector to look for '-I' & '/I' flags
/// \param [in,out] File - File to look for, may mutate to an absolute path
/// \param [in] FM - File manger to resolve current dir with (can be null)
/// \param [in] FileType - File type for logging or nullptr for no logging
///
/// \return true if File is reachable and is a regular file
///
bool LookForFile(const std::vector<const char*>& Args, std::string& File,
const clang::FileManager* FM = nullptr,
const char* FileType = nullptr);

///\brief Adds multiple include paths separated by a delimter into the
/// given HeaderSearchOptions. This adds the paths but does no further
/// processing. See Interpreter::AddIncludePaths or CIFactory::createCI
Expand Down Expand Up @@ -145,19 +116,6 @@ void CopyIncludePaths(const clang::HeaderSearchOptions& Opts,
llvm::SmallVectorImpl<std::string>& Paths,
bool WithSystem, bool WithFlags);

///\brief Prints the current include paths into the HeaderSearchOptions.
///
///\param[in] Opts - HeaderSearchOptions to read from
///\param[in] Out - Stream to dump to
///\param[in] WithSystem - dump contain system paths (framework, STL etc).
///\param[in] WithFlags - if true, each line will be prefixed
/// with a "-I" or similar, and some entries of incpaths will signal
/// a new include path region (e.g. "-cxx-isystem"). Also, flags
/// defining header search behavior will be included in incpaths, e.g.
/// "-nostdinc".
///
void DumpIncludePaths(const clang::HeaderSearchOptions& Opts,
llvm::raw_ostream& Out, bool WithSystem, bool WithFlags);
} // namespace utils
} // namespace Cpp

Expand Down