std::vector<std::string> DriverManager::GetDriverNames(const std::string& path) { fs::path driver_path(driver_path_default); if (!fs::is_directory(driver_path)) { std::cerr << "Error : Path " << fs::absolute(driver_path) << " is not a directory." << std::endl; exit(EXIT_FAILURE); } std::vector<std::string> res; fs::directory_iterator path_it(driver_path), end; // loop through each subdirectory in 'driver_path' for (; path_it != end; path_it++) { // if not a regular file, move on if (!fs::is_regular_file(path_it->path())) { continue; } // get filename from path iterator auto filename = path_it->path().filename().string(); // store matches into a string match result std::smatch sm; // if it matches - add it to the result if (std::regex_match(filename, sm, cppdb::driver_file_regex)) { res.push_back(sm[1]); } } return res; }
void DriverManager::LoadDrivers(const std::string& path) { fs::path driver_path(driver_path_default); if (!fs::is_directory(driver_path)) { std::cerr << "Error : Path " << fs::absolute(driver_path) << " is not a directory." << std::endl; exit(EXIT_FAILURE); } std::vector<std::string> res; fs::directory_iterator path_it(driver_path), end; for (; path_it != end; path_it++) { // if not a regular file, move on if (!fs::is_regular_file(path_it->path())) { continue; } // get filename from path iterator auto file_path = path_it->path(); // store matches into a string match result std::smatch sm; // if it matches - add it to the result if (std::regex_match(file_path.filename().string(), sm, cppdb::driver_file_regex)) { void* handle = dlopen(fs::absolute(file_path).string().c_str(), RTLD_LAZY); if (handle == nullptr) { std::cerr << "Could not dlopen file '" << file_path.filename().string() << "'\n"; std::cerr << " " << dlerror() << std::endl; exit(1); } _driver_libraries[sm[1]] = handle; } } DriverManager::_drivers_loaded = true; }
int main( int argc, char **argv ) { if( argc <= 0 ) return EXIT_FAILURE; if( argc != 2 && argc != 3 ) { fcppt::io::cerr() << FCPPT_TEXT("Usage: ") << fcppt::from_std_string( argv[0] ) << FCPPT_TEXT(" <build_dir> [src_dir]\n"); return EXIT_FAILURE; } boost::filesystem::path const build_dir( fcppt::from_std_string( argv[1] ) ); boost::filesystem::path const temp_dir( build_dir / FCPPT_TEXT("temp_make_headers") ); boost::filesystem::path const make_file( temp_dir / FCPPT_TEXT("Makefile") ); boost::filesystem::path const log_file( temp_dir / FCPPT_TEXT("log.txt") ); boost::filesystem::remove( log_file ); fcppt::string const source_subdir( argc == 3 ? fcppt::from_std_string( argv[2] ) : FCPPT_TEXT("src") ); if( !boost::filesystem::exists( temp_dir ) && !boost::filesystem::create_directory( temp_dir ) ) { fcppt::io::cerr() << FCPPT_TEXT("Cannot create ") << temp_dir << FCPPT_TEXT('\n'); return EXIT_FAILURE; } for( boost::filesystem::recursive_directory_iterator dir_it( FCPPT_TEXT("include") ), end_it; dir_it != end_it; ++dir_it ) { boost::filesystem::path const &path( dir_it->path() ); if( fcppt::filesystem::extension( path ) != FCPPT_TEXT(".hpp") ) continue; if( std::find( path.begin(), path.end(), fcppt::string( FCPPT_TEXT("impl") ) ) != path.end() ) continue; boost::filesystem::path::iterator path_it( path.begin() ); if( path_it == path.end() ) continue; // skip include/ ++path_it; if( path_it == path.end() ) continue; boost::filesystem::path const include_file( ::make_path_from_iter( path_it, path.end() ) ); // skip project name ++path_it; if( path_it == path.end() ) continue; // descend into the build dir as far as possible boost::filesystem::path make_path( build_dir / source_subdir ); while( boost::filesystem::exists( make_path ) ) make_path /= *path_it++; make_path = make_path.parent_path() / FCPPT_TEXT("CMakeFiles"); if( !boost::filesystem::exists( make_path ) ) { fcppt::io::cerr() << make_path << FCPPT_TEXT(" does not exist.\n"); continue; } optional_path const cmake_dir( ::find_cmake_dir( make_path ) ); if( !cmake_dir ) { fcppt::io::cerr() << FCPPT_TEXT("No *.dir found in ") << make_path << FCPPT_TEXT('\n'); continue; } boost::filesystem::path const flags_file( *cmake_dir / FCPPT_TEXT("flags.make") ); if( !boost::filesystem::exists( flags_file ) ) { fcppt::io::cerr() << flags_file << FCPPT_TEXT(" does not exist!\n"); continue; } boost::filesystem::path const source_file( temp_dir / boost::algorithm::replace_all_copy( fcppt::filesystem::path_to_string( fcppt::filesystem::replace_extension( include_file, FCPPT_TEXT("cpp") ) ), FCPPT_TEXT("/"), FCPPT_TEXT("_") ) ); if( !::write_file( make_file, FCPPT_TEXT("include ") + fcppt::filesystem::path_to_string( flags_file ) + FCPPT_TEXT("\n\n") + FCPPT_TEXT("check-syntax:\n") + FCPPT_TEXT("\tg++ -o /dev/null ${CXX_FLAGS} ${CXX_DEFINES} -S ") + fcppt::filesystem::path_to_string( source_file ) + FCPPT_TEXT(" -fsyntax-only\n\n") + FCPPT_TEXT(".PHONY: check-syntax*/\n") ) ) return EXIT_FAILURE; if( !::write_file( source_file, FCPPT_TEXT("#include <") + fcppt::filesystem::path_to_string( include_file ) + FCPPT_TEXT(">\n") ) ) return EXIT_FAILURE; int const system_ret( std::system( ( std::string( "make -f " ) + fcppt::to_std_string( fcppt::filesystem::path_to_string( make_file ) ) + " 2>>" + fcppt::to_std_string( fcppt::filesystem::path_to_string( log_file ) ) + " 1>/dev/null" ).c_str() ) ); FCPPT_PP_PUSH_WARNING FCPPT_PP_DISABLE_GCC_WARNING(-Wcast-qual) FCPPT_PP_DISABLE_GCC_WARNING(-Wold-style-cast) if( system_ret == -1 || ( WIFSIGNALED( system_ret ) && ( WTERMSIG( system_ret ) == SIGINT || WTERMSIG( system_ret ) == SIGQUIT ) ) ) return EXIT_FAILURE; FCPPT_PP_POP_WARNING } }