mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 16:41:06 +03:00
Replace deprecated LLVM functions.
Several functions regarding file handling are deprecated. This commit replaces these functions with the new one from llvm::sys::fs and llvm::sys::path. It also removes some warnings about signed/unsigned mismatches.
This commit is contained in:
parent
7431d58702
commit
1ecd536f45
2 changed files with 28 additions and 23 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
||||
#include "libconfig.h++"
|
||||
|
@ -31,7 +32,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 (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
// user configuration
|
||||
|
@ -40,14 +41,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 (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
#if _WIN32
|
||||
// try home dir
|
||||
p = sys::Path::GetUserHomeDirectory();
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
@ -57,14 +58,14 @@ 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 (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
#else
|
||||
// try the install-prefix/etc
|
||||
p = sys::Path(LDC_INSTALL_PREFIX);
|
||||
p.appendComponent("etc");
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
// try the install-prefix/etc/ldc
|
||||
|
@ -72,19 +73,19 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
|
|||
p.appendComponent("etc");
|
||||
p.appendComponent("ldc");
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
// try /etc (absolute path)
|
||||
p = sys::Path("/etc");
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
// try /etc/ldc (absolute path)
|
||||
p = sys::Path("/etc/ldc");
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
#endif
|
||||
|
||||
|
@ -92,7 +93,7 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
|
|||
p = sys::Path::GetMainExecutable(argv0, mainAddr);
|
||||
p.eraseComponent();
|
||||
p.appendComponent(filename);
|
||||
if (p.exists())
|
||||
if (sys::fs::exists(p.str()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -134,7 +135,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 = sys::path::parent_path(sys::Path::GetMainExecutable(argv0, mainAddr).str());
|
||||
|
||||
libconfig::Setting& arr = cfg->lookup("default.switches");
|
||||
int len = arr.getLength();
|
||||
|
|
|
@ -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"
|
||||
|
@ -96,9 +97,8 @@ 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()));
|
||||
if (!llvm::sys::fs::exists(exedir.str()))
|
||||
{
|
||||
exedir.createDirectoryOnDisk(true, &errstr);
|
||||
if (!errstr.empty())
|
||||
|
@ -145,7 +145,7 @@ int linkExecutable(const char* argv0)
|
|||
}
|
||||
|
||||
// additional linker switches
|
||||
for (int i = 0; i < global.params.linkswitches->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.linkswitches->data[i];
|
||||
args.push_back(p);
|
||||
|
@ -156,7 +156,7 @@ int linkExecutable(const char* argv0)
|
|||
|
||||
|
||||
// user libs
|
||||
for (int i = 0; i < global.params.libfiles->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.libfiles->data[i];
|
||||
args.push_back(p);
|
||||
|
@ -180,7 +180,7 @@ int linkExecutable(const char* argv0)
|
|||
}
|
||||
|
||||
// object files
|
||||
for (int i = 0; i < global.params.objfiles->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.objfiles->data[i];
|
||||
args.push_back(p);
|
||||
|
@ -232,7 +232,7 @@ int linkObjToExecutable(const char* argv0)
|
|||
args.push_back(gccStr);
|
||||
|
||||
// object files
|
||||
for (int i = 0; i < global.params.objfiles->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.objfiles->data[i];
|
||||
args.push_back(p);
|
||||
|
@ -265,9 +265,8 @@ 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()));
|
||||
if (!llvm::sys::fs::exists(exedir.str()))
|
||||
{
|
||||
exedir.createDirectoryOnDisk(true, &errstr);
|
||||
if (!errstr.empty())
|
||||
|
@ -278,14 +277,14 @@ int linkObjToExecutable(const char* argv0)
|
|||
}
|
||||
|
||||
// additional linker switches
|
||||
for (int i = 0; i < global.params.linkswitches->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.linkswitches->data[i];
|
||||
args.push_back(p);
|
||||
}
|
||||
|
||||
// user libs
|
||||
for (int i = 0; i < global.params.libfiles->dim; i++)
|
||||
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
|
||||
{
|
||||
char *p = (char *)global.params.libfiles->data[i];
|
||||
args.push_back(p);
|
||||
|
@ -363,7 +362,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);
|
||||
}
|
||||
}
|
||||
|
@ -392,7 +392,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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue