void config_cache::add_define(const std::string& define) { DBG_CACHE << "adding define: " << define << "\n"; defines_map_[define] = preproc_define(); if(config_cache_transaction::is_active()) { // we have to add this to active map too config_cache_transaction::instance().get_active_map(defines_map_).insert( std::make_pair(define, preproc_define())); } }
static preproc_map setup_test_preproc_map() { preproc_map defines_map; #if defined(__APPLE__) defines_map["APPLE"] = preproc_define(); #endif defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str()); return defines_map; }
void config_cache::clear_defines() { LOG_CACHE << "Clearing defines map!" << std::endl; defines_map_.clear(); // // Set-up default defines map. // #ifdef __APPLE__ defines_map_["APPLE"] = preproc_define(); #endif defines_map_["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str()); }
void config_cache::clear_defines() { LOG_CACHE << "Clearing defines map!\n"; defines_map_.clear(); // set-up default defines map #ifdef LOW_MEM defines_map_["LOW_MEM"] = preproc_define(); #endif #if defined(__APPLE__) defines_map_["APPLE"] = preproc_define(); #endif defines_map_["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str()); }
void config_cache::clear_defines() { defines_map_.clear(); // set-up default defines map #ifdef USE_TINY_GUI defines_map_["TINY"] = preproc_define(); #endif #ifdef LOW_MEM defines_map_["LOW_MEM"] = preproc_define(); #endif #if defined(__APPLE__) defines_map_["APPLE"] = preproc_define(); #endif }
void config_cache::clear_defines() { defines_map_.clear(); // set-up default defines map #if defined(__APPLE__) defines_map_["APPLE"] = preproc_define(); #endif }
/** * Loads a WML file into a config * - Arg 1: WML file path * - Arg 2: (optional) Array of preprocessor defines, or false to skip preprocessing (true is also valid) * - Arg 3: (optional) Path to a schema file for validation (omit for no validation) * - Ret: config */ static int intf_load_wml(lua_State* L) { std::string file = luaL_checkstring(L, 1); bool preprocess = true; preproc_map defines_map; if(lua_type(L, 2) == LUA_TBOOLEAN) { preprocess = luaW_toboolean(L, 2); } else if(lua_type(L, 2) == LUA_TTABLE || lua_type(L, 2) == LUA_TUSERDATA) { lua_len(L, 2); int n = lua_tonumber(L, -1); lua_pop(L, 1); for(int i = 0; i < n; i++) { lua_geti(L, 2, i); if(!lua_isstring(L, -1)) { return luaL_argerror(L, 2, "expected bool or array of strings"); } std::string define = lua_tostring(L, -1); lua_pop(L, 1); if(!define.empty()) { defines_map.emplace(define, preproc_define(define)); } } } else if(!lua_isnoneornil(L, 2)) { return luaL_argerror(L, 2, "expected bool or array of strings"); } std::string schema_path = luaL_optstring(L, 3, ""); std::shared_ptr<schema_validation::schema_validator> validator; if(!schema_path.empty()) { validator.reset(new schema_validation::schema_validator(filesystem::get_wml_location(schema_path))); validator->set_create_exceptions(false); // Don't crash if there's an error, just go ahead anyway } std::string wml_file = filesystem::get_wml_location(file); filesystem::scoped_istream stream; config result; if(preprocess) { stream = preprocess_file(wml_file, &defines_map); } else { stream.reset(new std::ifstream(wml_file)); } read(result, *stream, validator.get()); luaW_pushconfig(L, result); return 1; }
static void handle_preprocess_command(const commandline_options& cmdline_opts) { preproc_map input_macros; if( cmdline_opts.preprocess_input_macros ) { std::string file = *cmdline_opts.preprocess_input_macros; if ( filesystem::file_exists( file ) == false ) { std::cerr << "please specify an existing file. File "<< file <<" doesn't exist.\n"; return; } std::cerr << SDL_GetTicks() << " Reading cached defines from: " << file << "\n"; config cfg; try { filesystem::scoped_istream stream = filesystem::istream_file( file ); read( cfg, *stream ); } catch (config::error & e) { std::cerr << "Caught a config error while parsing file '" << file << "':\n" << e.message << std::endl; } int read = 0; // use static preproc_define::read_pair(config) to make a object for (const config::any_child &value : cfg.all_children_range()) { const preproc_map::value_type def = preproc_define::read_pair( value.cfg ); input_macros[def.first] = def.second; ++read; } std::cerr << SDL_GetTicks() << " Read " << read << " defines.\n"; } const std::string resourceToProcess(*cmdline_opts.preprocess_path); const std::string targetDir(*cmdline_opts.preprocess_target); Uint32 startTime = SDL_GetTicks(); // if the users add the SKIP_CORE define we won't preprocess data/core bool skipCore = false; bool skipTerrainGFX = false; // the 'core_defines_map' is the one got from data/core macros preproc_map defines_map( input_macros ); if ( cmdline_opts.preprocess_defines ) { // add the specified defines for (const std::string &define : *cmdline_opts.preprocess_defines) { if (define.empty()){ std::cerr << "empty define supplied\n"; continue; } LOG_PREPROC << "adding define: " << define << '\n'; defines_map.insert(std::make_pair(define, preproc_define(define))); if (define == "SKIP_CORE") { std::cerr << "'SKIP_CORE' defined.\n"; skipCore = true; } else if (define == "NO_TERRAIN_GFX") { std::cerr << "'NO_TERRAIN_GFX' defined." << std::endl; skipTerrainGFX = true; } } } // add the WESNOTH_VERSION define defines_map["WESNOTH_VERSION"] = preproc_define(game_config::wesnoth_version.str()); std::cerr << "added " << defines_map.size() << " defines.\n"; // preprocess core macros first if we don't skip the core if (skipCore == false) { std::cerr << "preprocessing common macros from 'data/core' ...\n"; // process each folder explicitly to gain speed preprocess_resource(game_config::path + "/data/core/macros",&defines_map); if (skipTerrainGFX == false) preprocess_resource(game_config::path + "/data/core/terrain-graphics",&defines_map); std::cerr << "acquired " << (defines_map.size() - input_macros.size()) << " 'data/core' defines.\n"; } else std::cerr << "skipped 'data/core'\n"; // preprocess resource std::cerr << "preprocessing specified resource: " << resourceToProcess << " ...\n"; preprocess_resource(resourceToProcess, &defines_map, true,true, targetDir); std::cerr << "acquired " << (defines_map.size() - input_macros.size()) << " total defines.\n"; if ( cmdline_opts.preprocess_output_macros ) { std::string outputFileName = "_MACROS_.cfg"; if (!cmdline_opts.preprocess_output_macros->empty()) { outputFileName = *cmdline_opts.preprocess_output_macros; } std::string outputPath = targetDir + "/" + outputFileName; std::cerr << "writing '" << outputPath << "' with " << defines_map.size() << " defines.\n"; filesystem::scoped_ostream out = filesystem::ostream_file(outputPath); if (!out->fail()) { config_writer writer(*out,false); for(preproc_map::iterator itor = defines_map.begin(); itor != defines_map.end(); ++itor) { (*itor).second.write(writer, (*itor).first); } } else std::cerr << "couldn't open the file.\n"; } std::cerr << "preprocessing finished. Took "<< SDL_GetTicks() - startTime << " ticks.\n"; }