From 20de60576f464aa87a38b5a270a5a72330452670 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Fri, 12 Dec 2014 14:33:20 -0500
Subject: [PATCH] Wrap call to autobuild in some diagnostic code. Hopefully
 this will make certain errors clearer, notably failure to launch autobuild
 due to "cannot find the file specified".

---
 scripts/packages-formatter.py | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/scripts/packages-formatter.py b/scripts/packages-formatter.py
index 1432cdaebec..34fc92e44ce 100755
--- a/scripts/packages-formatter.py
+++ b/scripts/packages-formatter.py
@@ -26,18 +26,41 @@
 """
 import os
 import sys
+import errno
 import re
 import subprocess
 
-autobuild=os.getenv('AUTOBUILD',
+_autobuild=os.getenv('AUTOBUILD',
                     'autobuild' if not ( sys.platform == 'win32' or sys.platform == 'cygwin')
                     else 'autobuild.cmd')
 
 pkg_line=re.compile('^([\w-]+):\s+(.*)$')
 
+def autobuild(*args):
+    """
+    Launch autobuild with specified command-line arguments.
+    Return its stdout pipe from which the caller can read.
+    """
+    # subprocess wants a list, not a tuple
+    command = [_autobuild] + list(args)
+    try:
+        child = subprocess.Popen(command,
+                                 stdin=None, stdout=subprocess.PIPE,
+                                 universal_newlines=True)
+    except OSError as err:
+        if err.errno != errno.ENOENT:
+            # Don't attempt to interpret anything but ENOENT
+            raise
+        # Here it's ENOENT: subprocess can't find the autobuild executable.
+        print >>sys.stderr, "packages-formatter on %s: can't run autobuild:\n%s\n%s" % \
+              (sys.platform, ' '.join(command), err)
+        sys.exit(1)
+
+    # no exceptions yet, let caller read stdout
+    return child.stdout
+
 version={}
-versions=subprocess.Popen([autobuild, 'install', '--versions'],
-                            stdin=None, stdout=subprocess.PIPE, universal_newlines=True).stdout
+versions=autobuild('install', '--versions')
 for line in versions:
     pkg_info = pkg_line.match(line)
     if pkg_info:
@@ -50,8 +73,7 @@
         sys.exit("Unrecognized --versions output: %s" % line)
 
 copyright={}
-copyrights=subprocess.Popen([autobuild, 'install', '--copyrights'],
-                            stdin=None, stdout=subprocess.PIPE, universal_newlines=True).stdout
+copyrights=autobuild('install', '--copyrights')
 viewer_copyright = copyrights.readline() # first line is the copyright for the viewer itself
 for line in copyrights:
     pkg_info = pkg_line.match(line)
-- 
GitLab