From a5ed42c1dd1d2ee42eb7510ef11195024de9dacd Mon Sep 17 00:00:00 2001 From: Pauli Nieminen Date: Wed, 20 Aug 2008 13:55:07 +0000 Subject: [PATCH] Broken dummylocales runtime configuration implementation. installation fails --- CMakeLists.txt | 57 ++++++++++++++-------------- Makefile.am | 4 +- SConstruct | 20 +++++++--- src/SConscript | 4 +- src/game.cpp | 3 ++ src/game_config.cpp | 6 +++ src/game_config.hpp | 2 + src/language.cpp | 66 +++++++++++++++++---------------- src/tests/main.cpp | 6 ++- src/tests/test_config_cache.cpp | 2 +- 10 files changed, 99 insertions(+), 71 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc090185ac7..c43b582630f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,36 +173,37 @@ add_subdirectory(src) if(ENABLE_DUMMY_LOCALES) add_definitions(-DUSE_DUMMYLOCALES) - set(DUMMY_LOCALE_C_DIR ${CMAKE_SOURCE_DIR}/locales/C) - - add_custom_command(OUTPUT ${DUMMY_LOCALE_C_DIR} - COMMAND mkdir -p ${DUMMY_LOCALE_C_DIR} - && echo | localedef --force ${DUMMY_LOCALE_C_DIR} 2> /dev/null || true) - - file(GLOB_RECURSE LANGS RELATIVE ${CMAKE_SOURCE_DIR}/data/languages data/languages/*.cfg) - - set(DUMMY_LOCALES) - foreach(LANGFILE ${LANGS}) - string(REGEX REPLACE "(.*)\\.cfg" "\\1" LANG ${LANGFILE}) - if(NOT LANG STREQUAL "C") - set(DUMMY_LOCALE_DIR ${CMAKE_SOURCE_DIR}/locales/${LANG}) - add_custom_command(OUTPUT ${DUMMY_LOCALE_DIR} - COMMAND ln -s - ARGS ${DUMMY_LOCALE_C_DIR} ${DUMMY_LOCALE_DIR} - DEPENDS ${DUMMY_LOCALE_C_DIR}) - - set(DUMMY_LOCALES ${DUMMY_LOCALES} ${DUMMY_LOCALE_DIR}) - endif() - - endforeach() - add_custom_target(dummy-locales ALL DEPENDS ${DUMMY_LOCALES}) - - # this is a workaround for a bug in 2.4-7 - file(MAKE_DIRECTORY locales) - install(DIRECTORY locales DESTINATION ${DATADIR} ) - endif() +set(DUMMY_LOCALE_C_DIR ${CMAKE_SOURCE_DIR}/locales/C) + +add_custom_command(OUTPUT ${DUMMY_LOCALE_C_DIR} + COMMAND mkdir -p ${DUMMY_LOCALE_C_DIR} + && echo | localedef --force ${DUMMY_LOCALE_C_DIR} 2> /dev/null || true) + +file(GLOB_RECURSE LANGS RELATIVE ${CMAKE_SOURCE_DIR}/data/languages data/languages/*.cfg) + +set(DUMMY_LOCALES) +foreach(LANGFILE ${LANGS}) + string(REGEX REPLACE "(.*)\\.cfg" "\\1" LANG ${LANGFILE}) + if(NOT LANG STREQUAL "C") + set(DUMMY_LOCALE_DIR ${CMAKE_SOURCE_DIR}/locales/${LANG}) + add_custom_command(OUTPUT ${DUMMY_LOCALE_DIR} + COMMAND ln -s + ARGS ${DUMMY_LOCALE_C_DIR} ${DUMMY_LOCALE_DIR} + DEPENDS ${DUMMY_LOCALE_C_DIR}) + + set(DUMMY_LOCALES ${DUMMY_LOCALES} ${DUMMY_LOCALE_DIR}) + endif() + +endforeach() +add_custom_target(dummy-locales ALL DEPENDS ${DUMMY_LOCALES}) + +# this is a workaround for a bug in 2.4-7 +file(MAKE_DIRECTORY locales) +install(DIRECTORY locales DESTINATION ${DATADIR} ) + + # # shrink images for tinygui # diff --git a/Makefile.am b/Makefile.am index 51b892d2aae..7b19757d54f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,7 +92,7 @@ if INSTALLDATA echo $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(docdir)/$$f"; \ $(INSTALL_DATA) "$$d$$p" "$(DESTDIR)$(docdir)/$$f"; cd ..; \ done -if DUMMYLOCALES +#if DUMMYLOCALES @echo "Create dummy locales beneath the Wesnoth data directory" $(mkdir_p) "$(DESTDIR)$(pkgdatadir)/locales" if test -d "$(DESTDIR)$(pkgdatadir)/locales/C" ; then rm -r "$(DESTDIR)$(pkgdatadir)/locales/C" ; fi @@ -102,7 +102,7 @@ if DUMMYLOCALES if test -L "$$loclnk" ; then rm "$$loclnk" ; fi; \ ln -s C "$$loclnk"; done; \ true -endif +#endif if TINYGUI @echo "Shrink installed images by a factor of two." (cd $(top_srcdir) && find data/core/images data/campaigns images \( $(findfilterflags) -a -name '*.png' -and -not -name 'bar-energy-tinygui.png' -print \) ) | while read p; do \ diff --git a/SConstruct b/SConstruct index f91ec70a36e..a388ba964e1 100644 --- a/SConstruct +++ b/SConstruct @@ -293,10 +293,18 @@ if env["PLATFORM"] == 'win32': if env["PLATFORM"] == 'darwin': # Mac OS X env.Append(FRAMEWORKS = "Carbon") # Carbon GUI -try: - env["svnrev"] = Popen(Split("svnversion -n ."), stdout=PIPE).communicate()[0] -except: - env["svnrev"] = "" +if os.path.exists('.git'): + import re + p = re.compile('Revision: ([0-9]+)'); + try: + env["svnrev"] = p.search(Popen(Split("git-svn info"), stdout=PIPE).communicate()[0]).group(1) + except: + env["svnrev"] = "" +else: + try: + env["svnrev"] = Popen(Split("svnversion -n ."), stdout=PIPE).communicate()[0] + except: + env["svnrev"] = "" Export(Split("env have_client_prereqs have_server_prereqs have_test_prereqs")) SConscript(dirs = Split("po doc packaging/windows")) @@ -342,7 +350,7 @@ env.Clean(all, 'TAGS') # Dummy locales # -if env["dummy_locales"]: +if env["nls"]: env.Command(Dir("locales/C"), [], "-mkdir -p locales;echo | localedef --force \"$TARGET\" 2> /dev/null") language_cfg_re = re.compile(r"data/languages/(.*)\.cfg") language_cfgs = glob("data/languages/*.cfg") @@ -373,7 +381,7 @@ docdir = env['docdir'] installable_subs = Split('data fonts icons images sounds') if env['nls']: installable_subs.append("translations") -if env['dummy_locales']: +if env['nls']: installable_subs.append("locales") fifodir = env['fifodir'] mandir = env["mandir"] diff --git a/src/SConscript b/src/SConscript index 218e1e471c8..88dd99da46d 100644 --- a/src/SConscript +++ b/src/SConscript @@ -66,6 +66,7 @@ libwesnoth_sources = Split(""" hotkeys.cpp image.cpp key.cpp + language.cpp loadscreen.cpp map_create.cpp map_label.cpp @@ -104,7 +105,6 @@ libwesnoth_sources = Split(""" """) libwesnoth_sources.extend([ env.Object("font.cpp", EXTRA_DEFINE = env['fribidi'] and "HAVE_FRIBIDI" or None), - env.Object("language.cpp", EXTRA_DEFINE = env['dummy_locales'] and "USE_DUMMYLOCALES" or None) ]) libwesnoth = env.Library("wesnoth", libwesnoth_sources) @@ -370,6 +370,8 @@ if env["svnrev"] != "" and env["svnrev"] != "exported": "Generating revision.hpp..." )) game_config_env.Append(CPPDEFINES = 'HAVE_REVISION') +if env['dummy_locales']: + game_config_env.Append(CPPDEFINES = 'USE_DUMMYLOCALES') sources = [] if "TAGS" in COMMAND_LINE_TARGETS: diff --git a/src/game.cpp b/src/game.cpp index 71b81edd963..7662ed11cc5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -363,6 +363,8 @@ game_controller::game_controller(int argc, char** argv) : } else if(val == "-e" || val == "--editor") { jump_to_editor_ = true; #endif + } else if(val == "--dummylocales") { + game_config::use_dummylocales = true; } else if(val[0] == '-') { std::cerr << "unknown option: " << val << std::endl; throw config::error("unknown option"); @@ -1957,6 +1959,7 @@ static int process_command_args(int argc, char** argv) { << " by id.\n" << " --turns=value sets the number of turns. The default is \"50\".\n" << " --exit-at-end exit Wesnoth at end of scenario.\n" + << " --dummylocales Enable dummylocales for switching to non-system locale.\n" << " --new-widgets there is a new WIP widget toolkit this switch enables the new toolkit\n" << " (VERY EXPERIMENTAL don't file bug reports since most are known).\n" ; diff --git a/src/game_config.cpp b/src/game_config.cpp index bb75c820ed4..45ec7cc18c2 100644 --- a/src/game_config.cpp +++ b/src/game_config.cpp @@ -53,6 +53,12 @@ namespace game_config std::string wesnothd_name; bool debug = false, editor = false, ignore_replay_errors = false, mp_debug = false, exit_at_end = false, no_delay = false, small_gui = false, disable_autosave = false; +#ifdef USE_DUMMYLOCALES + bool use_dummylocales = true; +#else + bool use_dummylocales = false; +#endif + std::string game_icon = "wesnoth-icon.png", game_title, game_logo, title_music, lobby_music; int title_logo_x = 0, title_logo_y = 0, title_buttons_x = 0, title_buttons_y = 0, title_buttons_padding = 0, title_tip_x = 0, title_tip_width = 0, title_tip_padding = 0; diff --git a/src/game_config.hpp b/src/game_config.hpp index c18a17b72e7..828fa4ddda5 100644 --- a/src/game_config.hpp +++ b/src/game_config.hpp @@ -48,6 +48,8 @@ namespace game_config extern bool debug, editor, ignore_replay_errors, mp_debug, exit_at_end, no_delay, small_gui, disable_autosave; + extern bool use_dummylocales; + extern std::string path; struct server_info { diff --git a/src/language.cpp b/src/language.cpp index 368fdbe768d..3250dbd6f22 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -104,21 +104,22 @@ bool language_def::operator== (const language_def& a) const bool language_def::available() const { -#ifdef USE_DUMMYLOCALES - // Dummy has every language available. - return true; -#else - if(has_language(localename)) { + if (game_config::use_dummylocales) + { + // Dummy has every language available. return true; - } else { - foreach(const std::string& lang, alternates) { - if(has_language(lang)) { - return true; + }else{ + if(has_language(localename)) { + return true; + } else { + foreach(const std::string& lang, alternates) { + if(has_language(lang)) { + return true; + } } } + return false; } - return false; -#endif } symbol_table string_table; @@ -218,28 +219,29 @@ static void wesnoth_setlocale(int category, std::string const &slocale, category = LC_ALL; #endif -#ifdef USE_DUMMYLOCALES - static enum { UNINIT, NONE, PRESENT } status = UNINIT; - static std::string locpath; - if (status == UNINIT) { - if (char const *p = getenv("LOCPATH")) { - locpath = p; - status = PRESENT; - } else status = NONE; + if (game_config::use_dummylocales) + { + static enum { UNINIT, NONE, PRESENT } status = UNINIT; + static std::string locpath; + if (status == UNINIT) { + if (char const *p = getenv("LOCPATH")) { + locpath = p; + status = PRESENT; + } else status = NONE; + } + if (slocale.empty()) + if (status == NONE) + unsetenv("LOCPATH"); + else + setenv("LOCPATH", locpath.c_str(), 1); + else setenv("LOCPATH", (game_config::path + "/locales").c_str(), 1); + std::string xlocale; + if (!slocale.empty()) { + // dummy suffix to prevent locale aliasing from kicking in + xlocale = slocale + "@wesnoth"; + locale = xlocale.c_str(); + } } - if (slocale.empty()) - if (status == NONE) - unsetenv("LOCPATH"); - else - setenv("LOCPATH", locpath.c_str(), 1); - else setenv("LOCPATH", (game_config::path + "/locales").c_str(), 1); - std::string xlocale; - if (!slocale.empty()) { - // dummy suffix to prevent locale aliasing from kicking in - xlocale = slocale + "@wesnoth"; - locale = xlocale.c_str(); - } -#endif char *res = NULL; #ifdef _WIN32 diff --git a/src/tests/main.cpp b/src/tests/main.cpp index bd3fbee525c..7ef75e1875b 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -19,10 +19,12 @@ #include "SDL.h" +#include "game_config.hpp" #include "game_errors.hpp" #include "network.hpp" #include "config.hpp" #include "log.hpp" +#include "language.hpp" #include "tests/utils/fake_display.hpp" /** @@ -47,12 +49,13 @@ static void exception_translator_game(const game::error& e) struct wesnoth_global_fixture { wesnoth_global_fixture() { + game_config::use_dummylocales = true; // Initialize unit tests SDL_Init(SDL_INIT_TIMER); test_utils::get_fake_display(); -// lg::set_log_domain_severity("all",3); + lg::set_log_domain_severity("all",3); // Set more report as default if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level) @@ -63,6 +66,7 @@ struct wesnoth_global_fixture { boost::unit_test::unit_test_monitor.register_exception_translator(&exception_translator_game); boost::unit_test::unit_test_monitor.register_exception_translator(&exception_translator_network); boost::unit_test::unit_test_monitor.register_exception_translator(&exception_translator_config); + load_language_list(); } ~wesnoth_global_fixture() { diff --git a/src/tests/test_config_cache.cpp b/src/tests/test_config_cache.cpp index fd2706465a4..5da1ff1890c 100644 --- a/src/tests/test_config_cache.cpp +++ b/src/tests/test_config_cache.cpp @@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE( test_translation_reload ) std::vector::const_iterator German = std::find_if(languages.begin(), languages.end(), match_german); // Using German because the most active translation - BOOST_REQUIRE_MESSAGE(German != languages.end(), "German translation not found"); + BOOST_REQUIRE_MESSAGE(German != languages.end() && German->available(), "German translation not found"); ::set_language(*German); cache.reload_translations();