mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-09 12:32:33 +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
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <string>
|
||||
|
||||
#include "array.h"
|
||||
|
@ -23,7 +24,7 @@ class ConfigFile {
|
|||
public:
|
||||
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);
|
||||
|
||||
|
|
|
@ -368,6 +368,9 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!cfg_file.path().empty())
|
||||
global.inifilename = dupPathString(cfg_file.path());
|
||||
|
||||
// Print some information if -v was passed
|
||||
// - path to compiler binary
|
||||
// - version number
|
||||
|
@ -376,9 +379,8 @@ void parseCommandLine(int argc, char **argv, Strings &sourceFiles,
|
|||
message("binary %s", exe_path::getExePath().c_str());
|
||||
message("version %s (DMD %s, LLVM %s)", global.ldc_version,
|
||||
global.version, global.llvm_version);
|
||||
const std::string path = cfg_file.path();
|
||||
if (!path.empty()) {
|
||||
message("config %s (%s)", path.c_str(), cfg_triple.c_str());
|
||||
if (global.inifilename) {
|
||||
message("config %s (%s)", global.inifilename, cfg_triple.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,14 @@
|
|||
|
||||
namespace opts {
|
||||
|
||||
char *dupPathString(const std::string &src) {
|
||||
char *r = mem.xstrdup(src.c_str());
|
||||
char *dupPathString(llvm::StringRef src) {
|
||||
const auto length = src.size();
|
||||
char *r = static_cast<char *>(mem.xmalloc(length + 1));
|
||||
memcpy(r, src.data(), length);
|
||||
#if _WIN32
|
||||
std::replace(r, r + src.length(), '/', '\\');
|
||||
std::replace(r, r + length, '/', '\\');
|
||||
#endif
|
||||
r[length] = '\0';
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace opts {
|
|||
namespace cl = llvm::cl;
|
||||
|
||||
/// 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.
|
||||
/// llvm::cl::opt<std::string> --> char*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue