Merge pull request #332 from ftk/develop
Ability to disable module loading support at compile time
This commit is contained in:
commit
0f9d9cae4a
18
.travis.yml
18
.travis.yml
@ -25,12 +25,19 @@ matrix:
|
|||||||
compiler: gcc
|
compiler: gcc
|
||||||
- os: linux
|
- os: linux
|
||||||
sudo: false
|
sudo: false
|
||||||
env: GCC_VER="5"
|
env: GCC_VER="4.9" CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1
|
||||||
|
compiler: gcc
|
||||||
|
- os: linux
|
||||||
|
sudo: false
|
||||||
|
env: GCC_VER="5" CPPCHECK=1 COVERAGE=1 CMAKE_OPTIONS="-D RUN_FUZZY_TESTS:BOOL=TRUE"
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
- os: osx
|
- os: osx
|
||||||
compiler: clang
|
compiler: clang
|
||||||
osx_image: xcode8
|
osx_image: xcode8
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
osx_image: xcode8
|
||||||
|
env: CMAKE_OPTIONS="-D DYNLOAD_ENABLED:BOOL=FALSE -D MULTITHREAD_SUPPORT_ENABLED:BOOL=FALSE -D USE_STD_MAKE_SHARED:BOOL=TRUE" BUILD_ONLY=1
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
@ -40,14 +47,13 @@ env:
|
|||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- if [ "${GCC_VER}" != "" ]; then export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER" ; fi
|
- if [ "${GCC_VER}" != "" ]; then export CXX="g++-$GCC_VER" CC="gcc-$GCC_VER" GCOV="gcov-$GCC_VER" ; fi
|
||||||
- if [ "${GCC_VER}" == "5" ]; then export CPPCHECK=1 COVERAGE=1 FUZZY_CMD="-D RUN_FUZZY_TESTS:BOOL=TRUE" ; fi
|
|
||||||
- pip install --user cpp-coveralls
|
- pip install --user cpp-coveralls
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug $FUZZY_CMD .
|
- cmake -D ENABLE_COVERAGE:BOOL=TRUE -D CMAKE_BUILD_TYPE:STRING=Debug $CMAKE_OPTIONS .
|
||||||
- cmake --build . -- -j2
|
- cmake --build . -- -j2
|
||||||
- ctest
|
- if [ "${BUILD_ONLY}" != "1" ]; then ctest; fi
|
||||||
- if [ ${COVERAGE} = 1 ]; then bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -x $GCOV -a "-s `pwd`" ; fi
|
- if [ "${COVERAGE}" = "1" ]; then bash <(curl -s https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -x $GCOV -a "-s `pwd`" ; fi
|
||||||
|
|
||||||
#after_script:
|
#after_script:
|
||||||
# - if [ ${CPPCHECK} = 1 ]; then contrib/codeanalysis/runcppcheck.sh ; fi
|
# - if [ ${CPPCHECK} = 1 ]; then contrib/codeanalysis/runcppcheck.sh ; fi
|
||||||
|
@ -14,6 +14,7 @@ ELSE()
|
|||||||
project(chaiscript)
|
project(chaiscript)
|
||||||
|
|
||||||
option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE)
|
option(MULTITHREAD_SUPPORT_ENABLED "Multithreaded Support Enabled" TRUE)
|
||||||
|
option(DYNLOAD_ENABLED "Dynamic Loading Support Enabled" TRUE)
|
||||||
|
|
||||||
|
|
||||||
option(BUILD_MODULES "Build Extra Modules (stl)" TRUE)
|
option(BUILD_MODULES "Build Extra Modules (stl)" TRUE)
|
||||||
@ -221,9 +222,15 @@ if(NOT MULTITHREAD_SUPPORT_ENABLED)
|
|||||||
add_definitions(-DCHAISCRIPT_NO_THREADS)
|
add_definitions(-DCHAISCRIPT_NO_THREADS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT DYNLOAD_ENABLED)
|
||||||
|
add_definitions(-DCHAISCRIPT_NO_DYNLOAD)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CMAKE_HOST_UNIX)
|
if(CMAKE_HOST_UNIX)
|
||||||
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
|
if(DYNLOAD_ENABLED)
|
||||||
list(APPEND LIBS "dl")
|
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "Haiku")
|
||||||
|
list(APPEND LIBS "dl")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MULTITHREAD_SUPPORT_ENABLED)
|
if(MULTITHREAD_SUPPORT_ENABLED)
|
||||||
|
@ -216,7 +216,11 @@ namespace chaiscript {
|
|||||||
|
|
||||||
static inline std::vector<Options> default_options()
|
static inline std::vector<Options> default_options()
|
||||||
{
|
{
|
||||||
|
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
return {Options::No_Load_Modules, Options::External_Scripts};
|
||||||
|
#else
|
||||||
return {Options::Load_Modules, Options::External_Scripts};
|
return {Options::Load_Modules, Options::External_Scripts};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -36,12 +36,13 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
#if !defined(CHAISCRIPT_NO_DYNLOAD) && defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CHAISCRIPT_NO_DYNLOAD)
|
||||||
#ifdef CHAISCRIPT_WINDOWS
|
#include "chaiscript_unknown.hpp"
|
||||||
|
#elif defined(CHAISCRIPT_WINDOWS)
|
||||||
#include "chaiscript_windows.hpp"
|
#include "chaiscript_windows.hpp"
|
||||||
#elif _POSIX_VERSION
|
#elif _POSIX_VERSION
|
||||||
#include "chaiscript_posix.hpp"
|
#include "chaiscript_posix.hpp"
|
||||||
@ -242,7 +243,7 @@ namespace chaiscript
|
|||||||
m_parser(std::move(parser)),
|
m_parser(std::move(parser)),
|
||||||
m_engine(*m_parser)
|
m_engine(*m_parser)
|
||||||
{
|
{
|
||||||
#if defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
#if !defined(CHAISCRIPT_NO_DYNLOAD) && defined(_POSIX_VERSION) && !defined(__CYGWIN__)
|
||||||
// If on Unix, add the path of the current executable to the module search path
|
// If on Unix, add the path of the current executable to the module search path
|
||||||
// as windows would do
|
// as windows would do
|
||||||
|
|
||||||
@ -278,6 +279,7 @@ namespace chaiscript
|
|||||||
build_eval_system(t_lib, t_opts);
|
build_eval_system(t_lib, t_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_NO_DYNLOAD
|
||||||
/// \brief Constructor for ChaiScript.
|
/// \brief Constructor for ChaiScript.
|
||||||
///
|
///
|
||||||
/// This version of the ChaiScript constructor attempts to find the stdlib module to load
|
/// This version of the ChaiScript constructor attempts to find the stdlib module to load
|
||||||
@ -307,6 +309,12 @@ namespace chaiscript
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else // CHAISCRIPT_NO_DYNLOAD
|
||||||
|
explicit ChaiScript_Basic(std::unique_ptr<parser::ChaiScript_Parser_Base> &&parser,
|
||||||
|
std::vector<std::string> t_module_paths = {},
|
||||||
|
std::vector<std::string> t_use_paths = {},
|
||||||
|
const std::vector<chaiscript::Options> &t_opts = chaiscript::default_options()) = delete;
|
||||||
|
#endif
|
||||||
|
|
||||||
parser::ChaiScript_Parser_Base &get_parser()
|
parser::ChaiScript_Parser_Base &get_parser()
|
||||||
{
|
{
|
||||||
@ -548,6 +556,10 @@ namespace chaiscript
|
|||||||
/// \throw chaiscript::exception::load_module_error In the event that no matching module can be found.
|
/// \throw chaiscript::exception::load_module_error In the event that no matching module can be found.
|
||||||
std::string load_module(const std::string &t_module_name)
|
std::string load_module(const std::string &t_module_name)
|
||||||
{
|
{
|
||||||
|
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
(void)t_module_name; // -Wunused-parameter
|
||||||
|
throw chaiscript::exception::load_module_error("Loadable module support was disabled (CHAISCRIPT_NO_DYNLOAD)");
|
||||||
|
#else
|
||||||
std::vector<exception::load_module_error> errors;
|
std::vector<exception::load_module_error> errors;
|
||||||
std::string version_stripped_name = t_module_name;
|
std::string version_stripped_name = t_module_name;
|
||||||
size_t version_pos = version_stripped_name.find("-" + Build_Info::version());
|
size_t version_pos = version_stripped_name.find("-" + Build_Info::version());
|
||||||
@ -581,6 +593,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw chaiscript::exception::load_module_error(t_module_name, errors);
|
throw chaiscript::exception::load_module_error(t_module_name, errors);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Load a binary module from a dynamic library. Works on platforms that support
|
/// \brief Load a binary module from a dynamic library. Works on platforms that support
|
||||||
|
@ -16,7 +16,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
Loadable_Module(const std::string &, const std::string &)
|
Loadable_Module(const std::string &, const std::string &)
|
||||||
{
|
{
|
||||||
|
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
throw chaiscript::exception::load_module_error("Loadable module support was disabled (CHAISCRIPT_NO_DYNLOAD)");
|
||||||
|
#else
|
||||||
throw chaiscript::exception::load_module_error("Loadable module support not available for your platform");
|
throw chaiscript::exception::load_module_error("Loadable module support not available for your platform");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ModulePtr m_moduleptr;
|
ModulePtr m_moduleptr;
|
||||||
|
@ -68,6 +68,7 @@ std::vector<std::string> default_search_paths()
|
|||||||
{
|
{
|
||||||
std::vector<std::string> paths;
|
std::vector<std::string> paths;
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_NO_DYNLOAD
|
||||||
#ifdef CHAISCRIPT_WINDOWS // force no unicode
|
#ifdef CHAISCRIPT_WINDOWS // force no unicode
|
||||||
CHAR path[4096];
|
CHAR path[4096];
|
||||||
int size = GetModuleFileNameA(0, path, sizeof(path) - 1);
|
int size = GetModuleFileNameA(0, path, sizeof(path) - 1);
|
||||||
@ -137,6 +138,7 @@ std::vector<std::string> default_search_paths()
|
|||||||
paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/");
|
paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ifndef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ std::vector<std::string> default_search_paths()
|
|||||||
{
|
{
|
||||||
std::vector<std::string> paths;
|
std::vector<std::string> paths;
|
||||||
|
|
||||||
|
#ifndef CHAISCRIPT_NO_DYNLOAD
|
||||||
#ifdef CHAISCRIPT_WINDOWS // force no unicode
|
#ifdef CHAISCRIPT_WINDOWS // force no unicode
|
||||||
CHAR path[4096];
|
CHAR path[4096];
|
||||||
int size = GetModuleFileNameA(nullptr, path, sizeof(path)-1);
|
int size = GetModuleFileNameA(nullptr, path, sizeof(path)-1);
|
||||||
@ -140,6 +141,7 @@ std::vector<std::string> default_search_paths()
|
|||||||
paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/");
|
paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif // ifndef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
#include <chaiscript/chaiscript.hpp>
|
||||||
|
#endif
|
||||||
#include <chaiscript/chaiscript_basic.hpp>
|
#include <chaiscript/chaiscript_basic.hpp>
|
||||||
#include <chaiscript/language/chaiscript_parser.hpp>
|
#include <chaiscript/language/chaiscript_parser.hpp>
|
||||||
|
|
||||||
@ -57,18 +60,22 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> modulepaths;
|
std::vector<std::string> modulepaths;
|
||||||
|
|
||||||
|
#ifdef CHAISCRIPT_NO_DYNLOAD
|
||||||
|
chaiscript::ChaiScript chai(/* unused */modulepaths, usepaths);
|
||||||
|
#else
|
||||||
modulepaths.push_back("");
|
modulepaths.push_back("");
|
||||||
if (modulepath)
|
if (modulepath)
|
||||||
{
|
{
|
||||||
modulepaths.push_back(modulepath);
|
modulepaths.push_back(modulepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For this test we are going to load the dynamic stdlib
|
// For this test we are going to load the dynamic stdlib
|
||||||
// to make sure it continues to work
|
// to make sure it continues to work
|
||||||
chaiscript::ChaiScript_Basic chai(
|
chaiscript::ChaiScript_Basic chai(
|
||||||
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>(),
|
std::make_unique<chaiscript::parser::ChaiScript_Parser<chaiscript::eval::Noop_Tracer, chaiscript::optimizer::Optimizer_Default>>(),
|
||||||
modulepaths,usepaths);
|
modulepaths,usepaths);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::vector<std::shared_ptr<std::thread> > threads;
|
std::vector<std::shared_ptr<std::thread> > threads;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user