mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-11 13:26:08 +03:00
Include config file path in JSON output
Required for dmd-testsuite's compilable/json2.d. Also fixes a bug regarding ConfigFile::path() with a null config file path (e.g., when disabled explicitly via `-conf=`) - the std::string(const char *) ctor segfaults for a null pointer arg, whereas llvm::StringRef handles null pointers gracefully.
This commit is contained in:
parent
426555f354
commit
32b7637528
4 changed files with 14 additions and 8 deletions
|
@ -15,6 +15,7 @@
|
||||||
#define LDC_DRIVER_CONFIGFILE_H
|
#define LDC_DRIVER_CONFIGFILE_H
|
||||||
|
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "array.h"
|
#include "array.h"
|
||||||
|
@ -23,7 +24,7 @@ class ConfigFile {
|
||||||
public:
|
public:
|
||||||
bool read(const char *explicitConfFile, const char *section);
|
bool read(const char *explicitConfFile, const char *section);
|
||||||
|
|
||||||
std::string path() { return std::string(pathcstr); }
|
llvm::StringRef path() { return pathcstr; }
|
||||||
|
|
||||||
void extendCommandLine(llvm::SmallVectorImpl<const char *> &args);
|
void extendCommandLine(llvm::SmallVectorImpl<const char *> &args);
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,9 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cfg_file.path().empty())
|
||||||
|
global.inifilename = dupPathString(cfg_file.path());
|
||||||
|
|
||||||
// Print some information if -v was passed
|
// Print some information if -v was passed
|
||||||
// - path to compiler binary
|
// - path to compiler binary
|
||||||
// - version number
|
// - version number
|
||||||
|
@ -376,9 +379,8 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
||||||
message("binary %s", exe_path::getExePath().c_str());
|
message("binary %s", exe_path::getExePath().c_str());
|
||||||
message("version %s (DMD %s, LLVM %s)", global.ldc_version,
|
message("version %s (DMD %s, LLVM %s)", global.ldc_version,
|
||||||
global.version, global.llvm_version);
|
global.version, global.llvm_version);
|
||||||
const std::string path = cfg_file.path();
|
if (global.inifilename) {
|
||||||
if (!path.empty()) {
|
message("config %s (%s)", global.inifilename, cfg_triple.c_str());
|
||||||
message("config %s (%s)", path.c_str(), cfg_triple.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,14 @@
|
||||||
|
|
||||||
namespace opts {
|
namespace opts {
|
||||||
|
|
||||||
char *dupPathString(const std::string &src) {
|
char *dupPathString(llvm::StringRef src) {
|
||||||
char *r = mem.xstrdup(src.c_str());
|
const auto length = src.size();
|
||||||
|
char *r = static_cast<char *>(mem.xmalloc(length + 1));
|
||||||
|
memcpy(r, src.data(), length);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
std::replace(r, r + src.length(), '/', '\\');
|
std::replace(r, r + length, '/', '\\');
|
||||||
#endif
|
#endif
|
||||||
|
r[length] = '\0';
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace opts {
|
||||||
namespace cl = llvm::cl;
|
namespace cl = llvm::cl;
|
||||||
|
|
||||||
/// Duplicate the string and replace '/' with '\' on Windows.
|
/// Duplicate the string and replace '/' with '\' on Windows.
|
||||||
char *dupPathString(const std::string &src);
|
char *dupPathString(llvm::StringRef src);
|
||||||
|
|
||||||
/// Helper function to handle -of, -od, etc.
|
/// Helper function to handle -of, -od, etc.
|
||||||
/// llvm::cl::opt<std::string> --> char*
|
/// llvm::cl::opt<std::string> --> char*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue