mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-05 17:43:35 +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 <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
|
|
||||||
#include "libconfig.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
|
// try the current working dir
|
||||||
p = sys::Path::GetCurrentDirectory();
|
p = sys::Path::GetCurrentDirectory();
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// user configuration
|
// user configuration
|
||||||
|
@ -40,14 +41,14 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
|
||||||
p = sys::Path::GetUserHomeDirectory();
|
p = sys::Path::GetUserHomeDirectory();
|
||||||
p.appendComponent(".ldc");
|
p.appendComponent(".ldc");
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
// try home dir
|
// try home dir
|
||||||
p = sys::Path::GetUserHomeDirectory();
|
p = sys::Path::GetUserHomeDirectory();
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -57,14 +58,14 @@ bool ConfigFile::locate(sys::Path& p, const char* argv0, void* mainAddr, const c
|
||||||
// try the install-prefix
|
// try the install-prefix
|
||||||
p = sys::Path(LDC_INSTALL_PREFIX);
|
p = sys::Path(LDC_INSTALL_PREFIX);
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
// try the install-prefix/etc
|
// try the install-prefix/etc
|
||||||
p = sys::Path(LDC_INSTALL_PREFIX);
|
p = sys::Path(LDC_INSTALL_PREFIX);
|
||||||
p.appendComponent("etc");
|
p.appendComponent("etc");
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// try the install-prefix/etc/ldc
|
// 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("etc");
|
||||||
p.appendComponent("ldc");
|
p.appendComponent("ldc");
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// try /etc (absolute path)
|
// try /etc (absolute path)
|
||||||
p = sys::Path("/etc");
|
p = sys::Path("/etc");
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// try /etc/ldc (absolute path)
|
// try /etc/ldc (absolute path)
|
||||||
p = sys::Path("/etc/ldc");
|
p = sys::Path("/etc/ldc");
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#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 = sys::Path::GetMainExecutable(argv0, mainAddr);
|
||||||
p.eraseComponent();
|
p.eraseComponent();
|
||||||
p.appendComponent(filename);
|
p.appendComponent(filename);
|
||||||
if (p.exists())
|
if (sys::fs::exists(p.str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -134,7 +135,7 @@ bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
|
||||||
{
|
{
|
||||||
std::string binpathkey = "%%ldcbinarypath%%";
|
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");
|
libconfig::Setting& arr = cfg->lookup("default.switches");
|
||||||
int len = arr.getLength();
|
int len = arr.getLength();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "gen/linker.h"
|
#include "gen/linker.h"
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "llvm/Linker.h"
|
#include "llvm/Linker.h"
|
||||||
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Program.h"
|
#include "llvm/Support/Program.h"
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
#include "llvm/Support/SystemUtils.h"
|
#include "llvm/Support/SystemUtils.h"
|
||||||
|
@ -96,9 +97,8 @@ int linkExecutable(const char* argv0)
|
||||||
assert(gExePath.isValid());
|
assert(gExePath.isValid());
|
||||||
|
|
||||||
// create path to exe
|
// create path to exe
|
||||||
llvm::sys::Path exedir(gExePath);
|
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
|
||||||
exedir.set(gExePath.getDirname());
|
if (!llvm::sys::fs::exists(exedir.str()))
|
||||||
if (!exedir.exists())
|
|
||||||
{
|
{
|
||||||
exedir.createDirectoryOnDisk(true, &errstr);
|
exedir.createDirectoryOnDisk(true, &errstr);
|
||||||
if (!errstr.empty())
|
if (!errstr.empty())
|
||||||
|
@ -145,7 +145,7 @@ int linkExecutable(const char* argv0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// additional linker switches
|
// 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];
|
char *p = (char *)global.params.linkswitches->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
|
@ -156,7 +156,7 @@ int linkExecutable(const char* argv0)
|
||||||
|
|
||||||
|
|
||||||
// user libs
|
// 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];
|
char *p = (char *)global.params.libfiles->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
|
@ -180,7 +180,7 @@ int linkExecutable(const char* argv0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// object files
|
// 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];
|
char *p = (char *)global.params.objfiles->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
|
@ -232,7 +232,7 @@ int linkObjToExecutable(const char* argv0)
|
||||||
args.push_back(gccStr);
|
args.push_back(gccStr);
|
||||||
|
|
||||||
// object files
|
// 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];
|
char *p = (char *)global.params.objfiles->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
|
@ -265,9 +265,8 @@ int linkObjToExecutable(const char* argv0)
|
||||||
assert(gExePath.isValid());
|
assert(gExePath.isValid());
|
||||||
|
|
||||||
// create path to exe
|
// create path to exe
|
||||||
llvm::sys::Path exedir(gExePath);
|
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
|
||||||
exedir.set(gExePath.getDirname());
|
if (!llvm::sys::fs::exists(exedir.str()))
|
||||||
if (!exedir.exists())
|
|
||||||
{
|
{
|
||||||
exedir.createDirectoryOnDisk(true, &errstr);
|
exedir.createDirectoryOnDisk(true, &errstr);
|
||||||
if (!errstr.empty())
|
if (!errstr.empty())
|
||||||
|
@ -278,14 +277,14 @@ int linkObjToExecutable(const char* argv0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// additional linker switches
|
// 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];
|
char *p = (char *)global.params.linkswitches->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// user libs
|
// 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];
|
char *p = (char *)global.params.libfiles->data[i];
|
||||||
args.push_back(p);
|
args.push_back(p);
|
||||||
|
@ -363,7 +362,8 @@ void deleteExecutable()
|
||||||
if (!gExePath.isEmpty())
|
if (!gExePath.isEmpty())
|
||||||
{
|
{
|
||||||
assert(gExePath.isValid());
|
assert(gExePath.isValid());
|
||||||
assert(!gExePath.isDirectory());
|
bool is_directory;
|
||||||
|
assert(!(!llvm::sys::fs::is_directory(gExePath.str(), is_directory) && is_directory));
|
||||||
gExePath.eraseFromDisk(false);
|
gExePath.eraseFromDisk(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,11 @@ int runExecutable()
|
||||||
int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr);
|
int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
{
|
{
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
error("program received signal %d", -status);
|
||||||
|
#else
|
||||||
error("program received signal %d (%s)", -status, strsignal(-status));
|
error("program received signal %d (%s)", -status, strsignal(-status));
|
||||||
|
#endif
|
||||||
return -status;
|
return -status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue