diff --git a/CMakeLists.txt b/CMakeLists.txt index 484b2032..a9875725 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -356,14 +356,25 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) ) endif() -add_definitions( -D_GNU_SOURCE - -DCLING_VERSION=${CLING_VERSION} - -DCLING_INCLUDE_PATHS="${CMAKE_INSTALL_PREFIX}/include:${CMAKE_CURRENT_SOURCE_DIR}/include:${CMAKE_CURRENT_SOURCE_DIR}/../clang/include:${CMAKE_CURRENT_SOURCE_DIR}/../../include" ) +add_definitions( -D_GNU_SOURCE -DCLING_VERSION=${CLING_VERSION}) option(CLING_INCLUDE_TESTS "Generate build targets for the Cling unit tests." ${LLVM_INCLUDE_TESTS}) +#Allow user to prepend to list via cmake -DCLING_INCLUDE_PATHS= +set(cling_include_deflt "\ +${CMAKE_INSTALL_PREFIX}/include:${CMAKE_CURRENT_SOURCE_DIR}/include:\ +${CMAKE_CURRENT_SOURCE_DIR}/../clang/include:\ +${CMAKE_CURRENT_SOURCE_DIR}/../../include" +) + +if(NOT CLING_INCLUDE_PATHS) + set(CLING_INCLUDE_PATHS "${cling_include_deflt}") +else() + set(CLING_INCLUDE_PATHS "${CLING_INCLUDE_PATHS}:${cling_include_deflt}") +endif() + # All targets below may depend on all tablegen'd files. get_property(CLANG_TABLEGEN_TARGETS GLOBAL PROPERTY CLANG_TABLEGEN_TARGETS) list(APPEND LLVM_COMMON_DEPENDS ${CLANG_TABLEGEN_TARGETS}) diff --git a/include/cling/Utils/Paths.h b/include/cling/Utils/Paths.h new file mode 100644 index 00000000..ba087e4c --- /dev/null +++ b/include/cling/Utils/Paths.h @@ -0,0 +1,37 @@ +//--------------------------------------------------------------------*- C++ -*- +// CLING - the C++ LLVM-based InterpreterG :) +// author: +// +// This file is dual-licensed: you can choose to license it under the University +// of Illinois Open Source License or the GNU Lesser General Public License. See +// LICENSE.TXT for details. +//------------------------------------------------------------------------------ + +#ifndef CLING_UTILS_PATHS_H +#define CLING_UTILS_PATHS_H + +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" + +namespace cling { + namespace utils { + + ///\brief Collect the constituant paths from a PATH string. + /// /bin:/usr/bin:/usr/local/bin -> {/bin, /usr/bin, /usr/local/bin} + /// + /// All paths returned existed at the time of the call + /// \param [in] PathStr - The PATH string to be split + /// \param [out] Paths - All the paths in the string that exist + /// \param [in] EarlyOut - If any path doesn't exist stop and return false + /// \param [in] Delim - The delimeter to use + /// + /// \return true if all paths existed, otherwise false + /// + bool SplitPaths(llvm::StringRef PathStr, + llvm::SmallVectorImpl& Paths, + bool EarlyOut = false, + llvm::StringRef Delim = llvm::StringRef(":")); + } +} + +#endif // CLING_UTILS_PATHS_H diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index 07513611..8b8583fe 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -8,6 +8,7 @@ //------------------------------------------------------------------------------ #include "cling/Interpreter/CIFactory.h" +#include "cling/Utils/Paths.h" #include "ClingUtils.h" #include "DeclCollector.h" @@ -588,27 +589,14 @@ namespace { } static bool AddCxxPaths(llvm::StringRef PathStr, AdditionalArgList& Args) { - bool Success = true; - llvm::SmallVector Paths; - for (std::pair Split - = PathStr.split(':'); - !Split.second.empty(); Split = PathStr.split(':')) { - if (!llvm::sys::fs::is_directory(Split.first)) { - Success = false; - break; - } - Paths.push_back(Split.first); - PathStr = Split.second; - } - // Add remaining part - if (Success && llvm::sys::fs::is_directory(PathStr)) { + llvm::SmallVector Paths; + if (!cling::utils::SplitPaths(PathStr, Paths, true)) + return false; + for (llvm::StringRef Path : Paths) Args.addArgument("-I", Path.str()); - Args.addArgument("-I", PathStr.str()); return true; } - return false; - } #endif diff --git a/lib/Interpreter/CMakeLists.txt b/lib/Interpreter/CMakeLists.txt index 99eeb559..1ff5900e 100644 --- a/lib/Interpreter/CMakeLists.txt +++ b/lib/Interpreter/CMakeLists.txt @@ -253,12 +253,14 @@ if (UNIX) #define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\" #define CLING_CXX_PATH \"${CLING_CXX_PATH} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\" #define CLING_CXX_RLTV \"${CLING_CXX_RLTV} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\" + #define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\" ") else() file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in " #define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\" #define CLING_CXX_PATH \"${CLING_CXX_PATH} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\" + #define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\" ") endif() else() @@ -267,22 +269,28 @@ if (UNIX) " #define CLING_CXX_INCL \"${CLING_CXX_HEADERS}\" #define CLING_CXX_RLTV \"${CLING_CXX_RLTV} ${CMAKE_CXX_FLAGS_NO_I} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}\" + #define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\" ") endif() - # Make sure this goes last so so we can pick up any changes that occured - # Also means cling-compiledata.h.in should be edited never cling-compiledata.h +else() + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in + " + #define CLING_INCLUDE_PATHS \"${CLING_INCLUDE_PATHS}\" + ") +endif() - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in - ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h - MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in - COMMENT "Updating cling-compiledata.h") +# Make sure this goes last so so we can pick up any changes that occured +# Also means cling-compiledata.h.in should be edited never cling-compiledata.h - add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/CIFactory.cpp - ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h) - add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/Interpreter.cpp - ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h) +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in + ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h + MAIN_DEPENDENCY ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h.in + COMMENT "Updating cling-compiledata.h") -endif() # UNIX +add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/CIFactory.cpp + ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h) +add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/Interpreter.cpp + ${CMAKE_CURRENT_BINARY_DIR}/cling-compiledata.h) diff --git a/lib/Interpreter/Interpreter.cpp b/lib/Interpreter/Interpreter.cpp index fa6a513c..aa111061 100644 --- a/lib/Interpreter/Interpreter.cpp +++ b/lib/Interpreter/Interpreter.cpp @@ -8,8 +8,10 @@ //------------------------------------------------------------------------------ #include "cling/Interpreter/Interpreter.h" +#include "cling/Utils/Paths.h" #include "ClingUtils.h" +#include "cling-compiledata.h" #include "DynamicLookup.h" #include "ExternalInterpreterSource.h" #include "ForwardDeclPrinter.h" @@ -298,16 +300,10 @@ namespace cling { void Interpreter::AddRuntimeIncludePaths(const char* argv0) { // Add configuration paths to interpreter's include files. #ifdef CLING_INCLUDE_PATHS - llvm::StringRef InclPaths(CLING_INCLUDE_PATHS); - for (std::pair Split - = InclPaths.split(':'); - !Split.second.empty(); Split = InclPaths.split(':')) { - if (llvm::sys::fs::is_directory(Split.first)) - AddIncludePath(Split.first); - InclPaths = Split.second; - } - // Add remaining part - AddIncludePath(InclPaths); + llvm::SmallVector Paths; + utils::SplitPaths(CLING_INCLUDE_PATHS, Paths); + for (llvm::StringRef Path : Paths) + AddIncludePath(Path); #endif llvm::SmallString<512> P(GetExecutablePath(argv0)); if (!P.empty() @@ -323,7 +319,6 @@ namespace cling { if (llvm::sys::fs::is_directory(P.str())) AddIncludePath(P.str()); } - } void Interpreter::IncludeCXXRuntime() { diff --git a/lib/Utils/CMakeLists.txt b/lib/Utils/CMakeLists.txt index c385070e..2867981b 100644 --- a/lib/Utils/CMakeLists.txt +++ b/lib/Utils/CMakeLists.txt @@ -11,6 +11,7 @@ set( LLVM_LINK_COMPONENTS add_cling_library(clingUtils OBJECT AST.cpp + Paths.cpp SourceNormalization.cpp Validation.cpp diff --git a/lib/Utils/Paths.cpp b/lib/Utils/Paths.cpp new file mode 100644 index 00000000..b3a66c23 --- /dev/null +++ b/lib/Utils/Paths.cpp @@ -0,0 +1,41 @@ +//--------------------------------------------------------------------*- C++ -*- +// CLING - the C++ LLVM-based InterpreterG :) +// author: +// +// This file is dual-licensed: you can choose to license it under the University +// of Illinois Open Source License or the GNU Lesser General Public License. See +// LICENSE.TXT for details. +//------------------------------------------------------------------------------ + +#include "cling/Utils/Paths.h" +#include "llvm/Support/FileSystem.h" + +namespace cling { +namespace utils { + +bool SplitPaths(llvm::StringRef PathStr, + llvm::SmallVectorImpl& Paths, bool EarlyOut, + llvm::StringRef Delim) { + bool AllExisted = true; + for (std::pair Split = PathStr.split(Delim); + !Split.second.empty(); Split = PathStr.split(Delim)) { + if (!llvm::sys::fs::is_directory(Split.first)) { + if (EarlyOut) + return false; + AllExisted = false; + } else + Paths.push_back(Split.first); + PathStr = Split.second; + } + + // Add remaining part + if (llvm::sys::fs::is_directory(PathStr)) + Paths.push_back(PathStr); + else + AllExisted = false; + + return AllExisted; +} + +} // namespace utils +} // namespace cling