Skip to content
Closed
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
27 changes: 17 additions & 10 deletions gen/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstring>

#include "llvm/Support/Path.h"
#include "llvm/Support/FileSystem.h"

#include "libconfig.h++"

Expand All @@ -23,6 +24,12 @@ ConfigFile::~ConfigFile()
delete cfg;
}

// TODO Replace with llvm::sys::fs::exists() on LLVM 3.0
static inline bool exists(const sys::Path& path)
{
bool exists;
return !sys::fs::exists(path.str(), exists) && exists;
}

bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const char* filename)
{
Expand All @@ -31,7 +38,7 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
// try the current working dir
p = sys::Path::GetCurrentDirectory();
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

// user configuration
Expand All @@ -40,14 +47,14 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
p = sys::Path::GetUserHomeDirectory();
p.appendComponent(".ldc");
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

#if _WIN32
// try home dir
p = sys::Path::GetUserHomeDirectory();
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;
#endif

Expand All @@ -57,42 +64,42 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
// try the install-prefix
p = sys::Path(LDC_INSTALL_PREFIX);
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;
#else
// try the install-prefix/etc
p = sys::Path(LDC_INSTALL_PREFIX);
p.appendComponent("etc");
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

// try the install-prefix/etc/ldc
p = sys::Path(LDC_INSTALL_PREFIX);
p.appendComponent("etc");
p.appendComponent("ldc");
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

// try /etc (absolute path)
p = sys::Path("/etc");
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

// try /etc/ldc (absolute path)
p = sys::Path("/etc/ldc");
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;
#endif

// try next to the executable
p = sys::Path::GetMainExecutable(argv0, mainAddr);
p.eraseComponent();
p.appendComponent(filename);
if (p.exists())
if (exists(p))
return true;

return false;
Expand Down Expand Up @@ -134,7 +141,7 @@ bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
{
std::string binpathkey = "%%ldcbinarypath%%";

std::string binpath = sys::Path::GetMainExecutable(argv0, mainAddr).getDirname();
std::string binpath = llvm::sys::path::parent_path(sys::Path::GetMainExecutable(argv0, mainAddr).str());

libconfig::Setting& arr = cfg->lookup("default.switches");
int len = arr.getLength();
Expand Down
20 changes: 13 additions & 7 deletions gen/linker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gen/linker.h"
#include "gen/llvm.h"
#include "llvm/Linker.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h"
#if _WIN32
#include "llvm/Support/SystemUtils.h"
Expand Down Expand Up @@ -96,9 +97,9 @@ int linkExecutable(const char* argv0)
assert(gExePath.isValid());

// create path to exe
llvm::sys::Path exedir(gExePath);
exedir.set(gExePath.getDirname());
if (!exedir.exists())
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
bool exists;
if (!(!llvm::sys::fs::exists(exedir.str(), exists) && exists))
{
exedir.createDirectoryOnDisk(true, &errstr);
if (!errstr.empty())
Expand Down Expand Up @@ -265,9 +266,9 @@ int linkObjToExecutable(const char* argv0)
assert(gExePath.isValid());

// create path to exe
llvm::sys::Path exedir(gExePath);
exedir.set(gExePath.getDirname());
if (!exedir.exists())
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
bool exists;
if (!(!llvm::sys::fs::exists(exedir.str(), exists) && exists))
{
exedir.createDirectoryOnDisk(true, &errstr);
if (!errstr.empty())
Expand Down Expand Up @@ -363,7 +364,8 @@ void deleteExecutable()
if (!gExePath.isEmpty())
{
assert(gExePath.isValid());
assert(!gExePath.isDirectory());
bool is_directory;
assert(!(!llvm::sys::fs::is_directory(gExePath.str(), is_directory) && is_directory));
gExePath.eraseFromDisk(false);
}
}
Expand Down Expand Up @@ -392,7 +394,11 @@ int runExecutable()
int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr);
if (status < 0)
{
#if defined(_MSC_VER)
error("program received signal %d", -status);
#else
error("program received signal %d (%s)", -status, strsignal(-status));
#endif
return -status;
}

Expand Down