From b891b0acaeb1ff1980ebb6af6b6768ec9b9be8d0 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Fri, 23 Jul 2010 19:56:24 +0000 Subject: [PATCH] * broke out locale-related jam rules into their own file, LocaleRules * made locale build tools shut up about anything except warnings or errors git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37723 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- Jamrules | 1 + build/jam/BeOSRules | 137 -------------------------- build/jam/LocaleRules | 137 ++++++++++++++++++++++++++ headers/os/locale/Catalog.h | 11 ++- src/kits/locale/Jamfile | 2 - src/tools/locale/DefaultCatalog.cpp | 6 +- src/tools/locale/PlainTextCatalog.cpp | 2 +- src/tools/locale/collectcatkeys.cpp | 2 +- 8 files changed, 151 insertions(+), 147 deletions(-) create mode 100644 build/jam/LocaleRules diff --git a/Jamrules b/Jamrules index 8cb41ec59a..f0742771f6 100644 --- a/Jamrules +++ b/Jamrules @@ -34,6 +34,7 @@ include BuildConfig ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) HelperRules ] ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) MathRules ] ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) BeOSRules ] ; +include [ FDirName $(HAIKU_BUILD_RULES_DIR) LocaleRules ] ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) CommandLineArguments ] ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) ConfigRules ] ; include [ FDirName $(HAIKU_BUILD_RULES_DIR) DocumentationRules ] ; diff --git a/build/jam/BeOSRules b/build/jam/BeOSRules index 5deff28d80..46b88025f3 100644 --- a/build/jam/BeOSRules +++ b/build/jam/BeOSRules @@ -268,140 +268,3 @@ actions ResAttr1 fi $(2[1]) -O -o "$(1)" "$(2[2-])" } - -# Localization rules - -# Extract catalog entries from the sourcefile and put the output textfile in -# target. This output file is then used to create the binary catalog with -# linkcatkeys. -rule ExtractCatalogEntries target : source : signature : regexp -{ - # get compiler and defines for the platform - local headers ; - local sysHeaders ; - local cc ; - local defines ; - local localIncludesOption ; - local systemIncludesOption ; - - on $(target) { # use on $(target) variable values - headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS) - $(HDRS) ; - sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; - defines = $(DEFINES) ; - - if $(PLATFORM) = host { - sysHeaders += $(HOST_HDRS) ; - defines += $(HOST_DEFINES) ; - - if $(USES_BE_API) { - sysHeaders += $(HOST_BE_API_HEADERS) ; - } - - defines += $(HOST_DEFINES) ; - cc = $(HOST_CC) ; - localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; - systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; - } else { - sysHeaders += $(TARGET_HDRS) ; - defines += $(TARGET_DEFINES) ; - defines += $(TARGET_DEFINES) ; - cc = $(TARGET_CC) ; - localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; - systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; - } - } - - DEFINES on $(target) = $(defines) ; - CCDEFS on $(target) = [ FDefines $(defines) ] ; - HDRS on $(target) = [ FIncludes $(headers) : $(localIncludesOption) ] - $(includesSeparator) - [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; - CC on $(target) = $(cc) ; - - HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; - if $(regexp) = "" { - HAIKU_CATALOG_REGEXP on $(target) = ; - } else { - HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ; - } - - SEARCH on $(source) += $(SEARCH_SOURCE) ; - - MakeLocatePlatform $(target) ; - Depends $(target) : $(source) collectcatkeys ; - LocalClean clean : $(target).pre ; - ExtractCatalogEntries1 $(target) : collectcatkeys $(source) ; -} - -actions ExtractCatalogEntries1 -{ - $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre - $(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) -w -o "$(1)" "$(1)".pre -} - -rule LinkApplicationCatalog target : sources : signature : language -{ - # Link catalog entries from given catkey file into output compiled catalog - # file. Compiled catalog file will then be copied into the image, but only - # if the fingerprint matches the one from the untranslated catalog for the - # same file. - - MakeLocateArch $(target) ; - Depends $(target) : $(sources) linkcatkeys ; - LocalClean clean : $(target) ; - - HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; - HAIKU_CATALOG_LANGUAGE on $(target) = $(language) ; - LinkApplicationCatalog1 $(target) : linkcatkeys $(sources) ; -} - -actions LinkApplicationCatalog1 -{ - $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) - $(2[1]) "$(2[2-])" -l $(HAIKU_CATALOG_LANGUAGE) -v \ - -s $(HAIKU_CATALOG_SIGNATURE) -o "$(1)" -} - -rule DoCatalogs target : signature : sources : sourceLanguage : regexp -{ - # DoCatalogs : : [ : ] - # [ : ] - # - # Extracts the catkeys from a target's source files, generates the - # default catalog from them, and also generates catalogs for all - # translations. - # - # target: The target. - # signature: Application MIME signature (must match the one - # declared in the sourcecode). - # sources: List of cpp files where to search keys. - # sourceLanguage Short name of the language of used for the strings in - # the sources. Optional: default is "en". - # regexp The regular expression used to parse the files. - # Optional: default is matching be_catalog->GetString - - local generatedCatalog = [ FGristFiles $(sourceLanguage:E=en:S=.catalog) ] ; - - # generate catkeys file from sources - ExtractCatalogEntries $(generatedCatalog:S=.catkeys) - : [ FGristFiles $(sources) ] : $(signature) : $(regexp) ; - - # find translations - local translationsDir - = [ FDirName $(HAIKU_TOP) data catalogs $(SUBDIR_TOKENS[2-]) ] ; - local translations = [ Glob $(translationsDir) : *.catkeys ] ; - translations = [ FGristFiles $(translations:BS) ] ; - SEARCH on $(translations) += $(translationsDir) ; - - # generate catalogs from all catkeys files - local catkeysFiles = $(generatedCatalog:S=.catkeys) $(translations) ; - for catkeysFile in $(catkeysFiles) { - LinkApplicationCatalog $(catkeysFile:S=.catalog) : $(catkeysFile) - : $(signature) : $(catkeysFile:B) ; - } - - HAIKU_CATALOG_FILES on $(target) = $(catkeysFiles:S=.catalog) ; - HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; -} diff --git a/build/jam/LocaleRules b/build/jam/LocaleRules new file mode 100644 index 0000000000..0d280004d2 --- /dev/null +++ b/build/jam/LocaleRules @@ -0,0 +1,137 @@ +# Localization rules + +# Extract catalog entries from the sourcefile and put the output textfile in +# target. This output file is then used to create the binary catalog with +# linkcatkeys. +rule ExtractCatalogEntries target : source : signature : regexp +{ + # get compiler and defines for the platform + local headers ; + local sysHeaders ; + local cc ; + local defines ; + local localIncludesOption ; + local systemIncludesOption ; + + on $(target) { # use on $(target) variable values + headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS) + $(HDRS) ; + sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; + defines = $(DEFINES) ; + + if $(PLATFORM) = host { + sysHeaders += $(HOST_HDRS) ; + defines += $(HOST_DEFINES) ; + + if $(USES_BE_API) { + sysHeaders += $(HOST_BE_API_HEADERS) ; + } + + defines += $(HOST_DEFINES) ; + cc = $(HOST_CC) ; + localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; + systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; + } else { + sysHeaders += $(TARGET_HDRS) ; + defines += $(TARGET_DEFINES) ; + defines += $(TARGET_DEFINES) ; + cc = $(TARGET_CC) ; + localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; + systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; + } + } + + DEFINES on $(target) = $(defines) ; + CCDEFS on $(target) = [ FDefines $(defines) ] ; + HDRS on $(target) = [ FIncludes $(headers) : $(localIncludesOption) ] + $(includesSeparator) + [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; + CC on $(target) = $(cc) ; + + HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; + if $(regexp) = "" { + HAIKU_CATALOG_REGEXP on $(target) = ; + } else { + HAIKU_CATALOG_REGEXP on $(target) = -r $(regexp) ; + } + + SEARCH on $(source) += $(SEARCH_SOURCE) ; + + MakeLocatePlatform $(target) ; + Depends $(target) : $(source) collectcatkeys ; + LocalClean clean : $(target).pre ; + ExtractCatalogEntries1 $(target) : collectcatkeys $(source) ; +} + +actions ExtractCatalogEntries1 +{ + $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) + cat "$(2[2-])" | $(CC) -E $(CCDEFS) $(HDRS) - > "$(1)".pre + $(2[1]) $(HAIKU_CATALOG_REGEXP) -s $(HAIKU_CATALOG_SIGNATURE) \ + -w -o "$(1)" "$(1)".pre +} + +rule LinkApplicationCatalog target : sources : signature : language +{ + # Link catalog entries from given catkey file into output compiled catalog + # file. Compiled catalog file will then be copied into the image, but only + # if the fingerprint matches the one from the untranslated catalog for the + # same file. + + MakeLocateArch $(target) ; + Depends $(target) : $(sources) linkcatkeys ; + LocalClean clean : $(target) ; + + HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; + HAIKU_CATALOG_LANGUAGE on $(target) = $(language) ; + LinkApplicationCatalog1 $(target) : linkcatkeys $(sources) ; +} + +actions LinkApplicationCatalog1 +{ + $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) + $(2[1]) "$(2[2-])" -l $(HAIKU_CATALOG_LANGUAGE) \ + -s $(HAIKU_CATALOG_SIGNATURE) -o "$(1)" +} + +rule DoCatalogs target : signature : sources : sourceLanguage : regexp +{ + # DoCatalogs : : [ : ] + # [ : ] + # + # Extracts the catkeys from a target's source files, generates the + # default catalog from them, and also generates catalogs for all + # translations. + # + # target: The target. + # signature: Application MIME signature (must match the one + # declared in the sourcecode). + # sources: List of cpp files where to search keys. + # sourceLanguage Short name of the language of used for the strings in + # the sources. Optional: default is "en". + # regexp The regular expression used to parse the files. + # Optional: default is matching be_catalog->GetString + + local generatedCatalog = [ FGristFiles $(sourceLanguage:E=en:S=.catalog) ] ; + + # generate catkeys file from sources + ExtractCatalogEntries $(generatedCatalog:S=.catkeys) + : [ FGristFiles $(sources) ] : $(signature) : $(regexp) ; + + # find translations + local translationsDir + = [ FDirName $(HAIKU_TOP) data catalogs $(SUBDIR_TOKENS[2-]) ] ; + local translations = [ Glob $(translationsDir) : *.catkeys ] ; + translations = [ FGristFiles $(translations:BS) ] ; + SEARCH on $(translations) += $(translationsDir) ; + + # generate catalogs from all catkeys files + local catkeysFiles = $(generatedCatalog:S=.catkeys) $(translations) ; + for catkeysFile in $(catkeysFiles) { + LinkApplicationCatalog $(catkeysFile:S=.catalog) : $(catkeysFile) + : $(signature) : $(catkeysFile:B) ; + } + + HAIKU_CATALOG_FILES on $(target) = $(catkeysFiles:S=.catalog) ; + HAIKU_CATALOG_SIGNATURE on $(target) = $(signature) ; +} diff --git a/headers/os/locale/Catalog.h b/headers/os/locale/Catalog.h index e54af57774..f267739b74 100644 --- a/headers/os/locale/Catalog.h +++ b/headers/os/locale/Catalog.h @@ -288,17 +288,22 @@ BCatalogAddOn::Next() return fNext; } - +// HACK: newline before '::' to avoid this being a false positive for +// collectcatkeys inline const char * -BCatalogAddOn::MarkForTranslation(const char *str, const char *ctx, +BCatalogAddOn +::MarkForTranslation(const char *str, const char *ctx, const char *cmt) { return str; } +// HACK: newline before '::' to avoid this being a false positive for +// collectcatkeys inline int32 -BCatalogAddOn::MarkForTranslation(int32 id) +BCatalogAddOn +::MarkForTranslation(int32 id) { return id; } diff --git a/src/kits/locale/Jamfile b/src/kits/locale/Jamfile index c5cf851fc9..f10af4c4e8 100644 --- a/src/kits/locale/Jamfile +++ b/src/kits/locale/Jamfile @@ -64,6 +64,4 @@ DoCatalogs liblocale.so : system : StringForSize.cpp ColorControl.cpp - : - : '"(gLocaleBackend\\s*->\\s*GetString\\s*|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)"' ; diff --git a/src/tools/locale/DefaultCatalog.cpp b/src/tools/locale/DefaultCatalog.cpp index 5711e293c8..2ab23b6b6f 100644 --- a/src/tools/locale/DefaultCatalog.cpp +++ b/src/tools/locale/DefaultCatalog.cpp @@ -82,9 +82,9 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef) BHashMapCatalog("", "", 0) { fInitCheck = ReadFromResource(appOrAddOnRef); - fprintf(stderr, - "trying to load embedded catalog from resources results in %s", - strerror(fInitCheck)); + // fprintf(stderr, + // "trying to load embedded catalog from resources results in %s", + // strerror(fInitCheck)); } diff --git a/src/tools/locale/PlainTextCatalog.cpp b/src/tools/locale/PlainTextCatalog.cpp index a73c131385..7e8bbc55c2 100644 --- a/src/tools/locale/PlainTextCatalog.cpp +++ b/src/tools/locale/PlainTextCatalog.cpp @@ -189,7 +189,7 @@ PlainTextCatalog::ReadFromFile(const char *path) // We managed to open the file, so we remember it's the one we are using fPath = path; - fprintf(stderr, "LocaleKit Plaintext: found catalog at %s\n", path); + // fprintf(stderr, "LocaleKit Plaintext: found catalog at %s\n", path); std::string originalString; std::string context; diff --git a/src/tools/locale/collectcatkeys.cpp b/src/tools/locale/collectcatkeys.cpp index 80e88d3733..08b962e5fd 100644 --- a/src/tools/locale/collectcatkeys.cpp +++ b/src/tools/locale/collectcatkeys.cpp @@ -28,7 +28,7 @@ const char *inputFile = NULL; BString outputFile; const char *catalogSig = NULL; const char *catalogLang = "English"; -BString rxString("(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*" +BString rxString("/\\*TR\\*/(be_locale_roster->GetCatalog\\(\\)\\s*->\\s*GetString\\s*" "|BCatalogAddOn\\s*::\\s*MarkForTranslation\\s*)");