bug-gnulib
[Top][All Lists]
Advanced

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

gnulib-tool.py: Bring the output into the right order


From: Bruno Haible
Subject: gnulib-tool.py: Bring the output into the right order
Date: Sun, 24 Mar 2024 22:51:58 +0100

In the test-create-testdir-4.sh output, entire chunks of output are not
in the natural order. The reason is that a subprocess produces output
while the parent process still has some output sitting it its buffers.

This patch fixes it, by adding a 'flush()' invocation when there was
output and the parent process is about to invoke a subprocess that
may produce output.

I don't like having "flush" in function names, because it's ambiguous.
So I picked the unambiguous function name known from Lisp.
<http://www.ai.mit.edu/projects/iiip/doc/CommonLISP/HyperSpec/Body/fun_finish-ou_clear-output.html>


2024-03-24  Bruno Haible  <bruno@clisp.org>

        gnulib-tool.py: Bring the output into the right order.
        * pygnulib/constants.py (force_output): New function.
        (execute): Flush stdout after printing the "executing ..." line.
        * pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute):
        Invoke force_output.
        * pygnulib/main.py (test, megatest): Likewise.

diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index d6d6a9f954..aaff6d59ff 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -692,6 +692,7 @@ class GLTestDir(object):
         # Create autogenerated files.
         # Do not use "${AUTORECONF} --force --install", because it may invoke
         # autopoint, which brings in older versions of some of our .m4 files.
+        constants.force_output()
         os.chdir(self.testdir)
         # gettext
         if isfile(joinpath(m4base, 'gettext.m4')):
@@ -853,6 +854,7 @@ class GLTestDir(object):
 
         os.chdir(self.testdir)
         if distributed_built_sources or tests_distributed_built_sources:
+            constants.force_output()
             sp.call('./configure')
             if distributed_built_sources:
                 os.chdir(sourcebase)
@@ -1040,6 +1042,7 @@ class GLMegaTestDir(object):
             file.write(emit)
 
         # Create autogenerated files.
+        constants.force_output()
         os.chdir(self.megatestdir)
         args = [UTILS['aclocal']]
         constants.execute(args, verbose)
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index c3a5aeae09..6ee7d4eb18 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -206,10 +206,19 @@ else:
 
#===============================================================================
 # Define global functions
 
#===============================================================================
+
+def force_output():
+    '''This function is to be invoked before invoking external programs.
+    It initiates bringing the the contents of process-internal output buffers
+    to their respective destinations.'''
+    sys.stdout.flush()
+    sys.stderr.flush()
+
+
 def execute(args, verbose):
     '''Execute the given shell command.'''
     if verbose >= 0:
-        print("executing %s" % ' '.join(args))
+        print("executing %s" % ' '.join(args), flush=True)
         try:  # Try to run
             retcode = sp.call(args)
         except Exception as error:
diff --git a/pygnulib/main.py b/pygnulib/main.py
index eea92a925d..e90b9d00ae 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -1055,6 +1055,7 @@ def main():
         config.setAuxDir(auxdir)
         testdir = classes.GLTestDir(config, destdir)
         testdir.execute()
+        constants.force_output()
         os.chdir(destdir)
         os.mkdir('build')
         os.chdir('build')
@@ -1087,6 +1088,7 @@ def main():
         config.setAuxDir(auxdir)
         testdir = classes.GLMegaTestDir(config, destdir)
         testdir.execute()
+        constants.force_output()
         os.chdir(destdir)
         os.mkdir('build')
         os.chdir('build')






reply via email to

[Prev in Thread] Current Thread [Next in Thread]