From ef9f22c18f26b90e3f4693858ba337881d14740d Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:15:39 +0100 Subject: [PATCH 01/24] adhoc config parser and representation --- driver/config.d | 494 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 494 insertions(+) create mode 100644 driver/config.d diff --git a/driver/config.d b/driver/config.d new file mode 100644 index 00000000000..834e71c5f01 --- /dev/null +++ b/driver/config.d @@ -0,0 +1,494 @@ +//===-- driver/configfile.d - LDC config file parsing -------------*- D -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the BSD-style LDC license. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Parsing engine for the LDC config file (ldc2.conf). +// +//===----------------------------------------------------------------------===// +module driver.config; + +import core.stdc.ctype; +import core.stdc.stdio; +import core.stdc.string; + + +class Setting +{ + enum Type + { + scalar, + array, + group, + } + + this(string name, Type type) + { + _name = name; + _type = type; + } + + @property string name() const + { + return _name; + } + + @property Type type() const + { + return _type; + } + + private string _name; + private Type _type; +} + + +class ScalarSetting : Setting +{ + this (string name, string val) + { + super(name, Type.scalar); + _val = val; + } + + @property string val() const + { + return _val; + } + + private string _val; +} + + +class ArraySetting : Setting +{ + this (string name, string[] vals) + { + super(name, Type.array); + _vals = vals; + } + + @property const(string)[] vals() const + { + return _vals; + } + + private string[] _vals; +} + +class GroupSetting : Setting +{ + this (string name, Setting[] children) + { + super(name, Type.group); + _children = children; + } + + @property const(Setting)[] children() const + { + return _children; + } + + private Setting[] _children; +} + + +Setting[] parseConfigFile(const(char)* filename) +{ + auto parser = new Parser(filename); + return parser.parseConfig(); +} + +private: + +/+ + +What follows is a recursive descent parser that reads the following EBNF grammar + +config = { ows , setting } , ows ; +setting = name , (":" | "=") , value , [";" | ","] ; +name = alpha , { alpha | digit | "_" | "-" } ; +value = string | array | group ; +array = "[" , ows , + { string , ows , "," , ows } , + "]" ; +group = "{" , ows , { setting , ows } , "}" ; +string = quotstr, { ows , quotstr } ; +quotstr = '"' , { ? any char but '"', '\n' and '\r' ? | escseq } , '"' ; +escseq = "\" , ["\" | '"' | "r" | "n" | "t" ] ; +alpha = ? any char between "a" and "z" included + or between "A" and "Z" included ? ; +digit = ? any char between "0" and "9" included ? ; +ows = [ ws ] ; (* optional white space *) +ws = ? white space (space, tab, line feed ...) ? ; + + +Single line comments are also supported in the form of "//" until line feed. +The "//" sequence is however allowed within strings and doesn't need to be +escaped. +Line feed are not allowed within strings. To span a string over multiple lines, +use concatenation. ("string 1" "string 2") + ++/ + + +immutable(char)* toStringz(in string s) +{ + auto nullTerm = s ~ '\0'; + return nullTerm.ptr; +} + + +enum Token +{ + name, + assign, // ':' or '=' + str, + lbrace, // '{' + rbrace, // '}' + lbracket, // '[' + rbracket, // ']' + semicolon, // ';' + comma, // ',' + unknown, + eof, +} + +string humanReadableToken(in Token tok) +{ + final switch(tok) + { + case Token.name: return "\"name\""; + case Token.assign: return "':' or '='"; + case Token.str: return "\"string\""; + case Token.lbrace: return "'{'"; + case Token.rbrace: return "'}'"; + case Token.lbracket: return "'['"; + case Token.rbracket: return "']'"; + case Token.semicolon: return "';'"; + case Token.comma: return "','"; + case Token.unknown: return "\"unknown token\""; + case Token.eof: return "\"end of file\""; + } +} + +class Parser +{ + const(char)[] filename; + FILE* file; + int lineNum; + + int lastChar = ' '; + + struct Ahead + { + Token tok; + string s; + } + Ahead ahead; + Ahead* aheadp; + + this (const(char)* filename) + { + this.filename = filename[0 .. strlen(filename)]; + file = fopen(filename, "r"); + if (!file) + { + throw new Exception( + "could not open config file " ~ + this.filename.idup ~ " for reading"); + } + this.file = file; + } + + void error(in string msg) + { + enum fmt = "Error while reading config file: %s\nline %d: %s"; + char[1024] buf; + // filename was null terminated + auto len = snprintf(buf.ptr, 1024, fmt, + filename.ptr, lineNum, toStringz(msg)); + throw new Exception(buf[0 .. len].idup); + } + + int getChar() + { + int c = fgetc(file); + if (c == '\n') lineNum += 1; + return c; + } + + void ungetChar(int c) + { + ungetc(c, file); + } + + Token getTok(out string outStr) + { + if (aheadp) + { + immutable tok = aheadp.tok; + outStr = aheadp.s; + aheadp = null; + return tok; + } + + while(isspace(lastChar)) + { + lastChar = getChar(); + } + + if (lastChar == '/') + { + lastChar = getChar(); + if (lastChar != '/') + { + outStr = "/"; + return Token.unknown; + } + else do + { + lastChar = getChar(); + } + while(lastChar != '\n' && lastChar != EOF); + return getTok(outStr); + } + + if (isalpha(lastChar)) + { + string name; + do + { + name ~= cast(char)lastChar; + lastChar = getChar(); + } + while (isalnum(lastChar) || lastChar == '-'); + outStr = name; + return Token.name; + } + + switch (lastChar) + { + case ':': + case '=': + lastChar = getChar(); + return Token.assign; + case ';': + lastChar = getChar(); + return Token.semicolon; + case ',': + lastChar = getChar(); + return Token.comma; + case '{': + lastChar = getChar(); + return Token.lbrace; + case '}': + lastChar = getChar(); + return Token.rbrace; + case '[': + lastChar = getChar(); + return Token.lbracket; + case ']': + lastChar = getChar(); + return Token.rbracket; + case EOF: + return Token.eof; + default: + break; + } + + if (lastChar == '"') + { + string str; + while (lastChar == '"') + { + while(1) + { + lastChar = getChar(); + if (lastChar == '"') break; + if (lastChar == '\n' || lastChar == '\r') + { + error("Unexpected end of line in string literal"); + } + else if (lastChar == EOF) + { + error("Unexpected end of file in string literal"); + } + if (lastChar == '\\') + { + lastChar = getChar(); + switch(lastChar) + { + case '\\': + case '"': + break; + case 'r': + lastChar = '\r'; + break; + case 'n': + lastChar = '\n'; + break; + case 't': + lastChar = '\t'; + break; + default: + error("Unexpected escape sequence: \\"~cast(char)lastChar); + break; + } + } + str ~= cast(char)lastChar; + } + lastChar = getChar(); + while(isspace(lastChar)) lastChar = getChar(); + } + + outStr = str; + return Token.str; + } + + outStr = [cast(char)lastChar]; + lastChar = getChar(); + return Token.unknown; + } + + void ungetTok(in Token tok, in string s) + { + assert(!aheadp, "can only have one look ahead"); + ahead.tok = tok; + ahead.s = s; + aheadp = &ahead; + } + + void unexpectedTokenError(in Token tok, in Token expected, string s) + { + s = s.length ? " ("~s~")" : ""; + error("Was expecting token "~humanReadableToken(expected)~ + ". Got "~humanReadableToken(tok)~s~" instead."); + } + + string accept(in Token expected) + { + string s; + immutable tok = getTok(s); + if (tok != expected) + { + unexpectedTokenError(tok, expected, s); + } + return s; + } + + Setting[] parseConfig() + { + Setting[] res; + while(1) + { + { + string s; + auto t = getTok(s); + if (t == Token.eof) break; + else ungetTok(t, s); + } + res ~= parseSetting(); + } + return res; + } + + Setting parseSetting() + { + immutable name = accept(Token.name); + + accept(Token.assign); + + string val; + string[] arrVal; + Setting[] grpVal; + + Setting res; + + final switch(parseValue(val, arrVal, grpVal)) + { + case Setting.Type.scalar: + res = new ScalarSetting(name, val); + break; + case Setting.Type.array: + res = new ArraySetting(name, arrVal); + break; + case Setting.Type.group: + res = new GroupSetting(name, grpVal); + break; + } + + string s; + immutable t = getTok(s); + if (t != Token.semicolon && t != Token.comma) + { + ungetTok(t, s); + } + + return res; + } + + Setting.Type parseValue(out string val, + out string[] arrVal, + out Setting[] grpVal) + { + string s; + auto t = getTok(s); + if (t == Token.str) + { + val = s; + return Setting.Type.scalar; + } + else if (t == Token.lbracket) + { + while (1) + { + // get string or rbracket + t = getTok(s); + switch(t) + { + case Token.str: + arrVal ~= s; + break; + case Token.rbracket: + return Setting.Type.array; + default: + unexpectedTokenError(t, Token.str, s); + assert(false); + } + + // get commar or rbracket + t = getTok(s); + switch(t) + { + case Token.comma: + break; + case Token.rbracket: + return Setting.Type.array; + default: + unexpectedTokenError(t, Token.comma, s); + assert(false); + } + } + } + else if (t == Token.lbrace) + { + while (1) + { + t = getTok(s); + if (t == Token.rbrace) + { + return Setting.Type.group; + } + ungetTok(t, s); + grpVal ~= parseSetting(); + } + } + error("Was expecting value."); + assert(false); + } +} From 2c501301d96834b9de9cd67f5729b9264f885c9b Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:18:35 +0100 Subject: [PATCH 02/24] adapt config file to use adhoc parser --- driver/configfile.cpp | 59 ++--------------- driver/configfile.d | 149 ++++++++++++++++++++++++++++++++++++++++++ driver/configfile.h | 24 ++++--- 3 files changed, 166 insertions(+), 66 deletions(-) create mode 100644 driver/configfile.d diff --git a/driver/configfile.cpp b/driver/configfile.cpp index 9e338842b12..4959d7d226f 100644 --- a/driver/configfile.cpp +++ b/driver/configfile.cpp @@ -10,7 +10,6 @@ #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" @@ -85,12 +84,8 @@ static bool ReadPathFromRegistry(llvm::SmallString<128> &p) { } #endif -ConfigFile::ConfigFile() { - cfg = new config_t; - config_init(cfg); -} -bool ConfigFile::locate() { +bool ConfigFile::locate(std::string& pathstr) { // temporary configuration llvm::SmallString<128> p; @@ -175,6 +170,7 @@ bool ConfigFile::locate() { } bool ConfigFile::read(const char *explicitConfFile, const char* section) { + std::string pathstr; // explicitly provided by user in command line? if (explicitConfFile) { const std::string clPath = explicitConfFile; @@ -193,56 +189,13 @@ bool ConfigFile::read(const char *explicitConfFile, const char* section) { // locate file automatically if path is not set yet if (pathstr.empty()) { - if (!locate()) { + if (!locate(pathstr)) { 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())); - } - } + pathcstr = strdup(pathstr.c_str()); + auto binpath = exe_path::getBinDir(); - return true; + return readConfig(pathcstr, section, binpath.c_str()); } diff --git a/driver/configfile.d b/driver/configfile.d new file mode 100644 index 00000000000..7edde4bca21 --- /dev/null +++ b/driver/configfile.d @@ -0,0 +1,149 @@ +//===-- driver/configfile.d - LDC config file handling ------------*- D -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the BSD-style LDC license. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Handles reading and parsing of an LDC config file (ldc.conf/ldc2.conf). +// +//===----------------------------------------------------------------------===// +module driver.configfile; + +import driver.config; +import core.stdc.stdio; +import core.stdc.string; + + +string fromStringz(const(char)* cstr) +{ + return cstr[0 .. strlen(cstr)].idup; +} + +immutable(char)* toStringz(in string s) +{ + auto nullTerm = s ~ '\0'; + return nullTerm.ptr; +} + + +string prepareBinDir(const(char)* binDir) +{ + immutable len = strlen(binDir); + auto res = binDir[0 .. len].dup; + foreach (ref c; res) + { + if (c == '\\') c = '/'; + } + return cast(string)res; // assumeUnique +} + + +ArraySetting findSwitches(Setting s) +{ + auto grp = cast(GroupSetting)s; + if (!grp) return null; + foreach (c; grp.children) + { + if (c.name == "switches") + { + return cast(ArraySetting)c; + } + } + return null; +} + + +string replace(string str, string pattern, string replacement) +{ + string res; + size_t cap = str.length; + if (replacement.length > pattern.length) + cap += replacement.length - pattern.length; + reserve(res, cap); + + while(str.length) + { + if (str.length < pattern.length) + { + res ~= str; + str = null; + } + else if (str[0 .. pattern.length] == pattern) + { + res ~= replacement; + str = str[pattern.length .. $]; + } + else + { + res ~= str[0]; + str = str[1 .. $]; + } + } + return res; +} + +struct ConfigFile +{ +public: + + alias s_iterator = const(char)**; + +private: + + // representation + + const(char)* pathcstr; + s_iterator switches_b; + s_iterator switches_e; + + extern(C++) + bool readConfig(const(char)* cfPath, const(char)* section, const(char)* binDir) + { + immutable dBinDir = prepareBinDir(binDir); + immutable dSec = fromStringz(section); + + try + { + auto settings = parseConfigFile(cfPath); + + ArraySetting secSwitches; + ArraySetting defSwitches; + + foreach (s; settings) + { + if (s.name == dSec) { + secSwitches = findSwitches(s); + } + else if (s.name == "default") + { + defSwitches = findSwitches(s); + } + } + + auto switches = secSwitches ? secSwitches : defSwitches; + if (!switches) + { + throw new Exception("could not look up switches in "~cfPath[0 .. strlen(cfPath)].idup); + } + + auto slice = new const(char)*[switches.vals.length]; + foreach (i, sw; switches.vals) + { + slice[i] = toStringz(sw.replace("%%ldcbinarypath%%", dBinDir)); + } + + switches_b = slice.ptr; + switches_e = slice.ptr+slice.length; + + return true; + } + catch (Exception ex) + { + fprintf(stderr, "%s\n", toStringz(ex.msg)); + return false; + } + } +} diff --git a/driver/configfile.h b/driver/configfile.h index 4b1164c6f1e..15eea1d654d 100644 --- a/driver/configfile.h +++ b/driver/configfile.h @@ -16,31 +16,29 @@ #include #include -#include "llvm/ADT/SmallString.h" -#include "libconfig.h" class ConfigFile { public: - typedef std::vector s_vector; - typedef s_vector::iterator s_iterator; + using s_iterator = const char **; public: - ConfigFile(); - bool read(const char *explicitConfFile, const char* section); + bool read(const char *explicitConfFile, const char *section); - s_iterator switches_begin() { return switches.begin(); } - s_iterator switches_end() { return switches.end(); } + s_iterator switches_begin() { return switches_b; } + s_iterator switches_end() { return switches_e; } - const std::string &path() { return pathstr; } + std::string path() { return std::string(pathcstr); } private: - bool locate(); + bool locate(std::string& pathstr); - config_t *cfg; - std::string pathstr; + // implemented in D + bool readConfig(const char* cfPath, const char* section, const char* binDir); - s_vector switches; + const char *pathcstr =nullptr; + s_iterator switches_b =nullptr; + s_iterator switches_e =nullptr; }; #endif // LDC_DRIVER_CONFIGFILE_H From dd0cca8e4a668029f5e80a69db94585a5a443927 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:29:41 +0100 Subject: [PATCH 03/24] change comment in config file template --- ldc2.conf.in | 4 ++-- ldc2_install.conf.in | 4 ++-- ldc2_phobos.conf.in | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ldc2.conf.in b/ldc2.conf.in index 0282a03f579..f5a9b9290a3 100644 --- a/ldc2.conf.in +++ b/ldc2.conf.in @@ -1,5 +1,5 @@ -// This configuration file uses libconfig. -// See http://www.hyperrealm.com/libconfig/ for syntax details. +// See comments in driver/config.d in ldc source tree for grammar description of +// this config file. // The default group is required default: diff --git a/ldc2_install.conf.in b/ldc2_install.conf.in index 943c29ec6b2..c73b7424522 100644 --- a/ldc2_install.conf.in +++ b/ldc2_install.conf.in @@ -1,5 +1,5 @@ -// This configuration file uses libconfig. -// See http://www.hyperrealm.com/libconfig/ for syntax details. +// See comments in driver/config.d in ldc source tree for grammar description of +// this config file. // The default group is required default: diff --git a/ldc2_phobos.conf.in b/ldc2_phobos.conf.in index b2360df2b0c..02e87e444fc 100644 --- a/ldc2_phobos.conf.in +++ b/ldc2_phobos.conf.in @@ -1,5 +1,5 @@ -// This configuration file uses libconfig. -// See http://www.hyperrealm.com/libconfig/ for syntax details. +// See comments in driver/config.d in ldc source tree for grammar description of +// this config file. // The default group is required default: From 031003dc68cf3d17659e6a35cf6c7c60d60204e6 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:31:01 +0100 Subject: [PATCH 04/24] cmake does not look for libconfig --- CMakeLists.txt | 13 ++----------- cmake/Modules/FindLibConfig.cmake | 15 --------------- 2 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 cmake/Modules/FindLibConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e109c5ee1..c831841b6ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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. # @@ -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"))) diff --git a/cmake/Modules/FindLibConfig.cmake b/cmake/Modules/FindLibConfig.cmake deleted file mode 100644 index cf81c433448..00000000000 --- a/cmake/Modules/FindLibConfig.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# - Find the libconfig includes and library -# -# This module defines -# LIBCONFIG_INCLUDE_DIR, where to find libconfig include files, etc. -# LIBCONFIG_LIBRARY, the library to link against to use libconfig. -# LIBCONFIG_FOUND, If false, do not try to use libconfig. - -find_path(LIBCONFIG_INCLUDE_DIR libconfig.h) - -find_library(LIBCONFIG_LIBRARY config) - -# Use the default CMake facilities for handling QUIET/REQUIRED. -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibConfig - REQUIRED_VARS LIBCONFIG_INCLUDE_DIR LIBCONFIG_LIBRARY) From 172eb30c1069e3c2f35238c31c392ac86e559d8b Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:31:25 +0100 Subject: [PATCH 05/24] CI is not handling libconfig anymore --- .travis.yml | 3 +-- appveyor.yml | 13 ++----------- circle.yml | 4 ++-- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1b89c88cb12..503861afa1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,6 @@ addons: sources: - ubuntu-toolchain-r-test packages: - - libconfig++8-dev - gdb - gcc-4.9 - g++-4.9 @@ -71,7 +70,7 @@ 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; + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew update; fi; - eval "${DC} --version" - pip install --user lit - python -c "import lit; lit.main();" --version | head -n 1 diff --git a/appveyor.yml b/appveyor.yml index aa19a17b320..b10deaf11a7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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 @@ -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 diff --git a/circle.yml b/circle.yml index c94d47db763..27ad5649499 100644 --- a/circle.yml +++ b/circle.yml @@ -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: @@ -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 From 037d0d045e8463221d1aeafcd7d18ea14403e9dc Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:31:50 +0100 Subject: [PATCH 06/24] remove libconfig license --- LICENSE | 513 -------------------------------------------------------- 1 file changed, 513 deletions(-) diff --git a/LICENSE b/LICENSE index d2b0dac83ea..b1f6f7ea172 100644 --- a/LICENSE +++ b/LICENSE @@ -14,8 +14,6 @@ Compiler (bin/ in binary packages): by David Friedman for GDC and released under the Artistic license or the GPL version 2 or later. - - LDC uses the libconfig++ library under the terms of the GNU LGPL 2.1. - - The LDC project makes use of the LLVM framework, which is governed by the University of Illinois Open Source License. A few LDC source files directly incorporate code derived from LLVM, see the file headers for details. @@ -539,514 +537,3 @@ necessary. Here a sample; alter the names: Ty Coon, President of Vice That's all there is to it! - - - --- libconfig license ----------------------------------------------------------- - -Copyright (C) 2005-2016 Mark A Lindner - --- - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! From de8fd625a19f961612be6cc2a9f266556b403f5d Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:32:12 +0100 Subject: [PATCH 07/24] remove libconfig from README --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 49ed512d322..47fa5718845 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,8 @@ libraries is available on the project wiki for [Linux and OS X](http://wiki.dlang.org/Building_LDC_from_source) and [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. +If you have a working C++ build environment, CMake, and a current LLVM (>= 3.5) +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, and for that reason we try to maintain it in the 'ltsmaster' branch). From 7dcd7e222831eb2270a1e5577a039bf0d9e32534 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Fri, 24 Feb 2017 23:40:48 +0100 Subject: [PATCH 08/24] config file grammar comment --- driver/config.d | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/driver/config.d b/driver/config.d index 834e71c5f01..e9b31ec75ab 100644 --- a/driver/config.d +++ b/driver/config.d @@ -107,7 +107,9 @@ private: /+ -What follows is a recursive descent parser that reads the following EBNF grammar +What follows is a recursive descent parser that reads the following +EBNF grammar. +It is a subset of the libconfig grammar (http://www.hyperrealm.com/libconfig). config = { ows , setting } , ows ; setting = name , (":" | "=") , value , [";" | ","] ; @@ -127,11 +129,19 @@ ows = [ ws ] ; (* optional white space *) ws = ? white space (space, tab, line feed ...) ? ; -Single line comments are also supported in the form of "//" until line feed. +Single line comments are also supported. They start with "//" and span until +line feed. The "//" sequence is however allowed within strings and doesn't need to be escaped. -Line feed are not allowed within strings. To span a string over multiple lines, -use concatenation. ("string 1" "string 2") +White space are significant only within strings. +Physical line feeds are not allowed within strings. To span a string over +multiple lines, use concatenation ("hello " "world" == "hello world"). +The following escape sequences are allowed in strings: + - \\ + - \" + - \r + - \n + - \t +/ From d36d06620630e5ed65bead370f5aeb247e71402a Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sat, 25 Feb 2017 11:16:03 +0100 Subject: [PATCH 09/24] move config utility functions --- driver/config.d | 20 ++++++++++++-------- driver/configfile.d | 12 ------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/driver/config.d b/driver/config.d index e9b31ec75ab..1b18a7cf687 100644 --- a/driver/config.d +++ b/driver/config.d @@ -103,6 +103,18 @@ Setting[] parseConfigFile(const(char)* filename) return parser.parseConfig(); } + +string fromStringz(const(char)* cstr) +{ + return cstr[0 .. strlen(cstr)].idup; +} + +immutable(char)* toStringz(in string s) +{ + auto nullTerm = s ~ '\0'; + return nullTerm.ptr; +} + private: /+ @@ -145,14 +157,6 @@ The following escape sequences are allowed in strings: +/ - -immutable(char)* toStringz(in string s) -{ - auto nullTerm = s ~ '\0'; - return nullTerm.ptr; -} - - enum Token { name, diff --git a/driver/configfile.d b/driver/configfile.d index 7edde4bca21..45e8aeca992 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -17,18 +17,6 @@ import core.stdc.stdio; import core.stdc.string; -string fromStringz(const(char)* cstr) -{ - return cstr[0 .. strlen(cstr)].idup; -} - -immutable(char)* toStringz(in string s) -{ - auto nullTerm = s ~ '\0'; - return nullTerm.ptr; -} - - string prepareBinDir(const(char)* binDir) { immutable len = strlen(binDir); From 94e76273c4a49f1c0212670dec46c32495c45dd0 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 25 Feb 2017 16:01:17 +0100 Subject: [PATCH 10/24] Misc. config tweaks (aesthetic ones + less C strings) --- .travis.yml | 1 - driver/config.d | 84 ++++++++++++++++++++------------------------- driver/configfile.d | 21 +++++++----- driver/configfile.h | 12 +++---- 4 files changed, 55 insertions(+), 63 deletions(-) diff --git a/.travis.yml b/.travis.yml index 503861afa1a..0885f5b998f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,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; fi; - eval "${DC} --version" - pip install --user lit - python -c "import lit; lit.main();" --version | head -n 1 diff --git a/driver/config.d b/driver/config.d index 1b18a7cf687..231cc6ab79c 100644 --- a/driver/config.d +++ b/driver/config.d @@ -1,4 +1,4 @@ -//===-- driver/configfile.d - LDC config file parsing -------------*- D -*-===// +//===-- driver/config.d - LDC config file parsing -----------------*- D -*-===// // // LDC – the LLVM D compiler // @@ -49,7 +49,7 @@ class Setting class ScalarSetting : Setting { - this (string name, string val) + this(string name, string val) { super(name, Type.scalar); _val = val; @@ -66,7 +66,7 @@ class ScalarSetting : Setting class ArraySetting : Setting { - this (string name, string[] vals) + this(string name, string[] vals) { super(name, Type.array); _vals = vals; @@ -82,7 +82,7 @@ class ArraySetting : Setting class GroupSetting : Setting { - this (string name, Setting[] children) + this(string name, Setting[] children) { super(name, Type.group); _children = children; @@ -104,17 +104,6 @@ Setting[] parseConfigFile(const(char)* filename) } -string fromStringz(const(char)* cstr) -{ - return cstr[0 .. strlen(cstr)].idup; -} - -immutable(char)* toStringz(in string s) -{ - auto nullTerm = s ~ '\0'; - return nullTerm.ptr; -} - private: /+ @@ -176,29 +165,29 @@ string humanReadableToken(in Token tok) { final switch(tok) { - case Token.name: return "\"name\""; - case Token.assign: return "':' or '='"; - case Token.str: return "\"string\""; - case Token.lbrace: return "'{'"; - case Token.rbrace: return "'}'"; - case Token.lbracket: return "'['"; - case Token.rbracket: return "']'"; - case Token.semicolon: return "';'"; - case Token.comma: return "','"; - case Token.unknown: return "\"unknown token\""; - case Token.eof: return "\"end of file\""; + case Token.name: return `"name"`; + case Token.assign: return `':' or '='`; + case Token.str: return `"string"`; + case Token.lbrace: return `'{'`; + case Token.rbrace: return `'}'`; + case Token.lbracket: return `'['`; + case Token.rbracket: return `']'`; + case Token.semicolon: return `';'`; + case Token.comma: return `','`; + case Token.unknown: return `"unknown token"`; + case Token.eof: return `"end of file"`; } } class Parser { - const(char)[] filename; + string filename; FILE* file; int lineNum; int lastChar = ' '; - struct Ahead + static struct Ahead { Token tok; string s; @@ -206,26 +195,25 @@ class Parser Ahead ahead; Ahead* aheadp; - this (const(char)* filename) + this(const(char)* filename) { - this.filename = filename[0 .. strlen(filename)]; + this.filename = filename[0 .. strlen(filename)].idup; file = fopen(filename, "r"); if (!file) { throw new Exception( "could not open config file " ~ - this.filename.idup ~ " for reading"); + this.filename ~ " for reading"); } this.file = file; } void error(in string msg) { - enum fmt = "Error while reading config file: %s\nline %d: %s"; + enum fmt = "Error while reading config file: %.*s\nline %d: %.*s"; char[1024] buf; - // filename was null terminated - auto len = snprintf(buf.ptr, 1024, fmt, - filename.ptr, lineNum, toStringz(msg)); + auto len = snprintf(buf.ptr, buf.length, fmt, + filename.length, filename.ptr, lineNum, msg.length, msg.ptr); throw new Exception(buf[0 .. len].idup); } @@ -251,7 +239,7 @@ class Parser return tok; } - while(isspace(lastChar)) + while (isspace(lastChar)) { lastChar = getChar(); } @@ -264,11 +252,12 @@ class Parser outStr = "/"; return Token.unknown; } - else do + + do { lastChar = getChar(); - } - while(lastChar != '\n' && lastChar != EOF); + } while (lastChar != '\n' && lastChar != EOF); + return getTok(outStr); } @@ -320,7 +309,7 @@ class Parser string str; while (lastChar == '"') { - while(1) + while (1) { lastChar = getChar(); if (lastChar == '"') break; @@ -357,7 +346,7 @@ class Parser str ~= cast(char)lastChar; } lastChar = getChar(); - while(isspace(lastChar)) lastChar = getChar(); + while (isspace(lastChar)) lastChar = getChar(); } outStr = str; @@ -380,8 +369,8 @@ class Parser void unexpectedTokenError(in Token tok, in Token expected, string s) { s = s.length ? " ("~s~")" : ""; - error("Was expecting token "~humanReadableToken(expected)~ - ". Got "~humanReadableToken(tok)~s~" instead."); + error("Was expecting token " ~ humanReadableToken(expected) ~ + ". Got " ~ humanReadableToken(tok) ~ s ~ " instead."); } string accept(in Token expected) @@ -398,13 +387,16 @@ class Parser Setting[] parseConfig() { Setting[] res; - while(1) + while (1) { { string s; auto t = getTok(s); - if (t == Token.eof) break; - else ungetTok(t, s); + if (t == Token.eof) + { + break; + } + ungetTok(t, s); } res ~= parseSetting(); } diff --git a/driver/configfile.d b/driver/configfile.d index 45e8aeca992..9a822b387de 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -52,7 +52,7 @@ string replace(string str, string pattern, string replacement) cap += replacement.length - pattern.length; reserve(res, cap); - while(str.length) + while (str.length) { if (str.length < pattern.length) { @@ -91,7 +91,7 @@ private: bool readConfig(const(char)* cfPath, const(char)* section, const(char)* binDir) { immutable dBinDir = prepareBinDir(binDir); - immutable dSec = fromStringz(section); + const dSec = section[0 .. strlen(section)]; try { @@ -102,7 +102,8 @@ private: foreach (s; settings) { - if (s.name == dSec) { + if (s.name == dSec) + { secSwitches = findSwitches(s); } else if (s.name == "default") @@ -114,23 +115,25 @@ private: auto switches = secSwitches ? secSwitches : defSwitches; if (!switches) { - throw new Exception("could not look up switches in "~cfPath[0 .. strlen(cfPath)].idup); + const dCfPath = cfPath[0 .. strlen(cfPath)]; + throw new Exception("could not look up switches in " ~ cast(string) dCfPath); } - auto slice = new const(char)*[switches.vals.length]; + auto finalSwitches = new const(char)*[switches.vals.length]; foreach (i, sw; switches.vals) { - slice[i] = toStringz(sw.replace("%%ldcbinarypath%%", dBinDir)); + const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0'; + finalSwitches[i] = finalSwitch.ptr; } - switches_b = slice.ptr; - switches_e = slice.ptr+slice.length; + switches_b = finalSwitches.ptr; + switches_e = finalSwitches.ptr + finalSwitches.length; return true; } catch (Exception ex) { - fprintf(stderr, "%s\n", toStringz(ex.msg)); + fprintf(stderr, "%.*s\n", ex.msg.length, ex.msg.ptr); return false; } } diff --git a/driver/configfile.h b/driver/configfile.h index 15eea1d654d..8f184c1aa73 100644 --- a/driver/configfile.h +++ b/driver/configfile.h @@ -21,8 +21,6 @@ class ConfigFile { public: using s_iterator = const char **; -public: - bool read(const char *explicitConfFile, const char *section); s_iterator switches_begin() { return switches_b; } @@ -31,14 +29,14 @@ class ConfigFile { std::string path() { return std::string(pathcstr); } private: - bool locate(std::string& pathstr); + bool locate(std::string &pathstr); // implemented in D - bool readConfig(const char* cfPath, const char* section, const char* binDir); + bool readConfig(const char *cfPath, const char *section, const char *binDir); - const char *pathcstr =nullptr; - s_iterator switches_b =nullptr; - s_iterator switches_e =nullptr; + const char *pathcstr = nullptr; + s_iterator switches_b = nullptr; + s_iterator switches_e = nullptr; }; #endif // LDC_DRIVER_CONFIGFILE_H From 47054d29c610b702ff668cee8414cbb37405a16f Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sat, 25 Feb 2017 17:58:08 +0100 Subject: [PATCH 11/24] config unittest --- driver/config.d | 68 +++++++++++++++++++++++++++++++++++++++++++++ driver/configfile.d | 15 ++++++++++ 2 files changed, 83 insertions(+) diff --git a/driver/config.d b/driver/config.d index 231cc6ab79c..0fd4c7726ae 100644 --- a/driver/config.d +++ b/driver/config.d @@ -498,3 +498,71 @@ class Parser assert(false); } } + + +version(unittest) +{ + void writeToFile(const char *filepath, const char *text) + { + FILE *fp = fopen(filepath, "w"); + assert(fp, "Cannot open test file for writing: "~fromStringz(filepath)); + + fputs(text, fp); + fclose(fp); + } +} + +unittest +{ + enum confstr = +`// This configuration file uses libconfig. +// See http://www.hyperrealm.com/libconfig/ for syntax details. + +// The default group is required +default: +{ + // 'switches' holds array of string that are appends to the command line + // arguments before they are parsed. + switches = [ + "-I/opt/dev/ldc/runtime/druntime/src", + "-I/opt/dev/ldc/runtime/profile-rt/d", + "-I/opt/dev/ldc/runtime/phobos", + "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib", + "-defaultlib=phobos2-ldc,druntime-ldc", + "-debuglib=phobos2-ldc-debug,druntime-ldc-debug" + ]; + + test_cat = "concatenated" " multiline" + " strings"; +}; +`; + + enum filename = "ldc_config_test.conf"; + + writeToFile(filename, confstr); + scope(exit) remove(filename); + + auto settings = parseConfigFile(filename); + + assert(settings.length == 1); + assert(settings[0].name == "default"); + assert(settings[0].type == Setting.Type.group); + auto grp = cast(GroupSetting)settings[0]; + assert(grp.children.length == 2); + + assert(grp.children[0].name == "switches"); + assert(grp.children[0].type == Setting.Type.array); + auto arr = cast(ArraySetting)grp.children[0]; + assert(arr.vals.length == 6); + assert(arr.vals[0] == "-I/opt/dev/ldc/runtime/druntime/src"); + assert(arr.vals[1] == "-I/opt/dev/ldc/runtime/profile-rt/d"); + assert(arr.vals[2] == "-I/opt/dev/ldc/runtime/phobos"); + assert(arr.vals[3] == "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib"); + assert(arr.vals[4] == "-defaultlib=phobos2-ldc,druntime-ldc"); + assert(arr.vals[5] == "-debuglib=phobos2-ldc-debug,druntime-ldc-debug"); + + assert(grp.children[1].name == "test_cat"); + assert(grp.children[1].type == Setting.Type.scalar); + auto scalar = cast(ScalarSetting)grp.children[1]; + assert(scalar.val == "concatenated multiline strings"); +} diff --git a/driver/configfile.d b/driver/configfile.d index 9a822b387de..3c1cb70f496 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -73,6 +73,21 @@ string replace(string str, string pattern, string replacement) return res; } +unittest +{ + enum pattern = "pattern"; + enum test1 = "find the pattern in a sentence"; + enum test2 = "find the pattern"; + enum test3 = "pattern in a sentence"; + enum test4 = "a pattern, yet other patterns"; + + assert(replace(test1, pattern, "word") == "find the word in a sentence"); + assert(replace(test2, pattern, "word") == "find the word"); + assert(replace(test3, pattern, "word") == "word in a sentence"); + assert(replace(test4, pattern, "word") == "a word, yet other words"); +} + + struct ConfigFile { public: From 8b05b821410f7d526e57ce71a66030aefcb0d43a Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sat, 25 Feb 2017 17:58:45 +0100 Subject: [PATCH 12/24] config: fix underscore in names --- driver/config.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver/config.d b/driver/config.d index 0fd4c7726ae..0dadd6edb37 100644 --- a/driver/config.d +++ b/driver/config.d @@ -269,7 +269,7 @@ class Parser name ~= cast(char)lastChar; lastChar = getChar(); } - while (isalnum(lastChar) || lastChar == '-'); + while (isalnum(lastChar) || lastChar == '_' || lastChar == '-'); outStr = name; return Token.name; } From 1bcbf0a219fa5da679b833fa86b99d37f4183220 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sat, 25 Feb 2017 18:43:44 +0100 Subject: [PATCH 13/24] remove config unittest --- driver/config.d | 68 --------------------------------------------- driver/configfile.d | 14 ---------- 2 files changed, 82 deletions(-) diff --git a/driver/config.d b/driver/config.d index 0dadd6edb37..ef3fad8e209 100644 --- a/driver/config.d +++ b/driver/config.d @@ -498,71 +498,3 @@ class Parser assert(false); } } - - -version(unittest) -{ - void writeToFile(const char *filepath, const char *text) - { - FILE *fp = fopen(filepath, "w"); - assert(fp, "Cannot open test file for writing: "~fromStringz(filepath)); - - fputs(text, fp); - fclose(fp); - } -} - -unittest -{ - enum confstr = -`// This configuration file uses libconfig. -// See http://www.hyperrealm.com/libconfig/ for syntax details. - -// The default group is required -default: -{ - // 'switches' holds array of string that are appends to the command line - // arguments before they are parsed. - switches = [ - "-I/opt/dev/ldc/runtime/druntime/src", - "-I/opt/dev/ldc/runtime/profile-rt/d", - "-I/opt/dev/ldc/runtime/phobos", - "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib", - "-defaultlib=phobos2-ldc,druntime-ldc", - "-debuglib=phobos2-ldc-debug,druntime-ldc-debug" - ]; - - test_cat = "concatenated" " multiline" - " strings"; -}; -`; - - enum filename = "ldc_config_test.conf"; - - writeToFile(filename, confstr); - scope(exit) remove(filename); - - auto settings = parseConfigFile(filename); - - assert(settings.length == 1); - assert(settings[0].name == "default"); - assert(settings[0].type == Setting.Type.group); - auto grp = cast(GroupSetting)settings[0]; - assert(grp.children.length == 2); - - assert(grp.children[0].name == "switches"); - assert(grp.children[0].type == Setting.Type.array); - auto arr = cast(ArraySetting)grp.children[0]; - assert(arr.vals.length == 6); - assert(arr.vals[0] == "-I/opt/dev/ldc/runtime/druntime/src"); - assert(arr.vals[1] == "-I/opt/dev/ldc/runtime/profile-rt/d"); - assert(arr.vals[2] == "-I/opt/dev/ldc/runtime/phobos"); - assert(arr.vals[3] == "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib"); - assert(arr.vals[4] == "-defaultlib=phobos2-ldc,druntime-ldc"); - assert(arr.vals[5] == "-debuglib=phobos2-ldc-debug,druntime-ldc-debug"); - - assert(grp.children[1].name == "test_cat"); - assert(grp.children[1].type == Setting.Type.scalar); - auto scalar = cast(ScalarSetting)grp.children[1]; - assert(scalar.val == "concatenated multiline strings"); -} diff --git a/driver/configfile.d b/driver/configfile.d index 3c1cb70f496..c001c0e4227 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -73,20 +73,6 @@ string replace(string str, string pattern, string replacement) return res; } -unittest -{ - enum pattern = "pattern"; - enum test1 = "find the pattern in a sentence"; - enum test2 = "find the pattern"; - enum test3 = "pattern in a sentence"; - enum test4 = "a pattern, yet other patterns"; - - assert(replace(test1, pattern, "word") == "find the word in a sentence"); - assert(replace(test2, pattern, "word") == "find the word"); - assert(replace(test3, pattern, "word") == "word in a sentence"); - assert(replace(test4, pattern, "word") == "a word, yet other words"); -} - struct ConfigFile { From 1af0a7bb6691fc625411357d85a40e718cd18832 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sun, 26 Feb 2017 00:39:33 +0100 Subject: [PATCH 14/24] driver/unittests.d with config file tests --- driver/unittests.d | 89 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 driver/unittests.d diff --git a/driver/unittests.d b/driver/unittests.d new file mode 100644 index 00000000000..883b59972ce --- /dev/null +++ b/driver/unittests.d @@ -0,0 +1,89 @@ +module driver.unittests; + +version(unittest): + +import driver.config; +import driver.configfile; + +import core.stdc.stdio; +import core.stdc.string; + + +void writeToFile(const(char)* filepath, const(char)* text) +{ + FILE *fp = fopen(filepath, "w"); + assert(fp, "Cannot open test file for writing: "~filepath[0 .. strlen(filepath)]); + + fputs(text, fp); + fclose(fp); +} + + +// testing driver.configfile.replace +unittest +{ + enum pattern = "pattern"; + enum test1 = "find the pattern in a sentence"; + enum test2 = "find the pattern"; + enum test3 = "pattern in a sentence"; + enum test4 = "a pattern, yet other patterns"; + + assert(replace(test1, pattern, "word") == "find the word in a sentence"); + assert(replace(test2, pattern, "word") == "find the word"); + assert(replace(test3, pattern, "word") == "word in a sentence"); + assert(replace(test4, pattern, "word") == "a word, yet other words"); +} + + +unittest +{ + enum confstr = +`// This configuration file uses libconfig. +// See http://www.hyperrealm.com/libconfig/ for syntax details. +// The default group is required +default: +{ + // 'switches' holds array of string that are appends to the command line + // arguments before they are parsed. + switches = [ + "-I/opt/dev/ldc/runtime/druntime/src", + "-I/opt/dev/ldc/runtime/profile-rt/d", + "-I/opt/dev/ldc/runtime/phobos", + "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib", + "-defaultlib=phobos2-ldc,druntime-ldc", + "-debuglib=phobos2-ldc-debug,druntime-ldc-debug" + ]; + test_cat = "concatenated" " multiline" + " strings"; +}; +`; + + enum filename = "ldc_config_test.conf"; + + writeToFile(filename, confstr); + scope(exit) remove(filename); + + auto settings = parseConfigFile(filename); + + assert(settings.length == 1); + assert(settings[0].name == "default"); + assert(settings[0].type == Setting.Type.group); + auto grp = cast(GroupSetting)settings[0]; + assert(grp.children.length == 2); + + assert(grp.children[0].name == "switches"); + assert(grp.children[0].type == Setting.Type.array); + auto arr = cast(ArraySetting)grp.children[0]; + assert(arr.vals.length == 6); + assert(arr.vals[0] == "-I/opt/dev/ldc/runtime/druntime/src"); + assert(arr.vals[1] == "-I/opt/dev/ldc/runtime/profile-rt/d"); + assert(arr.vals[2] == "-I/opt/dev/ldc/runtime/phobos"); + assert(arr.vals[3] == "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib"); + assert(arr.vals[4] == "-defaultlib=phobos2-ldc,druntime-ldc"); + assert(arr.vals[5] == "-debuglib=phobos2-ldc-debug,druntime-ldc-debug"); + + assert(grp.children[1].name == "test_cat"); + assert(grp.children[1].type == Setting.Type.scalar); + auto scalar = cast(ScalarSetting)grp.children[1]; + assert(scalar.val == "concatenated multiline strings"); +} From 003216acd66dd0d0836f6df90aade1b44f1278a0 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sun, 26 Feb 2017 00:40:58 +0100 Subject: [PATCH 15/24] add custom test executable --- CMakeLists.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c831841b6ca..aa4cc087a35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -709,6 +709,31 @@ add_subdirectory(tools) # Test and runtime targets. Note that enable_testing() is order-sensitive! # enable_testing() + +# build unittest executable + +set(LDC_TEST_EXE ldc2_test) +set(LDC_TEST_EXE_NAME ${PROGRAM_PREFIX}${LDC_TEST_EXE}${PROGRAM_SUFFIX}) +set(LDC_TEST_EXE_FULL ${PROJECT_BINARY_DIR}/bin/${LDC_TEST_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}) +add_custom_target(${LDC_TEST_EXE} ALL DEPENDS ${LDC_TEST_EXE_FULL}) + +set(LDC_TEST_D_COMPILE_ARGS + -unittest + ${LDC_D_SOURCE_FILES} +) + +build_d_executable( + "${LDC_TEST_EXE_FULL}" + "${LDC_TEST_D_COMPILE_ARGS}" + "$" + "${LDC_D_SOURCE_FILES};${PROJECT_BINARY_DIR}/${DDMDFE_PATH}/id.d" + "${LDC_LIB}" +) + +add_test(NAME ldc2-unittest + COMMAND ${LDC_TEST_EXE_FULL} --version +) + add_subdirectory(runtime) if(D_VERSION EQUAL 2) add_subdirectory(tests/d2) From 851ebcf1d732250d94adf368e6b8723bfd4623e9 Mon Sep 17 00:00:00 2001 From: Remi THEBAULT Date: Sun, 26 Feb 2017 00:54:18 +0100 Subject: [PATCH 16/24] ldc2 unittests are run directly by CI --- .travis.yml | 2 ++ CMakeLists.txt | 4 ---- appveyor.yml | 2 ++ circle.yml | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0885f5b998f..658d20510b9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,6 +82,8 @@ script: # Outputs some environment info, plus makes sure we only run the test suite # if we could actually build the executable. - bin/ldc2 -version || exit 1 + # run the general unittests + - bin/ldc2_test -version # Build Phobos & druntime unittest modules. - if [[ "${OPTS}" == *-DMULTILIB?ON* ]]; then diff --git a/CMakeLists.txt b/CMakeLists.txt index aa4cc087a35..64f349c88b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -730,10 +730,6 @@ build_d_executable( "${LDC_LIB}" ) -add_test(NAME ldc2-unittest - COMMAND ${LDC_TEST_EXE_FULL} --version -) - add_subdirectory(runtime) if(D_VERSION EQUAL 2) add_subdirectory(tests/d2) diff --git a/appveyor.yml b/appveyor.yml index b10deaf11a7..e055703d813 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -184,6 +184,8 @@ test_script: - ps: 'echo "import std.stdio; void main() { writeln(""Hello world!""); }" > hello.d' - bin\ldc2 hello.d - hello.exe + # Run general unittests + - bin\ldc2_test -version # Compile the druntime & phobos unit tests - ninja -j2 druntime-ldc-unittest-debug phobos2-ldc-unittest-debug druntime-ldc-unittest phobos2-ldc-unittest # Execute dmd-testsuite diff --git a/circle.yml b/circle.yml index 27ad5649499..de8a669d13a 100644 --- a/circle.yml +++ b/circle.yml @@ -61,6 +61,7 @@ test: - bin/ldc2 -version || exit 1 override: + - bin/ldc2_test -version - make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest - make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest --verbose -R "dmd-testsuite" From 8619592bac6fa921360e625ee241b1b5cde15c71 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 25 Feb 2017 22:52:05 +0100 Subject: [PATCH 17/24] config: Read from string instead of file to aid unittesting And re-locate the unittests incl. some new ones into their respective modules. --- driver/config.d | 172 +++++++++++++++++++++++++++++--------------- driver/configfile.d | 14 ++++ driver/unittests.d | 89 ----------------------- 3 files changed, 130 insertions(+), 145 deletions(-) delete mode 100644 driver/unittests.d diff --git a/driver/config.d b/driver/config.d index ef3fad8e209..8639f66db21 100644 --- a/driver/config.d +++ b/driver/config.d @@ -99,7 +99,25 @@ class GroupSetting : Setting Setting[] parseConfigFile(const(char)* filename) { - auto parser = new Parser(filename); + auto dFilename = filename[0 .. strlen(filename)].idup; + + auto file = fopen(filename, "r"); + if (!file) + { + throw new Exception( + "could not open config file " ~ + dFilename ~ " for reading"); + } + + fseek(file, 0, SEEK_END); + const fileLength = ftell(file); + rewind(file); + + auto content = new char[fileLength]; + const numRead = fread(content.ptr, 1, fileLength, file); + content = content[0 .. numRead]; + + auto parser = new Parser(cast(string) content, dFilename); return parser.parseConfig(); } @@ -182,10 +200,11 @@ string humanReadableToken(in Token tok) class Parser { string filename; - FILE* file; - int lineNum; + string content; + int index; + int lineNum = 1; - int lastChar = ' '; + char lastChar = ' '; static struct Ahead { @@ -195,17 +214,10 @@ class Parser Ahead ahead; Ahead* aheadp; - this(const(char)* filename) + this(string content, string filename = "") { - this.filename = filename[0 .. strlen(filename)].idup; - file = fopen(filename, "r"); - if (!file) - { - throw new Exception( - "could not open config file " ~ - this.filename ~ " for reading"); - } - this.file = file; + this.filename = filename; + this.content = content; } void error(in string msg) @@ -217,18 +229,16 @@ class Parser throw new Exception(buf[0 .. len].idup); } - int getChar() + char getChar() { - int c = fgetc(file); - if (c == '\n') lineNum += 1; + if (index == content.length) + return '\0'; + const c = content[index++]; + if (c == '\n') + ++lineNum; return c; } - void ungetChar(int c) - { - ungetc(c, file); - } - Token getTok(out string outStr) { if (aheadp) @@ -256,7 +266,7 @@ class Parser do { lastChar = getChar(); - } while (lastChar != '\n' && lastChar != EOF); + } while (lastChar != '\n' && lastChar != '\0'); return getTok(outStr); } @@ -266,7 +276,7 @@ class Parser string name; do { - name ~= cast(char)lastChar; + name ~= lastChar; lastChar = getChar(); } while (isalnum(lastChar) || lastChar == '_' || lastChar == '-'); @@ -298,7 +308,7 @@ class Parser case ']': lastChar = getChar(); return Token.rbracket; - case EOF: + case '\0': return Token.eof; default: break; @@ -317,7 +327,7 @@ class Parser { error("Unexpected end of line in string literal"); } - else if (lastChar == EOF) + else if (lastChar == '\0') { error("Unexpected end of file in string literal"); } @@ -339,11 +349,11 @@ class Parser lastChar = '\t'; break; default: - error("Unexpected escape sequence: \\"~cast(char)lastChar); + error("Unexpected escape sequence: \\" ~ lastChar); break; } } - str ~= cast(char)lastChar; + str ~= lastChar; } lastChar = getChar(); while (isspace(lastChar)) lastChar = getChar(); @@ -353,7 +363,7 @@ class Parser return Token.str; } - outStr = [cast(char)lastChar]; + outStr = [lastChar]; lastChar = getChar(); return Token.unknown; } @@ -409,24 +419,7 @@ class Parser accept(Token.assign); - string val; - string[] arrVal; - Setting[] grpVal; - - Setting res; - - final switch(parseValue(val, arrVal, grpVal)) - { - case Setting.Type.scalar: - res = new ScalarSetting(name, val); - break; - case Setting.Type.array: - res = new ArraySetting(name, arrVal); - break; - case Setting.Type.group: - res = new GroupSetting(name, grpVal); - break; - } + Setting res = parseValue(name); string s; immutable t = getTok(s); @@ -438,19 +431,17 @@ class Parser return res; } - Setting.Type parseValue(out string val, - out string[] arrVal, - out Setting[] grpVal) + Setting parseValue(string name) { string s; auto t = getTok(s); if (t == Token.str) { - val = s; - return Setting.Type.scalar; + return new ScalarSetting(name, s); } else if (t == Token.lbracket) { + string[] arrVal; while (1) { // get string or rbracket @@ -461,20 +452,20 @@ class Parser arrVal ~= s; break; case Token.rbracket: - return Setting.Type.array; + return new ArraySetting(name, arrVal); default: unexpectedTokenError(t, Token.str, s); assert(false); } - // get commar or rbracket + // get comma or rbracket t = getTok(s); switch(t) { case Token.comma: break; case Token.rbracket: - return Setting.Type.array; + return new ArraySetting(name, arrVal);; default: unexpectedTokenError(t, Token.comma, s); assert(false); @@ -483,12 +474,13 @@ class Parser } else if (t == Token.lbrace) { + Setting[] grpVal; while (1) { t = getTok(s); if (t == Token.rbrace) { - return Setting.Type.group; + return new GroupSetting(name, grpVal); } ungetTok(t, s); grpVal ~= parseSetting(); @@ -498,3 +490,71 @@ class Parser assert(false); } } + +unittest +{ + static void testScalar(string input, string expected) + { + auto setting = new Parser(input).parseValue(null); + assert(setting.type == Setting.Type.scalar); + assert((cast(ScalarSetting) setting).val == expected); + } + + testScalar(`"abc\r\ndef\t\"quoted/\\123\""`, + "abc\r\ndef\t\"quoted/\\123\""); + testScalar(`"concatenated" " multiline" + " strings"`, "concatenated multiline strings"); + + enum input = +`// comment + +// comment +group-1: +{ + // comment + scalar = "abc"; + // comment + array_1 = [ "a", "b" ]; + array_2 = [ + "c", + ]; +}; +// comment +group-2: { emptyArray = []; }; +`; + + auto settings = new Parser(input).parseConfig(); + assert(settings.length == 2); + + assert(settings[0].name == "group-1"); + assert(settings[0].type == Setting.Type.group); + auto group1 = cast(GroupSetting) settings[0]; + assert(group1.children.length == 3); + + assert(group1.children[0].name == "scalar"); + assert(group1.children[0].type == Setting.Type.scalar); + assert((cast(ScalarSetting) group1.children[0]).val == "abc"); + + assert(group1.children[1].name == "array_1"); + assert(group1.children[1].type == Setting.Type.array); + auto array1 = cast(ArraySetting) group1.children[1]; + assert(array1.vals.length == 2); + assert(array1.vals[0] == "a"); + assert(array1.vals[1] == "b"); + + assert(group1.children[2].name == "array_2"); + assert(group1.children[2].type == Setting.Type.array); + auto array2 = cast(ArraySetting) group1.children[2]; + assert(array2.vals.length == 1); + assert(array2.vals[0] == "c"); + + assert(settings[1].name == "group-2"); + assert(settings[1].type == Setting.Type.group); + auto group2 = cast(GroupSetting) settings[1]; + assert(group2.children.length == 1); + + assert(group2.children[0].name == "emptyArray"); + assert(group2.children[0].type == Setting.Type.array); + auto emptyArray = cast(ArraySetting) group2.children[0]; + assert(emptyArray.vals.length == 0); +} diff --git a/driver/configfile.d b/driver/configfile.d index c001c0e4227..3c1cb70f496 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -73,6 +73,20 @@ string replace(string str, string pattern, string replacement) return res; } +unittest +{ + enum pattern = "pattern"; + enum test1 = "find the pattern in a sentence"; + enum test2 = "find the pattern"; + enum test3 = "pattern in a sentence"; + enum test4 = "a pattern, yet other patterns"; + + assert(replace(test1, pattern, "word") == "find the word in a sentence"); + assert(replace(test2, pattern, "word") == "find the word"); + assert(replace(test3, pattern, "word") == "word in a sentence"); + assert(replace(test4, pattern, "word") == "a word, yet other words"); +} + struct ConfigFile { diff --git a/driver/unittests.d b/driver/unittests.d deleted file mode 100644 index 883b59972ce..00000000000 --- a/driver/unittests.d +++ /dev/null @@ -1,89 +0,0 @@ -module driver.unittests; - -version(unittest): - -import driver.config; -import driver.configfile; - -import core.stdc.stdio; -import core.stdc.string; - - -void writeToFile(const(char)* filepath, const(char)* text) -{ - FILE *fp = fopen(filepath, "w"); - assert(fp, "Cannot open test file for writing: "~filepath[0 .. strlen(filepath)]); - - fputs(text, fp); - fclose(fp); -} - - -// testing driver.configfile.replace -unittest -{ - enum pattern = "pattern"; - enum test1 = "find the pattern in a sentence"; - enum test2 = "find the pattern"; - enum test3 = "pattern in a sentence"; - enum test4 = "a pattern, yet other patterns"; - - assert(replace(test1, pattern, "word") == "find the word in a sentence"); - assert(replace(test2, pattern, "word") == "find the word"); - assert(replace(test3, pattern, "word") == "word in a sentence"); - assert(replace(test4, pattern, "word") == "a word, yet other words"); -} - - -unittest -{ - enum confstr = -`// This configuration file uses libconfig. -// See http://www.hyperrealm.com/libconfig/ for syntax details. -// The default group is required -default: -{ - // 'switches' holds array of string that are appends to the command line - // arguments before they are parsed. - switches = [ - "-I/opt/dev/ldc/runtime/druntime/src", - "-I/opt/dev/ldc/runtime/profile-rt/d", - "-I/opt/dev/ldc/runtime/phobos", - "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib", - "-defaultlib=phobos2-ldc,druntime-ldc", - "-debuglib=phobos2-ldc-debug,druntime-ldc-debug" - ]; - test_cat = "concatenated" " multiline" - " strings"; -}; -`; - - enum filename = "ldc_config_test.conf"; - - writeToFile(filename, confstr); - scope(exit) remove(filename); - - auto settings = parseConfigFile(filename); - - assert(settings.length == 1); - assert(settings[0].name == "default"); - assert(settings[0].type == Setting.Type.group); - auto grp = cast(GroupSetting)settings[0]; - assert(grp.children.length == 2); - - assert(grp.children[0].name == "switches"); - assert(grp.children[0].type == Setting.Type.array); - auto arr = cast(ArraySetting)grp.children[0]; - assert(arr.vals.length == 6); - assert(arr.vals[0] == "-I/opt/dev/ldc/runtime/druntime/src"); - assert(arr.vals[1] == "-I/opt/dev/ldc/runtime/profile-rt/d"); - assert(arr.vals[2] == "-I/opt/dev/ldc/runtime/phobos"); - assert(arr.vals[3] == "-L-L/opt/dev/build/ldc/llvm-3.9.1-Debug/lib"); - assert(arr.vals[4] == "-defaultlib=phobos2-ldc,druntime-ldc"); - assert(arr.vals[5] == "-debuglib=phobos2-ldc-debug,druntime-ldc-debug"); - - assert(grp.children[1].name == "test_cat"); - assert(grp.children[1].type == Setting.Type.scalar); - auto scalar = cast(ScalarSetting)grp.children[1]; - assert(scalar.val == "concatenated multiline strings"); -} From 2d38752e457521d4fc0b64701d74460fdd4953b4 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Feb 2017 03:18:00 +0100 Subject: [PATCH 18/24] Build LDC D unittests on demand only --- .travis.yml | 12 ++++++------ CMakeLists.txt | 24 +++++++++--------------- appveyor.yml | 16 ++++++++-------- circle.yml | 8 ++++---- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index 658d20510b9..7c8c56752d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -82,8 +82,6 @@ script: # Outputs some environment info, plus makes sure we only run the test suite # if we could actually build the executable. - bin/ldc2 -version || exit 1 - # run the general unittests - - bin/ldc2_test -version # Build Phobos & druntime unittest modules. - if [[ "${OPTS}" == *-DMULTILIB?ON* ]]; then @@ -94,11 +92,13 @@ script: make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest; fi # Run dmd-testsuite. - - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest --verbose -R "dmd-testsuite" - # Run LLVM IR testsuite. - - ctest --output-on-failure -V -R "lit-tests" + - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest -V -R "dmd-testsuite" + # Run lit testsuite. + - ctest -V -R "lit-tests" + # Build and run LDC D unittests. + - ctest --output-on-failure -R "ldc2-unittest" # Link and run Phobos & druntime unittest runners. - - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests" + - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest" after_success: - diff --git a/CMakeLists.txt b/CMakeLists.txt index 64f349c88b2..38fe96ff161 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -710,25 +710,19 @@ add_subdirectory(tools) # enable_testing() -# build unittest executable - -set(LDC_TEST_EXE ldc2_test) -set(LDC_TEST_EXE_NAME ${PROGRAM_PREFIX}${LDC_TEST_EXE}${PROGRAM_SUFFIX}) -set(LDC_TEST_EXE_FULL ${PROJECT_BINARY_DIR}/bin/${LDC_TEST_EXE_NAME}${CMAKE_EXECUTABLE_SUFFIX}) -add_custom_target(${LDC_TEST_EXE} ALL DEPENDS ${LDC_TEST_EXE_FULL}) - -set(LDC_TEST_D_COMPILE_ARGS - -unittest - ${LDC_D_SOURCE_FILES} -) - +# LDC unittest executable (D unittests only). +set(LDC_UNITTEST_EXE_FULL ${PROJECT_BINARY_DIR}/bin/${LDC_EXE_NAME}-unittest${CMAKE_EXECUTABLE_SUFFIX}) build_d_executable( - "${LDC_TEST_EXE_FULL}" - "${LDC_TEST_D_COMPILE_ARGS}" + "${LDC_UNITTEST_EXE_FULL}" + "-unittest;${LDC_D_SOURCE_FILES}" "$" - "${LDC_D_SOURCE_FILES};${PROJECT_BINARY_DIR}/${DDMDFE_PATH}/id.d" + "${LDC_D_SOURCE_FILES}" "${LDC_LIB}" ) +add_custom_target(ldc2-unittest DEPENDS ${LDC_UNITTEST_EXE_FULL}) +add_test(NAME build-ldc2-unittest COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ldc2-unittest) +add_test(NAME ldc2-unittest COMMAND ${LDC_UNITTEST_EXE_FULL} --version) +set_tests_properties(ldc2-unittest PROPERTIES DEPENDS build-ldc2-unittest) add_subdirectory(runtime) if(D_VERSION EQUAL 2) diff --git a/appveyor.yml b/appveyor.yml index e055703d813..1103db03948 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -184,18 +184,18 @@ test_script: - ps: 'echo "import std.stdio; void main() { writeln(""Hello world!""); }" > hello.d' - bin\ldc2 hello.d - hello.exe - # Run general unittests - - bin\ldc2_test -version # Compile the druntime & phobos unit tests - ninja -j2 druntime-ldc-unittest-debug phobos2-ldc-unittest-debug druntime-ldc-unittest phobos2-ldc-unittest - # Execute dmd-testsuite + # Run dmd-testsuite - if "%APPVEYOR_JOB_ARCH%"=="x64" ( set OS=Win_64) else ( set OS=Win_32) - set DMD_TESTSUITE_MAKE_ARGS=-j2 - - ctest --verbose -R dmd-testsuite - # Execute the LLVM IR tests - - ctest --output-on-failure -V -R lit-tests - # Execute the unit tests - - ctest -j2 --output-on-failure -E "dmd-testsuite|lit-tests" + - ctest -V -R "dmd-testsuite" + # Run lit testsuite + - ctest -V -R "lit-tests" + # Build and run LDC D unittests + - ctest --output-on-failure -R "ldc2-unittest" + # Link and run Phobos & druntime unittest runners + - ctest -j2 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest" #---------------------------------# # deployment configuration # diff --git a/circle.yml b/circle.yml index de8a669d13a..ea84c86f72f 100644 --- a/circle.yml +++ b/circle.yml @@ -61,12 +61,12 @@ test: - bin/ldc2 -version || exit 1 override: - - bin/ldc2_test -version - make -j2 phobos2-ldc-unittest-debug phobos2-ldc-unittest - make -j3 druntime-ldc-unittest-debug druntime-ldc-unittest - - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest --verbose -R "dmd-testsuite" - - ctest --output-on-failure -V -R "lit-tests" - - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests" + - CC="" DMD_TESTSUITE_MAKE_ARGS=-j3 ctest -V -R "dmd-testsuite" + - ctest -V -R "lit-tests" + - ctest --output-on-failure -R "ldc2-unittest" + - ctest -j3 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest" # To add more value the test results could be collected, see https://circleci.com/docs/test-metadata # A way how to convert the ctest output is described here: From e53c669bc80ae59a9cef2f93195860c95af52127 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Feb 2017 03:35:01 +0100 Subject: [PATCH 19/24] Close config file properly after reading --- driver/config.d | 1 + 1 file changed, 1 insertion(+) diff --git a/driver/config.d b/driver/config.d index 8639f66db21..637fd972b53 100644 --- a/driver/config.d +++ b/driver/config.d @@ -116,6 +116,7 @@ Setting[] parseConfigFile(const(char)* filename) auto content = new char[fileLength]; const numRead = fread(content.ptr, 1, fileLength, file); content = content[0 .. numRead]; + fclose(file); auto parser = new Parser(cast(string) content, dFilename); return parser.parseConfig(); From 93facb0b7072d01b7872c87f834f8a140260a4a6 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Feb 2017 13:20:46 +0100 Subject: [PATCH 20/24] Add some more config parser unittests --- driver/config.d | 96 ++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/driver/config.d b/driver/config.d index 637fd972b53..22c4ae0dcba 100644 --- a/driver/config.d +++ b/driver/config.d @@ -104,9 +104,8 @@ Setting[] parseConfigFile(const(char)* filename) auto file = fopen(filename, "r"); if (!file) { - throw new Exception( - "could not open config file " ~ - dFilename ~ " for reading"); + throw new Exception("could not open config file " ~ + dFilename ~ " for reading"); } fseek(file, 0, SEEK_END); @@ -118,7 +117,7 @@ Setting[] parseConfigFile(const(char)* filename) content = content[0 .. numRead]; fclose(file); - auto parser = new Parser(cast(string) content, dFilename); + auto parser = Parser(cast(string) content, dFilename); return parser.parseConfig(); } @@ -198,7 +197,7 @@ string humanReadableToken(in Token tok) } } -class Parser +struct Parser { string filename; string content; @@ -225,8 +224,8 @@ class Parser { enum fmt = "Error while reading config file: %.*s\nline %d: %.*s"; char[1024] buf; - auto len = snprintf(buf.ptr, buf.length, fmt, - filename.length, filename.ptr, lineNum, msg.length, msg.ptr); + auto len = snprintf(buf.ptr, buf.length, fmt, filename.length, + filename.ptr, lineNum, msg.length, msg.ptr); throw new Exception(buf[0 .. len].idup); } @@ -267,8 +266,8 @@ class Parser do { lastChar = getChar(); - } while (lastChar != '\n' && lastChar != '\0'); - + } + while (lastChar != '\n' && lastChar != '\0'); return getTok(outStr); } @@ -381,7 +380,7 @@ class Parser { s = s.length ? " ("~s~")" : ""; error("Was expecting token " ~ humanReadableToken(expected) ~ - ". Got " ~ humanReadableToken(tok) ~ s ~ " instead."); + ". Got " ~ humanReadableToken(tok) ~ s ~ " instead."); } string accept(in Token expected) @@ -466,7 +465,7 @@ class Parser case Token.comma: break; case Token.rbracket: - return new ArraySetting(name, arrVal);; + return new ArraySetting(name, arrVal); default: unexpectedTokenError(t, Token.comma, s); assert(false); @@ -501,61 +500,68 @@ unittest assert((cast(ScalarSetting) setting).val == expected); } + testScalar(`""`, ""); testScalar(`"abc\r\ndef\t\"quoted/\\123\""`, "abc\r\ndef\t\"quoted/\\123\""); testScalar(`"concatenated" " multiline" " strings"`, "concatenated multiline strings"); +} + +unittest +{ + static void testArray(string input, string[] expected) + { + auto setting = new Parser(input).parseValue(null); + assert(setting.type == Setting.Type.array); + assert((cast(ArraySetting) setting).vals == expected); + } + + testArray(`[]`, []); + testArray(`[ "a" ]`, [ "a" ]); + testArray(`[ "a", ]`, [ "a" ]); + testArray(`[ "a", "b" ]`, [ "a", "b" ]); + testArray(`[ + // comment + "a", + // comment + "b" + ]`, [ "a", "b" ]); +} +unittest +{ enum input = `// comment // comment -group-1: +group-1: {}; +// comment +Group-2: { // comment scalar = "abc"; // comment - array_1 = [ "a", "b" ]; - array_2 = [ - "c", - ]; + Array_1 = [ "a" ]; }; -// comment -group-2: { emptyArray = []; }; `; - auto settings = new Parser(input).parseConfig(); + auto settings = Parser(input).parseConfig(); assert(settings.length == 2); assert(settings[0].name == "group-1"); assert(settings[0].type == Setting.Type.group); - auto group1 = cast(GroupSetting) settings[0]; - assert(group1.children.length == 3); - - assert(group1.children[0].name == "scalar"); - assert(group1.children[0].type == Setting.Type.scalar); - assert((cast(ScalarSetting) group1.children[0]).val == "abc"); - - assert(group1.children[1].name == "array_1"); - assert(group1.children[1].type == Setting.Type.array); - auto array1 = cast(ArraySetting) group1.children[1]; - assert(array1.vals.length == 2); - assert(array1.vals[0] == "a"); - assert(array1.vals[1] == "b"); - - assert(group1.children[2].name == "array_2"); - assert(group1.children[2].type == Setting.Type.array); - auto array2 = cast(ArraySetting) group1.children[2]; - assert(array2.vals.length == 1); - assert(array2.vals[0] == "c"); - - assert(settings[1].name == "group-2"); + assert((cast(GroupSetting) settings[0]).children == []); + + assert(settings[1].name == "Group-2"); assert(settings[1].type == Setting.Type.group); auto group2 = cast(GroupSetting) settings[1]; - assert(group2.children.length == 1); + assert(group2.children.length == 2); + + assert(group2.children[0].name == "scalar"); + assert(group2.children[0].type == Setting.Type.scalar); + assert((cast(ScalarSetting) group2.children[0]).val == "abc"); - assert(group2.children[0].name == "emptyArray"); - assert(group2.children[0].type == Setting.Type.array); - auto emptyArray = cast(ArraySetting) group2.children[0]; - assert(emptyArray.vals.length == 0); + assert(group2.children[1].name == "Array_1"); + assert(group2.children[1].type == Setting.Type.array); + assert((cast(ArraySetting) group2.children[1]).vals == [ "a" ]); } From 55e912641d8d83a48930b853b21a602ad03d8a91 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Feb 2017 13:46:29 +0100 Subject: [PATCH 21/24] Extend config file grammar by backtick-enclosed strings --- driver/config.d | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/driver/config.d b/driver/config.d index 22c4ae0dcba..42ccad73ab8 100644 --- a/driver/config.d +++ b/driver/config.d @@ -138,9 +138,11 @@ array = "[" , ows , { string , ows , "," , ows } , "]" ; group = "{" , ows , { setting , ows } , "}" ; -string = quotstr, { ows , quotstr } ; +string = ( quotstr , { ows , quotstr } ) | + ( btstr , { ows, btstr } ) ; quotstr = '"' , { ? any char but '"', '\n' and '\r' ? | escseq } , '"' ; escseq = "\" , ["\" | '"' | "r" | "n" | "t" ] ; +btstr = '`' , { ? any char but '`' ? } , '`' ; alpha = ? any char between "a" and "z" included or between "A" and "Z" included ? ; digit = ? any char between "0" and "9" included ? ; @@ -214,7 +216,7 @@ struct Parser Ahead ahead; Ahead* aheadp; - this(string content, string filename = "") + this(string content, string filename = null) { this.filename = filename; this.content = content; @@ -363,6 +365,29 @@ struct Parser return Token.str; } + if (lastChar == '`') + { + string str; + while (lastChar == '`') + { + while (1) + { + lastChar = getChar(); + if (lastChar == '`') break; + if (lastChar == '\0') + { + error("Unexpected end of file in string literal"); + } + str ~= lastChar; + } + lastChar = getChar(); + while (isspace(lastChar)) lastChar = getChar(); + } + + outStr = str; + return Token.str; + } + outStr = [lastChar]; lastChar = getChar(); return Token.unknown; @@ -505,6 +530,8 @@ unittest "abc\r\ndef\t\"quoted/\\123\""); testScalar(`"concatenated" " multiline" " strings"`, "concatenated multiline strings"); + testScalar("`abc\n\\ //comment \"`", + "abc\n\\ //comment \""); } unittest From fdea747fb1d59a803c74b42703754e49ddfdbd87 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 26 Feb 2017 14:56:39 +0100 Subject: [PATCH 22/24] Support config files with UTF-8 BOM --- driver/config.d | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/driver/config.d b/driver/config.d index 42ccad73ab8..ff5ce6cf13c 100644 --- a/driver/config.d +++ b/driver/config.d @@ -114,9 +114,14 @@ Setting[] parseConfigFile(const(char)* filename) auto content = new char[fileLength]; const numRead = fread(content.ptr, 1, fileLength, file); - content = content[0 .. numRead]; fclose(file); + // skip UTF-8 BOM + int start = 0; + if (numRead >= 3 && content[0 .. 3] == "\xEF\xBB\xBF") + start = 3; + content = content[start .. numRead]; + auto parser = Parser(cast(string) content, dFilename); return parser.parseConfig(); } @@ -520,7 +525,7 @@ unittest { static void testScalar(string input, string expected) { - auto setting = new Parser(input).parseValue(null); + auto setting = Parser(input).parseValue(null); assert(setting.type == Setting.Type.scalar); assert((cast(ScalarSetting) setting).val == expected); } @@ -532,13 +537,14 @@ unittest " strings"`, "concatenated multiline strings"); testScalar("`abc\n\\ //comment \"`", "abc\n\\ //comment \""); + testScalar(`"Üņïčöđë"`, "Üņïčöđë"); } unittest { static void testArray(string input, string[] expected) { - auto setting = new Parser(input).parseValue(null); + auto setting = Parser(input).parseValue(null); assert(setting.type == Setting.Type.array); assert((cast(ArraySetting) setting).vals == expected); } From a1f484b688cda49c471622d40d56fae94c473ad5 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Fri, 3 Mar 2017 21:55:53 +0100 Subject: [PATCH 23/24] Add extra diagnostics for not-found sections in config file. --- driver/configfile.d | 21 +++++++++++++++++---- tests/driver/config_diag.d | 13 +++++++++++++ tests/driver/inputs/noswitches.conf | 3 +++ tests/driver/inputs/override_default.conf | 9 +++++++++ tests/driver/inputs/section_aaa.conf | 4 ++++ 5 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 tests/driver/config_diag.d create mode 100644 tests/driver/inputs/noswitches.conf create mode 100644 tests/driver/inputs/override_default.conf create mode 100644 tests/driver/inputs/section_aaa.conf diff --git a/driver/configfile.d b/driver/configfile.d index 3c1cb70f496..6dca8636df8 100644 --- a/driver/configfile.d +++ b/driver/configfile.d @@ -110,28 +110,41 @@ private: try { - auto settings = parseConfigFile(cfPath); + auto settingSections = parseConfigFile(cfPath); + bool sectionFound; ArraySetting secSwitches; ArraySetting defSwitches; - foreach (s; settings) + foreach (s; settingSections) { if (s.name == dSec) { + sectionFound = true; secSwitches = findSwitches(s); } else if (s.name == "default") { + sectionFound = true; defSwitches = findSwitches(s); } } + if (!sectionFound) + { + const dCfPath = cfPath[0 .. strlen(cfPath)]; + if (section) + throw new Exception("Could not look up section '" ~ cast(string) dSec + ~ "' nor the 'default' section in " ~ cast(string) dCfPath); + else + throw new Exception("Could not look up 'default' section in " ~ cast(string) dCfPath); + } + auto switches = secSwitches ? secSwitches : defSwitches; if (!switches) { const dCfPath = cfPath[0 .. strlen(cfPath)]; - throw new Exception("could not look up switches in " ~ cast(string) dCfPath); + throw new Exception("Could not look up switches in " ~ cast(string) dCfPath); } auto finalSwitches = new const(char)*[switches.vals.length]; @@ -148,7 +161,7 @@ private: } catch (Exception ex) { - fprintf(stderr, "%.*s\n", ex.msg.length, ex.msg.ptr); + fprintf(stderr, "Error: %.*s\n", ex.msg.length, ex.msg.ptr); return false; } } diff --git a/tests/driver/config_diag.d b/tests/driver/config_diag.d new file mode 100644 index 00000000000..6edb5a7d3ff --- /dev/null +++ b/tests/driver/config_diag.d @@ -0,0 +1,13 @@ +// RUN: not %ldc -conf=%S/inputs/noswitches.conf %s 2>&1 | FileCheck %s --check-prefix=NOSWITCHES +// NOSWITCHES: Could not look up switches in {{.*}}noswitches.conf + +// RUN: not %ldc -conf=%S/inputs/section_aaa.conf %s 2>&1 | FileCheck %s --check-prefix=NO_SEC +// NO_SEC: Could not look up section '{{.*}}' nor the 'default' section in {{.*}}section_aaa.conf + +// RUN: %ldc -conf=%S/inputs/override_default.conf -mtriple=x86-apple-windows-msvc -c -o- %s | FileCheck %s --check-prefix=OVERRIDE_DEFAULT +// OVERRIDE_DEFAULT: LDC - the LLVM D compiler + + +void foo() +{ +} diff --git a/tests/driver/inputs/noswitches.conf b/tests/driver/inputs/noswitches.conf new file mode 100644 index 00000000000..8afe5dec6f6 --- /dev/null +++ b/tests/driver/inputs/noswitches.conf @@ -0,0 +1,3 @@ +default: +{ +}; diff --git a/tests/driver/inputs/override_default.conf b/tests/driver/inputs/override_default.conf new file mode 100644 index 00000000000..b21a736dcf5 --- /dev/null +++ b/tests/driver/inputs/override_default.conf @@ -0,0 +1,9 @@ +x86-apple-windows-msvc: +{ + switches = [ "-version" ]; +}; + +default: +{ + switches = [ "" ]; +}; diff --git a/tests/driver/inputs/section_aaa.conf b/tests/driver/inputs/section_aaa.conf new file mode 100644 index 00000000000..a85b08f3083 --- /dev/null +++ b/tests/driver/inputs/section_aaa.conf @@ -0,0 +1,4 @@ +aaa: +{ + switches = [ "" ]; +}; From c08bc716a6df1d0388a8c8f3ed8fc5140ca8e942 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Fri, 3 Mar 2017 22:04:09 +0100 Subject: [PATCH 24/24] Make sure the configfile diagnostic tests also pass when LLVM X86 target is not available. --- tests/driver/config_diag.d | 3 --- tests/driver/config_diag_x86.d | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 tests/driver/config_diag_x86.d diff --git a/tests/driver/config_diag.d b/tests/driver/config_diag.d index 6edb5a7d3ff..281ead8cd40 100644 --- a/tests/driver/config_diag.d +++ b/tests/driver/config_diag.d @@ -4,9 +4,6 @@ // RUN: not %ldc -conf=%S/inputs/section_aaa.conf %s 2>&1 | FileCheck %s --check-prefix=NO_SEC // NO_SEC: Could not look up section '{{.*}}' nor the 'default' section in {{.*}}section_aaa.conf -// RUN: %ldc -conf=%S/inputs/override_default.conf -mtriple=x86-apple-windows-msvc -c -o- %s | FileCheck %s --check-prefix=OVERRIDE_DEFAULT -// OVERRIDE_DEFAULT: LDC - the LLVM D compiler - void foo() { diff --git a/tests/driver/config_diag_x86.d b/tests/driver/config_diag_x86.d new file mode 100644 index 00000000000..ed8026cb3d5 --- /dev/null +++ b/tests/driver/config_diag_x86.d @@ -0,0 +1,9 @@ +// REQUIRES: target_X86 + +// RUN: %ldc -conf=%S/inputs/override_default.conf -mtriple=x86-apple-windows-msvc -c -o- %s | FileCheck %s --check-prefix=OVERRIDE_DEFAULT +// OVERRIDE_DEFAULT: LDC - the LLVM D compiler + + +void foo() +{ +}