From a5f3fee85a160c9aebd14661890f7b0476323125 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= <jedrzej.nowacki@digia.com>
Date: Mon, 18 Feb 2013 15:24:05 +0100
Subject: [PATCH] Post Qt doc bot logs in case of a build failure.

Change-Id: I9af54a1c6a75159a5f18f318f5e99332d8437dcc
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
---
 git-hooks/qdoc-bot | 44 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/git-hooks/qdoc-bot b/git-hooks/qdoc-bot
index 23cd83c..11bd0c2 100755
--- a/git-hooks/qdoc-bot
+++ b/git-hooks/qdoc-bot
@@ -62,6 +62,26 @@ config = None # configuration object, it is initialized in main and passed to ev
 
 
 
+def pasteKDE(data):
+    import httplib, urllib, json
+    params = urllib.urlencode({'paste_data': data,
+                               'paste_lang': 'text',
+                               'api_submit': True,
+                               'mode': 'json',
+                               'paste_project':'Qt',
+                               'paste_user': 'Qt Doc bot',
+                               'paste_private': 'yes',
+                               'paste_expire': 2629744 # around 1 month
+                              })
+    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
+    conn = httplib.HTTPConnection("paste.kde.org")
+    try:
+        conn.request("POST", "", params, headers)
+        response = json.loads(conn.getresponse().read())
+        logging.debug("Making a paste %s", response)
+        return "http://paste.kde.org/" + str(response['result']['id']) + "/" + str(response['result']['hash'])
+    finally:
+        conn.close()
 
 #make sub-qdoc in src/tools
 def run_qdoc(module_name):
@@ -70,8 +90,18 @@ def run_qdoc(module_name):
         environment = os.environ
         environment["CCACHE_BASEDIR"] =  os.getcwd()
         environment["QT_HASH_SEED"] = "1234"
-        cmd = "(./configure -opensource -confirm-license -release && make sub-src-qmake_all && cd src/tools && make sub-qdoc) > /dev/null"
-        subprocess.check_call(cmd, shell=True, env=environment)
+        for cmd in ["/bin/sh ./configure --opensource --confirm-license --release", "make sub-src-qmake_all", "make -Csrc/tools sub-qdoc"]:
+            logging.debug("Executing command: %s", cmd)
+            try:
+                proc = subprocess.Popen(cmd.split(), env=environment, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+                buildOutput = proc.communicate()[0]
+            except Exception, e:
+                logging.error("Unknown error. Command execution failed: %s", str(e))
+                raise e
+
+            if proc.returncode:
+                raise subprocess.CalledProcessError(proc.returncode, cmd, buildOutput)
+
         cmd = "make html_docs".split()
         output.append(subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environment).communicate()[1])
         def smart_concatenate(r, x):
@@ -99,7 +129,7 @@ def post_review(event, message, score):
     logging.debug(command)
     if not config.sandbox:
         subprocess.check_call(command)
-    elif event["change"]["number"] == '33219' or event["change"]["number"] == '33224':
+    elif event["change"]["number"] == '48230':
         subprocess.check_call(command)
 
 def remove_moved_doc_errors(fixes, errors):
@@ -285,7 +315,13 @@ def process_event(event_string):
                 output_with_patch = run_qdoc(module_name)
             except subprocess.CalledProcessError, e:
                 logging.debug("RUNNING QDOC FAILED: %s", e)
-                msg = "Running command\n " + str(e.cmd) + "\nfailed."
+                msg = "Qt Doc Bot tried to build the change on Linux, without success. Most likely because of a bug in the patch. "
+                msg += "Please verify that a clean build works."
+                msg += "\n\nRunning command\n " + str(e.cmd) + "\nfailed."
+                if e.output != None:
+                    link = pasteKDE(e.output)
+                    msg += "\n\nBuild log can be found here: "
+                    msg += link
                 post_review(event, msg, -1)
                 return -1
 
-- 
GitLab