ldc/driver/exe_path.cpp
Johan Engelen 52685e186a Don't use angled brackets for LLVM includes [NFC] (#2204)
Don't use angled brackets for LLVM includes and sort the includes too [NFC]
2017-07-14 14:08:58 +02:00

65 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//===-- exe_path.cpp ------------------------------------------------------===//
//
// LDC the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "exe_path.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
using std::string;
namespace path = llvm::sys::path;
namespace {
string exePath;
}
void exe_path::initialize(const char *arg0) {
assert(exePath.empty());
// Some platforms can't implement LLVM's getMainExecutable
// without being given the address of a function in the main executable.
// Thus getMainExecutable needs the address of a function;
// any function address in the main executable will do.
exePath = llvm::sys::fs::getMainExecutable(
arg0, reinterpret_cast<void *>(&exe_path::initialize));
}
const string &exe_path::getExePath() {
assert(!exePath.empty());
return exePath;
}
string exe_path::getBinDir() {
assert(!exePath.empty());
return path::parent_path(exePath);
}
string exe_path::getBaseDir() {
string binDir = getBinDir();
assert(!binDir.empty());
return path::parent_path(binDir);
}
string exe_path::getLibDir() {
llvm::SmallString<128> r(getBaseDir());
path::append(r, "lib" LDC_LIBDIR_SUFFIX);
return r.str();
}
string exe_path::prependBinDir(const char *suffix) {
llvm::SmallString<128> r(getBinDir());
path::append(r, suffix);
return r.str();
}
string exe_path::prependLibDir(const char *suffix) {
llvm::SmallString<128> r(getLibDir());
path::append(r, suffix);
return r.str();
}