Skip to content

Commit

Permalink
Merge branch 'master' into merge-2.068
Browse files Browse the repository at this point in the history
  • Loading branch information
kinke committed Oct 2, 2015
2 parents 49424d7 + 7f8d653 commit 8ee0e25
Show file tree
Hide file tree
Showing 23 changed files with 246 additions and 172 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Expand Up @@ -36,11 +36,12 @@ addons:
- llvm-3.7-dev
install:
- if [[ "${LLVM_CONFIG}" == *3\.[567]* ]]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi
- if [[ "${OPTS}" == *TEST_COVERAGE*ON* ]]; then pip install --user coveralls; fi
env:
- LLVM_CONFIG="llvm-config-3.7"
- LLVM_CONFIG="llvm-config-3.6" OPTS="-DMULTILIB=ON"
- LLVM_CONFIG="llvm-config-3.5" OPTS="-DBUILD_SHARED_LIBS=ON"
- LLVM_CONFIG="llvm-config-3.4" OPTS="-DTEST_COVERAGE=ON"
- LLVM_CONFIG="llvm-config-3.7" OPTS="-DMULTILIB=ON"
- LLVM_CONFIG="llvm-config-3.6" OPTS="-DBUILD_SHARED_LIBS=ON"
- LLVM_CONFIG="llvm-config-3.5" OPTS="-DTEST_COVERAGE=ON"
- LLVM_CONFIG="llvm-config-3.4"
- LLVM_CONFIG="llvm-config-3.3"
- LLVM_CONFIG="llvm-config-3.2"
- LLVM_CONFIG="llvm-config-3.1"
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Expand Up @@ -248,6 +248,7 @@ set(DRV_SRC
driver/cl_options.cpp
driver/codegenerator.cpp
driver/configfile.cpp
driver/exe_path.cpp
driver/targetmachine.cpp
driver/toobj.cpp
driver/tool.cpp
Expand All @@ -260,6 +261,7 @@ set(DRV_HDR
driver/cl_options.h
driver/codegenerator.h
driver/configfile.h
driver/exe_path.h
driver/ldc-version.h
driver/targetmachine.h
driver/toobj.h
Expand Down Expand Up @@ -498,7 +500,7 @@ endif()
set_source_files_properties(driver/ldmd.cpp driver/response.cpp PROPERTIES
COMPILE_FLAGS "${LDC_CXXFLAGS}"
)
add_executable(${LDMD_EXE} dmd2/root/man.c driver/ldmd.cpp driver/response.cpp)
add_executable(${LDMD_EXE} dmd2/root/man.c driver/exe_path.cpp driver/ldmd.cpp driver/response.cpp driver/exe_path.h)
set_target_properties(${LDMD_EXE} PROPERTIES
COMPILE_DEFINITIONS LDC_EXE_NAME="${LDC_EXE_NAME}"
COMPILE_FLAGS "${LLVM_CXXFLAGS}"
Expand Down Expand Up @@ -534,6 +536,10 @@ if(${BUILD_SHARED})
endif()
install(FILES ${PROJECT_BINARY_DIR}/bin/${LDC_EXE}_install.conf DESTINATION ${CONF_INST_DIR} RENAME ${LDC_EXE}.conf)

if(MSVC)
install(DIRECTORY vcbuild/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin FILES_MATCHING PATTERN "*.bat")
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
find_package(bash-completion QUIET)
if(NOT BASH_COMPLETION_FOUND)
Expand Down
4 changes: 0 additions & 4 deletions appveyor.yml
Expand Up @@ -90,10 +90,6 @@ before_build:

build_script:
- cd c:\projects
# Config file templates: add a lib required in combination with VS 2015
- ps: (gc ldc\ldc2.conf.in).replace('@ADDITIONAL_DEFAULT_LDC_SWITCHES@', ', "-Llegacy_stdio_definitions.lib"@ADDITIONAL_DEFAULT_LDC_SWITCHES@') | sc ldc\ldc2.conf.in
- ps: (gc ldc\ldc2_install.conf.in).replace('@ADDITIONAL_DEFAULT_LDC_SWITCHES@', ', "-Llegacy_stdio_definitions.lib"@ADDITIONAL_DEFAULT_LDC_SWITCHES@') | sc ldc\ldc2_install.conf.in
- ps: (gc ldc\ldc2_phobos.conf.in).replace('@ADDITIONAL_DEFAULT_LDC_SWITCHES@', ', "-Llegacy_stdio_definitions.lib"@ADDITIONAL_DEFAULT_LDC_SWITCHES@') | sc ldc\ldc2_phobos.conf.in
# Generate build files for LDC
- md ninja-ldc
- cd ninja-ldc
Expand Down
8 changes: 8 additions & 0 deletions cmake/Modules/FindLLVM.cmake
Expand Up @@ -83,6 +83,10 @@ if ((WIN32 AND NOT(MINGW OR CYGWIN)) OR NOT LLVM_CONFIG)
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
# Versions beginning with 3.8 do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()

if(${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
llvm_map_components_to_libraries(tmplibs ${LLVM_FIND_COMPONENTS})
Expand Down Expand Up @@ -163,6 +167,10 @@ else()
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "debuginfodwarf" index)
list(APPEND LLVM_FIND_COMPONENTS "debuginfo")
endif()
if(${LLVM_VERSION_STRING} MATCHES "^3\\.[8-9][\\.0-9A-Za-z]*")
# Versions beginning with 3.8 do not support component ipa
list(REMOVE_ITEM LLVM_FIND_COMPONENTS "ipa" index)
endif()

llvm_set(LDFLAGS ldflags)
if(NOT ${LLVM_VERSION_STRING} MATCHES "^3\\.[0-4][\\.0-9A-Za-z]*")
Expand Down
27 changes: 7 additions & 20 deletions driver/configfile.cpp
Expand Up @@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//

#include "driver/configfile.h"
#include "driver/exe_path.h"
#include "mars.h"
#include "libconfig.h"
#include "llvm/Support/FileSystem.h"
Expand Down Expand Up @@ -51,16 +52,6 @@ std::string getUserHomeDirectory() {
}
#endif

#if LDC_LLVM_VER >= 304
static std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
return sys::fs::getMainExecutable(argv0, MainExecAddr);
}
#else
static std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
return llvm::sys::Path::GetMainExecutable(argv0, MainExecAddr).str();
}
#endif

#if _WIN32
static bool ReadPathFromRegistry(llvm::SmallString<128> &p)
{
Expand Down Expand Up @@ -98,7 +89,7 @@ ConfigFile::~ConfigFile()
}


bool ConfigFile::locate(llvm::SmallString<128> &p, const char* argv0, void* mainAddr, const char* filename)
bool ConfigFile::locate(llvm::SmallString<128>& p, const char* filename)
{
// temporary configuration

Expand All @@ -111,9 +102,7 @@ bool ConfigFile::locate(llvm::SmallString<128> &p, const char* argv0, void* main
}

// try next to the executable
p = getMainExecutable(argv0, mainAddr);
sys::path::remove_filename(p);
sys::path::append(p, filename);
p = exe_path::prependBinDir(filename);
if (sys::fs::exists(p.str()))
return true;

Expand All @@ -138,9 +127,7 @@ bool ConfigFile::locate(llvm::SmallString<128> &p, const char* argv0, void* main

// try in etc relative to the executable: exe\..\etc
// do not use .. in path because of security risks
p = getMainExecutable(argv0, mainAddr);
sys::path::remove_filename(p);
sys::path::remove_filename(p);
p = exe_path::getBaseDir();
if (!p.empty())
{
sys::path::append(p, "etc");
Expand Down Expand Up @@ -190,10 +177,10 @@ bool ConfigFile::locate(llvm::SmallString<128> &p, const char* argv0, void* main
return false;
}

bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
bool ConfigFile::read(const char* filename)
{
llvm::SmallString<128> p;
if (!locate(p, argv0, mainAddr, filename))
if (!locate(p, filename))
{
// failed to find cfg, users still have the DFLAGS environment var
std::cerr << "Error failed to locate the configuration file: " << filename << std::endl;
Expand Down Expand Up @@ -228,7 +215,7 @@ bool ConfigFile::read(const char* argv0, void* mainAddr, const char* filename)
{
std::string binpathkey = "%%ldcbinarypath%%";

std::string binpath = sys::path::parent_path(getMainExecutable(argv0, mainAddr));
std::string binpath = exe_path::getBinDir();

int len = config_setting_length(sw);
for (int i = 0; i < len; i++)
Expand Down
4 changes: 2 additions & 2 deletions driver/configfile.h
Expand Up @@ -29,15 +29,15 @@ class ConfigFile
ConfigFile();
~ConfigFile();

bool read(const char* argv0, void* mainAddr, const char* filename);
bool read(const char* filename);

s_iterator switches_begin() { return switches.begin(); }
s_iterator switches_end() { return switches.end(); }

const std::string& path() { return pathstr; }

private:
bool locate(llvm::SmallString<128> &path, const char* argv0, void* mainAddr, const char* filename);
bool locate(llvm::SmallString<128> &path, const char* filename);

config_t* cfg;
std::string pathstr;
Expand Down
56 changes: 56 additions & 0 deletions driver/exe_path.cpp
@@ -0,0 +1,56 @@
//===-- exe_path.cpp ------------------------------------------------------===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//

#include "exe_path.h"

#include <llvm/Support/Path.h>
#if LDC_LLVM_VER >= 304
#include <llvm/Support/FileSystem.h>
#endif

using std::string;
namespace path = llvm::sys::path;

namespace { string exePath; }

void exe_path::initialize(const char* arg0, void* mainAddress)
{
assert(exePath.empty());
#if LDC_LLVM_VER >= 304
exePath = llvm::sys::fs::getMainExecutable(arg0, mainAddress);
#else
exePath = llvm::sys::Path::GetMainExecutable(arg0, mainAddress).str();
#endif
}

const string& exe_path::getExePath()
{
assert(!exePath.empty());
return exePath;
}

string exe_path::getBinDir()
{
assert(!exePath.empty());
return path::parent_path(exePath);
}

string exe_path::getBaseDir()
{
string binDir = getBinDir();
assert(!binDir.empty());
return path::parent_path(binDir);
}

string exe_path::prependBinDir(const char* suffix)
{
llvm::SmallString<128> r(getBinDir());
path::append(r, suffix);
return r.str();
}
30 changes: 30 additions & 0 deletions driver/exe_path.h
@@ -0,0 +1,30 @@
//===-- driver/exe_path.h - Executable path management ----------*- C++ -*-===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
//
// Stores the program's executable path and provides some helpers to generate
// derived paths.
//
//===----------------------------------------------------------------------===//

#ifndef LDC_DRIVER_EXE_PATH_H
#define LDC_DRIVER_EXE_PATH_H

#include <string>

namespace exe_path
{
void initialize(const char* arg0, void* mainAddress);

const std::string& getExePath(); // <baseDir>/bin/ldc2
std::string getBinDir(); // <baseDir>/bin
std::string getBaseDir(); // <baseDir>
std::string prependBinDir(const char* suffix); // <baseDir>/bin/<suffix>
}

#endif // LDC_DRIVER_EXE_PATH_H
66 changes: 11 additions & 55 deletions driver/ldmd.cpp
Expand Up @@ -48,6 +48,7 @@
# error "Please define LDC_EXE_NAME to the name of the LDC executable to use."
#endif

#include "driver/exe_path.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -94,58 +95,8 @@ error_code createUniqueFile(const Twine &Model, int &ResultFD,
}
#endif

#if LDC_LLVM_VER >= 304
std::string getEXESuffix() {
#if _WIN32
return "exe";
#else
return llvm::StringRef();
#endif
}
#else
std::string getEXESuffix() {
return ls::Path::GetEXESuffix().str();
}
#endif

#if LDC_LLVM_VER >= 304
namespace llvm {
/// Prepend the path to the program being executed
/// to \p ExeName, given the value of argv[0] and the address of main()
/// itself. This allows us to find another LLVM tool if it is built in the same
/// directory. An empty string is returned on error; note that this function
/// just mainpulates the path and doesn't check for executability.
/// @brief Find a named executable.
static std::string prependMainExecutablePath(const std::string &ExeName,
const char *Argv0, void *MainAddr) {
// Check the directory that the calling program is in. We can do
// this if ProgramPath contains at least one / character, indicating that it
// is a relative path to the executable itself.
llvm::SmallString<128> Result(ls::fs::getMainExecutable(Argv0, MainAddr));
sys::path::remove_filename(Result);

if (!Result.empty()) {
sys::path::append(Result, ExeName);

// Do not use path::append here, this is not a path component before which
// to insert the path seperator.
Result.append(getEXESuffix());
}

return Result.str();
}
}
#else
namespace llvm {
static std::string prependMainExecutablePath(const std::string &ExeName,
const char *Argv0, void *MainAddr) {
return llvm::PrependMainExecutablePath(ExeName, Argv0, MainAddr).str();
}
}
#endif

// We reuse DMD's response file parsing routine for maximum compatibilty - it
// handles quotes in a very peciuliar way.
// handles quotes in a very peculiar way.
int response_expand(size_t *pargc, char ***pargv);
void browse(const char *url);

Expand Down Expand Up @@ -1090,10 +1041,9 @@ size_t maxCommandLineLen()
* nothing was found. Search paths: 1. Directory where this binary resides.
* 2. System PATH.
*/
std::string locateBinary(std::string exeName, const char* argv0)
std::string locateBinary(std::string exeName)
{
std::string path = llvm::prependMainExecutablePath(exeName,
argv0, (void*)&locateBinary);
std::string path = exe_path::prependBinDir(exeName.c_str());
if (ls::fs::can_execute(path)) return path;

#if LDC_LLVM_VER >= 306
Expand Down Expand Up @@ -1130,7 +1080,13 @@ static size_t addStrlen(size_t acc, const char* str)

int main(int argc, char *argv[])
{
std::string ldcPath = locateBinary(LDC_EXE_NAME, argv[0]);
exe_path::initialize(argv[0], reinterpret_cast<void*>(main));

std::string ldcExeName = LDC_EXE_NAME;
#ifdef _WIN32
ldcExeName += ".exe";
#endif
std::string ldcPath = locateBinary(ldcExeName);
if (ldcPath.empty())
{
error("Could not locate " LDC_EXE_NAME " executable.");
Expand Down

0 comments on commit 8ee0e25

Please sign in to comment.