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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ addons:
sources:
- ubuntu-toolchain-r-test
packages:
- libconfig++8-dev
- gdb
- gcc-4.9
- g++-4.9
Expand Down Expand Up @@ -71,7 +70,6 @@ before_install:
export LLVM_CONFIG="llvm-$LLVM_VERSION/bin/llvm-config";
install:
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew update; brew install libconfig; fi;
- eval "${DC} --version"
- pip install --user lit
- python -c "import lit; lit.main();" --version | head -n 1
Expand Down
13 changes: 2 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ project(ldc)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")

if(MSVC)
set(LIBCONFIG_DLL OFF CACHE BOOL "Use libconfig DLL instead of static library")
endif()

include(FindDCompiler)
include(CheckIncludeFile)
include(CheckLibraryExists)
Expand All @@ -29,11 +25,6 @@ math(EXPR LDC_LLVM_VER ${LLVM_VERSION_MAJOR}*100+${LLVM_VERSION_MINOR})
string(REGEX MATCH "^-.*LLVMTableGen[^;]*;|;-.*LLVMTableGen[^;]*" LLVM_TABLEGEN_LIBRARY "${LLVM_LIBRARIES}")
string(REGEX REPLACE "^-.*LLVMTableGen[^;]*;|;-.*LLVMTableGen[^;]*" "" LLVM_LIBRARIES "${LLVM_LIBRARIES}")

#
# Locate libconfig.
#
find_package(LibConfig REQUIRED)

#
# Get info about used Linux distribution.
#
Expand Down Expand Up @@ -542,8 +533,8 @@ add_custom_target(${LDC_EXE} ALL DEPENDS ${LDC_EXE_FULL})
add_custom_target(${LDMD_EXE} ALL DEPENDS ${LDMD_EXE_FULL})

# Figure out how to link the main LDC executable, for which we need to take the
# libconfig/LLVM flags into account.
set(LDC_LINKERFLAG_LIST "${SANITIZE_LDFLAGS};${LIBCONFIG_LIBRARY};${LLVM_LIBRARIES};${LLVM_LDFLAGS}")
# LLVM flags into account.
set(LDC_LINKERFLAG_LIST "${SANITIZE_LDFLAGS};${LLVM_LIBRARIES};${LLVM_LDFLAGS}")

set(LDC_LINK_MANUALLY OFF)
if(UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")))
Expand Down
513 changes: 0 additions & 513 deletions LICENSE

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ libraries is available on the project wiki for
[Windows](http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC).

If you have a working C++ build environment, CMake, a current LLVM (>= 3.5),
and [libconfig](http://hyperrealm.com/libconfig/libconfig.html) available
there should be no big surprises.
Building LDC also requires a working D compiler, DMD and LDC are supported.
(LDC 0.17 is the last version that does not need a D compiler,
Expand Down
13 changes: 2 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ install:
- cd ldc
- git submodule update --init --recursive
- cd ..
# Clone libconfig (v1.6 does not work due to https://github.com/hyperrealm/libconfig/issues/47)
- git clone https://github.com/hyperrealm/libconfig.git libconfig
- cd libconfig
- git checkout 7585cf6
- cd ..
# Download & extract libcurl
- appveyor DownloadFile "http://d.darktech.org/libcurl-7.48.0-WinSSL-zlib-x86-x64.zip" -FileName libcurl.zip
- md libcurl
Expand Down Expand Up @@ -118,18 +113,14 @@ install:
#---------------------------------#

before_build:
- cd c:\projects
# Build libconfig
- if "%APPVEYOR_JOB_ARCH%"=="x64" ( msbuild libconfig\lib\libconfig.vcxproj /p:Configuration=ReleaseStatic /p:Platform=x64 )
- if "%APPVEYOR_JOB_ARCH%"=="x86" ( msbuild libconfig\lib\libconfig.vcxproj /p:Configuration=ReleaseStatic /p:Platform=Win32 )

build_script:
- cd c:\projects
# Generate build files for LDC
- md ninja-ldc
- cd ninja-ldc
- if "%APPVEYOR_JOB_ARCH%"=="x64" ( cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=c:\projects\ldc-x64 -DLLVM_ROOT_DIR=c:/projects/llvm-x64 -DLIBCONFIG_INCLUDE_DIR=c:/projects/libconfig/lib -DLIBCONFIG_LIBRARY=c:/projects/libconfig/lib/x64/ReleaseStatic/libconfig.lib ..\ldc )
- if "%APPVEYOR_JOB_ARCH%"=="x86" ( cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=c:\projects\ldc-x86 -DLLVM_ROOT_DIR=c:/projects/llvm-x86 -DLIBCONFIG_INCLUDE_DIR=c:/projects/libconfig/lib -DLIBCONFIG_LIBRARY=c:/projects/libconfig/lib/ReleaseStatic/libconfig.lib ..\ldc )
- if "%APPVEYOR_JOB_ARCH%"=="x64" ( cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=c:\projects\ldc-x64 -DLLVM_ROOT_DIR=c:/projects/llvm-x64 ..\ldc )
- if "%APPVEYOR_JOB_ARCH%"=="x86" ( cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=c:\projects\ldc-x86 -DLLVM_ROOT_DIR=c:/projects/llvm-x86 ..\ldc )
# Build LDC, druntime and phobos
- ninja -j2

Expand Down
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:

override:
- sudo apt-get remove clang llvm
- sudo apt-get install libconfig++8-dev libedit-dev
- sudo apt-get install libedit-dev
- sudo apt-get install llvm-4.0 llvm-4.0-dev clang-4.0
- pip install --user lit
post:
Expand Down Expand Up @@ -75,7 +75,7 @@ test:
# The containers were started but only the tests from container 0 were run.
# Containers 1-3 also started the tests but stop with the message
# "No tests were found!!!"
#
#
# - ? |
# echo $CIRCLE_NODE_INDEX
# case $CIRCLE_NODE_INDEX in
Expand Down
15 changes: 0 additions & 15 deletions cmake/Modules/FindLibConfig.cmake

This file was deleted.

219 changes: 4 additions & 215 deletions driver/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,11 @@
#include "driver/configfile.h"
#include "driver/exe_path.h"
#include "mars.h"
#include "libconfig.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include <cassert>
#include <cstring>
#include <iostream>
#include <string>
#if _WIN32
#define WIN32_LEAN_AND_MEAN
#include "llvm/Support/ConvertUTF.h"
#include <windows.h>
#include <shlobj.h>
#include <tchar.h>
// Prevent name clash with LLVM
#undef GetCurrentDirectory
#endif

namespace sys = llvm::sys;

Expand All @@ -36,213 +24,14 @@ llvm::cl::opt<std::string>
clConf("conf", llvm::cl::desc("Use configuration file <filename>"),
llvm::cl::value_desc("filename"));

#if _WIN32
std::string getUserHomeDirectory() {
char buff[MAX_PATH];
HRESULT res = SHGetFolderPathA(NULL, CSIDL_FLAG_CREATE | CSIDL_APPDATA, NULL,
SHGFP_TYPE_CURRENT, buff);
if (res != S_OK)
assert(0 && "Failed to get user home directory");
return buff;
}
#else
std::string getUserHomeDirectory() {
const char *home = getenv("HOME");
return home ? home : "/";
}
#endif

#if _WIN32
static bool ReadPathFromRegistry(llvm::SmallString<128> &p) {
HKEY hkey;
bool res = false;
// FIXME: Version number should be a define.
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\ldc-developers\\LDC\\0.11.0"),
NULL, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) {
DWORD length;
if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, NULL, &length) ==
ERROR_SUCCESS) {
TCHAR *data = static_cast<TCHAR *>(_alloca(length * sizeof(TCHAR)));
if (RegGetValue(hkey, NULL, _T("Path"), RRF_RT_REG_SZ, NULL, data, &length) ==
ERROR_SUCCESS) {
#if UNICODE
#if LDC_LLVM_VER >= 400
using UTF16 = llvm::UTF16;
#endif
std::string out;
res = llvm::convertUTF16ToUTF8String(
llvm::ArrayRef<UTF16>(reinterpret_cast<UTF16 *>(data), length), out);
p = out;
#else
p = std::string(data);
res = true;
#endif
}
}
RegCloseKey(hkey);
}
return res;
}
#endif

ConfigFile::ConfigFile() {
cfg = new config_t;
config_init(cfg);
}

bool ConfigFile::locate() {
// temporary configuration

llvm::SmallString<128> p;
const char *filename = "ldc2.conf";

#define APPEND_FILENAME_AND_RETURN_IF_EXISTS \
{ \
sys::path::append(p, filename); \
if (sys::fs::exists(p.str())) { \
pathstr = p.str(); \
return true; \
} \
}

// try the current working dir
if (!sys::fs::current_path(p))
APPEND_FILENAME_AND_RETURN_IF_EXISTS

// try next to the executable
p = exe_path::getBinDir();
APPEND_FILENAME_AND_RETURN_IF_EXISTS

// user configuration

// try ~/.ldc
p = getUserHomeDirectory();
sys::path::append(p, ".ldc");
APPEND_FILENAME_AND_RETURN_IF_EXISTS

#if _WIN32
// try home dir
p = getUserHomeDirectory();
APPEND_FILENAME_AND_RETURN_IF_EXISTS
#endif

// system configuration

// try in etc relative to the executable: exe\..\etc
// do not use .. in path because of security risks
p = exe_path::getBaseDir();
if (!p.empty()) {
sys::path::append(p, "etc");
APPEND_FILENAME_AND_RETURN_IF_EXISTS
}

#if _WIN32
// Try reading path from registry
if (ReadPathFromRegistry(p)) {
sys::path::append(p, "etc");
APPEND_FILENAME_AND_RETURN_IF_EXISTS
}
#else
const char *getLdcInstallPrefixCStr()
{
#define STR(x) #x
#define XSTR(x) STR(x)
// try the install-prefix/etc
p = XSTR(LDC_INSTALL_PREFIX);
sys::path::append(p, "etc");
APPEND_FILENAME_AND_RETURN_IF_EXISTS

// try the install-prefix/etc/ldc
p = XSTR(LDC_INSTALL_PREFIX);
sys::path::append(p, "etc");
sys::path::append(p, "ldc");
APPEND_FILENAME_AND_RETURN_IF_EXISTS
return XSTR(LDC_INSTALL_PREFIX);

#undef XSTR
#undef STR

// try /etc (absolute path)
p = "/etc";
APPEND_FILENAME_AND_RETURN_IF_EXISTS

// try /etc/ldc (absolute path)
p = "/etc/ldc";
APPEND_FILENAME_AND_RETURN_IF_EXISTS
#endif

#undef APPEND_FILENAME_AND_RETURN_IF_EXISTS

fprintf(stderr, "Warning: failed to locate the configuration file %s\n",
filename);
return false;
}

bool ConfigFile::read(const char *explicitConfFile, const char* section) {
// explicitly provided by user in command line?
if (explicitConfFile) {
const std::string clPath = explicitConfFile;
// treat an empty path (`-conf=`) as missing command-line option,
// defaulting to an auto-located config file, analogous to DMD
if (!clPath.empty()) {
if (sys::fs::exists(clPath)) {
pathstr = clPath;
} else {
fprintf(stderr, "Warning: configuration file '%s' not found, falling "
"back to default\n",
clPath.c_str());
}
}
}

// locate file automatically if path is not set yet
if (pathstr.empty()) {
if (!locate()) {
return false;
}
}

// read the cfg
if (!config_read_file(cfg, pathstr.c_str())) {
std::cerr << "error reading configuration file" << std::endl;
return false;
}

config_setting_t *root = nullptr;
if (section && *section)
root = config_lookup(cfg, section);

// make sure there's a default group
if (!root) {
section = "default";
root = config_lookup(cfg, section);
}
if (!root) {
std::cerr << "no default settings in configuration file" << std::endl;
return false;
}
if (!config_setting_is_group(root)) {
std::cerr << section << " is not a group" << std::endl;
return false;
}

// handle switches
if (config_setting_t *sw = config_setting_get_member(root, "switches")) {
// replace all %%ldcbinarypath%% occurrences by the path to the
// LDC bin directory (using forward slashes)
std::string binpathkey = "%%ldcbinarypath%%";

std::string binpath = exe_path::getBinDir();
std::replace(binpath.begin(), binpath.end(), '\\', '/');

int len = config_setting_length(sw);
for (int i = 0; i < len; i++) {
std::string v(config_setting_get_string(config_setting_get_elem(sw, i)));

size_t p;
while (std::string::npos != (p = v.find(binpathkey))) {
v.replace(p, binpathkey.size(), binpath);
}

switches.push_back(strdup(v.c_str()));
}
}

return true;
}
Loading