Skip to content
Merged
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
Refactor resource path code into own function.
This is a preparation because we want to ship module configuration
files in the future in the cling resource directory (Clang VFS overlay
files and modulemaps). This means that we will need to know this path
in a few other places (e.g. where we specify the -ivfsoverlayPATH
arguments and potential -fmodule-map-file=PATH args)

It also makes this giant function a bit easier on the eyes.
  • Loading branch information
Teemperor committed Sep 1, 2017
commit 947c5f7fed43dab5e075fffe881e76f9bf3ed79a
48 changes: 26 additions & 22 deletions interpreter/cling/lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,31 @@ namespace {
}

#endif


static std::string getResourceDir(const char* llvmdir) {
if (!llvmdir) {
// FIXME: The first arg really does need to be argv[0] on FreeBSD.
//
// Note: The second arg is not used for Apple, FreeBSD, Linux,
// or cygwin, and can only be used on systems which support
// the use of dladdr().
//
// Note: On linux and cygwin this uses /proc/self/exe to find the path
// Note: On Apple it uses _NSGetExecutablePath().
// Note: On FreeBSD it uses getprogpath().
// Note: Otherwise it uses dladdr().
//
return CompilerInvocation::GetResourcesPath(
"cling", (void*)intptr_t(GetExecutablePath));
} else {
std::string resourcePath;
llvm::SmallString<512> tmp(llvmdir);
llvm::sys::path::append(tmp, "lib", "clang", CLANG_VERSION_STRING);
resourcePath.assign(&tmp[0], tmp.size());
return resourcePath;
}
}

///\brief Adds standard library -I used by whatever compiler is found in PATH.
static void AddHostArguments(llvm::StringRef clingBin,
std::vector<const char*>& args,
Expand Down Expand Up @@ -315,27 +339,7 @@ namespace {
#endif // _MSC_VER

if (!opts.ResourceDir && !opts.NoBuiltinInc) {
std::string resourcePath;
if (!llvmdir) {
// FIXME: The first arg really does need to be argv[0] on FreeBSD.
//
// Note: The second arg is not used for Apple, FreeBSD, Linux,
// or cygwin, and can only be used on systems which support
// the use of dladdr().
//
// Note: On linux and cygwin this uses /proc/self/exe to find the path
// Note: On Apple it uses _NSGetExecutablePath().
// Note: On FreeBSD it uses getprogpath().
// Note: Otherwise it uses dladdr().
//
resourcePath
= CompilerInvocation::GetResourcesPath("cling",
(void*)intptr_t(GetExecutablePath));
} else {
llvm::SmallString<512> tmp(llvmdir);
llvm::sys::path::append(tmp, "lib", "clang", CLANG_VERSION_STRING);
resourcePath.assign(&tmp[0], tmp.size());
}
std::string resourcePath = getResourceDir(llvmdir);

// FIXME: Handle cases, where the cling is part of a library/framework.
// There we can't rely on the find executable logic.
Expand Down