Mesa (master): util/xmlpool: Update for meson generation

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 31 23:39:23 UTC 2018


Module: Mesa
Branch: master
Commit: 0621e91a8c975e34f2c2092ad3013d6ff81b5ac2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0621e91a8c975e34f2c2092ad3013d6ff81b5ac2

Author: Dylan Baker <dylan at pnwbakers.com>
Date:   Fri Aug 24 06:49:55 2018 -0700

util/xmlpool: Update for meson generation

Meson won't put the .gmo files in the layout that python's
gettext.translation() expects, it puts them in the build directory in a
flat layout. This modifies android and autotools to do the same (scons
doesn't work with translations at all)

v3: - Squash 4 patches into this patch

Reviewed-by: Emil Velikov <emil.velikov at collabora.com>

---

 src/util/Android.mk             |  4 ++--
 src/util/xmlpool/Makefile.am    | 10 ++++++----
 src/util/xmlpool/gen_xmlpool.py | 12 +++++++-----
 src/util/xmlpool/meson.build    |  2 +-
 4 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/util/Android.mk b/src/util/Android.mk
index e463b63e10..993a7f179f 100644
--- a/src/util/Android.mk
+++ b/src/util/Android.mk
@@ -87,13 +87,13 @@ $(MESA_DRI_OPTIONS_LANGS:%=$(intermediates)/xmlpool/%.po): $(intermediates)/xmlp
 PRIVATE_SCRIPT := $(LOCAL_PATH)/xmlpool/gen_xmlpool.py
 PRIVATE_LOCALEDIR := $(intermediates)/xmlpool
 PRIVATE_TEMPLATE_HEADER := $(LOCAL_PATH)/xmlpool/t_options.h
-PRIVATE_MO_FILES := $(MESA_DRI_OPTIONS_LANGS:%=$(intermediates)/xmlpool/%/LC_MESSAGES/options.mo)
+PRIVATE_MO_FILES := $(MESA_DRI_OPTIONS_LANGS:%=$(intermediates)/xmlpool/%.gmo)
 
 LOCAL_GENERATED_SOURCES += $(PRIVATE_MO_FILES)
 
 $(LOCAL_GENERATED_SOURCES): PRIVATE_PYTHON := $(MESA_PYTHON2)
 
-$(PRIVATE_MO_FILES): $(intermediates)/xmlpool/%/LC_MESSAGES/options.mo: $(intermediates)/xmlpool/%.po
+$(PRIVATE_MO_FILES): $(intermediates)/xmlpool/%.gmo: $(intermediates)/xmlpool/%.po
 	mkdir -p $(dir $@)
 	msgfmt -o $@ $<
 
diff --git a/src/util/xmlpool/Makefile.am b/src/util/xmlpool/Makefile.am
index 1c14311dcf..f993070ef6 100644
--- a/src/util/xmlpool/Makefile.am
+++ b/src/util/xmlpool/Makefile.am
@@ -47,10 +47,10 @@ POS=ca.po de.po es.po nl.po fr.po sv.po
 # Don't change anything below, unless you know what you're doing.
 #
 LANGS=$(POS:%.po=%)
-MOS=$(POS:%.po=%/LC_MESSAGES/options.mo)
+MOS=$(POS:%.po=%.gmo)
 POT=xmlpool.pot
 
-.PHONY: all clean pot po mo
+.PHONY: all clean clean-local pot po mo
 
 EXTRA_DIST = \
 	gen_xmlpool.py \
@@ -69,17 +69,19 @@ CLEANFILES = \
 	$(POS) \
 	$(MOS)
 
+clean-local:
+	rm -f $(MOS)
+
 # Default target options.h
 LOCALEDIR := .
 options.h: t_options.h $(MOS)
 	$(AM_V_GEN) $(PYTHON) $(PYTHON_FLAGS) $(srcdir)/gen_xmlpool.py $(srcdir)/t_options.h $(LOCALEDIR) $(LANGS) > options.h
 
 # Update .mo files from the corresponding .po files.
-%/LC_MESSAGES/options.mo: %.po
+%.gmo: %.po
 	@mo="$@"; \
 	lang=$${mo%%/*}; \
 	echo "Updating ($$lang) $@ from $?."; \
-	$(MKDIR_P) $$lang/LC_MESSAGES; \
 	msgfmt -o $@ $?
 
 # Use this target to create or update .po files with new messages in
diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
index b40f295738..0ad51eaa78 100644
--- a/src/util/xmlpool/gen_xmlpool.py
+++ b/src/util/xmlpool/gen_xmlpool.py
@@ -8,12 +8,12 @@
 #
 
 from __future__ import print_function
-
 import argparse
-import io
-import sys
 import gettext
+import io
+import os
 import re
+import sys
 
 parser = argparse.ArgumentParser()
 parser.add_argument('template')
@@ -166,8 +166,10 @@ def expandMatches (matches, translations, end=None):
 translations = [("en", gettext.NullTranslations())]
 for lang in args.languages:
     try:
-        trans = gettext.translation ("options", args.localedir, [lang])
-    except IOError:
+        filename = os.path.join(args.localedir, '{}.gmo'.format(lang))
+        with io.open(filename, 'rb') as f:
+            trans = gettext.GNUTranslations(f)
+    except (IOError, OSError):
         sys.stderr.write ("Warning: language '%s' not found.\n" % lang)
         continue
     translations.append ((lang, trans))
diff --git a/src/util/xmlpool/meson.build b/src/util/xmlpool/meson.build
index 8d645ce385..ae7c951a09 100644
--- a/src/util/xmlpool/meson.build
+++ b/src/util/xmlpool/meson.build
@@ -30,7 +30,7 @@ xmlpool_options_h = custom_target(
   input : ['gen_xmlpool.py', 't_options.h'],
   output : 'options.h',
   command : [
-    prog_python, '@INPUT@', meson.current_source_dir(), _langs,
+    prog_python, '@INPUT@', meson.current_build_dir(), _langs,
   ],
   capture : true,
   depend_files : _langs_po_files,




More information about the mesa-commit mailing list