Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment wrapper #38

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT(metaSMT)
cmake_minimum_required(VERSION 2.8.9)
cmake_minimum_required(VERSION 2.8.12)

include(CheckIncludeFileCXX)
include(FeatureSummary)
Expand Down Expand Up @@ -30,6 +30,7 @@ include(cmake/get_git_version.cmake)
include(cmake/build_type.cmake)
include(cmake/default_compliler_flags.cmake)
include(cmake/config_file.cmake)
include(cmake/EnvironmentWrapper.cmake)

###
# Options to force disable certain solvers.
Expand Down
53 changes: 53 additions & 0 deletions cmake/EnvironmentWrapper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
include( CMakeParseArguments )

set( WRAPPER_DIR ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/wrapper CACHE INTERNAL "" )

# ensure no old wrapper files stay around
file( REMOVE_RECURSE ${WRAPPER_DIR} )
file( MAKE_DIRECTORY ${WRAPPER_DIR} )

add_executable( env_wrapper ${CMAKE_SOURCE_DIR}/cmake/EnvironmentWrapper.cpp )
target_compile_definitions( env_wrapper PRIVATE "-DWRAPPER_DIR=\"${WRAPPER_DIR}\"" )
target_include_directories( env_wrapper PRIVATE ${Boost_INCLUDE_DIRS} )
target_link_libraries( env_wrapper PRIVATE ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} )

function( add_wrapper name )

set( flags )
set( single )
set( multi PATH LIB )
cmake_parse_arguments( arg "${flags}" "${single}" "${multi}" ${ARGN} )

set( theFilePath "${WRAPPER_DIR}/${name}.wrp" )

set( content "" )

foreach( path ${arg_PATH} )
if( TARGET "${path}" )
set( content "${content}\nPATH $<TARGET_FILE_DIR:${path}>" )
elseif( IS_DIRECTORY "${path}" )
set( content "${content}\nPATH ${path}" )
elseif( EXISTS "${path}" )
get_filename_component( dir ${path} PATH )
set( content "${content}\nPATH ${dir}" )
else( )
message( FATAL_ERROR "invalid specification add_wrapper( ${name} PATH ${path} )" )
endif( )
endforeach( )

foreach( path ${arg_LIB} )
if( TARGET "${path}" )
set( content "${content}\nLD_LIBRARY_DIR $<TARGET_FILE_DIR:${path}>" )
elseif( IS_DIRECTORY "${path}" )
set( content "${content}\nLD_LIBRARY_DIR ${path}" )
elseif( EXISTS "${path}" )
get_filename_component( dir ${path} PATH )
set( content "${content}\nLD_LIBRARY_DIR ${dir}" )
else( )
message( FATAL_ERROR "invalid specification add_wrapper( ${name} LIB ${path} )" )
endif( )
endforeach( )

file( GENERATE OUTPUT ${theFilePath} CONTENT "${content}" )

endfunction( )
61 changes: 61 additions & 0 deletions cmake/EnvironmentWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/foreach.hpp>

#include <stdlib.h>
#include <iostream>
#include <sstream>

namespace fs = boost::filesystem;

void append_env(std::string const& var, std::string value)
{
char* cOldValue = getenv(var.c_str());
std::string oldValue ( (cOldValue? cOldValue : "") );

if (!oldValue.empty() ) {
value += ":" + oldValue;
}

setenv(var.c_str(), value.c_str(), /*overwrite*/ 1);
}


void append_env_from_file(fs::path const& envFile)
{
fs::ifstream input(envFile);

std::string var;
std::string value;

while( input >> var >> value ) {
append_env(var, value);
}

}

int main(int argc, char** argv)
{
fs::path wrapper_dir( WRAPPER_DIR );

fs::directory_iterator it(wrapper_dir), eod;

BOOST_FOREACH(fs::path const &p, std::make_pair(it, eod)) {
if(is_regular_file(p) && p.extension() == ".wrp" ) {
append_env_from_file(p);
}
}

std::ostringstream buf;

for (int i = 1; i < argc; ++i) {
buf << argv[i] << ' ';
}

if ( system( buf.str().c_str() ) == 0 ) {
return 0;
} else {
perror(NULL);
return 1;
}
}
13 changes: 8 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ include(CMakeParseArguments)

include_directories(../src ${metaSMT_INCLUDES})

add_wrapper( z3 PATH ${Z3_BIN_DIRS} )
add_wrapper( stp PATH ${STP_EXECUTABLE} LIB ${STP_SHARED_LIBRARY} )

add_library(boost_test boost_test.cpp)
link_libraries(boost_test metaSMT)

Expand All @@ -19,7 +22,7 @@ function (add_all_tests prog cfile)

foreach(test ${test_cases})
#message(STATUS "${prog}/${test} ${prog} -t ${test}")
add_test("${prog}/${test}" ${prog} -t ${test} ${opts_ARGS})
add_test(NAME "${prog}/${test}" COMMAND $<TARGET_FILE:env_wrapper> $<TARGET_FILE:${prog}> -t ${test} ${opts_ARGS})
set_tests_properties ("${prog}/${test}" PROPERTIES TIMEOUT ${TIMEOUT})
if(opts_ENVIRONMENT)
set_tests_properties("${prog}/${test}" PROPERTIES ENVIRONMENT ${opts_ENVIRONMENT})
Expand Down Expand Up @@ -83,22 +86,22 @@ add_test_executable( graph_Boolector graph_Boolector.cpp
REQUIRES Boolector_FOUND )

add_test_executable( SMT2Parser_Boolector SMT2Parser_Boolector.cpp
REQUIRES Z3_FOUND Boolector_FOUND
REQUIRES Z3_FOUND Boolector_FOUND metaSMT_ENABLE_TOOLBOX
LIBRARIES ${Boost_IOSTREAMS_LIBRARY}
)

add_test_executable( SMT2Parser_SMT2 SMT2Parser_SMT2.cpp
REQUIRES Z3_FOUND
REQUIRES Z3_FOUND metaSMT_ENABLE_TOOLBOX
LIBRARIES ${Boost_IOSTREAMS_LIBRARY}
)

add_test_executable( SMT2Parser_STP SMT2Parser_STP.cpp
REQUIRES Z3_FOUND STP_FOUND
REQUIRES Z3_FOUND STP_FOUND metaSMT_ENABLE_TOOLBOX
LIBRARIES ${Boost_IOSTREAMS_LIBRARY}
)

add_test_executable( SMT2Parser_Z3_Backend SMT2Parser_Z3_Backend.cpp
REQUIRES Z3_FOUND
REQUIRES Z3_FOUND metaSMT_ENABLE_TOOLBOX
LIBRARIES ${Boost_IOSTREAMS_LIBRARY}
)

Expand Down
2 changes: 2 additions & 0 deletions toolbox/smt2Input_evaluator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ add_tool_executable( smt2InputEvaluator_Z3_Backend
REQUIRES
Z3_FOUND
)

add_wrapper( smt2InputEvaluator PATH ${CMAKE_CURRENT_BINARY_DIR} )