diff --git a/.travis.yml b/.travis.yml index 1b89c88cb12..7c8c56752d3 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,6 @@ before_install: export LLVM_CONFIG="llvm-$LLVM_VERSION/bin/llvm-config"; install: - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi - - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew update; brew install libconfig; fi; - eval "${DC} --version" - pip install --user lit - python -c "import lit; lit.main();" --version | head -n 1 @@ -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 18e109c5ee1..38fe96ff161 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"))) @@ -718,6 +709,21 @@ add_subdirectory(tools) # Test and runtime targets. Note that enable_testing() is order-sensitive! # enable_testing() + +# 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_UNITTEST_EXE_FULL}" + "-unittest;${LDC_D_SOURCE_FILES}" + "$" + "${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) add_subdirectory(tests/d2) 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! 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). diff --git a/appveyor.yml b/appveyor.yml index aa19a17b320..1103db03948 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 @@ -195,14 +186,16 @@ test_script: - hello.exe # 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 c94d47db763..ea84c86f72f 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: @@ -63,9 +63,10 @@ test: override: - 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: @@ -75,7 +76,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 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) diff --git a/driver/config.d b/driver/config.d new file mode 100644 index 00000000000..ff5ce6cf13c --- /dev/null +++ b/driver/config.d @@ -0,0 +1,600 @@ +//===-- driver/config.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 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); + 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(); +} + + +private: + +/+ + +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 , [";" | ","] ; +name = alpha , { alpha | digit | "_" | "-" } ; +value = string | array | group ; +array = "[" , ows , + { string , ows , "," , ows } , + "]" ; +group = "{" , ows , { setting , ows } , "}" ; +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 ? ; +ows = [ ws ] ; (* optional white space *) +ws = ? white space (space, tab, 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. +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 + ++/ + +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"`; + } +} + +struct Parser +{ + string filename; + string content; + int index; + int lineNum = 1; + + char lastChar = ' '; + + static struct Ahead + { + Token tok; + string s; + } + Ahead ahead; + Ahead* aheadp; + + this(string content, string filename = null) + { + this.filename = filename; + this.content = content; + } + + void error(in string msg) + { + 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); + throw new Exception(buf[0 .. len].idup); + } + + char getChar() + { + if (index == content.length) + return '\0'; + const c = content[index++]; + if (c == '\n') + ++lineNum; + return c; + } + + 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; + } + + do + { + lastChar = getChar(); + } + while (lastChar != '\n' && lastChar != '\0'); + return getTok(outStr); + } + + if (isalpha(lastChar)) + { + string name; + do + { + name ~= lastChar; + lastChar = getChar(); + } + while (isalnum(lastChar) || 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 '\0': + 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 == '\0') + { + 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: \\" ~ lastChar); + break; + } + } + str ~= lastChar; + } + lastChar = getChar(); + while (isspace(lastChar)) lastChar = getChar(); + } + + outStr = str; + 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; + } + + 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; + } + ungetTok(t, s); + } + res ~= parseSetting(); + } + return res; + } + + Setting parseSetting() + { + immutable name = accept(Token.name); + + accept(Token.assign); + + Setting res = parseValue(name); + + string s; + immutable t = getTok(s); + if (t != Token.semicolon && t != Token.comma) + { + ungetTok(t, s); + } + + return res; + } + + Setting parseValue(string name) + { + string s; + auto t = getTok(s); + if (t == Token.str) + { + return new ScalarSetting(name, s); + } + else if (t == Token.lbracket) + { + string[] arrVal; + while (1) + { + // get string or rbracket + t = getTok(s); + switch(t) + { + case Token.str: + arrVal ~= s; + break; + case Token.rbracket: + return new ArraySetting(name, arrVal); + default: + unexpectedTokenError(t, Token.str, s); + assert(false); + } + + // get comma or rbracket + t = getTok(s); + switch(t) + { + case Token.comma: + break; + case Token.rbracket: + return new ArraySetting(name, arrVal); + default: + unexpectedTokenError(t, Token.comma, s); + assert(false); + } + } + } + else if (t == Token.lbrace) + { + Setting[] grpVal; + while (1) + { + t = getTok(s); + if (t == Token.rbrace) + { + return new GroupSetting(name, grpVal); + } + ungetTok(t, s); + grpVal ~= parseSetting(); + } + } + error("Was expecting value."); + assert(false); + } +} + +unittest +{ + static void testScalar(string input, string expected) + { + auto setting = Parser(input).parseValue(null); + assert(setting.type == Setting.Type.scalar); + 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"); + testScalar("`abc\n\\ //comment \"`", + "abc\n\\ //comment \""); + testScalar(`"Üņïčöđë"`, "Üņïčöđë"); +} + +unittest +{ + static void testArray(string input, string[] expected) + { + auto setting = 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: {}; +// comment +Group-2: +{ + // comment + scalar = "abc"; + // comment + Array_1 = [ "a" ]; +}; +`; + + auto settings = Parser(input).parseConfig(); + assert(settings.length == 2); + + assert(settings[0].name == "group-1"); + assert(settings[0].type == Setting.Type.group); + 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 == 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[1].name == "Array_1"); + assert(group2.children[1].type == Setting.Type.array); + assert((cast(ArraySetting) group2.children[1]).vals == [ "a" ]); +} 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..6dca8636df8 --- /dev/null +++ b/driver/configfile.d @@ -0,0 +1,168 @@ +//===-- 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 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; +} + +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: + + 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); + const dSec = section[0 .. strlen(section)]; + + try + { + auto settingSections = parseConfigFile(cfPath); + + bool sectionFound; + ArraySetting secSwitches; + ArraySetting defSwitches; + + 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); + } + + auto finalSwitches = new const(char)*[switches.vals.length]; + foreach (i, sw; switches.vals) + { + const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0'; + finalSwitches[i] = finalSwitch.ptr; + } + + switches_b = finalSwitches.ptr; + switches_e = finalSwitches.ptr + finalSwitches.length; + + return true; + } + catch (Exception ex) + { + fprintf(stderr, "Error: %.*s\n", ex.msg.length, ex.msg.ptr); + return false; + } + } +} diff --git a/driver/configfile.h b/driver/configfile.h index 4b1164c6f1e..8f184c1aa73 100644 --- a/driver/configfile.h +++ b/driver/configfile.h @@ -16,31 +16,27 @@ #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 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: diff --git a/tests/driver/config_diag.d b/tests/driver/config_diag.d new file mode 100644 index 00000000000..281ead8cd40 --- /dev/null +++ b/tests/driver/config_diag.d @@ -0,0 +1,10 @@ +// 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 + + +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() +{ +} 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 = [ "" ]; +};