// (C) Copyright John Maddock 2004. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // This progam scans for *.ipp files in the libs/config/test // directory and then generates the *.cpp test files from them // along with config_test.cpp and a Jamfile. // #include #include #include #include #include #include #include #include #include #include namespace fs = boost::filesystem; fs::path config_path; std::string copyright( "// Copyright John Maddock 2002-4.\n" "// Use, modification and distribution are subject to the \n" "// Boost Software License, Version 1.0. (See accompanying file \n" "// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n" "\n" "// See http://www.boost.org/libs/config for the most recent version."); std::stringstream config_test1; std::stringstream config_test1a; std::stringstream config_test2; std::stringstream jamfile; std::stringstream jamfile_v2; std::set macro_list; void write_config_info() { // load the file into memory so we can scan it: fs::ifstream ifs(config_path / "config_info.cpp"); std::string file_text; std::copy(std::istreambuf_iterator(ifs), std::istreambuf_iterator(), std::back_inserter(file_text)); ifs.close(); // create macro list: std::stringstream ss; for(std::set::const_iterator i(macro_list.begin()), j(macro_list.end()); i != j; ++i) { ss << " PRINT_MACRO(" << *i << ");\n"; } std::string macros = ss.str(); // scan for Boost macro block: boost::regex re("BEGIN\\s+GENERATED\\s+BLOCK\\s+DO\\s+NOT\\s+EDIT\\s+THIS[^\\n]+\\n(.*?)\\n\\s+//\\s*END\\s+GENERATED\\s+BLOCK"); boost::smatch what; if(boost::regex_search(file_text, what, re)) { std::string new_text; new_text.append(what.prefix().first, what[1].first); new_text.append(macros); new_text.append(what[1].second, what.suffix().second); fs::ofstream ofs(config_path / "config_info.cpp"); ofs << new_text; } } void write_config_test() { fs::ofstream ofs(config_path / "config_test.cpp"); time_t t = std::time(0); ofs << "// This file was automatically generated on " << std::ctime(&t); ofs << "// by libs/config/tools/generate.cpp\n" << copyright << std::endl; ofs << "// Test file for config setup\n" "// This file should compile, if it does not then\n" "// one or more macros need to be defined.\n" "// see boost_*.ipp for more details\n\n" "// Do not edit this file, it was generated automatically by\n\n" "#include \n#include \n#include \"test.hpp\"\n\n" "int error_count = 0;\n\n"; ofs << config_test1.str() << std::endl; ofs << config_test1a.str() << std::endl; ofs << "int main( int, char *[] )\n{\n" << config_test2.str() << " return error_count;\n}\n\n"; } void write_jamfile() { fs::ofstream ofs(config_path / "Jamfile"); time_t t = std::time(0); ofs << "#\n# Regression test Jamfile for boost configuration setup.\n# *** DO NOT EDIT THIS FILE BY HAND ***\n" "# This file was automatically generated on " << std::ctime(&t); ofs << "# by libs/config/tools/generate.cpp\n" "# Copyright John Maddock.\n" "# Use, modification and distribution are subject to the \n" "# Boost Software License, Version 1.0. (See accompanying file \n" "# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n" "#\n# If you need to alter build preferences then set them in\n" "# the template defined in options.jam.\n#\n" "subproject libs/config/test ;\n" "# bring in the rules for testing\n" "import testing ./options ;\n\n" "run config_info.cpp