[gtk-doc/wip/lantw/scangobj-reset-locale-environment-variables-before-running: 7/7] scangobj: reset locale environment variables before running



commit 16f365f002c6540d4e04df2b945ea58c832206e7
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Fri Jul 5 16:08:10 2019 +0800

    scangobj: reset locale environment variables before running
    
    GNU gettext runtime doesn't always honor the locale controlled by libc.
    On non-glibc platforms, if per-thread locale isn't set, it may try to
    read environment variables by itself in order to figure out the locale.
    Therefore, even if setlocale is never called, gettext may still decide
    to translate text based on environment variables, causing the content of
    the documentation to be irreproducible because it depends on the
    environment on the build machine. Furthermore, since setlocale isn't
    called, LC_CTYPE defaults to C and non-ASCII characters coming from
    translations get converted to question marks. The result is that the
    documentation for GObject properties without gtk-doc comments becomes
    unreadable because blurbs of properties are translated in a broken way.
    
    To avoid gettext from doing unnecessary translation during building the
    documentation, we should set LC_MESSAGES environment variable to C
    before running the main program. LC_ALL is unset because it overrides
    LC_MESSAGES. Doing so should be harmless because the program already
    operates in C locale on systems using glibc.

 gtkdoc/scangobj.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gtkdoc/scangobj.py b/gtkdoc/scangobj.py
index 5c604fb..683634a 100644
--- a/gtkdoc/scangobj.py
+++ b/gtkdoc/scangobj.py
@@ -1187,14 +1187,14 @@ MAIN_CODE_END = """
 """
 
 
-def execute_command(options, description, command):
+def execute_command(options, description, command, env=None):
     if options.verbose:
         call = subprocess.check_call
     else:
         call = subprocess.check_output
 
     try:
-        call(command)
+        call(command, env=env)
     except subprocess.CalledProcessError as e:
         logging.warning('%s scanner failed: %d, command: %s', description,
                         e.returncode, ' '.join(command))
@@ -1306,8 +1306,12 @@ def run(options):
     if res:
         return res
 
+    run_env = os.environ.copy()
+    run_env['LC_MESSAGES'] = 'C'
+    run_env.pop('LC_ALL', None)
     res = execute_command(options, 'Running',
-                          shlex.split(options.run) + ['./' + x_file])
+                          shlex.split(options.run) + ['./' + x_file],
+                          env=run_env)
     if res:
         return res
 


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