[PATCH v2 03/24] build: force a UTF-8 locale for python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Python3 versions less than 3.7 have very unhelpful handling
of the C locale where they assume data is 7-bit only. This
violates POSIX which requires the C locale to be 8-bit clean.
Python3 >= 3.7 now assumes that the C locale is always UTF-8.

Set env variables to force LC_CTYPE to en_US.UTF-8 so that
we get UTF-8 handling on all python versions. Note we do
not use C.UTF-8 since not all C libraries support that.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 Makefile.am                | 2 +-
 configure.ac               | 8 ++++++++
 docs/Makefile.am           | 3 ++-
 src/esx/Makefile.inc.am    | 2 +-
 src/hyperv/Makefile.inc.am | 2 +-
 src/util/Makefile.inc.am   | 8 ++++----
 6 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cf9ff94f4f..711f365504 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,7 +69,7 @@ NEWS: \
 	    $(srcdir)/docs/news.xml \
 	  >$@-tmp \
 	    || { rm -f $@-tmp; exit 1; }; \
-	  $(PYTHON) $(srcdir)/docs/reformat-news.py $@-tmp >$@ \
+	  $(RUNUTF8) $(PYTHON) $(srcdir)/docs/reformat-news.py $@-tmp >$@ \
 	    || { rm -f $@-tmp; exit 1; }; \
 	  rm -f $@-tmp; \
 	fi
diff --git a/configure.ac b/configure.ac
index 7c76a9c9ec..31810b9010 100644
--- a/configure.ac
+++ b/configure.ac
@@ -706,6 +706,14 @@ AC_PATH_PROGS([PYTHON], [python3 python2 python])
 if test -z "$PYTHON"; then
     AC_MSG_ERROR(['python3', 'python2' or 'python' binary is required to build libvirt])
 fi
+
+dnl Python3 < 3.7 treats the C locale as 7-bit only.
+dnl We must force env vars so it treats it as UTF-8
+dnl regardless of the user's locale.
+RUNUTF8="LC_ALL= LANG=C LC_CTYPE=en_US.UTF-8"
+AC_SUBST(RUNUTF8)
+
+
 AC_PATH_PROG([PERL], [perl])
 if test -z "$PERL"; then
          AC_MSG_ERROR(['perl' binary is required to build libvirt])
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 1cdb584b0b..14f3faffd4 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -348,7 +348,8 @@ $(APIBUILD_STAMP): $(srcdir)/apibuild.py \
 		$(top_srcdir)/src/util/virerror.c \
 		$(top_srcdir)/src/util/virevent.c \
 		$(top_srcdir)/src/util/virtypedparam.c
-	$(AM_V_GEN)srcdir=$(srcdir) builddir=$(builddir) $(PYTHON) $(APIBUILD)
+	$(AM_V_GEN)srcdir=$(srcdir) builddir=$(builddir) \
+		$(RUNUTF8) $(PYTHON) $(APIBUILD)
 	touch $@
 
 
diff --git a/src/esx/Makefile.inc.am b/src/esx/Makefile.inc.am
index 2d55c6573c..70a13ea829 100644
--- a/src/esx/Makefile.inc.am
+++ b/src/esx/Makefile.inc.am
@@ -63,7 +63,7 @@ $(ESX_DRIVER_GENERATED): $(ESX_GENERATED_STAMP)
 
 $(ESX_GENERATED_STAMP): $(srcdir)/esx/esx_vi_generator.input \
                          $(srcdir)/esx/esx_vi_generator.py
-	$(AM_V_GEN)srcdir=$(srcdir) $(PYTHON) $(srcdir)/esx/esx_vi_generator.py \
+	$(AM_V_GEN)srcdir=$(srcdir) $(RUNUTF8) $(PYTHON) $(srcdir)/esx/esx_vi_generator.py \
 	  && touch $@
 
 MAINTAINERCLEANFILES += $(ESX_DRIVER_GENERATED) $(ESX_GENERATED_STAMP)
diff --git a/src/hyperv/Makefile.inc.am b/src/hyperv/Makefile.inc.am
index 51be8bcacc..6728b39c90 100644
--- a/src/hyperv/Makefile.inc.am
+++ b/src/hyperv/Makefile.inc.am
@@ -41,7 +41,7 @@ $(HYPERV_DRIVER_GENERATED): $(HYPERV_GENERATED_STAMP)
 
 $(HYPERV_GENERATED_STAMP): $(srcdir)/hyperv/hyperv_wmi_generator.input \
                             $(srcdir)/hyperv/hyperv_wmi_generator.py
-	$(AM_V_GEN)srcdir=$(srcdir) $(PYTHON) \
+	$(AM_V_GEN)srcdir=$(srcdir) $(RUNUTF8) $(PYTHON) \
 	  $(srcdir)/hyperv/hyperv_wmi_generator.py \
 	  && touch $@
 
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index 46866cf213..adb5e6d727 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -300,7 +300,7 @@ util/virkeycodetable_%.h: $(srcdir)/keycodemapdb/data/keymaps.csv \
 	$(AM_V_GEN)export NAME=`echo $@ | sed -e 's,util/virkeycodetable_,,' \
 					      -e 's,\.h,,'` && \
 		$(MKDIR_P) util/ && \
-		$(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
+		$(RUNUTF8) $(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
 			--lang stdc --varname virKeyCodeTable_$$NAME code-table \
 			$(srcdir)/keycodemapdb/data/keymaps.csv $$NAME > $@-tmp && \
 		mv $@-tmp $@ || rm -f $@-tmp
@@ -310,7 +310,7 @@ util/virkeynametable_%.h: $(srcdir)/keycodemapdb/data/keymaps.csv \
 	$(AM_V_GEN)export NAME=`echo $@ | sed -e 's,util/virkeynametable_,,' \
 					      -e 's,\.h,,'` && \
 		$(MKDIR_P) util/ && \
-		$(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
+		$(RUNUTF8) $(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
 			--lang stdc --varname virKeyNameTable_$$NAME name-table \
 			$(srcdir)/keycodemapdb/data/keymaps.csv $$NAME > $@-tmp && \
 		mv $@-tmp $@ || rm -f $@-tmp
@@ -320,7 +320,7 @@ util/virkeycode-%.pod: $(srcdir)/keycodemapdb/data/keymaps.csv \
 	$(AM_V_GEN)export NAME=`echo $@ | sed -e 's,util/virkeycode-,,' \
 					      -e 's,\.pod,,'` && \
 		$(MKDIR_P) util/ && \
-		$(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
+		$(RUNUTF8) $(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
 		--lang pod \
 		--varname "virkeycode-$$NAME - Key code values for $$NAME" \
 		code-docs \
@@ -332,7 +332,7 @@ util/virkeyname-%.pod: $(srcdir)/keycodemapdb/data/keymaps.csv \
 	$(AM_V_GEN)export NAME=`echo $@ | sed -e 's,util/virkeyname-,,' \
 					      -e 's,\.pod,,'` && \
 		$(MKDIR_P) util/ && \
-		$(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
+		$(RUNUTF8) $(PYTHON) $(srcdir)/keycodemapdb/tools/keymap-gen \
 		--lang pod \
 		--varname "virkeyname-$$NAME - Key name values for $$NAME" \
 		name-docs \
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux